Q_CreationDate stringlengths 23 23 | Title stringlengths 11 149 | Question stringlengths 25 6.53k | Answer stringlengths 15 5.1k | Score float64 -1 1.2 | Is_accepted bool 2
classes | N_answers int64 1 17 | Q_Id int64 0 6.76k |
|---|---|---|---|---|---|---|---|
2015-05-15 14:12:53.997 | Calling python scripts from anywehre | I have a collection of python scripts that import from each other. If I want to use these in a location where the scripts are not physically present, how can I do this. I tried adding the path of the dir with the scripts to my $PATH but got no joy. Any help appreciated, thanks. | Python doesn't share its own path with the general $PATH, so to be able to do what you're looking for, you must add your scripts in the $PYTHONPATH instead. | 1.2 | true | 1 | 3,737 |
2015-05-15 16:10:05.953 | zipline error. No module named zipline | I installed zipline package via Enthought Cantopy. Now I try to run a script using it in command prompt, but get error ImportError: No module named zipline.
I also tried to run the same code using IPython, with the same output.
I think it is related to python virtual environments, but don't know how to fix that. | I figured it out. The problem was in the version of python I have. I have 32-bit python and Enthought Cantopy with 64 bit python, installed zipline package was under 64 bit python while command prompt was using 32 bit version. Installing 64 bit python fixed the issue. | 1.2 | true | 2 | 3,738 |
2015-05-15 16:10:05.953 | zipline error. No module named zipline | I installed zipline package via Enthought Cantopy. Now I try to run a script using it in command prompt, but get error ImportError: No module named zipline.
I also tried to run the same code using IPython, with the same output.
I think it is related to python virtual environments, but don't know how to fix that. | These are the Requirements/ Steps to Make Zipline Work:
Install Microsoft Visual C++ 2010 Express
Download and install python 3.4
Download zipline from github and Extract in C:/
Set Anaconda as project interpreter
Since zipline is compatible with Python 3.4, you need to create an environment with Python 3.4
Run this c... | 0 | false | 2 | 3,738 |
2015-05-15 17:12:07.913 | is there a way to install six if I do not have access to internet? | I am trying to install matplotlib on my lab computer that does not have internet access. Since it requires six for its full implementation, I am unable to run the scripts that has matplotlib module.
I know how to install six by using pip but am stuck when there is no internet access.
Thanks in advance! | You can install the package by running pip install six-1.9.0.tar.gz which requires you to copy six-1.9.0.tar.gz to the machine somehow. | 0 | false | 1 | 3,739 |
2015-05-19 01:47:23.650 | Getting my drawing into pygame without .blit() | I've got my own drawing loaded on to the screen and scaled it to the size I want, but the background of the program I used to make the drawing is still on the image. I noticed that when I move the image, the background doesn't move with the picture, but it actually looks like it's stretching out and it will cover where... | Not sure if this is the problem, but the stretching might be caused by not redrawing the background. Blitting is like painting, you can't erase stuff. When you want to move something, you need to repaint all the places that have changed - also the background that is not visible after movement.
The quickest way to do th... | 1.2 | true | 1 | 3,740 |
2015-05-19 06:24:41.447 | Python: How to handle 'crontab' command? | We know the crontab command is used for scheduled tasks in Linux.
I want to write a Python script. Its function is to receive some data (these data are related to crontab setting) and execute a 'crontab' command in order to reset the content of the user's crontab file.
I know how to execute external Linux commands in P... | You could/should first dump your current crontab with crontab -l, edit it the way you want (e. g. add some lines, or modify) and then install the new one.
This usually works with crontab <filename>, but should as well work with crontab - and then piping the new contents into the process's stdin. | 0 | false | 2 | 3,741 |
2015-05-19 06:24:41.447 | Python: How to handle 'crontab' command? | We know the crontab command is used for scheduled tasks in Linux.
I want to write a Python script. Its function is to receive some data (these data are related to crontab setting) and execute a 'crontab' command in order to reset the content of the user's crontab file.
I know how to execute external Linux commands in P... | If all you want to do is reset the content of user crontab file , then just remove the crontab file (or overwrite with your default) , and reload the cron service . | 0 | false | 2 | 3,741 |
2015-05-19 08:20:39.510 | Find out Python version from source code (or Heroku) | We run a site called inteokej.nu and I need to find out which version of Python it runs on. I have pulled all the files to my computer but I don't know if and how I can find out the version number from them? The site is hosted on Heroku and maybe there's a way to find out the version with some kind of Heroku command?
A... | If you didn't have access to source code, from headers I can see that server is using Gunicorn 0.17.2, which is compatible with Python 2.x >= 2.6, which rules out i.e. Python 3. | 0 | false | 1 | 3,742 |
2015-05-19 11:41:48.527 | Printing to the penultimate line of a file | I am wondering if there is a simple way to get to the penultimate line of an open file. f.seek is giving me no end of trouble. I can easily get to the final line, but I can't figure out how to get to the line above that. | Assuming the file isn't too big and memory isn't a concern
open('file.txt').readlines()[-2] | 0.296905 | false | 1 | 3,743 |
2015-05-19 11:47:22.170 | Django - Cannot find Directory 'mysite' | I am currently learning how to use Python/Django. I have successfully installed and setup Django. I am experiencing problems creating a project using the django-admin startproject mysite command. I have executed the command from command prompt using the path: C:\Python34\Scripts\django-admin startproject mysite I tried... | To Summarize the comments:
This is because you're in c:\Windows\system32. By default when you open command prompt is in that system32 directory. you need to change it first. To change directory use cd <what path you want>.
Once you're in the correct directory, you can start the project with django-admin startproject c... | 1.2 | true | 1 | 3,744 |
2015-05-19 15:58:35.287 | Detect if connected to the internet using a tethered phone in Python | I was wondering if there is a way to detect, from a python script, if the computer is connected to the internet using a tethered cell phone?
I have a Python script which runs a bunch of network measurement tests. Ideally, depending on the type of network the client is using (ethernet, wifi, LTE, ...) the tests should c... | Normally not - from the computer's prospective the tethered cell phone is simply just another wifi router/provider.
You might be able to detect some of the phone carrier networks from the traceroute info to some known servers (DNS names or even IP address ranges of network nodes - they don't change that often).
If you ... | 0.201295 | false | 1 | 3,745 |
2015-05-20 18:28:29.657 | Tornado ioloop + threading | i have been working on tornado web framework from sometime, but still i didnt understood the ioloop functionality clearly, especially how to use it in multithreading.
Is it possible to create separate instance of ioloop for multiple server ?? | The vast majority of Tornado apps should have only one IOLoop, running in the main thread. You can run multiple HTTPServers (or other servers) on the same IOLoop.
It is possible to create multiple IOLoops and give each one its own thread, but this is rarely useful, because the GIL ensures that only one thread is runnin... | 1.2 | true | 1 | 3,746 |
2015-05-21 03:00:00.813 | How can I control which Python distribution to pip install a package to when I have Python 2, Python 3, and Anaconda on my computer? | I have the following Python distributions installed on my Windows computer:
Python 2.7 (IDLE)
Python 3.4 (IDLE)
Anaconda (Python 3.4)
Obviously, they all store their libraries in different locations.
So, how can I easily make a targeted installation to (a different) one of them each time I need to do so?
For example... | (in command prompt)C:\Python34\scripts\pip.exe install pytz
this assumes your path is similar to mine. I used the default install location for all my pythons(2.7,3.4). | 0 | false | 1 | 3,747 |
2015-05-21 07:43:23.393 | Issue with pycharm:(Pycharm:Py_Initialize: can't initialize sys standard streams) | I just started to us Python and Pycharm today. I installed Python 3.4.3 and pycharm 4.5, and I'm using Windows 7 OS on a acer TravelMate 8471 laptop.
When I try to print("hello"), the error is:
"Fatal Python error: Py_Initialize: can't initialize sys standard streams
LookupError: unknown encoding: x-windows-950"
Do... | Just put the hello.py file in a subdirectory of your project directory.
All the files in the project directory essentially provides relevant "system information" of the project. One project may contains couple of applications. Each application should be put in one subdirectory.
set:
"Settings/Editor/File Encodings/Proj... | 0.545705 | false | 1 | 3,748 |
2015-05-21 08:22:17.117 | Python / Django | How to store sent emails? | I was wondering how can I store sent emails
I have a send_email() function in a pre_save() and now I want to store the emails that have been sent so that I can check when an email was sent and if it was sent at all. | Another way to look at it: send the mail to your backup email account ex: backup@yourdomain.com. So you can store the email, check if the email is sent or not.
Other than that, having an extra model for logged emails is a way to go. | 0.265586 | false | 2 | 3,749 |
2015-05-21 08:22:17.117 | Python / Django | How to store sent emails? | I was wondering how can I store sent emails
I have a send_email() function in a pre_save() and now I want to store the emails that have been sent so that I can check when an email was sent and if it was sent at all. | I think the easiest way before messing up with middleware or whatever is to simply create a model for your logged emails and add a new record if send was successful. | 1.2 | true | 2 | 3,749 |
2015-05-22 03:38:57.727 | How to do django syncdb in version 1.4.2? | How to do syncdb in django 1.4.2?
i.e. having data in database, how to load the models again when the data schema is updated?
Thanks in advance | Thanks Amyth for the hints.
btw the commands is a bit different, i will post a 10x tested result here.
Using south
1. setup the model
python manage.py schemamigration models --initial
dump data if you have to
python manage.py dumpdata -e contenttypes -e auth.Permission --natural > data.json
syncdb
python manage.... | 1.2 | true | 1 | 3,750 |
2015-05-23 01:50:36.047 | Python Libtcod: How to do pathfinding with variable move cost terrain? | I am building a turn-based strategy game using Libtcod and Python. The game map has variable terrain and each tile can be 1 of 5 types:
Plains - Costs 1 to move over
Forest - Costs 2
River - Costs 4
Hill - Costs 3
Mountain - Impassable
Each type has its own movement cost, so that it costs less "move points" to move t... | As far as I understand, what you want to achieve is very well possible with tcod's built-in pathfinding function.
path_new_using_function will call your path_func with adjacent cells, so you can simply have it return the values you listed above depending on the terrain below (xFrom, yFrom) and/or (xTo, yTo). | 0 | false | 1 | 3,751 |
2015-05-24 08:12:14.570 | What does In [*] in IPython Notebook mean and how to turn it off? | I use Windows 7, Python 2.7.9 plus latest version of IPython 3.1.
I ran %python inside an IPython Notebook and ran the cell, instead of returning the Python version, it did not run and jumped to a new line and printed a In [*] instead of a line number. Now no line is running in ipython everything is ignored when I try ... | The kernel is busy. Go to the menu Kernel and click Interrupt. If this does not work click Restart. You need to go in a new cell and press Shift + Enter to see if it worked. | 1.2 | true | 3 | 3,752 |
2015-05-24 08:12:14.570 | What does In [*] in IPython Notebook mean and how to turn it off? | I use Windows 7, Python 2.7.9 plus latest version of IPython 3.1.
I ran %python inside an IPython Notebook and ran the cell, instead of returning the Python version, it did not run and jumped to a new line and printed a In [*] instead of a line number. Now no line is running in ipython everything is ignored when I try ... | The issue causing your kernel to be busy can be a specific line of code. If that is the case, your computer may just need time to work through that line.
To find out which line or lines are taking so long, as mentioned by Mike Muller you need to restart the program or interrupt the kernel. Then go through carefully... | 0.740859 | false | 3 | 3,752 |
2015-05-24 08:12:14.570 | What does In [*] in IPython Notebook mean and how to turn it off? | I use Windows 7, Python 2.7.9 plus latest version of IPython 3.1.
I ran %python inside an IPython Notebook and ran the cell, instead of returning the Python version, it did not run and jumped to a new line and printed a In [*] instead of a line number. Now no line is running in ipython everything is ignored when I try ... | For me to resolve this issue, I had to stop my anti-virus program. | 0.265586 | false | 3 | 3,752 |
2015-05-24 19:12:21.647 | Email API for connecting in a marketplace? | I'm looking into what it would take to add a feature to my site so this is a pretty naive question.
I'd like to be able to connect buyers and sellers via an email message once the buyer clicks "buy".
I can see how I could do this in java script, querying the user database and sending an email with both parties involv... | What you're describing would be handled largely by your backend. If this were my project, I would choose the following simple route:
Store the messages the buyers/sellers send in your own database, then simply send notification emails when messages are sent. Have them reply to each other on your own site, like Faceboo... | 0 | false | 1 | 3,753 |
2015-05-24 21:01:53.183 | how do you disable a text command from another text command in Sublimetext | I'm creating a plugin in sublime Text 3, and I've hit a snag that I can't figure out. This is my first using python, and the first time I've done even driven desktop development in over a decade, so hopefully this is just a lack of knowledge on my part.
The plugin I'm writing uses text commands to gather data and then ... | After another 5 hours of reading, I figured it out. As I assumed, it was a lack of Python knowledge on my part.
All I needed to do was create a module level variable to use as a flag. | 0 | false | 1 | 3,754 |
2015-05-25 11:41:59.033 | Python: str.split() - is it possible to only specify the "limit" parameter? | I want to split a string on whitespaces (default behavior), but I want it to split it only once - I.e. I want it to return an array with 2 items at most.
If it is not possible - i.e. if for specifying the limit I have to also specify the pattern - could you please tell how to specify the default one? | Split string on consecutive whitespace† at most maxsplit times††
† Resulting list will contain no leading or trailing empty strings ("") if the string has leading or trailing whitespace
†† Splits are made left to right. To split the other way (right to left), use the str.rsplit() method (requires Python 2.4+)
Python 2... | 0.386912 | false | 1 | 3,755 |
2015-05-25 14:57:57.010 | Concatenate large files in sql-like way with limited RAM | I have a large A.csv file (~5 Gb) with several columns. One of the columns is Model.
There is another large B.csv file (~15 Gb) with Vendor, Name and Model columns.
Two questions:
1) How can I create result file that combines all columns from A.csv and corresponding Vendor and Name from B.csv (join on Model). The trick... | As @Marc B said, reading one row at a time is the solution.
About the join I would do the following (pseudocode: I don't know python).
"Select distinct Model from A" on first file A.csv
Read all rows, search for Model field and collect distinct values in a list/array/map
"Select distinct Model from B" on second file... | 0 | false | 1 | 3,756 |
2015-05-26 01:20:09.210 | can one spider handle multiple items and multiple pipelines? | New to scrapy.There are something confused me:what's the relationship between spiders,pipelines and items?
1.should one pipeline handle only one specific item or it can handle multiple items?
2.how to use one spider to crawl multiple items or I should use one spider just to crawl one item? | Item refers to an item of data that it's scraped. You can also call it a record or an entry.
Spider is the thing that does crawling (starting requests and following links) and scraping (extracting data items from responses). They can schedule whatever amount of requests and extract whatever amount of items as you want,... | 0.386912 | false | 1 | 3,757 |
2015-05-26 16:32:26.633 | Functional Breadth First Search | Functional depth first search is lovely in directed acyclic graphs.
In graphs with cycles however, how do we avoid infinite recursion? In a procedural language I would mark nodes as I hit them, but let's say I can't do that.
A list of visited nodes is possible, but will be slow because using one will result in a linea... | You have to keep track of the nodes you visit. Lists are not king in the ML family, they're just one of the oligarchs. You should just use a set (tree based) to track the visited nodes. This will add a log factor compared to mutating the node state, but is so much cleaner it's not funny. If you know more about your nod... | 0.995055 | false | 2 | 3,758 |
2015-05-26 16:32:26.633 | Functional Breadth First Search | Functional depth first search is lovely in directed acyclic graphs.
In graphs with cycles however, how do we avoid infinite recursion? In a procedural language I would mark nodes as I hit them, but let's say I can't do that.
A list of visited nodes is possible, but will be slow because using one will result in a linea... | It is pretty OK to have a mutable state hidden inside the function. If it is not visible, then it doesn't exist. I usually use hash sets for this. But in general, you should stick to this if your profiling pinpointed that. Otherwise, just use set data structure. OCaml has an excellent Set based on eagerly balanced AVL ... | 0.296905 | false | 2 | 3,758 |
2015-05-26 17:18:26.903 | How to check all versions of python installed on osx and centos | I just started setting up a centos server today and noticed that the default version of python on centos is set to 2.6.6. I want to use python 2.7 instead. I googled around and found that 2.6.6 is used by system tools such as YUM so I should not tamper with it. Then I opened up a terminal on my mac and found that I had... | we can directly use this to see all the pythons installed both by current user and the root by the following:
whereis python | 0.591696 | false | 4 | 3,759 |
2015-05-26 17:18:26.903 | How to check all versions of python installed on osx and centos | I just started setting up a centos server today and noticed that the default version of python on centos is set to 2.6.6. I want to use python 2.7 instead. I googled around and found that 2.6.6 is used by system tools such as YUM so I should not tamper with it. Then I opened up a terminal on my mac and found that I had... | COMMAND: python --version && python3 --version
OUTPUT:
Python 2.7.10
Python 3.7.1
ALIAS COMMAND: pyver
OUTPUT:
Python 2.7.10
Python 3.7.1
You can make an alias like "pyver" in your .bashrc file or else using a text accelerator like AText maybe. | 0.135221 | false | 4 | 3,759 |
2015-05-26 17:18:26.903 | How to check all versions of python installed on osx and centos | I just started setting up a centos server today and noticed that the default version of python on centos is set to 2.6.6. I want to use python 2.7 instead. I googled around and found that 2.6.6 is used by system tools such as YUM so I should not tamper with it. Then I opened up a terminal on my mac and found that I had... | As someone mentioned in a comment, you can use which python if it is supported by CentOS. Another command that could work is whereis python. In the event neither of these work, you can start the Python interpreter, and it will show you the version, or you could look in /usr/bin for the Python files (python, python3 etc... | 0.135221 | false | 4 | 3,759 |
2015-05-26 17:18:26.903 | How to check all versions of python installed on osx and centos | I just started setting up a centos server today and noticed that the default version of python on centos is set to 2.6.6. I want to use python 2.7 instead. I googled around and found that 2.6.6 is used by system tools such as YUM so I should not tamper with it. Then I opened up a terminal on my mac and found that I had... | Use, yum list installed command to find the packages you installed. | 1.2 | true | 4 | 3,759 |
2015-05-27 21:16:22.860 | Django 1.8, Using Admin app as the main site | I am about to begin work on a project that will use Django to create a system with three tiers of users. Each user will login into the dashboard type interface (each user will have different types of tools on the dashboard). There will be a few CRUD type interfaces for each user tier among other things. Only users with... | This seems like a bad idea.
Out of the box, the information architecture presented by the admin interface is going to be very flat where views essentially mirror what's in the database 1:1. I can imagine a slim subset of users in internal IT apps or similar where that may be appropriate but the compromises in usability... | 1.2 | true | 1 | 3,760 |
2015-05-28 01:59:06.827 | Django 1.8, Multiple Custom User Types | I am creating a Django site that will have 4 types of users;
Super Admin: Essentially manages all types of users
UserTypeA: Can login to site and basically will have a CRUD interface for some arbitrary model. Also has extra attributes (specific info that only pertains to TypeA users)
UserTypeB: Can login to site a... | You should need just use Groups Django mechanism - you need to create four groups like userA and let say common and check whether user is in first or second group - then show him appropriate view | 0 | false | 1 | 3,761 |
2015-05-28 10:04:25.907 | how to convert YANG data model to JSON data? | How do I convert "YANG" data model to "JSON"?
As there is many many docs available in web, in that they changed in YANG
synatx to JSON but how the value for the leaf or leaf list they are getting? from where and how it will get actual data in JSON from YANG? | Yang is a modeling language, not a data generation language.
What you are asking for is a simulator that will contain the same or pseudo logic as your application to generate data. | -0.964028 | false | 1 | 3,762 |
2015-05-28 20:28:33.753 | How to extend/customize unittest's shortDescription()? | unittest.shortDescription() returns only the first line of the test method's docstring.
Is there a way to change this behavior, e.g. to display the entirety of the docstring, or to display another message ?
Would I need to override shortDescription() ?
EDIT: I did know that shortDescription() takes no arguments (beside... | unittest.shortDescription() takes no arguments. You would have to override it to get the entire docstring. | 0 | false | 1 | 3,763 |
2015-05-29 00:34:56.113 | Inconsistently slow queries in production (RDS) | First, the server setup:
nginx frontend to the world
gunicorn running a Flask app with gevent workers
Postgres database, connection pooled in the app, running from Amazon RDS, connected with psycopg2 patched to work with gevent
The problem I'm encountering is inexplicably slow queries that are sometimes running on th... | You could try this from within psql to get more details on query timing
EXPLAIN sql_statement
Also turn on more database logging. mysql has slow query analysis, maybe PostgreSQL has an equivalent. | 0 | false | 1 | 3,764 |
2015-05-29 01:34:03.343 | how to increment inside tuple in python? | Suppose that I have tuples of the form
[(('d',0),('g',0)),(('d',0),('d',1)),(('i',0),('g',0))]
Then how do I increment the numbers inside the tuple that they are of the form:-
[(('d',1),('g',1)),(('d',1),('d',2)),(('i',1),('g',1))]
?
I am able to do this in a single for loop. But I am looking for shorter methods.
P.... | You can't change the values in tuples, tuples are immutable. You would need to make them be lists or create a new tuple with the value you you want and store that. | 0.386912 | false | 1 | 3,765 |
2015-05-29 15:18:33.390 | VIM + netrw: open multiple files/buffers in the same window | I have recently switched to VIM using NERDTree and python-mode. As NERDTree seems to have a conflict with python-mode and breaks my layout if I close one out of multiple buffers, I decided to switch to netrw since it is shipped with VIM anyway.
But having a file opened, if I open netrw by typing :E and open another fil... | But having a file opened, if I open netrw by typing :E and open another file by hitting <enter> VIM closes the old one and opens the new one in the same window.
[...]
How can I open multiple files/buffers in the same window using netrw?
Buffers are added to a list, the buffer list, and facultatively displayed in one ... | 1.2 | true | 1 | 3,766 |
2015-05-29 20:17:50.047 | Robot Framework location and name of keyword | I want to create a python library with a 0 argument function that my custom Robot Framework keywords can call. It needs to know the absolute path of the file where the keyword is defined, and the name of the keyword. I know how to do something similar with test cases using the robot.libraries.BuiltIn library and the ... | I took a relatively quick look through the sources, and it seems that the execution context does have any reference to currently executing keyword. So, the only way I can think of resolving this is:
Your library needs also to be a listener, since listeners get events when a keyword is started
You need to go through ro... | 0.201295 | false | 1 | 3,767 |
2015-05-30 06:23:51.913 | How can i install python on OSX? | I'm new to computer programming!
I want to learn python and write my program and run it on my mac OS X machine.
How can i setup python programming tools on OS X and how can i use that ?
I before this never use any other programming language. | python is installed on OSX by default
and you just need to open terminal and write ‘python’ command, then you can start your python coding | 1.2 | true | 1 | 3,768 |
2015-05-30 14:02:37.227 | Running complex calculations (using python/pandas) in a Django server | I have developed a RESTful API using the Django-rest-framework in python. I developed the required models, serialised them, set up token authentication and all the other due diligence that goes along with it.
I also built a front-end using Angular, hosted on a different domain. I setup CORS modifications so I can acces... | I assume your question is about "how do I do these calculations in the restful framework for django?", but I think in this case you need to move away from that idea.
You did everything correctly but RESTful APIs serve resources -- basically your model.
A computation however is nothing like that. As I see it, you have t... | 1.2 | true | 1 | 3,769 |
2015-05-31 04:12:51.663 | Python: how does a dict with mixed key type work? | I understand that the following is valid in Python: foo = {'a': 0, 1: 2, some_obj: 'c'}
However, I wonder how the internal works. Does it treat everything (object, string, number, etc.) as object? Does it type check to determine how to compute the hash code given a key? | Types aren't used the same way in Python as statically types languages. A hashable object is simply one with a valid hash method. The interpreter simply calls that method, no type checking or anything. From there on out, standard hash map principles apply: for an object to fulfill the contract, it must implement both h... | 1.2 | true | 1 | 3,770 |
2015-05-31 17:05:49.843 | How to update PyQt4 widget locations based on window size? | I'm working on developing a PyQt4 application that will require a lot of widgets and I have run into an issue. When you say where to move the widget to (such as: btn.move(100, 100) it moves it properly, but if you resize the window, you can't see it). I'm not sure how to fix this. I don't want to restrict resizing of t... | Use a Qt layout (like a QVBoxLayout, QHBoxLayout, or a QGridLayout) | 0 | false | 1 | 3,771 |
2015-06-01 00:10:14.853 | How to generate random points in a circular distribution | I am wondering how i could generate random numbers that appear in a circular distribution.
I am able to generate random points in a rectangular distribution such that the points are generated within the square of (0 <= x < 1000, 0 <= y < 1000):
How would i go upon to generate the points within a circle such that:
(... | FIRST ANSWER:
An easy solution would be to do a check to see if the result satisfies your equation before proceeding.
Generate x, y (there are ways to randomize into a select range)
Check if ((x−500)^2 + (y−500)^2 < 250000) is true
if not, regenerate.
The only downside would be inefficiency.
SECOND ANSWER:
OR, you coul... | 0.435345 | false | 1 | 3,772 |
2015-06-01 03:57:28.207 | Deploy python web server on AWS Elastic Beanstalk | I'm deploying an python web server on AWS now and I have a some question about it. I'm using websocket to communicate between back end and front end.
Do I have to use framework like django or flask?
If not, where should I put the index.html file? in other word, after deploying, how do AWS know the default page of my a... | AWS doesn't "know" anything about your content. The webserver that you install will be configured to point to the "root" directory in which index.html (or something equivalent) should be.
Since it depends on which webserver (django, flask, Jinja etc) you install - you should lookup its documentation! | 1.2 | true | 1 | 3,773 |
2015-06-01 13:53:59.447 | Django how to not use cached queryset while iterating? | I have a queryset which I iterate through in a loop. I use data from the queryset to change data inside the queryset which might be needed in a lter step of the loop.
Now the queryset is only loaded once at the beginning of the loop. How can I make django reload the data in every iteration? | You can reload each object in the start of the loop body. Just use TheModel.objects.get(pk=curr_instance.pk) to do this. | 1.2 | true | 1 | 3,774 |
2015-06-01 17:23:35.457 | Conceptual: how to code battleships between two computers in Python? | this is a conceptual question. As part hobby, part art project I'm looking to build a Python script that allows two people to play battleships between their computers (across the net, without being on the same network).
The idea would be you could run the program something like:
python battleships.py 192.168.1.1
Where ... | I think the simpliest way to do this is reading socket server in this battleship game. But here is a problem, in this case you will have a problem with connecting, in case when your ip is invisible from the internet. | -0.386912 | false | 1 | 3,775 |
2015-06-02 09:16:22.150 | Can I link Django permissions to a model class instead of User instances? | I know how permissions/groups/user work together in a "normal" way.
However, I feel incomfortable with this way to do in my case, let me explain why.
In my Django models, all my users are extended with models like "Landlord" or "Tenant".
Every landlord will have the same permissions, every tenant will have other same p... | django.contrib.auth has groups and group permissions, so all you have to do is to define landlords and tenants groups with the appropriate permissions then on your models's save() method (or using signals or else) add your Landlord and Tenant instances to their respective groups. | 0.386912 | false | 1 | 3,776 |
2015-06-02 09:36:33.623 | html buttons calling python functions using bottle | I'm currently trying to right a python script that overnight turns off all of our EC2 instances then in the morning my QA team can go to a webpage and press a button to turn the instances back on.
I have written my python script that turns the severs off using boto. I also have a function which when ran turns them bac... | What I have ended up doing to fix this issue is used bottle to make a url which completes the needed function. Then just made an html button that links to the relevant url. | 0.995055 | false | 1 | 3,777 |
2015-06-02 12:20:15.600 | Building a simple progress bar or loading animation in Kivy? | I am writing a Kivy UI for cmd line utility I have developed. Everything works fine, but some of the processes can take from a few seconds to a few minutes to process and I would like to provide some indication to the user that the process is running. Ideally, this would be in the form of a spinning wheel or loading ba... | I've dealt with similar problem and creating new thread didn't do the trick. I had to use Clock.schedule_once(new_func) function. It schedules function call to the next frame, so it is going to run almost immediately after callback ends. | 0.135221 | false | 1 | 3,778 |
2015-06-02 12:38:51.593 | How to open PYW files in Windows 8 | Someone gave me a python file to open and use as a resource. The only issue is I don't know anything about python, it's very different from my basic knowledge of coding.
The file is not a normal .py file, but rather a console-less .pyw file. I have imported the newest version of python and installed PySide, but I have... | Right-click the file, click properties, under general it says "opens with:"...
Click the "Change" button to the right of that, and then click more options. On that menu there should be an option called "pythonw" click that. Then on the bottom-right click "apply", then "OK". Then just double-click on the file and it sho... | 0.386912 | false | 1 | 3,779 |
2015-06-02 18:05:55.643 | How to import a 3rd party Python library into Bluemix? | My Python app needs web.py to run but I'm unable to figure out how to get it up to bluemix. I see no options using cf push. I tried to "import web" and added some additional code to my app without success.
When I push my Python app to bluemix without web.py it fails (naturally) since it does not have what it needs to r... | The cause for this problem was that I was not correctly telling my Python app the needed configuration information when I pushed it out to Bluemix.
What I ended up having to do was add a requirements.txt file and a Procfile file into the root directory of my Python application, to draw that connection between my Python... | 0.496174 | false | 1 | 3,780 |
2015-06-03 04:31:22.410 | API key encryption for Github? | I'm writing a Python application that utilizes the Tumblr API and was wondering how I would go about hiding, or encrypting, the API key.
Github warns against pushing this information to a repo, so how would I make the application available to the public and still follow that policy? | Why do you need to post your API key? Why not post your app code to Github without your API key and have a configuration parameter for your users to add their own API key? | 1.2 | true | 1 | 3,781 |
2015-06-03 09:06:51.870 | Generate random permutation of huge list (in Python) | I'd like to create a random permutation of the numbers [1,2,...,N] where N is a big number. So I don't want to store all elements of the permutation in memory, but rather iterate over the elements of my particular permutation without holding former values in memory.
Any idea how to do that in Python? | This is a generic issue and rather not a Python-specific. In most languages, even when iterators are used for using structures, the whole structure is kept in memory. So, iterators are mainly used as "functional" tools and not as "memory-optimization" tools.
In python, a lot of people end up using a lot of memory due ... | 0 | false | 1 | 3,782 |
2015-06-03 21:25:54.653 | Changing css styles from view in Django | Sorry in advance if there is an obvious answer to this, I'm still learning the ropes with Django.
I'm creating a website which has 6 pre determined subjects (not stored in DB)
english, civics, literature, language, history, bible
each subject is going to be associated with a unique color.
I've got a template for a subj... | You can do this is many ways.
In general you need to return some variable from your view to the html and depending on this variable select a style sheet, if your variable name will match you style sheet's name you can do "{{variable}}.css", if not you can use JQuery. | 0.135221 | false | 1 | 3,783 |
2015-06-04 11:12:55.897 | how to drop dataframe in pandas? | Tips are there for dropping column and rows depending on some condition.
But I want to drop the whole dataframe created in pandas.
like in R : rm(dataframe) or in SQL: drop table
This will help to release the ram utilization. | Generally creating a new object and binding it to a variable will allow the deletion of any object the variable previously referred to. del, mentioned in @EdChum's comment, removes both the variable and any object it referred to.
This is an over-simplification, but it will serve. | 1.2 | true | 1 | 3,784 |
2015-06-04 16:35:32.813 | Django: call index function on page reload | I was wondering how to call my index(request) function thats in views.py upon every page reload. Currently index(request) only gets called when the app originally loads. Every other page reload after that calls another function in views.py called filter_report(request). The problem I am running into is that 85% of t... | Well, that really is not how it works. Each view is separate and is only called from the URLs that map to it. If you have shared code, you probably want to either factor it out into separate functions that you can call from each view, or use something like a template tag or context processor to add the relevant informa... | 1.2 | true | 1 | 3,785 |
2015-06-04 22:35:49.017 | Creating and Storing Multi-Dimensional Array in a netCDF File | This question has potentially two parts but maybe only one if the first part can be encapsulated by the second. I am using python with numpy and netCDF4
First:
I have four lists of different variable values (hereafter referred to elevation values) each of which has a length of 28. These four lists are one set of 5 diff... | After talking to a few people where I work we came up with this solution:
First we made an array of zeroes using the following argument:
array1=np.zeros((28,5,24,4))
Then appended this array by specifying where in the array we wanted to change:
array1[:,0,0,0]=list1
This inserted the values of the list into the first e... | 0 | false | 1 | 3,786 |
2015-06-05 14:51:17.007 | How to track Django model changes with git? | Suppose you write a Django website and use git to manage the source code. Your website has various instances (one for each developer, at least).
When you perform a change on the model in a commit, everybody needs to update its own database. In some cases it is enough to run python manage.py migrate, in some other cases... | All changes to models should be in migrations. If you "need to run a few custom SQL queries and/or run some Python code to update values" then those are migrations too, and should be written in a migration file. | 1.2 | true | 2 | 3,787 |
2015-06-05 14:51:17.007 | How to track Django model changes with git? | Suppose you write a Django website and use git to manage the source code. Your website has various instances (one for each developer, at least).
When you perform a change on the model in a commit, everybody needs to update its own database. In some cases it is enough to run python manage.py migrate, in some other cases... | You should track migrations. The only thing that you must keep an eye out for is at branch merge. If everyone uses a feature branch and develops on his branch then the changes are applied once the branch is integrated. At that point (pull request time or integration time) you need to make sure that the migrations make ... | 0.101688 | false | 2 | 3,787 |
2015-06-07 23:56:57.770 | PYTHON py2exe makes too many files.. how do I execute only one .EXE file? | After I make an exe file, there are many files such as .pyd that my exe depend on them..
I want to make a program with only one exe file which will be handie..
please help me | Py2exe is a tool provides an exe application which can be run without installing python interpreter, after packaging you find your exe and dlls of interpreter and all modules... In dist folder. It does nt provide all in one exe, use pyinstaller instead | 0 | false | 1 | 3,788 |
2015-06-08 15:58:46.647 | How to stop the iPython notebook to run the command line, run only python code | I am using iPython notebook build a online interactive teaching website, but I don't want users to run command line, any idea how to remove iPython notebook command line function? Is there any configuration or something? I have been stuck here for 3 days! | You can't make os.system or subprocess unavailable, and users could use these to build themselves terminals even if you disable the built in terminals. However, if you run the ipython instance in a sandbox then it won't matter that they have command line access. | 0 | false | 1 | 3,789 |
2015-06-09 06:05:53.853 | how to import file csv without using bulk insert query? | i have tried import file csv using bulk insert but it is failed, is there another way in query to import csv file without using bulk insert ?
so far this is my query but it use bulk insert :
bulk insert [dbo].[TEMP] from
'C:\Inetpub\vhosts\topimerah.org\httpdocs\SNASPV0374280960.txt' with
(firstrow=2,fieldterminato... | My answer is to work with bulk-insert.
1. Make sure you have bulk-admin permission in server.
2. Use SQL authentication login (For me most of the time window authentication login haven't worked.) for bulk-insert operation. | 1.2 | true | 1 | 3,790 |
2015-06-09 15:41:58.077 | Restrict MKL optimized scipy to single thread | I just installed a intel MKL optimized version of scipy and when running my benchmarks, I got remarkable speedup with it. I then looked closer and found out it was running on 20 cores ... how do I restrict it to single threaded mode? Is there a way I could have installed it to single threaded mode by default, while lea... | Upon further investigation it looks you are able to set the environment variable MKL_NUM_THREADS to achieve this. | 1.2 | true | 1 | 3,791 |
2015-06-11 00:59:37.047 | commands in tkinter when to use lambda and callbacks | I'm confused as to the difference between using a function in commands of tkinter items. say I have self.mb_BO.add_radiobutton(label= "Red", variable=self.BO, value=2, command=self.red)
what is the difference in how the add statement works from this:
self.mb_BO.add_radiobutton(label= "Red", variable=self.BO, val... | A good way to look at it is to imagine the button or binding asking you the question "what command should I call when the button is clicked?". If you give it something like self.red(), you aren't telling it what command to run, you're actually running the command. Instead, you have to give it the name (or more accurate... | 1.2 | true | 1 | 3,792 |
2015-06-11 01:45:17.020 | What does it mean for statically linking and dynamically linking in Python? | I know the difference between static and dynamic linking in C or C++. But what does it mean in Python? Since it's just an interpreter, and only having one style of import mechanism of modules, how does this make sense?
If I freeze my Python application with cx_freeze by excluding a specific library, is it a kind of dy... | In python there's no static linking. All the imports requires the correct dependencies to be installed on our target machine. The choice of the version of such libraries are in our decision.
Now let's come to the binary builders for python. In this case, we'll have to determine the linking type based on the GNU definit... | 1.2 | true | 1 | 3,793 |
2015-06-11 16:58:32.057 | I want to write a django application that can respond to the HttpClient requests from an android device. Can I have an example code? | I am working on a sensor app in android and I've to store the accelerometer readings on a django server and then retrieve them on my device. I am new to django and I don't know how to communicate with Android's HttpClient and a django server. | Django doesn't care what the client is, and Android's HttpClient don't care whether the url are served by Django, Tomcat, Rails, Apache or whatever. It's only HTTP. IOW:
learn to write a Django App (it's fully documented)
learn to use the Android's HttpClient (it's fully documented too IIRC)
connect the dots... | 0 | false | 1 | 3,794 |
2015-06-11 17:20:51.380 | Pycharm, virtualenv and kivy setup | I'm moving to pycharm from sublime text and can't get it working with kivy and virtualenv. I've created a virtualenv with a new project in pycharm but I can't figure out how to get kivy working. The kivy help shows using the kivy.bat as the python interpreter but I want to use the virtualenv. One possible option would ... | I found a way to set the environmental variables found in the kivy.bat. I simply created a new .bat that sets the environmental variables and then runs pycharm from the command line. This allows the variables to persist between projects. | 0 | false | 1 | 3,795 |
2015-06-12 13:50:56.797 | Django south schemamigration KeyError | I am trying to do a schemamigration in Django with south using the following command where core is the app I would like to migrate.
$ python manage.py schemamigration core --auto
Unfortunately this throws the following KeyError:
KeyError: u"The model 'externaltoolstatus' from the app 'core' is not available in this mi... | I figured out the last migration files were accidentally corrupted and caused the KeyError. | 0 | false | 1 | 3,796 |
2015-06-15 06:48:01.703 | output of one file input to next | How would the output of one script be passed as the input to another? For example if a.py outputs format.xml then how would a.py call b.py and pass it the argument format.xml? I think it's supposed to work like piping done on the command line.
I've been hired by a bunch of scientists with domain specific knowledge but ... | The pattern makes sense in some cases, but for me it's when you want to be able to run each module as a self sustained executeable.
I.E. Should you want to use the script from within FORTRAN or similar language, it is the easiest way, to build the python module to an executeable, and then call it from FORTRAN.
That wou... | 0.201295 | false | 1 | 3,797 |
2015-06-15 22:53:38.777 | Run an existing python web application inside a virtalenv | I am new to python development using virtualenv. I have installed python 2.7, pip, virtualenv, virtualenvwrapper in windows and I am using windows PS. I have referred lots of tutorials for setting this up. Most of them contained the same steps and almost all of them stopped short of explaining what to do after the vir... | testenv/bin/pip and testenv/bin/python
I'd check it in a local repository and check it out in the virtualenv.
No, you have not. | 0 | false | 1 | 3,798 |
2015-06-16 14:21:37.800 | how to kill a python programs using another python program on raspberry? | i am using 2 python programs with rc.local for my raspberry, first program is my main program and the other is the second program. The second program is shutdown the raspberry, but when i do the second program my first program is still running and will stopped until raspberry truly shutdown.
I want to make the second ... | Maybe an easier way would be to use the shell to kill the process in question? Each process in linux has a number assigned to it, which you can see by typing
pstree -p
In your terminal. You can then kill the process by typing in
sudo kill process number
Does that help, or were you thinking of something a bit more compl... | 0 | false | 1 | 3,799 |
2015-06-17 00:25:11.380 | Creating Multi-user chat with sockets on python, how to handle the departure of the server? | I was trying to implement a multiuser chat (group chat) with socket on python.
It basically works like this: Each messages that a user send is received by the server and the server sends it back to the rest of the users.
The problem is that if the server close the program, it crashes for everyone else.
So, how can yo... | could you make your server log for heartbeats? and also post heartbeats to the clients on the socket?
if so, have a monitor check for the server heartbeats and restart the server application if the heartbeats exceed the threshold value.
also, check for heartbeats on the client and reestablish connection when you did n... | 1.2 | true | 1 | 3,800 |
2015-06-17 08:35:36.093 | How does result changes by using .distinct() in spark? | I was working with Apache Log File. And I created RDD with tuple (day,host) from each log line. Next step was to Group up host and then display the result.
I used distinct() with mapping of first RDD into (day,host) tuple. When I don't use distinct I get different result as when I do. So how does a result change when u... | I think when you only use map action on FIRST_RDD(logs) you will get SECOND_RDD count of new this SECOND_RDD will be equal to count of FIRST_RDD.But if you use distinct on SECOND_RDD, count will decrease to number of distinct tuples present in SECOND_RDD. | 0 | false | 1 | 3,801 |
2015-06-17 15:44:26.960 | How to install GSSAPI Python module? | I am trying to install the GSSAPI module through pip but I receive this error that I don't know how to resolve.
Could not find main GSSAPI shared library. Please try setting
GSSAPI_MAIN_LIB yourself or setting ENABLE_SUPPORT_DETECTION to
'false'
I need this to work on Python 2.6 for LDAP3 authentication. | For me, the issue got resolved after installing the package "krb5-libs" in Centos.
Basically we need to have libgssapi_krb5.so file for installing gssapi. | 0 | false | 2 | 3,802 |
2015-06-17 15:44:26.960 | How to install GSSAPI Python module? | I am trying to install the GSSAPI module through pip but I receive this error that I don't know how to resolve.
Could not find main GSSAPI shared library. Please try setting
GSSAPI_MAIN_LIB yourself or setting ENABLE_SUPPORT_DETECTION to
'false'
I need this to work on Python 2.6 for LDAP3 authentication. | sudo apt install libkrb5-dev
actually installs /usr/bin/krb5-config and /usr/lib/libgssapi_krb5.so
so none of the symlinking was needed, just install libkrb5-dev and you should be good. | 0.999823 | false | 2 | 3,802 |
2015-06-19 12:01:52.220 | NaiveBayes classifier handling different data types in python | I am trying to implement Naive Bayes classifier in Python. My attributes are of different data types : Strings, Int, float, Boolean, Ordinal
I could use Gaussian Naive Bayes classifier (Sklearn.naivebayes : Python package) , But I do not know how the different data types are to be handled. The classifier throws an err... | Yes, you will need to convert the strings to numerical values
The naive Bayes classifier can not handle strings as there is not a way an string can enter in a mathematical equation.
If your strings have some "scalar value" for example "large, medium, small" you might want to classify them as "3,2,1",
However, if your... | 1.2 | true | 1 | 3,803 |
2015-06-19 20:58:08.757 | Trouble trying to run Python 2.7 and 3.4 in Eclipse | I've installed Python 3.4 and am currently using Python 2.7. I want to create a Project in Python 3.4, but, when I go to Run-->Run Configurations and then look to make a new entry under Python Run , I see that C:\Python34 doesn't show up. Also, when I try to create a new Project, the "Grammar Version" goes only up to 3... | I'm assuming you're using PyDev. I don't know if there are other alternatives but that's what I use for Python in Eclipse.
Right-click on your project folder in the Package Explorer view and select "Properties".
Select "PyDev - Interpreter/Grammar"
Select the appropriate Grammar Version and Interpreter, if those optio... | 1.2 | true | 1 | 3,804 |
2015-06-20 13:36:48.213 | Excuting cpp file from Python | I need to execute C++ code to acquire images to process in python.
I need to use these commands from python:
make and
./name_of_the_executable
Could anybody please help know me how to do it? | Look For python.net which is cable of making a call to the interfaces written in .net supported languages.
What all you need to do is
Steps:
Download and put it two files Python.Runtime.dll and clr.pyd in your DLLs folder.
From you >>>(triple greater than prompt )Python prompt Try
>>>import clr
if it doesn't gives a... | 0.386912 | false | 1 | 3,805 |
2015-06-22 09:13:23.270 | Find the tf-idf score of specific words in documents using sklearn | I have code that runs basic TF-IDF vectorizer on a collection of documents, returning a sparse matrix of D X F where D is the number of documents and F is the number of terms. No problem.
But how do I find the TF-IDF score of a specific term in the document? i.e. is there some sort of dictionary between terms (in their... | @kinkajou, No, TF and IDF are not same but they belong to the same algorithm- TF-IDF, i.e Term frequency Inverse document Frequency | 0 | false | 1 | 3,806 |
2015-06-22 17:04:09.033 | Python Module in Django | I am building my first Django web application and I need a bit of advice on code layout.
I need to integrate it with several other applications that are exposed through RESTful APIs and additionally Django's internal data. I need to develop the component that will pull data from various sources, django's DB, format it... | Definitely go for "way #1". Keeping an independent layer for your service(s) API will help a lot later when you have to enhance that layer for reliability or extending the API.
Stay away from singletons, they're just global variables with a new name. Use an appropriate life cycle for your interface objects. The obvi... | 0 | false | 1 | 3,807 |
2015-06-22 19:17:57.343 | Move .ipynb using the IPython Notebook Web Interface | After creating a .ipynb file in the root directory /, how can you move that .pynb file into a deeper directory ie: /subdirectory using the web UI? | Ran into this issue and solved it by :
Create a new folder in jupyter notebooks.
Go to the folder/directory and click the "Upload "button which is next to the "New" button.
Once you click "Upload", your pc file explorer window will pop-up, now simply find where you have your jupyter notebooks saved on your local mach... | 0 | false | 4 | 3,808 |
2015-06-22 19:17:57.343 | Move .ipynb using the IPython Notebook Web Interface | After creating a .ipynb file in the root directory /, how can you move that .pynb file into a deeper directory ie: /subdirectory using the web UI? | Duplicate the notebook and delete the original, was my workaround. | 0 | false | 4 | 3,808 |
2015-06-22 19:17:57.343 | Move .ipynb using the IPython Notebook Web Interface | After creating a .ipynb file in the root directory /, how can you move that .pynb file into a deeper directory ie: /subdirectory using the web UI? | Ipython 5.1:
1. Make new folder -- with IPython running, New, Folder, select 'Untitled folder' just created, rename (and remember the name!)
2. Go to the file you want to move, Move, write new directory name at prompt
Note: If the folder exists, skip 1.
Note: If you want to leave a copy in the original directory, Dupli... | 0.050976 | false | 4 | 3,808 |
2015-06-22 19:17:57.343 | Move .ipynb using the IPython Notebook Web Interface | After creating a .ipynb file in the root directory /, how can you move that .pynb file into a deeper directory ie: /subdirectory using the web UI? | If some stumbles here as of 2020, it's now possible to move .ipynb or other kind of files by simply checking it and clicking move.
Nevertheless, for .ipynb files you must be sure that the notebook isn't running (gray icon). If it's running it should be green and you must shut it down before moving. | 0.101688 | false | 4 | 3,808 |
2015-06-23 13:02:21.470 | move cursor in matplotlib window with keyboard stroke | I would like to move the cursor in a Python matplotlib window by a (data) pixel at a time (I'm displaying a 2D image), using the keyboard arrow keys. I can trap the keyboard keypress events, but how do I reposition the cursor based on these events? | One solution is to make MatPlotLib react to key events immediately.
Another solution is print a 'Cursor' or marker line on the plot, and change its coordinates with the mouse events. Eg. draw a vertical line, and update its X coordinates with the left and right keys. You can then add a label with the X coordinate along... | 0 | false | 1 | 3,809 |
2015-06-23 17:30:35.820 | Django Functional Test for Time Delayed Procedure | I am learning TDD and am using Django and Selenium to do some functional testing. I wanted to make it so that a user selects a checkbox that essentially says "add 1 to this number nightly". Then, for all of the users that have this setting on, a nightly process will automatically increment the number on these accounts.... | I've decided that I am just going to call the method of the nightly methods directly, instead of making a truly functional test. | 1.2 | true | 1 | 3,810 |
2015-06-24 09:09:39.370 | How to save a dataframe as a csv file with '/' in the file name | I want to save a dataframe to a .csv file with the name '123/123', but it will split it in to two strings if I just type like df.to_csv('123/123.csv').
Anyone knows how to keep the slash in the name of the file? | You can not use any of these chars in the file name ;
/:*?\"| | 0 | false | 1 | 3,811 |
2015-06-24 11:04:08.363 | Asynchronous way to listen web service for data change | I am new to python. I want to read JSON data from URL and if there is any change in JSON data on server, I want to update in my JSON file which is on client. How can I do that through python?
Actually i am ploting graph on django using JSON data which is on another server. That JSON data is updated frequently. So here ... | There's no way to "listen" for changes other than repeatedly requesting that URL to check if something has changed; i.e. classic "pull updates". To get actual live notifications of changes, that other server needs to offer a way to push such a notification to you. If it's just hosting the file and is not offering any a... | 0 | false | 1 | 3,812 |
2015-06-25 20:48:54.177 | how to use atexit when exception is raised | i have a scenario where some unknown exceptions may be raised during program execution and i can't except most of them and i want every time any exception will raise an email should send to me as exceptions cause program to terminate if not properly catch!
so i have read about python provide atexit module but it did no... | Look at sys.excepthook. As its name suggests, it's a hook into the exception. You can use it to send you an email when exceptions are raised. | 1.2 | true | 1 | 3,813 |
2015-06-26 08:43:03.097 | Is it feasible to unpickle large amounts of data in a Python web app that needs to be scalable? | I am working on my first web application. I am doing it in Python with Flask, and I want to run a piece of Python code that takes an object, with Pickle, from a (binary) file of several MB which contains all the necessary data. I have been told that so using Pickle in a web app is not a good idea because of scalability... | Pickle files is good way to load data in python. By the way consider using the C implementation: cPickle.
If you want to scale, using pickle files. Ideally you want to look for a partition key, that fits for your data and your project needs.
Let's say for example you have historical data, instead of having a single fil... | 0 | false | 1 | 3,814 |
2015-06-26 13:07:10.673 | Run script bash on saltstack master before minion | I allow myself to write to you, due to a block on my part at Salt.
I made a bash script that adds a host in my zabbix monitoring server. it works perfectly when I run .sh
the idea is that I want to automate this configuration through salt. I am when I do a highstate my state that contains the script runs in the master ... | If you need the highstate on the minion to cause something to occur on the master than you are going to want too look into using salt's Reactor (which is designed to do exactly this kind of multi-machine stuff). | 1.2 | true | 2 | 3,815 |
2015-06-26 13:07:10.673 | Run script bash on saltstack master before minion | I allow myself to write to you, due to a block on my part at Salt.
I made a bash script that adds a host in my zabbix monitoring server. it works perfectly when I run .sh
the idea is that I want to automate this configuration through salt. I am when I do a highstate my state that contains the script runs in the master ... | Run a minion on the same box as your master, then you can run the script on your master's minion and then on the other server. | 0 | false | 2 | 3,815 |
2015-06-26 21:12:34.690 | how to determine point anomalies given window anomalies? | I've been trying to determine how to detect point-anomalies given window-anomalies.
In more detail, I know for each 30-day window whether it contains an anomaly. For example, window 1 starts at 1/1/2009, window 2 at 1/2/2009, and so on.
Now I'm trying to use this knowledge to determine which dates these anomalies lie. ... | I just don't see how I can find the exact intervals where there are anomalies using windows.
You can't. How do you know there aren't two anomalies?
Is there an approximation method that anyone can come up with?
For each interval of windows where there is continuously an anomaly detected, assume that there is an anom... | 0 | false | 1 | 3,816 |
2015-06-28 09:40:41.023 | Solving system using linalg with constraints | I want to solve some system in the form of matrices using linalg, but the resulting solutions should sum up to 1. For example, suppose there are 3 unknowns, x, y, z. After solving the system their values should sum up to 1, like .3, .5, .2. Can anyone please tell me how I can do that?
Currently, I am using something l... | You could add a row consisting of ones to A and add one to B. After that use
result = linalg.lstsq(A, B)[0]
Or you can replace one of A's rows to row consisting of ones, also replace value in B to one in the same row. Then use
result = linalg.solve(A, B) | 0.265586 | false | 1 | 3,817 |
2015-06-29 14:44:25.193 | In wxPython Grid, creating event handler for Cell Selection disables moving the GridCursor | In the program I'm writing, the user needs to be able to select a cell in the grid and edit its value. The program also shows what the value of the currently selected value is in hexadecimal (so (0,0) is 0x00, (1,3) is 0x19, etc.) I originally had this display be updated through a binding to the wx.grd.EVT_GRID_SELECT_... | Adding event.Skip() at the end of my custom handler passes the event to the default handler. | 1.2 | true | 1 | 3,818 |
2015-06-30 18:35:08.947 | How to match and print list of comma separated numbers in python? | There are several questions regarding this topic, but none of them seem to answer this question specifically.
If I have the pattern p='([0-9]+)(,([0-9]+))*' and s='1,2,3,4,5' and I run m = re.match(p, s, 0) I get a match (as expected). However, I would like to be able to print the list ('1', '2', '3', '4', '5'). I ... | Don't use regexes for that. s.split(',') will do exactly what you want. | 1.2 | true | 1 | 3,819 |
2015-07-02 14:13:28.100 | How to generate a list of different lambda functions with list comprehension? | This question is distilled from the original application involving callback functions for Tkinter buttons. This is one line that illustrates the behavior.
lambdas = [lambda: i for i in range(3)]
if you then try invoking the lambda functions generated:
lambdas[0](), lambdas[1]() and lambdas[2]() all return 2.
The desir... | Ahhh, further Googling found a solution (admittedly one I would not have stumbled upon myself). The desired behavior can be invoked by use of a default argument:
lambdas = [lambda i=i: i for i in range(3)] | -0.201295 | false | 1 | 3,820 |
2015-07-03 00:40:59.403 | ipdb debugger, step out of cycle | Is there a command to step out of cycles (say, for or while) while debugging on ipdb without having to use breakpoints out of them?
I use the until command to step out of list comprehensions, but don't know how could I do a similar thing, if possible, of entire loop blocks. | You can use j <line number> (jump) to go to another line.
for example, j 28 to go to line 28. | 0.99998 | false | 2 | 3,821 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.