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
2013-11-15 20:36:15.347
Finding the cause of of 403 forbidden error in django admin
I have multiple users in django auth setup and a few simple models. For superusers I can view my model objects. For non superusers that have is_staff checked I get a 403 Permission denied when trying to view my models. I have tried adding all permissions to those users to find out if that was the cause but still receiv...
If you're using Firefox (or any browser) with Web Developer Toolbar, make sure you have cookies enabled. I temporarily had cookies turned off and forgot to turn it back on. Cookies => Disable Cookies => Disable All Cookies Solved my problem in Django 1.9.
0.201295
false
1
2,882
2013-11-17 03:33:43.687
animate visibility of QButtonGroup or layout containing it
I want to place group of buttons ontop of a QLabel showing image, the question is how do I animate the fade in visibility of the QButtonGroup, I want to place my buttons at the bottom area so whenever pointer is at the bottom area the button group should animate to fully visible but if I move the pointer out of the bot...
I did same thing with QLabels, QButtons and other Widgets. There are different solutions accordingly on what you need. In my case I just created a custom component with a QTimer and a QGraphicsOpacityEffect. The timer increases or decreases the opacity value (by a coefficient)..
0
false
1
2,883
2013-11-18 03:36:57.917
Remote control of an embedded system from Website
I am now using Django frame work to build a website which has the ability to control a remote embedded system (simply with functions like "Turn ON/OFF"). What i can image now is to use Socket Programming with Python (because Django is pure Python). As i have learnt, i only know how to send and receive messages with soc...
You basically have one major thing to decide: Is your embedded machine going to open up a port that allows any thing that knows it's IP and port details to control it and your web page write to that IP/Port OR Is your embedded device going to poll the web app to find out which state it should be in. The first option ...
1.2
true
1
2,884
2013-11-18 13:27:41.623
python 3.3.2 do I get the right understanding of the function "round"?
Sorry, but I really don't know what's the meaning of the defination of round in python 3.3.2 doc: round(number[, ndigits]) Return the floating point value number rounded to ndigits digits after the decimal point. If ndigits is omitted, it defaults to zero. Delegates to number.__round__(ndigits). For the built-in typ...
It helps to know that anything to the power of 0 equals 1. As ndigits increases, the function: f(ndigits) = 10-ndigits gets smaller as you increase ndigits. Specifically as you increase ndigits by 1, you simply shift the decimal place of precision one left. e.g. 10^-0 = 1, 10^-1 = .1 and 10^-2 = .01. The place where th...
0.386912
false
1
2,885
2013-11-19 13:03:15.640
Best way to show a user random data from an SQL database?
I'm working on a web app in Python (Flask) that, essentially, shows the user information from a PostgreSQL database (via Flask-SQLAlchemy) in a random order, with each set of information being shown on one page. Hitting a Next button will direct the user to the next set of data by replacing all data on the page with ne...
The easiest way is to do the random number generation in javascript at the client end... Tell the client what the highest number row is, then the client page keeps track of which ids it has requested (just a simple js array). Then when the "request next random page" button is clicked, it generates a new random number ...
0.201295
false
1
2,886
2013-11-19 21:57:24.747
How to install pip for Python 3 on Mac OS X?
OS X (Mavericks) has Python 2.7 stock installed. But I do all my own personal Python stuff with 3.3. I just flushed my 3.3.2 install and installed the new 3.3.3. So I need to install pyserial again. I can do it the way I've done it before, which is: Download pyserial from pypi untar pyserial.tgz cd pyserial python3 s...
pip is installed automatically with python2 using brew: brew install python3 pip3 --version
0.101688
false
3
2,887
2013-11-19 21:57:24.747
How to install pip for Python 3 on Mac OS X?
OS X (Mavericks) has Python 2.7 stock installed. But I do all my own personal Python stuff with 3.3. I just flushed my 3.3.2 install and installed the new 3.3.3. So I need to install pyserial again. I can do it the way I've done it before, which is: Download pyserial from pypi untar pyserial.tgz cd pyserial python3 s...
brew install python3 create alias in your shell profile eg. alias pip3="python3 -m pip" in my .zshrc ➜ ~ pip3 --version pip 9.0.1 from /usr/local/lib/python3.6/site-packages (python 3.6)
0.296905
false
3
2,887
2013-11-19 21:57:24.747
How to install pip for Python 3 on Mac OS X?
OS X (Mavericks) has Python 2.7 stock installed. But I do all my own personal Python stuff with 3.3. I just flushed my 3.3.2 install and installed the new 3.3.3. So I need to install pyserial again. I can do it the way I've done it before, which is: Download pyserial from pypi untar pyserial.tgz cd pyserial python3 s...
For a fresh new Mac, you need to follow below steps:- Make sure you have installed Xcode sudo easy_install pip /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)" brew doctor brew doctor brew install python3 And you are done, just type python3 on terminal and you will ...
0
false
3
2,887
2013-11-20 03:47:19.150
How can I make one canvas object collside with another canvas object using Tkinter?
So basically, I'm going to make a Brick Breaker type of game. Just my beginning CS Python class didn't teach much OO programming, and I was wondering how I could make this free moving ball register when it hits the slider. I think I have an idea, but I would like to see other peoples explanations.
You know the position of the two objects that can collide and compute the distance. When this is smaller than a threshold then they collide You use the Canvas.find_overlapping(*rectangle). to find out the figures on the canvas in a rectangle. I always prefer option 1. It helps dividing model and presentation to the us...
0
false
1
2,888
2013-11-21 13:03:05.913
The paths of picture locations in python
I have following problem. When i am trying to open Python game files which i downloaded from internet (on the cmd), then i cant run them, because my computer doesn't find pictures which are in code. Even though the main code and pictures are in the same folder. If i insert full paths of the pictures locations, then eve...
Try looking at Relative Paths. Additionally, without seeing your image loading code it is really quite hard to help you.
0
false
1
2,889
2013-11-21 17:57:27.770
how to find if specifc version is outdated
Is there a way to know if specific version is outdated? I know I can use pip list -o, but this goes over all packages, and I would like to get only for specific version. thanks. Eran
Ugly workaround: create virtualenv, install demanded package with pip, use pip list -o in both real environment and virtual one, compare output...
0
false
1
2,890
2013-11-22 08:09:48.693
Calling exe in Windows from Linux
Background knowledge: Website in Django run under apache. Briefly speaking, I need to call an .exe program in a windows machine from a Linux machine. The reason for this is our website runs on Linux, but one module relies on Windows DLL. So we plan to put it on a separate windows server, and use some methods to call ...
I can think of some ways to do this: Use web services with real REST protocol and cross-site scripting protection Use WINE (As OneOfOnes suggested in his comment) But this is very risky for real production and might not work at all (or just when the load will become heavier) Write some code in the windows machine a...
0
false
1
2,891
2013-11-24 08:55:13.307
how can I make a server communicate with more than 1 client at the same time?
I am developing a server using python but the server can communicate with only one client at a time . Even if the server establish connection with more than one clients, it can't make conversation with all clients at the same time. One client should wait until the started conversation end, which may last for several m...
You may use Tornado. It is asynchronic multithreading web-server framework.
0
false
1
2,892
2013-11-25 04:53:41.050
ipython notebook nbconvert - how to remove red 'out[N]' text in top left hand corner of cell output?
I am using nbconvert to produce something as close as possible to a polished journal article. I have successfully hidden input code using a custom nbconvert template. The doc is now looking very nice. But I don't know how to suppress the bright red 'out[x]' statement in the top left corner of the output cells. Anyone...
%%HTML <style> div.prompt {display:none} </style> This will hide both In and Out prompts Note that this is only in your browser, the notebook itself isn't modified of course, and nbconvert will work just the same as before. In case you want this in the nbconverted code as well, just put the <style>div.prompt {display:n...
0.591696
false
1
2,893
2013-11-25 16:49:37.957
Is it possible to debug a method called from the interactive window in PTVS?
When I'm developing in Python I often want to debug a specific method, in which case it makes sense to call the method from the interactive console or debug interactive console. However, when a method is called from the interactive windows in PTVS, it doesn't stop at the break points in said method. If it's possible, p...
When using the regular (non-debug) Python Interactive window, you can actually attach VS to the python.exe process that it is running by using Debug -> Attach to Process. Once that is done, if the interactive window does something to e.g. hit a breakpoint, the debugger will hit on that breakpoint. The tricky part is lo...
1.2
true
1
2,894
2013-11-25 18:18:16.677
Removing first bit
Is there an efficient way to remove the first bit of a number in C++ / Python, assuming you don't know how large the number is or its datatype? I know in Python I can do it by getting the bin(n), truncating the string by 1, and then recasting it to an int, but I am curious if there is a more "mathematical" way to do th...
looking at 110 (6 decimal) The Most Significant bit is 100 (4 decimal) // -- Note that this is always a power of 2 Create a mask: one less than the MSB is 011 (3 decimal) Mask off the highest bit using bitwise-and: 110 & 011 = 10 (2 decimal) Calculating the MSB (Most Significant Bit) has been handled here and elsewhe...
0.386912
false
2
2,895
2013-11-25 18:18:16.677
Removing first bit
Is there an efficient way to remove the first bit of a number in C++ / Python, assuming you don't know how large the number is or its datatype? I know in Python I can do it by getting the bin(n), truncating the string by 1, and then recasting it to an int, but I am curious if there is a more "mathematical" way to do th...
Well, you could create a loop in which you would double some variable (say x) in each iteration and then check whether this variable is greater than your number. If it is, divide it by two and subtract from your number. For example, if your number is 11: -first iteration: x=1<11, so continue -second iteration: x =2<11,...
0.16183
false
2
2,895
2013-11-26 06:19:52.390
Installing bigfloat, GMP and MPFR in windows for python
I am trying to install bigfloat in Python 3.2 on a Windows 7 machine. The documentation says that I first need to install GMP and MPFR. I have downloaded both of these to my desktop (as well as the bigfloat package). However as they are C packages I am not sure how to install them in python (I have tried to find a clea...
There are two versions of gmpy - version 1 (aka gmpy) and version 2 (aka gmpy2). gmpy2 includes MPFR. If you install gmpy2 then you probably don't need bigfloat since the functionality of MPFR can be directly accessed from gmpy2. Disclaimer: I maintain gmpy and gmpy2.
0.135221
false
1
2,896
2013-11-26 20:59:02.030
Recommendation engine using collaborative filtering in Python
I have developed a search engine for restaurants. I have a social network wherein users can add friends and form groups and recommend restaurants to each other. Each restaurant may serve multiple cuisines. All of this in Python. So based on what restaurants a user has recommended, we can zero in on the kind of cuisines...
I think you won't find any out-of-the box solution for you problem, as it is quite specific. What you could do with Neo4j is to store all your data that you use for building recommendations (users, friendships links, users' restaurants recommendations and reviews etc) and then build you recommendation engine on this da...
1.2
true
1
2,897
2013-11-27 04:01:41.600
Output file contains nothing before script finishing
I write a python script in which there are several print statement. The printed information can help me to monitor the progress of the script. But when I qsub the bash script, which contains python my_script &> output, onto computing nodes, the output file contains nothing even when the script is running and printing s...
I like to write data to sys.stderr sometimes for this sort of thing. It obviates the need to flush so much. But if you're generating output for piping sometimes, you remain better off with sys.stdout.
0
false
1
2,898
2013-11-27 13:28:24.903
Django-tables2 Sorting TemplateColumn
Is it somehow possible, to add custom sort method to values generated using TemplateColumn? because on basic it tries to find column name in model and returns FieldError: Cannot resolve keyword u'coulmn_name' into field. Choices are: [all fields in model].
In the matter of fact, this can't be done. if TemplateColumn name is based on name in model, sorting works fine. As far as I am concerned If you want present other data it is impossible.
1.2
true
1
2,899
2013-11-28 17:32:37.397
Mercurial hook: isn't recompiled after change?
Ok, this is really weird. I have an old Mercurial 2.02. with python 2.6 on an old Ubuntu-something (I think 10.4). We are a windows shop, und push regularly, so I wanted kind of a review service. It absolutely worked on windows.. pretxnchangegroup referencing the python file on the drive, worked.. But I made the mista...
I don't know exactly what happened, but it seams like it was not using the script because an exceptions somehow prohibited it from compiling to a pyc, and Mercurial somehow fetched the old version of that pyc file. Not too sure, but that's my best guess (as somehow noone else seems to have an idea and the Mercurial guy...
1.2
true
1
2,900
2013-11-29 10:00:26.797
StarUML for Python
Is there a way using StarUML for reverse engineering Python code to a class diagramm? In the StarUML docs, they say there are modules for language support, but I couldn't find any further information about where and how to install and use. Other UML tools I found didn't match my idea of how a diagramm should look like....
There is a simple possibility: Use PyCharm, a python IDE, which has an integrated UML generator (only in the pro version which is free for students).
0.386912
false
1
2,901
2013-11-29 17:53:48.443
Iterate through 2 loops in GAE Python templates
I am using Jinja2 template in python for Google App Engine. I need to iterate through 2 lists list1 and list2 in the same loop in the html file. I tried using zip as described in some of the posts but it is not working. Something similar in C : for(i=0.j=0; I<len(list1) && j < len(list2) ; I++,j++) Can anyone suggest ...
It sounds like you want to use itertools.product(list1, list2). This will create all combinations of list1 and list2. For example, if list1 = [1,2] and list2 = [1,2,3] then itertools.products(list1,list2) = [ (1,1),(2,1),(3,1),(2,1),(2,2),(2,3)]
0
false
1
2,902
2013-11-29 21:54:07.893
how to start external system application in python specifying startup directory?
For example I know this method: os.system("cmd") but it starts console in the directory of the script or in the dir of the interpreter, is there a way to gain control of this issue ?
You can use os.chdir(target_directory) to change your program's working directory before starting the external application.
-0.201295
false
1
2,903
2013-11-30 01:18:59.670
Custom sorting in for loop
Let's say I am given an array of n points(pair of coordinates). I want to generate a 2D array of points, where ith row has all elements sorted according to their distance from the ith point. There may be better and more efficient algorithms to get the final result, but for some reasons I want to do it by naive algorit...
Maybe use a nested for loop with the outside one looking at the ith point. then inside loop and calculate all the distances. After calculation use a native python sort for that row and then add it to the main 2d array.
0
false
1
2,904
2013-11-30 04:57:56.683
How can I find every pixel on a line with pygame?
Assuming I have a line with coordinates x1,y1 and x2,y2, and I know the length of the hypotenuse connecting those two points (thus also knowing the angle of rotation of the line through trig), if the line is 1 pixel thick how can I find every pixel on that line and store it to a list? I first proposed the simple vector...
Using float you should get all points without duplications - but you need int. Using int you always get duplications - int(0.1) == int(0.2) == int(0.3) == etc.. So you have to check if point is on your list.
0
false
1
2,905
2013-12-01 10:36:09.073
argparse: how to make group of options required only as group
I am using python2.7 and argparse for my script. I am executing script as below: python2.7 script.py -a valuefora -b valueforb -c valueforc -d valueford Now what I want is that, if option -a is given, then only -b, -c, -d options should be asked. In addition to above, I also want to make this group -a -b -c -d as ...
Your best choice is to test for the presence of various combinations after parse_args and use parser.error to issue an argparse compatible error message. And write your own usage line. And make sure the defaults clearly indicate whether an option has been parsed or not. If you can change the -a and -e options to comm...
0.995055
false
1
2,906
2013-12-01 17:29:57.740
Change menu name openerp
I want to change an openerp module menu name. I know how to do it, i'ts actually pretty easy, but this one is a core module sale and i don't want to touch it's code, because of updates issues and stuff. So, i'll need to inherit this view and change it's name, from another module, can i do this without a module.py or a ...
yes you can. you just need to create a module with two files. one is __openerp__.py with correct dependency to the base modules and an xml file for updating the menu name.
1.2
true
1
2,907
2013-12-02 09:29:00.120
I need to overwrite an existing Python installation in ubuntu 12.04.3
and thanks ahead of time. I am relatively new to Linux and am using Ubuntu 12.04.3. Basically, I've been messing around with some files trying to get Django to work. Well, I though I should do another install of Python2.7 for some reason. Stupidly, I manually installed it. Now when I open the Python shell and do 'i...
Sounds like an issue with your path - python not finding django becuase it doesnt know where to look for it. Look up issues regarding path and see if those help.
1.2
true
1
2,908
2013-12-02 20:27:08.573
Import in python, two modules sharing common resource
For instance, consider 3 modules namely "apple", "orange" and "fruit". Module "apple" imports "orange" and "fruit". Module "orange" imports "fruit" only. Since "fruit" is common for both, could this be done in a different way? Is this inefficient in terms of memory usage and speed? I wonder how this is done in profess...
Modules that are imported more than one are generally only initialized once and the namespace is introduced into the scope of the module. So in your example above there is one class fruit and the two classes that inherit from it and if you were to introduce 3 varieties of apple there would still only be one underlying...
1.2
true
1
2,909
2013-12-03 10:28:52.193
Compare two databases and find common value in a row
I have two databases (infact two database dump ... db1.sql and db2.sql) both database have only 1 table in each. in each table there are few columns (not equal number nor type) but 1 or 2 columns have same type and same value i just want to go through both databases and find a row from each table so that they both ha...
You can use Join with alias name.
0
false
2
2,910
2013-12-03 10:28:52.193
Compare two databases and find common value in a row
I have two databases (infact two database dump ... db1.sql and db2.sql) both database have only 1 table in each. in each table there are few columns (not equal number nor type) but 1 or 2 columns have same type and same value i just want to go through both databases and find a row from each table so that they both ha...
Not sure if I understand what it is you want to do. You want to match a value from a column from one table to a value from a column from another table? If you'd have the data in two tables in a database, you could make an inner join. Depending on how big the file is, you could use a manual comparison tool like WinMerge...
0
false
2
2,910
2013-12-03 16:01:50.257
Python: TypeError in referencing item in JSON feed
First, here is a sample JSON feed that I want to read in Python 2.7 with either simplejson or the built in JSON decoder. I am loading the .json file in Python and then searching for a key like "Apple" or "Orange" and when that key is found, I want to bring in the information for it like the types and quantities. Right ...
The problem is that the data structure has a list enclosing the dictionaries. If you have any control over the data source, that's the place to fix it. Otherwise, the best course is probably to post-process the data after parsing it to eliminate these extra list structures and merge the dictionaries in each list into a...
0.135221
false
1
2,911
2013-12-05 00:59:12.780
SQLAlchemy, how many rows were commited on last commit
Is there a way to know how many rows were commited on the last commit on a SQLAlchemy Session? For instance, if I had just inserted 2 rows, I wish to know that there were 2 rows inserted, etc.
You can look at session.new, .dirty, and .deleted to see what objects will be committed, but that doesn't necessarily represent the number of rows, since those objects may set extra rows in a many-to-many association, polymorphic table, etc.
1.2
true
1
2,912
2013-12-05 15:03:31.583
How to remove a package from Pypi
How do I remove a package from Pypi? I uploaded a package to Pypi several months ago. The package is now obsolete and I'd like to formally remove it. I cannot find any documentation on how to remove my package.
Login. Go to your packages. Check the "remove" checkbox for the particular package. Click "Remove" button.
1.2
true
1
2,913
2013-12-05 17:44:33.457
PHP / Python / Ruby - Long running tasks with short previews
I have a web frontend which uses data from a task that must be run frequently in bulk (which takes more time than I'd like to use PHP for). The data can be stored in a database so I was planning on writing a Java application to run the task and use the database as a middleman to get the results of this task accessible ...
Language is irrelevant. Just put "short" operation in function (object, if it is complex) and use it from 2 places: web-code which needs "preview" will call it once and get its piece of data long-running background process will call it iteratively as much as needed and will store result of function in DB instead of re...
1.2
true
1
2,914
2013-12-05 21:38:57.153
How to tie two windows together in pyqt4
I have two pyqt files that I made in qt4 designer. I put them both in a directory and created a file outside the directory, which I imported them with. The first file is a window with a button, that when clicked, should close the first window, and open the second window. I can import them, and launch them both at the...
In the handler of the button-click in the first window, instantiate the second window and invoke its show-method, and then close (emit the close-signal to) the first window.
0
false
1
2,915
2013-12-06 03:29:53.027
python pandas 3 smallest & 3 largest values
How can I find the index of the 3 smallest and 3 largest values in a column in my pandas dataframe? I saw ways to find max and min, but none to get the 3.
What have you tried? You could sort with s.sort() and then call s.head(3).index and s.tail(3).index.
0.386912
false
1
2,916
2013-12-06 10:47:19.093
How do I store files in googleappengine datastore
Just wondering how to store files in the google app engine datastore. There are lots of examples on the internet, but they are using blobstore I have tried importing db.BlobProperty, but when i put() the data it shows up as a <Blob> i think. It appears like there is no data Similar to None for a string Are there any ex...
Datastore has a limit on the size of objects stored there, thats why all examples and documentation say to use the blobstore or cloud storage. Do that.
0
false
1
2,917
2013-12-06 15:09:47.203
Web2py launch script
I need a launch script which has access to "db" and other web2py modules. This script must be running constantly. I know that Web2py has launch parameters from which you can run python files in the web2py enviroment, but i don't know how that works. Can this parameter solve my problem and if so, how do I go about it? T...
Look at section 4.17.1 of the web2py manual (or Google "web2py cron"). You can run a script on startup of web2py by registering it in the crontab file as: "@reboot web2py *scripts/myscript.py" web2py should be the username that it will run as, which should be the same as what web2py runs as. In my setup I have a user n...
1.2
true
1
2,918
2013-12-06 21:16:59.173
Using vagrant as part of development environment
I'm investigating ways to add vagrant to my development environment. I do most of my web development in python, and I'm interested in python-related specifics, however the question is more general. I like the idea of having all development-related stuff isolated in virtual machine, but I haven't yet discovered an effe...
In most IDE you can add "library" path which are outside the project so that your code completion etc works. About the traceback, I'm unfamiliar with python but this sounds like issue that are resolved by "mapping" paths between servers and dev machine. This is generally the reason why #2 is often the way to go (Except...
0
false
1
2,919
2013-12-08 15:29:14.193
Finding Locations with n Miles of Existing Locations
Problem I have a list of ~5000 locations with latitude and longitude coordinates called A, and a separate subset of this list called B. I want to find all locations from A that are within n miles of any of the locations in B. Structure All of this data is stored in a mysql database, and requested via a python script. A...
Load B into a python list and for each calculate maxlat, minlat, maxlong, minlong that everything outside of the box is definitely outside of your radius, if your radius is in nautical miles and lat/long in degrees. You can then raise an SQL query for points meeting criteria of minlat < lat < maxlat and minlong < long...
1.2
true
1
2,920
2013-12-08 19:35:20.770
How to use 2to3 properly for python?
I have some code in python 2.7 and I want to convert it all into python 3.3 code. I know 2to3 can be used but I am not sure exactly how to use it.
To convert all python 2 files in a directory to 3, you simply could run $ C:\Program Files\Python\Tools\Scripts\2to3.py -w -n. inside the directory that you want to translate. It would skip all the non .py files anyway, and convert the rest. note: remove the -n flag, if you want the backup file too.
0.222949
false
3
2,921
2013-12-08 19:35:20.770
How to use 2to3 properly for python?
I have some code in python 2.7 and I want to convert it all into python 3.3 code. I know 2to3 can be used but I am not sure exactly how to use it.
The python 2to3.py file is mostly found in the directory C:/Program Files/Python/Tools/scripts if you already have python installed. I have python 3.6 and 2to3 is in the directory C:/Program Files/Python36/Tools/scripts. To convert a certain python 2 code to python 3, go to your command promt, change the directory to C...
-0.090455
false
3
2,921
2013-12-08 19:35:20.770
How to use 2to3 properly for python?
I have some code in python 2.7 and I want to convert it all into python 3.3 code. I know 2to3 can be used but I am not sure exactly how to use it.
Running it is very simple! I am going to consider you already have it installed and explain step-by-step how to proceed after that: Open terminal (or cmd for win users) inside the main folder containing the files you want to convert e.g. C:\Users\{your_username}\Desktop\python2folder Type python {your_2to3.py_insta...
0.04532
false
3
2,921
2013-12-09 09:23:03.190
Which urllib I should choose?
as we know, python has two built-in url lib: urllib urllib2 and a third-party lib: urllib3 if my requirement is only to request a API by GET method, assume it return a JSON string. which lib I should use? do they have some duplicated functions? if the urllib can implement my require, but after if my requirem...
Personally I avoid to use third-party library when possible, so I can reduce the dependencies' list and improve portability. urllib and urllib2 are not mutually exclusive and are often mixed in the same project.
0.135221
false
2
2,922
2013-12-09 09:23:03.190
Which urllib I should choose?
as we know, python has two built-in url lib: urllib urllib2 and a third-party lib: urllib3 if my requirement is only to request a API by GET method, assume it return a JSON string. which lib I should use? do they have some duplicated functions? if the urllib can implement my require, but after if my requirem...
As Alexander says in the comments, use requests. That's all you need.
1.2
true
2
2,922
2013-12-09 17:37:41.567
How to know if a list has an even or odd number of elements
How can I find out if there is even, or odd, number of elements in an arbitrary list. I tried list.index() to get all of the indices... but I still don't know how I can tell the program what is an even and what is an odd number.
Even numbers are divisible by 2. Odd numbers are not. len(X) will get the length of X If the length of X is divisible by 2, then it is an Even number If the length of X is not divisible by 2 then it is an Odd Number len(X)%2 returns the "remainder" of a division problem for example 5%2 will return 1 which is NOT zero, ...
0
false
1
2,923
2013-12-10 08:32:08.283
How do I test the setup.py for my package?
I have a pretty big Python package I've written, about 3500 statements, with a robust unit and acceptance test suite. I feel quite confident about the quality of the code itself, but I'm uneasy about the install process going smoothly for users of the package as I don't know how to reliably test the install in an appro...
If you really want isolation instead just doing python setup.py install in virtualenv. Then use virtualbox and install some free linux os in it. Take a snapshot of the machine after the install so you can revert easily with one click to the starting point at any time and try python setup.py install there.
0.386912
false
1
2,924
2013-12-10 10:57:46.113
file upload turbogears 2.3.1
how to do file uploading in turbogears 2.3.1? I am using CrudRestController and tgext.datahelpers and it is uploading the file in the sqlite3 database but in an unknown format. I want to make a copy of the uploaded file in the hard drive. My query is how to ensure that when user uploads a file, it is loaded both in the...
tgext.datahelpers uploads files on disk inside the public/attachments directory (this can be change with tg.config['attachments_path']). So your file is already stored on disk, only the file metadata, like the URL, filename, thumbnail_url and so on are stored on database in JSON format
1.2
true
1
2,925
2013-12-10 17:05:45.103
How can I easily find out if a Python class accepts the with keyword?
The only time I ever use the with keyword is when reading and writing files, mostly because that's the only case I actually know that I can use it. I can imagine there are numerous instances where I preferably could have used with, but didn't know a class or method accepted it. So, how do I detect instances where the ...
Context managers all have __enter__() and __exit__() methods, so checking to see if those attributes exist and that they have __call__ attributes will work almost all the time. But yeah, read the code and/or documentation for the class first.
1.2
true
1
2,926
2013-12-10 18:45:50.950
Setting the angle of a turtle in Python
I'm creating a function that will cause a giraffe to move in a certain direction and distance (don't ask). If the user types "west" in the parameters, the turtle should move west however the direction is. But the turtle's angle changes every time, I can't fix a value for my turtle to turn to go a certain direction. I ...
turtle.right(90) this will turn the turtle 90
-0.905148
false
1
2,927
2013-12-11 00:00:29.757
how to Start python shell program on windows 7 startup?
I have made a program that takes infrared values serially, transmits them them to another program(the one im having trouble with), and uses the win32 python api to react to a matched value. It all works, but I need this program to run on the startup of my computer. It uses the IDLE python shell to run, and I need to op...
Create a batch file with the line start C:\python27\python.exe D:your_program_location\your_program.py' Drag the batch file from desktop to "Start - All Programs - Startup". That should do the trick.
1.2
true
2
2,928
2013-12-11 00:00:29.757
how to Start python shell program on windows 7 startup?
I have made a program that takes infrared values serially, transmits them them to another program(the one im having trouble with), and uses the win32 python api to react to a matched value. It all works, but I need this program to run on the startup of my computer. It uses the IDLE python shell to run, and I need to op...
It sounds like your actual problem is just that you didn't put the right extension on the file. Just rename it to, e.g., script.py, or script.pyw, and, unless you've changed the settings from the default, that should open the file with the command-line or windowed Python launcher, which will just run it. If you've chan...
0
false
2
2,928
2013-12-11 01:54:11.983
how to randomise the image shown in a sketchpad
I really appreciate any responses. I am thoroughly confused and never knew this experiment design/builder software was so complicated! I am a fast learner, but still a newbie so please be patient. Yes I have googled the answers for my question but no answers to similar questions seem to work. I have an experiment, ther...
To generate retrieve the path of a random image in a folder img_folder, it's not too difficult. You can use img_path_array = os.listdir('.../img_folder'). Randomly generate an integer between 0 and len(img_path_array) using random_index = randrange(len(img_path_array)) (import random to use this function), and gain acc...
0.201295
false
1
2,929
2013-12-11 19:19:37.837
Checkbox validation: how do i ensure user can only tick one box only?
I am trying to create a multiple choice quiz in Tkinter. Each question has between 2-4 different answers all displayed as checkboxes, how do I ensure the user can only tick one check box and not all of them? Thanks
Don't use checkboxes; use radoibuttons instead. The behavior of checkboxes and radiobuttons is well established -- checkboxes allow you to select N of N choices, radiobuttons are designed to allow you to select exactly 1 of N. Don't violate this design pattern or your users will be confused. To make radiobuttons work,...
0.201295
false
1
2,930
2013-12-11 21:04:04.753
Time complexity of os.walk in Python
I've to calculate the time-complexity of an algorithm, but in it I'm calling os.walk which I can't consider as a single operation but many. The sources of os.walk left me confused as the filetree may be ordered in many ways (1.000.000 files in a folder or a file per folder and 1.000.000 folders. I'm not an expert on t...
This is too long for a comment: in CPython, a yield passes its result to the immediate caller, not directly to the ultimate consumer of the result. So, if you have recursion going R levels deep, a chain of yields at each level delivering a result back up the call stack to the ultimate consumer takes O(R) time. It al...
0.591696
false
2
2,931
2013-12-11 21:04:04.753
Time complexity of os.walk in Python
I've to calculate the time-complexity of an algorithm, but in it I'm calling os.walk which I can't consider as a single operation but many. The sources of os.walk left me confused as the filetree may be ordered in many ways (1.000.000 files in a folder or a file per folder and 1.000.000 folders. I'm not an expert on t...
os.walk (unless you prune it, or have symlink issues) guarantees to list each directory in the subtree exactly once. So, if you assume that listing a directory is linear on the number of entries in the directory,* then if there are N total directory entries in your subtree, os.walk will take O(N) time. Or, if you want ...
0.265586
false
2
2,931
2013-12-12 12:34:05.943
How to save a temporary value in a security token?
Is it possible to save a value in a security token memory by using PyKCS11 and M2Crypto? I need to save an integer to token memory, so that the value can be carried out with the token I know how to create objects, but is it possible to create attributes in a token, so whenever I read that attribute I will know the stat...
using PKCS#11, the only way to store 'home made' data, it through the use of a CKO_DATA object type. Like any object, it can be persistent on the token (not lost when the token is powered off) or it can be a memory object (lost when the session to the token is closed). To create a CKO_DATA object is similar to any othe...
0
false
1
2,932
2013-12-12 15:08:01.373
In Python, how do I debug with an interactive command line (and visual breakpoints?)
I've recently moved from Matlab to Python. Python is a much better language (from the point of view of a computer scientist), but Python IDEs all seem to lack one important thing: A proper interactive debugger. I'm looking for: The ability to set breakpoints graphically by clicking next to a line of code in the editor...
You can do all this in the iPython Notebook. Use the magic command %pdb to stop on error.
1.2
true
1
2,933
2013-12-13 01:36:27.570
create files, with a template and a list of name and save on files
I have a list of fruits example: "banana", "apple", "grape", "strawberry" and I want to create files with the text: "This fruit is %fruit name%, its delicious" and save as %fruit name%.fruits how i do that? cam be in any language
I don't recommend trying this in batch file. Learning the basics of a scripting language such as Python or Perl is much better for this type of work.
-0.201295
false
1
2,934
2013-12-13 19:04:30.483
Distribution Python package to Debian package with installing additional things
I have a Django project needed to be installed in Debian. I make packages via stdeb. I do not understand two things, on which I can`t find answers: How to install not only Django project, but also Python and Django with it? What and where and how should I write the script? This project demand different additions, such...
How to install not only Django project, but also Python and Django with it? What and where and how should I write the script? If you created a deb file, as it gets interpreted, you should write the python dependency in the debian/control file. This project demand diffrent additions, such as grappelli, tinymce, filebr...
0
false
1
2,935
2013-12-14 20:26:58.557
Sqlalchemy, python, easiest way to populate database with data
I tend to start projects that are far beyond what I am capable of doing, bad habit or a good way to force myself to learn, I don't know. Anyway, this project uses a postgresql database, python and sqlalchemy. I am slowly learning everything from sql to sqlalchemy and python. I have started to figure out models and the ...
You could use a schema change management tool like liquibase. Normally this is used to keep your database schema in source control, and apply patches to update your schema. You can also use liquibase to load data from CSV files. So you could add a startup.csv file in liquibase that would be run the first time you run l...
1.2
true
1
2,936
2013-12-16 07:31:39.220
Adding external packages to elastic beanstalk python app
I was wanting to use some non-standard python packages in my project and was wondering how to add them. What is the benefit of using the AWS eb config files (.ebextensions and requirements.txt) rather than just downloading and including the package in my actual project under a lib directory like you would with a java a...
by including it in the requirements.txt, you can include only the packages you are calling. Pip then takes care of installing the dependencies and checking the versions. This has the additional advantage of when you are changing or upgrading your project, you can specify a new version of the library you are using and ...
1.2
true
1
2,937
2013-12-16 15:20:34.843
finding static scheduling of DAG for multiprocessors - library?
I have a graph of the dependencies of all tasks, and the costs of each task. Now I want to calculate a scheduling for a given amount of CPUs. I've found many papers on scheduling algorithms, optimal schedulers seem to be too expensive for my problem size (around 100 nodes) as it's an NP-hard problem. I'd settle for a h...
This is a pretty common problem. It also shows up in hardware design. There has been a lot of work on algorithms to solve it. If you are going to write something yourself, start by checking out "Hu's Algorithm". If you just want a solution, these functions are built into architectural synthesis programs. Look at ...
1.2
true
1
2,938
2013-12-17 12:35:37.353
How can I load a .ply file in blender-2.68 and apply modifier to it through command line/script?
I want to apply a modifier to large number of meshes stored in different .ply files. I wish to do this through command line so that the process can be automated. I know the basic of blender python API like how to write the modifier in python. But that required me to first import .ply file in blender using UI and then r...
I finally got the solution to the problem. 1. Invoke blender through command line blender.exe --background --python yourFile.py 2. In your python file, you could use the modules provided by blender such as import_ply (....Blender/2.68/scripts/addons/import_ply), etc. Just go through the module and you will be able to ...
1.2
true
1
2,939
2013-12-17 14:59:34.690
Skip rows during csv import pandas
I'm trying to import a .csv file using pandas.read_csv(), however, I don't want to import the 2nd row of the data file (the row with index = 1 for 0-indexing). I can't see how not to import it because the arguments used with the command seem ambiguous: From the pandas website: skiprows : list-like or integer Row numbe...
skip[1] will skip second line, not the first one.
-0.135221
false
1
2,940
2013-12-18 14:17:53.487
Can QRegExp do MULTILINE and DOTALL match?
Recently I've been working on a PyQt program. In the beginning I used python re module to process the regex, but the transformation between python string and QString makes me confused. So I tried to change QRegExp. However, I want to use the IGNORECASE, MULTILINE, DOTALL of the python re. I've found the QRegExp.setCase...
Just to post an answer on this side of things... In most cases I've played with, the DOTALL "(.*?)" approach doesn't seem to match anything when it comes to QRegExp(). However, here's something I use that works in almost all my cases for matching triple-quoted strings: single: "[^#][uUbB]?[rR]?(''')[^']*(''')" double: ...
0
false
1
2,941
2013-12-18 14:44:20.103
What's the difference between kmeans and kmeans2 in scipy?
I am new to machine learning and wondering the difference between kmeans and kmeans2 in scipy. According to the doc both of them are using the 'k-means' algorithm, but how to choose them?
Based on the documentation, it seems kmeans2 is the standard k-means algorithm and runs until converging to a local optimum - and allows you to change the seed initialization. The kmeans function will terminate early based on a lack of change, so it may not even reach a local optimum. Further, the goal of it is to gen...
0.999998
false
1
2,942
2013-12-18 19:40:29.793
screen support in kivy set to normal and large screens
Is there a way to establish a "supports-screens" kind of configuration to make my application available only for normal and large screens android devices.is there a way to do this with the build.py script?(i have bets on --intent-filters option but not sure how it might be used)
There is no way to do it from the build.py. However, you can change manually the templates/AndroidManifest.xml.tmpl and adapt it for your needs.
1.2
true
1
2,943
2013-12-19 14:40:27.707
Open .scd files in python?
I am trying to make a program with python that downloads a large .scd file, unpacks it, and then installs it. It is not at all difficult for me to download it or install it, (which is pretty much just using urllib and moving a few files around) but unpacking it seems to be a problem. After a couple hours of Googling I ...
OK, after numerous hours on google I found out that .scd's are basically .zip's with a 0% compression rate. Try using the built in zipfile module on your file as though it were a .zip.
0.386912
false
1
2,944
2013-12-19 22:45:09.260
Is this possible - Python script to fill a Google spreadsheet?
I dont even know if this is possible. But if it is, can someone give me the broadstrokes on how I can use a Python script to populate a Google spreadsheet? I want to scrape data from a web site and dump it into a google spreadsheet. I can imagine what the Python looks like (scrapy, etc). But does the language support w...
Yes, it is possible and this is how I am personally doing it so. search for "doGet" and "doPost(e)
0
false
1
2,945
2013-12-19 23:13:06.393
How do I run a keyboard program in the background?
I want to make a program where when you press a keyboard key it plays the next sound in a list of sounds (preferably using C++ or python), but I want this to work in any program (Microsoft Word etc.) and just be running in the background. I have no idea how to do this or even where to look. Also, if anyone knows a good...
You need to search for Keyboard Hooks. Most systems provide a away for you to ask to see any events that go by, either all events, or a subset (keyboard/mouse/etc). This can then be used to respond to them. Its used by Macro software such as AutoHotKey, and by Keyloggers, that try to capture peoples passwords and such...
1.2
true
1
2,946
2013-12-20 03:00:01.560
Dynamically generate valid image of a certain filesize for testing
I'm trying to work out a method for dynamically generating image files with PIL/Pillow that are a certain file size in order to better exercise certain code paths in my unit tests. For example, I have some image validation code that limits the file size to 100kb. I'd like to generate an image dynamically that is 150kb...
Does it have to be exactly 150kb, or just somewhere comfortably over 100kb? One approach would be to create a JPEG at 100% quality, and insert lots of (random) text into all the available EXIF and IPTC headers. Including a large thumbnail image will also push the size up. (And like Bo102010 suggested, you could also ...
0.386912
false
1
2,947
2013-12-23 19:42:21.650
AJAX and Django using the polls app from the tutorial: 2 problems
I'm a newbie here, and much of what I have learned about django and python have come from this website. Thank you all for being so helpful! This is my first question post. I've got 2 problems as I try to extend what I've learned from the Django tutorial (1.6) and try to get the Polls app to load via AJAX. I want to ...
This is a frequent mistake when writing JavaScript. You haven't disabled the default actions on click or submit. This means that the JS execute, calling the ajax, but then immediately the normal browser submit is also executed, causing a refresh. voteBehavior should accept an event parameter, and you should call event....
0.201295
false
1
2,948
2013-12-25 22:33:53.833
How to run Python 3 in Sublime 2 REPL Mac
My question is the following, I have sublime 2 and sublime repl plugin installed all working fine, the only thing i need is to change the version of python that is running on the sublimerepl built in console. What I mean is, I have python 2.7.5 (which is pre installed with maveriks) running fine in sublime (via sublime...
I would suggest to change the directory to /Library/Frameworks/Python.framework/Versions/Current/bin/python3 This way whenever you update python, SublimeREPL will always get the updated version.
0
false
1
2,949
2013-12-26 14:27:36.277
How to run different python versions in cmd
How can I configure windows command dialog to run different python versions in it? For example when I type python2 it runs python 2.7 and when I type python3 it runs python 3.3? I know how to configure environment variables for one version but two? I mean something like Linux terminal.
I also met the case to use both python2 and python3 on my Windows machine. Here's how i resolved it: download python2x and python3x, installed them. add C:\Python35;C:\Python35\Scripts;C:\Python27;C:\Python27\Scripts to environment variable PATH. Go to C:\Python35 to rename python.exe to python3.exe, also to C:\Pyth...
1
false
1
2,950
2013-12-27 02:01:57.977
How do I handle errors in Ren'py
I'm making a game using Ren'py (based on python) and most errors aren't shown, especially the errors in python code. Is there a possibility to check for possible errors at compile time and how do I get where some errors occur? If there are errors the game normally doesn't run or breaks at the a errors appearance withou...
Compile errors will be shown when you first try to compile the RPY files. They will be put in "errors.txt" in your project directory. Most errors are not found at compile-time, however, and will only show up once you encounter them at run-time. You can use Lint to check for some common errors (It's called "Check Scri...
0.201295
false
2
2,951
2013-12-27 02:01:57.977
How do I handle errors in Ren'py
I'm making a game using Ren'py (based on python) and most errors aren't shown, especially the errors in python code. Is there a possibility to check for possible errors at compile time and how do I get where some errors occur? If there are errors the game normally doesn't run or breaks at the a errors appearance withou...
If you're looking for some kind of intellisense like you have for some languages, where as you write the code the IDE shows errors, then it doesn't exist. You have to launch the game so that the code is compiled, just then Ren'py will show you errors. You can see them in the editor or in the errors.txt that Ren'Py crea...
0
false
2
2,951
2013-12-27 22:52:09.190
Apache: python directory restriction
Lets say I have directory with subdirectories where are projects stored. How to lock Python script inside that subdirectory ? That it can not scan parent directories, read files, import etc. Is it possible with mod_wsgi ? And how to disable any python functions ? Thank
There are two options. Use mod_wsgi daemon mode and run the daemon process as a distinct user. Then lock down all your file permissions appropriately to deny access from that user. The second is that mod_wsgi daemon mode also supports a chroot option. Using a chroot is obviously a lot more complicated to set up however...
0
false
1
2,952
2013-12-28 15:38:09.150
Architecture for a self-running Python script on Mac OSX
I have the following set-up A Python script A Mac OSX Automator application with said script An iCal alert that runs the Automator (and thus the Python script) on a regular schedule All of the above works just fine. But I need to make a change. I need the script to check a web site for a time in the future (that same...
Set a variable to the future time, and check it in a while() loop
0
false
1
2,953
2013-12-28 17:07:18.940
In PyCharm, how to navigate to the top of the file?
I'm new to PyCharm and haven't been able to figure out what I'm sure is a very simple thing -- what's the key stroke to go to the top of the current file? (Bonus question -- is there a way to scroll to the top of the current file without moving the cursor there also, a la the Home key in Sublime Text 2?)
Another way is to navigate to the first line using goto line: Ctrl-G and then 1. But this will move the cursor to the first line. A small disadvantage is it is a two step process and adds a navigation step. Moving back to your previous location with CtrlAlt-< will have to be done in two steps if you do an edit.
0.201295
false
2
2,954
2013-12-28 17:07:18.940
In PyCharm, how to navigate to the top of the file?
I'm new to PyCharm and haven't been able to figure out what I'm sure is a very simple thing -- what's the key stroke to go to the top of the current file? (Bonus question -- is there a way to scroll to the top of the current file without moving the cursor there also, a la the Home key in Sublime Text 2?)
You navigate to the top of the file using Ctrl+Home. It moves cursor too. So does navigating via Page Up and Page Down keys. Ctrl+Up and Ctrl+Down move the view without moving cursor but scrolling the long file takes some time. Additionally You can change the keymap (Settings > Keymap). There is 'Scroll to Top' in 'Edi...
1.2
true
2
2,954
2013-12-30 03:17:23.633
Display Python Output in Sublime text
New to Python & Sublime Problem: I type 'print ("Hello world") How do I get it to show me the output (Hello world), is it in a separate window? or... I understand I can use the Python Console built in, but that's a command line, what about when I get to use a ton of code, how do I get the output?
Click on tools > build systems > select Python, then Build with using ctr+shif B and select python, and it ll work. Second time you can use the build command, ctr + B since python is now set as default
0.99039
false
1
2,955
2013-12-30 20:36:27.943
How to achieve realtime updates on my website (with Flask)?
I am using Flask and I want to show the user how many visits that he has on his website in realtime. Currently, I think a way is to, create an infinite loop which has some delay after every iteration and which makes an ajax request getting the current number of visits. I have also heard about node.js however I think t...
In my opinion, the best option for achieving real time data streaming to a frontend UI is to use a messaging service like pubnub. They have libraries for any language you are going to want to be using. Basically, your user interfaces subscribe to a data channel. Things which create data then publish to that channel, an...
0.101688
false
1
2,956
2013-12-30 21:11:40.313
PyDev won't start in Aptana Studio3
Aptana Studio is my primary Python IDE and I have been using it for years with much joy and success! Recently, when I start Aptana Studio it fails to recognize any PyDev projects that I have previously created. I noticed that this was happening after installing a recent update of the IDE. I tried uninstalling Aptana an...
I went back to the Aptana website and this time around it gave me Aptana Studio 3, build: 3.4.2.201308081805 which works fine. 3.5.0 does still not appear to work for Python development at the moment.
0
false
2
2,957
2013-12-30 21:11:40.313
PyDev won't start in Aptana Studio3
Aptana Studio is my primary Python IDE and I have been using it for years with much joy and success! Recently, when I start Aptana Studio it fails to recognize any PyDev projects that I have previously created. I noticed that this was happening after installing a recent update of the IDE. I tried uninstalling Aptana an...
Aptana 3.5.0 and PyDev 3.0 does not work under Mac OS X 10.9 Mavericks yet. PyDev reports builtin symbols such as None could not be recognized. I rolled back to 3.4.2 as well.
0
false
2
2,957
2013-12-31 06:18:57.560
How can i get a list of all built-in objects in python recursively?
how can i get a list of all built-in objects in python recursively? what i'm exactly searching for is a function like dir() which returns a list of objects instead of strings. also, why does "dir(__builtins__.print)" fail in python's interactive mode with a syntax error? thanks for your answers!
A dictionary of key value pairs: __builtins__.__dict__ Only the objects: __builtins__.__dict__.values() These will give you a list of a dictionary you can iterate over to your hearts content! EDIT: Not recommended, see below comment and that users answer
0.496174
false
1
2,958
2013-12-31 08:24:52.163
Practical use of Python as Chrome Native Client
There is a Python interpreter in naclports (to run as Google Chrome Native Client App). Are there any examples for bundling the interpreter with a custom Python application and how to integrate this application with a HTML page?
The interpreter is currently the only python example in naclports. However, it should be possible to link libpython into any nacl binary, and use it just as you would embed python in any other C/C++ application. A couple of caveats: you must initialize nacl_io before making any python calls, and as you should not m...
1.2
true
1
2,959
2013-12-31 11:44:44.457
auth is not available in module
I have a web2py application where I have written various modules which hold business logic and database related stuff. In one of the files I am trying to access auth.settings.table_user_name but it doesn't work and throws and error as global name 'auth' is not defined. If I write the same line in controller, it works. ...
I was getting a very similar error ("name 'auth' is not defined"). Had to add from django.contrib import auth at the top of views.py and it worked.
0
false
1
2,960
2014-01-02 08:01:43.140
Lazy psql connection with Django
I have a Django app that has several database backends - all connected to different instances of Postgresql database. One of them is not guaranteed to be always online. It even can be offline when application starts up. Can I somehow configure Django to use lazy connections? I would like to: Try querying return "sorry...
The original confusion is that Django tries to connect to its databases on startup. This is actually not true. Django does not connect to database, until some app tries to access the database. Since my web application uses auth and site apps, it looks like it tries to connect on startup. But its not tied to startup, it...
0.673066
false
1
2,961
2014-01-03 05:28:22.077
How to draw and fill a polygon on a grid array using pure Numpy functions?
Here goes a difficult one for the expert Numpyer! Does someone know or can come up with a way to use pure Numpy arrays and functions to draw as well as fill colored polygons on top of a numpy array grid? This I think would take two steps: The ability to fill the grid array with color values so that the polygon fillin...
In this case the point to achieve speed is more the used algorithms than the language of choice. Drawing and filling poligons rasterized over a grid of pixel falls into the domain of image processing algorithms and for sure AggDraw is using algorithms from that field. The idea is that if you evaluate for each points a ...
1.2
true
1
2,962
2014-01-03 09:36:07.443
How to Write Python Script in html
I want to execute my python code on the side even though there might be security problem How can I write with importing modules and all? I have tried using of pyjs to convert the below code to JS import socket print socket.gethostbyname_ex(socket.gethostname())[2][0] but I am not find how to do the same. Please he...
There are more than just security problems. It's just not possible. You can't use the Python socket library inside the client browser. You can convert Python code to JS (probably badly) but you can't use a C based library that is probably not present on the client. You can access the browser only. You cannot reliably g...
0.386912
false
1
2,963
2014-01-03 19:20:04.257
Choose random seed and save it
I would like to choose a random seed for numpy.random and save it to a variable. I can set the seed using numpy.random.seed(seed=None) but how do you get numpy to choose a random seed and tell you what it is? Number seems to use /dev/urandom on linux by default.
When people need a random seed that can be recorded, people usually use the system time as a random seed. This means your program will act differently each time it is run, but can be saved and captured. Why don't you try that out? If you don't want to do that for some reason, use the null version, numpy.random.seed(see...
0.081452
false
1
2,964
2014-01-04 03:40:04.123
How do I reference all class instances at the same time?
I have a class called Mobilesuits and each instance of that class has an attribute called coordinates, which consists of its grid coordinates, which are in a list(x,y,z). I am trying to make a radar method which would detect how close a given vehicle is to other vehicles, but can't find a way to reference every objects...
I don't want to have to maintain a list It's what you are meant to do; and you would have to use loops anyway. You're effectively asking the language to create a list for you automatically. Well, why would it? Contrary to what you might expect, you almost always will not need or want a list of every single instance of...
0
false
1
2,965
2014-01-05 08:04:28.557
Bypassing Cloudflare Scrapeshield
I'm working on a webscraping project, and I am running into problems with cloudflare scrapeshield. Does anyone know how to get around it? I'm using selenium webdriver, which is getting redirected to some lightspeed page by scrapeshield. Built with python on top of firefox. Browsing normally does not cause it to redirec...
See, what scrapeshield does is checking if you are using a real browser, it's essentially checking your browser for certain bugs in them. Let's say that Chrome can't process an IFrame if there is a 303 error in the line at the same time, certain web browser react differently to different tests, so webdriver must not re...
0.386912
false
1
2,966
2014-01-05 11:51:43.673
Creating a tastypie resource for a "singleton" non-model object
I'm using tastypie and I want to create a Resource for a "singleton" non-model object. For the purposes of this question, let's assume what I want the URL to represent is some system settings that exist in an ini file. What this means is that...: The fields I return for this URL will be custom created for this Resour...
This sounds like something completely outside of TastyPie's wheelhouse. Why not have a single view somewhere decorated with @require_GET, if you want to control headers, and return an HttpResponse object with the desired payload as application/json? The fact that your object is a singleton and all other RESTful interac...
0.201295
false
1
2,967
2014-01-06 16:07:29.383
Keep URL while surfing data Structure in Django web app
I am attempting to create a django based website. The goal of one part of the site is to show the contents of a database in reference to its file structure. I would like to keep the URL the same while traveling deeper into the file structure, as opposed to developing another view for each level of the file structure...
I would suggest looking into forms on the Django documentation site. When the user submits the form the appropriate file structure information will be passed to your view code. The view code can then pass the new file structure information to your template. The template will create the forms and the process will start ...
0
false
1
2,968
2014-01-07 23:39:09.010
Dispersing Random Sampling in CSV through Python
I have a (large) directory CSV with columns [0:3] = Phone Number, Name, City, State. I created a random sample of 20,000 entries, but it was, of course, weighted drastically to more populated states and cities. How would I write a python code (using CSV or Pandas - I don't have linecache available) that would equally p...
There are many ways to implement this, but the abstract algorithm should be something like this. First, to create a new CSV that meets your second critera about each state being drawn with equal probability, draw each row as follows. 1) From the set of states, draw a state (each state is drawn with probability 1 / # o...
0.673066
false
1
2,969