title
stringlengths
10
172
question_id
int64
469
40.1M
question_body
stringlengths
22
48.2k
question_score
int64
-44
5.52k
question_date
stringlengths
20
20
answer_id
int64
497
40.1M
answer_body
stringlengths
18
33.9k
answer_score
int64
-38
8.38k
answer_date
stringlengths
20
20
tags
list
shelve gives strange error
2,601,081
<p>I'm trying to put some sites i crawled into a shelve, but the shelve won't accept any Site-objects. It will accept lists, strings, tuples, what have you, but as soon as i put in a Site-object, it crashes when i try to get the contents of the shelve</p> <p>So when i fill up my shelve like this: </p> <pre><code>def ...
2
2010-04-08T15:15:54Z
2,601,959
<p>It seems that Python is looking for a constructor for a 'Site' object, and not finding it. I have not used shelve, but I recall the rules for what can be pickled are byzantine, and suspect the shelve rules are similar.</p> <p>Try adding the line:</p> <p>Site = sitemodule.Site </p> <p>(with the name of the modul...
0
2010-04-08T17:12:36Z
[ "python", "shelve" ]
shelve gives strange error
2,601,081
<p>I'm trying to put some sites i crawled into a shelve, but the shelve won't accept any Site-objects. It will accept lists, strings, tuples, what have you, but as soon as i put in a Site-object, it crashes when i try to get the contents of the shelve</p> <p>So when i fill up my shelve like this: </p> <pre><code>def ...
2
2010-04-08T15:15:54Z
2,603,107
<p>It looks like you refactored your code after saving objects in the shelve. When retrieving objects from the shelve, Python rebuilds the object, and it needs to find the original class that, presumably, you have moved. This problem is typical when working with <code>pickle</code> (as the <code>shelve</code> module do...
5
2010-04-08T20:12:20Z
[ "python", "shelve" ]
Displaying a webcam feed using OpenCV and Python
2,601,194
<p>I have been trying to create a simple program with <a href="http://en.wikipedia.org/wiki/Python_%28programming_language%29">Python</a> which uses OpenCV to get a video feed from my webcam and display it on the screen.</p> <p>I know I am partly there because the window is created and the light on my webcam flicks on...
47
2010-04-08T15:30:14Z
2,602,410
<p>Try adding the line <code>c = cv.WaitKey(10)</code> at the bottom of your <code>repeat()</code> method.</p> <p>This waits for 10 ms for the user to enter a key. Even if you're not using the key at all, put this in. I think there just needed to be some delay, so <code>time.sleep(10)</code> may also work.</p> <p>I...
41
2010-04-08T18:22:33Z
[ "python", "opencv", "webcam" ]
Displaying a webcam feed using OpenCV and Python
2,601,194
<p>I have been trying to create a simple program with <a href="http://en.wikipedia.org/wiki/Python_%28programming_language%29">Python</a> which uses OpenCV to get a video feed from my webcam and display it on the screen.</p> <p>I know I am partly there because the window is created and the light on my webcam flicks on...
47
2010-04-08T15:30:14Z
9,780,526
<p>This didn't work for me, but the following Gist was "copy/paste play" <a href="https://gist.github.com/2130079" rel="nofollow">https://gist.github.com/2130079</a></p>
0
2012-03-20T02:11:56Z
[ "python", "opencv", "webcam" ]
Displaying a webcam feed using OpenCV and Python
2,601,194
<p>I have been trying to create a simple program with <a href="http://en.wikipedia.org/wiki/Python_%28programming_language%29">Python</a> which uses OpenCV to get a video feed from my webcam and display it on the screen.</p> <p>I know I am partly there because the window is created and the light on my webcam flicks on...
47
2010-04-08T15:30:14Z
9,816,454
<p>If you only have one camera, or you don't care which camera is the correct one, then use "-1" as the index. Ie for your example <code>capture = cv.CaptureFromCAM(-1)</code>.</p>
7
2012-03-22T04:29:28Z
[ "python", "opencv", "webcam" ]
Displaying a webcam feed using OpenCV and Python
2,601,194
<p>I have been trying to create a simple program with <a href="http://en.wikipedia.org/wiki/Python_%28programming_language%29">Python</a> which uses OpenCV to get a video feed from my webcam and display it on the screen.</p> <p>I know I am partly there because the window is created and the light on my webcam flicks on...
47
2010-04-08T15:30:14Z
10,278,137
<p>change <code>import cv</code> to <strong><code>import cv2.cv as cv</code></strong> See also the post <a href="http://xinyustudio.wordpress.com/2012/04/23/using-python-opencv-to-control-webcam-black-window-problem-and-troubleshooting-in-a-single-code-line/" rel="nofollow">here</a>.</p>
0
2012-04-23T09:42:33Z
[ "python", "opencv", "webcam" ]
Displaying a webcam feed using OpenCV and Python
2,601,194
<p>I have been trying to create a simple program with <a href="http://en.wikipedia.org/wiki/Python_%28programming_language%29">Python</a> which uses OpenCV to get a video feed from my webcam and display it on the screen.</p> <p>I know I am partly there because the window is created and the light on my webcam flicks on...
47
2010-04-08T15:30:14Z
11,449,901
<p>An update to show how to do it in the recent versions of OpenCV:</p> <pre><code>import cv2 cv2.namedWindow("preview") vc = cv2.VideoCapture(0) if vc.isOpened(): # try to get the first frame rval, frame = vc.read() else: rval = False while rval: cv2.imshow("preview", frame) rval, frame = vc.read()...
57
2012-07-12T10:28:07Z
[ "python", "opencv", "webcam" ]
Displaying a webcam feed using OpenCV and Python
2,601,194
<p>I have been trying to create a simple program with <a href="http://en.wikipedia.org/wiki/Python_%28programming_language%29">Python</a> which uses OpenCV to get a video feed from my webcam and display it on the screen.</p> <p>I know I am partly there because the window is created and the light on my webcam flicks on...
47
2010-04-08T15:30:14Z
19,993,303
<p>Try the following. It is simple, but I haven't figured out a graceful way to exit yet.</p> <pre><code>import cv2.cv as cv import time cv.NamedWindow("camera", 0) capture = cv.CaptureFromCAM(0) while True: img = cv.QueryFrame(capture) cv.ShowImage("camera", img) if cv.WaitKey(10) == 27: break ...
1
2013-11-15T04:01:32Z
[ "python", "opencv", "webcam" ]
Python to C/C++ const char question
2,601,226
<p>I am extending Python with some C++ code.</p> <p>One of the functions I'm using has the following signature:</p> <pre><code>int PyArg_ParseTupleAndKeywords(PyObject *arg, PyObject *kwdict, char *format, char **kwlist, ...); </code></pre> <p>(link: <a href="http://docs.python.org/re...
5
2010-04-08T15:32:55Z
2,601,358
<p>Does <code>PyArg_ParseTupleAndKeywords()</code> expect to modify the data you are passing in? Normally, in idiomatic C++, a <code>const &lt;something&gt; *</code> points to an object that the callee will only read from, whereas <code>&lt;something&gt; *</code> points to an object that the callee can write to.</p> <...
3
2010-04-08T15:50:35Z
[ "python", "c", "const-char" ]
Arguments, local variables, and global variables coding convention in Python
2,601,269
<p>In python, there is no way to differentiate between arguments, local variables, and global variables. The easy way to do so might be have some coding convention such as </p> <ul> <li>Global variables start with _ and capital letter</li> <li>arguments end with with _</li> </ul> <pre> _Gvariable = 10 def hello(x_, y...
1
2010-04-08T15:39:52Z
2,601,682
<p>I would do all your python programming according to PEP 8 guidelines. Anyone who has to read your code will thank you for it.</p> <p><a href="http://www.python.org/dev/peps/pep-0008/" rel="nofollow">http://www.python.org/dev/peps/pep-0008/</a></p> <p>Why is there a need to distinguish between arguments and local ...
2
2010-04-08T16:28:02Z
[ "python", "coding-style" ]
Arguments, local variables, and global variables coding convention in Python
2,601,269
<p>In python, there is no way to differentiate between arguments, local variables, and global variables. The easy way to do so might be have some coding convention such as </p> <ul> <li>Global variables start with _ and capital letter</li> <li>arguments end with with _</li> </ul> <pre> _Gvariable = 10 def hello(x_, y...
1
2010-04-08T15:39:52Z
2,601,829
<p>That's absolutly awful. There is no reason whatsoever to use a special naming scheme for global and local objects. Also you should avoid having global objects unless they are functions, classes or constants.</p> <p>Names for constants should be uppercase and seperated with underscores LIKE_THIS, class names look Li...
0
2010-04-08T16:51:04Z
[ "python", "coding-style" ]
Arguments, local variables, and global variables coding convention in Python
2,601,269
<p>In python, there is no way to differentiate between arguments, local variables, and global variables. The easy way to do so might be have some coding convention such as </p> <ul> <li>Global variables start with _ and capital letter</li> <li>arguments end with with _</li> </ul> <pre> _Gvariable = 10 def hello(x_, y...
1
2010-04-08T15:39:52Z
2,602,117
<p>It is usually obvious in python which variables are local and which are global, since to modify a global variable you have to declare it using the the <code>global</code> keyword at the start of a function. However I sometimes add a global declaration even if it is not necessary for python to compile it, in order t...
1
2010-04-08T17:32:59Z
[ "python", "coding-style" ]
What is the better error handling method for decoding Python bytes to unicode strings?
2,601,294
<p>I have an old C# program that is being ported to Python 3 for different reasons. Basically, what the program does is to fetch a website and search its content (and process it, but that is not really relevant). I have never really had any issues with the actual fetch-and-search routine, but once I ported it to Python...
0
2010-04-08T15:42:40Z
2,602,548
<p>According to <a href="http://msdn.microsoft.com/en-us/library/system.text.encoding.utf8.aspx" rel="nofollow">http://msdn.microsoft.com/en-us/library/system.text.encoding.utf8.aspx</a> the default UTF-8 decoder of C# ignores invalid bytes.</p> <p>Python's 'ignore' option for decoding unicode is the same as this.</p>...
2
2010-04-08T18:45:45Z
[ "python", "unicode" ]
Return unicode string from python via ajax
2,601,306
<p>I have a small webapp that runs Python on the server side and javascript (jQuery) on the client side. Now upon a certain request my Python script returns a unicode string and the client is supposed to put that string inside a div in the browser. However i get a unicode encode error from Python.</p> <p>If i run the ...
0
2010-04-08T15:44:04Z
2,601,861
<p>If the python interpreter can't determine the encoding of <code>sys.stdout</code> ascii is used as a fallback however the characters in the string are not part of ascii, therefore a <code>UnicodeEncodeError</code> exception is raised.</p> <p>A solution would be to encode the string yourself using something like <co...
3
2010-04-08T16:57:01Z
[ "python", "ajax", "unicode" ]
Django-Registration & Django-Profile, using your own custom form
2,601,487
<p>I am making use of django-registration and django-profile to handle registration and profiles. I would like to create a profile for the user at the time of registration. I have created a custom registration form, and added that to the urls.py using the tutorial on: </p> <p><a href="http://dewful.com/?p=70">http://d...
29
2010-04-08T16:05:30Z
2,687,377
<p>You're halfway there - you've successfully built a custom form that replaces the default form. But you're attempting to do your custom processing with a save() method on your model form. That was possible in older versions of django-registration, but I can see from the fact that you specified a backend in your URL ...
28
2010-04-22T00:03:59Z
[ "python", "django", "django-forms", "registration", "profile" ]
Django-Registration & Django-Profile, using your own custom form
2,601,487
<p>I am making use of django-registration and django-profile to handle registration and profiles. I would like to create a profile for the user at the time of registration. I have created a custom registration form, and added that to the urls.py using the tutorial on: </p> <p><a href="http://dewful.com/?p=70">http://d...
29
2010-04-08T16:05:30Z
2,947,546
<p><a href="http://dmitko.ru/?p=546">Solution with signals</a> - here I wrote how to use signals to save additional data</p>
8
2010-06-01T05:59:03Z
[ "python", "django", "django-forms", "registration", "profile" ]
Django-Registration & Django-Profile, using your own custom form
2,601,487
<p>I am making use of django-registration and django-profile to handle registration and profiles. I would like to create a profile for the user at the time of registration. I have created a custom registration form, and added that to the urls.py using the tutorial on: </p> <p><a href="http://dewful.com/?p=70">http://d...
29
2010-04-08T16:05:30Z
3,298,481
<p>As described in <a href="http://code.djangoproject.com/ticket/7018#comment:9" rel="nofollow">my comment on Django Trac ticket</a> I made a metaclass and mixin to allow multiple inheritance for <code>ModelForm</code> Django forms. With this you can simply make a form which allows registration with fields from user an...
10
2010-07-21T11:01:22Z
[ "python", "django", "django-forms", "registration", "profile" ]
Django-Registration & Django-Profile, using your own custom form
2,601,487
<p>I am making use of django-registration and django-profile to handle registration and profiles. I would like to create a profile for the user at the time of registration. I have created a custom registration form, and added that to the urls.py using the tutorial on: </p> <p><a href="http://dewful.com/?p=70">http://d...
29
2010-04-08T16:05:30Z
23,782,029
<p>With registration 0.8 and later:</p> <p>Create a subclass of registration.backends.default.views.RegistrationView in your views.py or equivalent:</p> <pre><code>from registration.backends.default.views import RegistrationView class MyRegistrationView(RegistrationView): form_class= MyCustomRegistrationForm ...
1
2014-05-21T11:35:07Z
[ "python", "django", "django-forms", "registration", "profile" ]
Executing / Running a python script from ubuntu server
2,601,714
<p>Can anybody help me how to run a python script through command line?</p> <p>My python script <a href="http://buffis.com/2007/07/25/getting-info_hash-for-xbt-tracker/comment-page-1/" rel="nofollow">http://buffis.com/2007/07/25/getting-info_hash-for-xbt-tracker/comment-page-1/</a></p> <p>I am using this command <cod...
1
2010-04-08T16:32:12Z
2,601,732
<p>Try <code>chmod 744</code></p>
0
2010-04-08T16:35:47Z
[ "python", "linux", "bash" ]
Executing / Running a python script from ubuntu server
2,601,714
<p>Can anybody help me how to run a python script through command line?</p> <p>My python script <a href="http://buffis.com/2007/07/25/getting-info_hash-for-xbt-tracker/comment-page-1/" rel="nofollow">http://buffis.com/2007/07/25/getting-info_hash-for-xbt-tracker/comment-page-1/</a></p> <p>I am using this command <cod...
1
2010-04-08T16:32:12Z
2,601,822
<pre><code>python /var/www/hash_info.py /var/www/Muha_Album.7912.torrent </code></pre>
4
2010-04-08T16:50:06Z
[ "python", "linux", "bash" ]
Executing / Running a python script from ubuntu server
2,601,714
<p>Can anybody help me how to run a python script through command line?</p> <p>My python script <a href="http://buffis.com/2007/07/25/getting-info_hash-for-xbt-tracker/comment-page-1/" rel="nofollow">http://buffis.com/2007/07/25/getting-info_hash-for-xbt-tracker/comment-page-1/</a></p> <p>I am using this command <cod...
1
2010-04-08T16:32:12Z
2,601,853
<p>Maybe it says:</p> <pre><code>bad interpreter: No such file or directory </code></pre> <p>Then, the first line, so called <a href="http://en.wikipedia.org/wiki/Shebang_(Unix)" rel="nofollow">shebang line</a> is the issue here. I guess you need to change it to where your python is really installed. On my Ubuntu ins...
3
2010-04-08T16:55:47Z
[ "python", "linux", "bash" ]
How to link as .so instead of .dylib on OSX 10.6 using qmake
2,601,965
<p>I am trying to use SWIG to wrap some C++ code for the use with Python. As described <a href="http://stackoverflow.com/questions/2488016/how-to-make-python-load-dylib-on-osx" title="here">here</a> it seems to be necessary to link my C++ code against an <code>.so</code> file, not a <code>.dylib</code> file. The thread...
2
2010-04-08T17:13:26Z
3,305,612
<p>I think you might have two issues. </p> <p>To get the output file to be a .so file, I set the compile option <strong>-o mylib.so</strong> and that forced gcc to name the file correctly.</p> <p>The other issue I think you might have is that on the Mac, linking against the python lib is not the same as on a Linux ma...
0
2010-07-22T03:34:44Z
[ "python", "swig", "qmake", "dylib", "shared-libraries" ]
how to call a program from python without waiting for it to return
2,602,052
<p>is there a way to call a program from python without waiting for it to return? i created a script which copies a program to a directory and runs that program. but when i call the program from python, the python script does not exit until the program i launched exits. i have tried os.system and Popen. is there anothe...
12
2010-04-08T17:23:13Z
2,602,089
<p>By using <code>poll()</code> instead of <code>wait()</code> on <code>Popen</code> it will not block and it won't wait for the program to run. However, I think the only way to really stop the entire program from waiting is by creating a daemonic thread which starts the process. That way you'll never have to wait for ...
3
2010-04-08T17:27:55Z
[ "python", "command", "subprocess", "popen" ]
how to call a program from python without waiting for it to return
2,602,052
<p>is there a way to call a program from python without waiting for it to return? i created a script which copies a program to a directory and runs that program. but when i call the program from python, the python script does not exit until the program i launched exits. i have tried os.system and Popen. is there anothe...
12
2010-04-08T17:23:13Z
2,602,235
<p>Under Windows, if you invoke the program using the shell <code>START</code> command you should be able to "release" the parent process and allow it to exit. Try <code>START /?</code> at the DOS prompt to learn more.</p>
1
2010-04-08T17:48:57Z
[ "python", "command", "subprocess", "popen" ]
how to call a program from python without waiting for it to return
2,602,052
<p>is there a way to call a program from python without waiting for it to return? i created a script which copies a program to a directory and runs that program. but when i call the program from python, the python script does not exit until the program i launched exits. i have tried os.system and Popen. is there anothe...
12
2010-04-08T17:23:13Z
2,602,752
<p>I posted a solution how to detach a process in a <a href="http://stackoverflow.com/questions/89228/how-to-call-external-command-in-python#2251026">previous question</a>.</p>
5
2010-04-08T19:21:44Z
[ "python", "command", "subprocess", "popen" ]
How to use methods defined in a python scipt from a console like ipython
2,602,188
<p>I have written a python script with methods in it. Now I want to use methods from that script in ipython. How do I import it for use in ipython?</p> <p>Cheers</p>
1
2010-04-08T17:43:03Z
2,602,208
<p>If the file with your functions in it is called mod.py, just:</p> <pre><code>&gt;&gt;&gt; import mod &gt;&gt;&gt; mod.myfunction() </code></pre>
2
2010-04-08T17:45:46Z
[ "python", "scripting", "import", "ipython" ]
How to use methods defined in a python scipt from a console like ipython
2,602,188
<p>I have written a python script with methods in it. Now I want to use methods from that script in ipython. How do I import it for use in ipython?</p> <p>Cheers</p>
1
2010-04-08T17:43:03Z
2,602,211
<p>Inside IPython:</p> <pre><code>cd folder/containing/module import module module.function(1, 2, 3) </code></pre>
0
2010-04-08T17:46:10Z
[ "python", "scripting", "import", "ipython" ]
How to use methods defined in a python scipt from a console like ipython
2,602,188
<p>I have written a python script with methods in it. Now I want to use methods from that script in ipython. How do I import it for use in ipython?</p> <p>Cheers</p>
1
2010-04-08T17:43:03Z
2,602,213
<p>There are several options and all of them work with specific advantages and disadvantages:</p> <pre><code>from module import * import module %edit module.py </code></pre>
1
2010-04-08T17:46:12Z
[ "python", "scripting", "import", "ipython" ]
Is it possible for BeautifulSoup to work in a case-insensitive manner?
2,602,390
<p>I am trying to extract Meta Description for fetched webpages. But here I am facing the problem of case sensitivity of BeautifulSoup. </p> <p>As some of the pages have <code>&lt;meta name="Description</code> and some have <code>&lt;meta name="description</code>. </p> <p>My problem is very much similar to that of <a...
12
2010-04-08T18:18:24Z
2,602,432
<p>You can give BeautifulSoup a regular expression to match attributes against. Something like</p> <pre><code>soup.findAll('meta', name=re.compile("^description$", re.I)) </code></pre> <p>might do the trick. Cribbed from <a href="http://www.crummy.com/software/BeautifulSoup/documentation.html#Searching%20the%20Pars...
11
2010-04-08T18:26:22Z
[ "python", "beautifulsoup" ]
Is it possible for BeautifulSoup to work in a case-insensitive manner?
2,602,390
<p>I am trying to extract Meta Description for fetched webpages. But here I am facing the problem of case sensitivity of BeautifulSoup. </p> <p>As some of the pages have <code>&lt;meta name="Description</code> and some have <code>&lt;meta name="description</code>. </p> <p>My problem is very much similar to that of <a...
12
2010-04-08T18:18:24Z
2,605,635
<p>With minor changes it works.</p> <pre><code>soup.findAll('meta', attrs={'name':re.compile("^description$", re.I)}) </code></pre>
7
2010-04-09T07:03:55Z
[ "python", "beautifulsoup" ]
Is it possible for BeautifulSoup to work in a case-insensitive manner?
2,602,390
<p>I am trying to extract Meta Description for fetched webpages. But here I am facing the problem of case sensitivity of BeautifulSoup. </p> <p>As some of the pages have <code>&lt;meta name="Description</code> and some have <code>&lt;meta name="description</code>. </p> <p>My problem is very much similar to that of <a...
12
2010-04-08T18:18:24Z
15,278,210
<p>A regular expression? Now we have <a href="http://xkcd.com/1171/">another problem</a>.</p> <p>Instead, you can pass in a lambda:</p> <pre><code>soup.findAll(lambda tag: tag.name.lower()=='meta', name=lambda x: x and x.lower()=='description') </code></pre> <p>(<code>x and</code> avoids an exception when the <c...
5
2013-03-07T17:49:57Z
[ "python", "beautifulsoup" ]
Is it possible for BeautifulSoup to work in a case-insensitive manner?
2,602,390
<p>I am trying to extract Meta Description for fetched webpages. But here I am facing the problem of case sensitivity of BeautifulSoup. </p> <p>As some of the pages have <code>&lt;meta name="Description</code> and some have <code>&lt;meta name="description</code>. </p> <p>My problem is very much similar to that of <a...
12
2010-04-08T18:18:24Z
30,557,612
<p>With bs4 use the following:</p> <pre><code>soup.find('meta', attrs={'name': lambda x: x and x.lower()=='description'}) </code></pre>
2
2015-05-31T12:47:12Z
[ "python", "beautifulsoup" ]
How do you determine an acceptable response time for App Engine DB requests?
2,602,527
<p>According to <a href="http://news.ycombinator.com/item?id=1249099" rel="nofollow">this discussion of Google App Engine on Hacker News</a>, </p> <blockquote> <p>A DB (read) request takes over 100ms on the datastore. That's insane and unusable for about 90% of applications.</p> </blockquote> <p>How do you dete...
1
2010-04-08T18:42:19Z
2,602,544
<p>If you haven't noticed any issues then it is by definition an acceptable response time. The only question is how long your users are happy to wait.</p>
1
2010-04-08T18:44:37Z
[ "java", "python", "database", "google-app-engine", "response-time" ]
How do you determine an acceptable response time for App Engine DB requests?
2,602,527
<p>According to <a href="http://news.ycombinator.com/item?id=1249099" rel="nofollow">this discussion of Google App Engine on Hacker News</a>, </p> <blockquote> <p>A DB (read) request takes over 100ms on the datastore. That's insane and unusable for about 90% of applications.</p> </blockquote> <p>How do you dete...
1
2010-04-08T18:42:19Z
2,602,712
<p>What do you mean by acceptable? What kind of application are you writing? Acceptable means different things for different domains/applications/people. First, you should decide how quickly you want your app to respond to a request. Let's pick 1 second, just for argument's sake. Now, how many DB requests do you n...
2
2010-04-08T19:15:33Z
[ "java", "python", "database", "google-app-engine", "response-time" ]
How do you determine an acceptable response time for App Engine DB requests?
2,602,527
<p>According to <a href="http://news.ycombinator.com/item?id=1249099" rel="nofollow">this discussion of Google App Engine on Hacker News</a>, </p> <blockquote> <p>A DB (read) request takes over 100ms on the datastore. That's insane and unusable for about 90% of applications.</p> </blockquote> <p>How do you dete...
1
2010-04-08T18:42:19Z
2,602,798
<p>An "an acceptable response time for a DB read request" depends entirely on your application and your users.</p> <p>If the net result is that your site runs fast enough to satisfy you and your users then the slow response time of the services provided by Google in their AppEngine are acceptable.</p> <p>Now, looking...
1
2010-04-08T19:28:52Z
[ "java", "python", "database", "google-app-engine", "response-time" ]
How do you determine an acceptable response time for App Engine DB requests?
2,602,527
<p>According to <a href="http://news.ycombinator.com/item?id=1249099" rel="nofollow">this discussion of Google App Engine on Hacker News</a>, </p> <blockquote> <p>A DB (read) request takes over 100ms on the datastore. That's insane and unusable for about 90% of applications.</p> </blockquote> <p>How do you dete...
1
2010-04-08T18:42:19Z
2,605,080
<p>You can measure precisely how much each RPC call (datastore or otherwise) is taking, thanks to Guido van Rossum's <a href="https://sites.google.com/site/appengineappstats/" rel="nofollow">AppStats</a> relatively-new component (it's part of the standard SDK since 1.3.1). See <a href="http://googleappengine.blogspot....
3
2010-04-09T04:29:38Z
[ "java", "python", "database", "google-app-engine", "response-time" ]
How do you determine an acceptable response time for App Engine DB requests?
2,602,527
<p>According to <a href="http://news.ycombinator.com/item?id=1249099" rel="nofollow">this discussion of Google App Engine on Hacker News</a>, </p> <blockquote> <p>A DB (read) request takes over 100ms on the datastore. That's insane and unusable for about 90% of applications.</p> </blockquote> <p>How do you dete...
1
2010-04-08T18:42:19Z
2,605,848
<p>The poster is wrong. Datastore get operations are much faster - about 15-20ms each, currently. Datastore <em>query</em> operations can be slower, because they're much more involved and return more data, but they still complete in anywhere from 30-100ms for a typical query. Other posters have amply addressed whether ...
2
2010-04-09T07:53:49Z
[ "java", "python", "database", "google-app-engine", "response-time" ]
PyQt WebKit CSS background image not showing
2,602,880
<p>I'm making a Twitter client with PyQt, which uses WebKit to draw the tweet list. Now I'm trying to use CSS to set a background image in the WebKit widget - but the image won't show up. This is the relevant part of the CSS:</p> <pre><code>body ...
1
2010-04-08T19:39:44Z
2,603,294
<p>Try removing the quotes. Also, bear in mind that if you declare a "background:" shorthand rule after a "backround-image:" rule, the background-image will be overwritten. Also, the file path should be relative to the css file, not the source file.</p>
2
2010-04-08T20:39:48Z
[ "python", "css", "webkit", "pyqt" ]
PyQt WebKit CSS background image not showing
2,602,880
<p>I'm making a Twitter client with PyQt, which uses WebKit to draw the tweet list. Now I'm trying to use CSS to set a background image in the WebKit widget - but the image won't show up. This is the relevant part of the CSS:</p> <pre><code>body ...
1
2010-04-08T19:39:44Z
3,030,847
<p>you could use the background-image like this:</p> <pre><code>body { background-image: url("qrc:///gradient2.jpg"); } <...
0
2010-06-13T02:21:30Z
[ "python", "css", "webkit", "pyqt" ]
How to set up global connection to database?
2,603,093
<p>I have problem with setting up database connection. I want to set connection, where I can see this connection in all my controllers.</p> <p>Now I use something like this in my controller:</p> <pre><code>db = create_engine('mysql://root:password@localhost/python') metadata = MetaData(db) email_list = Table('email'...
2
2010-04-08T20:09:20Z
2,861,281
<p>What you want to do is modify the <code>Globals</code> class in your <code>app_globals.py</code> file to include a <code>.engine</code> (or whatever) attribute. Then, in your controllers, you use <code>from pylons import app_globals</code> and <code>app_globals.engine</code> to access the engine (or metadata, sessi...
0
2010-05-18T21:29:03Z
[ "python", "sqlalchemy", "pylons" ]
How to set up global connection to database?
2,603,093
<p>I have problem with setting up database connection. I want to set connection, where I can see this connection in all my controllers.</p> <p>Now I use something like this in my controller:</p> <pre><code>db = create_engine('mysql://root:password@localhost/python') metadata = MetaData(db) email_list = Table('email'...
2
2010-04-08T20:09:20Z
3,019,767
<p>I hope you got pylons working; for anyone else that may later read question I'll present some pointers in the right direction.</p> <p>First of all, you are only creating a engine and a metadata object. While you can use the engine to create connections directly you would almost always use a Session to manage queryi...
1
2010-06-11T02:07:59Z
[ "python", "sqlalchemy", "pylons" ]
How to set up global connection to database?
2,603,093
<p>I have problem with setting up database connection. I want to set connection, where I can see this connection in all my controllers.</p> <p>Now I use something like this in my controller:</p> <pre><code>db = create_engine('mysql://root:password@localhost/python') metadata = MetaData(db) email_list = Table('email'...
2
2010-04-08T20:09:20Z
3,907,250
<p>1.0 version of Pylons use declarative syntax. More about this, you can see <a href="http://www.sqlalchemy.org/docs/orm/tutorial.html#creating-table-class-and-mapper-all-at-once-declaratively" rel="nofollow">here</a> .</p> <p>In mode/init.py you can write somthing like this: </p> <pre><code>from your_programm.model...
2
2010-10-11T14:43:43Z
[ "python", "sqlalchemy", "pylons" ]
Opening SSL URLs with Python
2,603,119
<p>I'm using mechanize to navigate pages, it works pretty well.</p> <p>Unfortunately I have a <strong>random error</strong> come up, by random I mean it occasionally appears.</p> <blockquote> <p>URLError at /test/</p> <p>urlopen error [Errno 1] _ssl.c:1325: error:140943FC:SSL routines:SSL3_READ_BYTES:sslv3 ale...
2
2010-04-08T20:14:53Z
3,149,458
<p>I had a similar error and found that <code>PycURL</code> works way better than <code>urllib</code>.</p> <p><a href="http://stackoverflow.com/questions/3134666/django-request-xml-file-with-ssl-io-error">http://stackoverflow.com/questions/3134666/django-request-xml-file-with-ssl-io-error</a></p>
1
2010-06-30T13:02:24Z
[ "python", "linux", "django", "ssl", "mechanize" ]
Update Tkinter Label from variable
2,603,169
<p>I wrote a Python script that does some task to generate, and then keep changing some text stored as a string variable. This works, and I can print the string each time it gets changed.</p> <p>I can get the Label to display the string for the first time, but it never updates. </p> <p>Here's my code:</p> <pre><code...
7
2010-04-08T20:22:12Z
2,603,371
<p>The window is only displayed once the mainloop is entered. So you won't see any changes you make in your <code>while True</code> block preceding the line <code>root.mainloop()</code>. </p> <hr> <p>GUI interfaces work by reacting to events while in the mainloop. Here's an example where the StringVar is also connect...
13
2010-04-08T20:50:56Z
[ "python", "label", "tkinter" ]
Problem with VIM - "f" calling the "fold" command instead of "find"
2,603,389
<p>This is happening in python files.</p> <p>For example, I want to do type "fC" in normal mode, and instead of finding the first "C" character, it is just doing code fold toggling.</p>
0
2010-04-08T20:53:07Z
2,603,420
<p>Real answer:</p> <p>Are you using <a href="http://www.vim.org/scripts/script.php?script_id=1494" rel="nofollow">this plugin</a>? Under 4, it says that pressing "f" toggles the fold (in certain conditions).</p> <p>Original answer:</p> <p>I'm not sure what fC does, because it doesn't do anything in my version of vi...
3
2010-04-08T20:59:05Z
[ "python", "vim" ]
Dumping one class type with Django dumpdata
2,603,427
<p>I use dumpdata to output all my apps's classes. One of my app has one class that never get's outputted and I don't know where to start looking to know what's wrong. The class is used regularly, every other classes in the app are dumped fine and dumpdata doesn't throw any error.</p> <p>Any clue ?</p>
2
2010-04-08T21:00:25Z
2,610,120
<p>You might try serializing it to json and see if you get any errors there -- maybe there's a subtle inconsistency that's messing up the serialization.</p> <pre><code>&gt;&gt;&gt; from django.core import serializers &gt;&gt;&gt; from myapp.mymodels import mymodel &gt;&gt;&gt; serializers.serialize('json', mymodel.obj...
1
2010-04-09T19:02:59Z
[ "python", "django", "dump" ]
Matching blank entries in django queryset for optional field with corresponding ones in a required field
2,603,694
<p>I have a django queryset in my views whose values I pack before passing to my template. There is a problem when the queryset returns <code>none</code> since associated values are not unpacked. the quersyet is called <code>comments</code>. </p> <p>Here is my views.py</p> <pre><code>def forums(request ): post_lis...
-1
2010-04-08T21:48:37Z
2,604,171
<p>You could just do this:</p> <pre><code>comments = list(queryset or []) </code></pre> <p>if the queryset resolves to None, then the empty list will be used and <code>comments</code> will just be an empty list.</p>
3
2010-04-08T23:43:03Z
[ "python", "django" ]
Matching blank entries in django queryset for optional field with corresponding ones in a required field
2,603,694
<p>I have a django queryset in my views whose values I pack before passing to my template. There is a problem when the queryset returns <code>none</code> since associated values are not unpacked. the quersyet is called <code>comments</code>. </p> <p>Here is my views.py</p> <pre><code>def forums(request ): post_lis...
-1
2010-04-08T21:48:37Z
2,617,381
<p>I don't think you are doing it right. I don't believe that queryset can return None. Why not just chain the <code>filter</code> methods?</p> <pre><code>list(forum.objects.filter(child='0').filter(deleted='0').order_by('postDate')) </code></pre> <p>If you have more complex queries, you can use the <a href="http://d...
0
2010-04-11T14:41:02Z
[ "python", "django" ]
Comparing (similar) images with Python/PIL
2,603,713
<p>I'm trying to calculate the <strong>similarity</strong> (read: <strong>Levenshtein distance</strong>) of two images, using Python 2.6 and PIL.</p> <p>I plan to us e the <a href="http://pypi.python.org/pypi/python-Levenshtein/0.10.1">python-levenshtein</a> library for fast comparison.</p> <p>Main question:</p> <p>...
8
2010-04-08T21:53:40Z
2,604,028
<p>You can take a look at the <a href="http://www.stsci.edu/resources/software_hardware/pyraf/stsci_python" rel="nofollow">stsci</a> library, it is made for comparing and analysing images. It should give you what you want but might be a little overkill.</p> <p>If ou want to keep it simple you could reduce the amount o...
3
2010-04-08T23:01:01Z
[ "python", "python-imaging-library", "fuzzy-logic", "fuzzy-comparison" ]
Comparing (similar) images with Python/PIL
2,603,713
<p>I'm trying to calculate the <strong>similarity</strong> (read: <strong>Levenshtein distance</strong>) of two images, using Python 2.6 and PIL.</p> <p>I plan to us e the <a href="http://pypi.python.org/pypi/python-Levenshtein/0.10.1">python-levenshtein</a> library for fast comparison.</p> <p>Main question:</p> <p>...
8
2010-04-08T21:53:40Z
7,912,225
<p>Check out <a href="http://www.imgseek.net/">imgSeek</a>:</p> <blockquote> <p>imgSeek is a collection of free open source visual similarity projects. The query (image you are looking for) can be expressed either as a rough sketch painted by the user or as another image you supply (or an image in your collect...
5
2011-10-27T06:03:21Z
[ "python", "python-imaging-library", "fuzzy-logic", "fuzzy-comparison" ]
IPython tab completion not working
2,603,798
<p>Tab completion on IPython seems not to be working. For example,</p> <pre><code>import numpy numpy.&lt;tab&gt; </code></pre> <p>simply adds a tab.</p> <pre><code>import numpy num&lt;tab&gt; </code></pre> <p>just adds a tab, too. Could you please suggest some possible causes for this problem? I am running Windows ...
53
2010-04-08T22:10:14Z
2,603,811
<p>Be sure you have installed the pyreadline library It is needed for Tab completion and other ipython functions. In windows it doesnt come with the ipython package and you have to install it separately. you can get it from <a href="https://launchpad.net/pyreadline">https://launchpad.net/pyreadline</a></p> <p>Edit 201...
69
2010-04-08T22:14:41Z
[ "python", "ipython", "tab-completion" ]
IPython tab completion not working
2,603,798
<p>Tab completion on IPython seems not to be working. For example,</p> <pre><code>import numpy numpy.&lt;tab&gt; </code></pre> <p>simply adds a tab.</p> <pre><code>import numpy num&lt;tab&gt; </code></pre> <p>just adds a tab, too. Could you please suggest some possible causes for this problem? I am running Windows ...
53
2010-04-08T22:10:14Z
8,057,327
<p>Your ipythonrc file may be out of date. Try running</p> <pre><code>ipython -upgrade </code></pre>
10
2011-11-08T21:31:27Z
[ "python", "ipython", "tab-completion" ]
IPython tab completion not working
2,603,798
<p>Tab completion on IPython seems not to be working. For example,</p> <pre><code>import numpy numpy.&lt;tab&gt; </code></pre> <p>simply adds a tab.</p> <pre><code>import numpy num&lt;tab&gt; </code></pre> <p>just adds a tab, too. Could you please suggest some possible causes for this problem? I am running Windows ...
53
2010-04-08T22:10:14Z
13,106,455
<p>As of right now, on a OSX, pip installed ipython doesn't give tab completion, pyreadline release.py is busted .. what WFM:</p> <pre><code>easy_install ipython readline </code></pre> <p>YMMV.</p>
1
2012-10-28T04:52:48Z
[ "python", "ipython", "tab-completion" ]
IPython tab completion not working
2,603,798
<p>Tab completion on IPython seems not to be working. For example,</p> <pre><code>import numpy numpy.&lt;tab&gt; </code></pre> <p>simply adds a tab.</p> <pre><code>import numpy num&lt;tab&gt; </code></pre> <p>just adds a tab, too. Could you please suggest some possible causes for this problem? I am running Windows ...
53
2010-04-08T22:10:14Z
14,913,550
<p>Someone else in StackOverflow posted this link: <a href="http://www.vankouteren.eu/blog/2009/06/getting-ipython-readline-and-auto-completion-to-work-on-mac-os-x/" rel="nofollow">http://www.vankouteren.eu/blog/2009/06/getting-ipython-readline-and-auto-completion-to-work-on-mac-os-x/</a></p> <p>Its basicly <code>easy...
1
2013-02-16T18:18:08Z
[ "python", "ipython", "tab-completion" ]
IPython tab completion not working
2,603,798
<p>Tab completion on IPython seems not to be working. For example,</p> <pre><code>import numpy numpy.&lt;tab&gt; </code></pre> <p>simply adds a tab.</p> <pre><code>import numpy num&lt;tab&gt; </code></pre> <p>just adds a tab, too. Could you please suggest some possible causes for this problem? I am running Windows ...
53
2010-04-08T22:10:14Z
16,582,395
<p><code>pip</code> told me I had pyreadline version 1.7.1 installed</p> <pre><code>C:\Users\me&gt;pip freeze | grep readline pyreadline==1.7.1 </code></pre> <p>Upgrading <code>pyreadline</code> fixed it for me:</p> <pre><code>C:\Users\me&gt;pip install --upgrade pyreadline C:\Users\me&gt;pip freeze | grep readline...
3
2013-05-16T08:23:08Z
[ "python", "ipython", "tab-completion" ]
IPython tab completion not working
2,603,798
<p>Tab completion on IPython seems not to be working. For example,</p> <pre><code>import numpy numpy.&lt;tab&gt; </code></pre> <p>simply adds a tab.</p> <pre><code>import numpy num&lt;tab&gt; </code></pre> <p>just adds a tab, too. Could you please suggest some possible causes for this problem? I am running Windows ...
53
2010-04-08T22:10:14Z
23,944,831
<p>Pyreadline is needed by ipython. Install pyreadline. This was done in Windows 7. Get pyreadline zip, <a href="https://github.com/pyreadline/pyreadline/archive/master.zip" rel="nofollow">pyreadline-master.zip</a>, unzip. In powershell change directory into uzipped pyreadline, make sure python is set in Path, and en...
0
2014-05-29T23:45:43Z
[ "python", "ipython", "tab-completion" ]
IPython tab completion not working
2,603,798
<p>Tab completion on IPython seems not to be working. For example,</p> <pre><code>import numpy numpy.&lt;tab&gt; </code></pre> <p>simply adds a tab.</p> <pre><code>import numpy num&lt;tab&gt; </code></pre> <p>just adds a tab, too. Could you please suggest some possible causes for this problem? I am running Windows ...
53
2010-04-08T22:10:14Z
24,764,198
<p>I realize this is a really old question, but none of the answers above worked for me (And this is the first hit you get when you google a question of this nature).</p> <p>I should mention that this is NOT exclusive to windows, I had the problem running CentOS 6.5 and Python 2.7</p> <p>Here is what I did:</p> <pre...
1
2014-07-15T17:10:39Z
[ "python", "ipython", "tab-completion" ]
IPython tab completion not working
2,603,798
<p>Tab completion on IPython seems not to be working. For example,</p> <pre><code>import numpy numpy.&lt;tab&gt; </code></pre> <p>simply adds a tab.</p> <pre><code>import numpy num&lt;tab&gt; </code></pre> <p>just adds a tab, too. Could you please suggest some possible causes for this problem? I am running Windows ...
53
2010-04-08T22:10:14Z
25,044,420
<p>The classic 'have you tried turning it off and on again' worked for me.</p> <pre><code>pip uninstall ipython pip install ipython </code></pre>
0
2014-07-30T18:36:34Z
[ "python", "ipython", "tab-completion" ]
IPython tab completion not working
2,603,798
<p>Tab completion on IPython seems not to be working. For example,</p> <pre><code>import numpy numpy.&lt;tab&gt; </code></pre> <p>simply adds a tab.</p> <pre><code>import numpy num&lt;tab&gt; </code></pre> <p>just adds a tab, too. Could you please suggest some possible causes for this problem? I am running Windows ...
53
2010-04-08T22:10:14Z
26,717,780
<p>I had this problem and knew that I had the pip installed for the module I was looking for. Performing <code>$ ipython --init</code> solved the problem for me.</p>
0
2014-11-03T15:49:08Z
[ "python", "ipython", "tab-completion" ]
IPython tab completion not working
2,603,798
<p>Tab completion on IPython seems not to be working. For example,</p> <pre><code>import numpy numpy.&lt;tab&gt; </code></pre> <p>simply adds a tab.</p> <pre><code>import numpy num&lt;tab&gt; </code></pre> <p>just adds a tab, too. Could you please suggest some possible causes for this problem? I am running Windows ...
53
2010-04-08T22:10:14Z
28,049,212
<p>I had to <code>mv ~/.ipython{,.bak}</code> in my case.</p>
0
2015-01-20T15:32:44Z
[ "python", "ipython", "tab-completion" ]
How to improve the speed of a loop containing a sqlalchemy query statement as conditional
2,603,905
<p>This loop checks if a record is in the sqlite database and builds a list of dictionaries for those records that are missing and then executes a multiple insert statement with the list. This works but it is very slow (at least i think it is slow) as it takes 5 minutes to loop over 3500 queries. I am a complete newbie...
4
2010-04-08T22:32:30Z
2,603,970
<p>3500 queries seems a big number,</p> <p>Have you consider fetching all entities in one query? Then you will be iterating over a list in memory, and not querying the database for each item.</p>
3
2010-04-08T22:48:23Z
[ "python", "sqlite", "sqlalchemy" ]
How to improve the speed of a loop containing a sqlalchemy query statement as conditional
2,603,905
<p>This loop checks if a record is in the sqlite database and builds a list of dictionaries for those records that are missing and then executes a multiple insert statement with the list. This works but it is very slow (at least i think it is slow) as it takes 5 minutes to loop over 3500 queries. I am a complete newbie...
4
2010-04-08T22:32:30Z
12,647,303
<p>Glad you found something that works, as an extra 2 cents:</p> <p>I agree with mcabral. As a general rule, if you are putting a query inside of a loop, you are asking for trouble. Popular SQL DBs are generally optimized for data acquisition. Looping through a query generally indicates that you are procedurally do...
0
2012-09-28T20:58:45Z
[ "python", "sqlite", "sqlalchemy" ]
Django repeating vars/cache issue?
2,603,937
<p>I'm trying to build a better/more powerful form class for Django. It's working well, except for these sub-forms. Actually, it works perfectly right after I re-start apache, but after I refresh the page a few times, my HTML output starts to look like this:</p> <pre><code>&lt;input class="text" type="text" id="pickup...
0
2010-04-08T22:40:23Z
2,604,045
<p>You're probably declaring your forms like this:</p> <pre><code>class SomeForm(Form): someField = Field(....) ... </code></pre> <p>Now, this means that one instance of <code>someField</code> will actually be shared among all your <code>SomeForm</code> instances. In your <code>__init__</code> you're changing...
1
2010-04-08T23:03:59Z
[ "python", "django", "wsgi" ]
Pre-generating GUIDs for use in python?
2,603,951
<p>I have a python program that needs to generate several guids and hand them back with some other data to a client over the network. It may be hit with a lot of requests in a short time period and I would like the latency to be as low as reasonably possible.</p> <p>Ideally, rather than generating new guids on the fly...
2
2010-04-08T22:43:49Z
2,603,967
<p>Are you certain that the <code>uuid</code> module would in fact be too slow to handle the requests you expect in a timely manner? I would be very surprised if UUID generation accounted for a bottleneck in your application.</p> <p>I would first build the application to simply use the <code>uuid</code> module and th...
6
2010-04-08T22:47:56Z
[ "python", "linux", "performance", "guid", "uuid" ]
Pre-generating GUIDs for use in python?
2,603,951
<p>I have a python program that needs to generate several guids and hand them back with some other data to a client over the network. It may be hit with a lot of requests in a short time period and I would like the latency to be as low as reasonably possible.</p> <p>Ideally, rather than generating new guids on the fly...
2
2010-04-08T22:43:49Z
2,603,988
<p>I have tested the performance of the uuid module for generating uuids:</p> <pre><code>&gt;&gt;&gt; import timeit &gt;&gt;&gt; timer=timeit.Timer('uuid.uuid1()','import uuid') &gt;&gt;&gt; timer.repeat(3, 10000) [0.84600019454956055, 0.8469998836517334, 0.84400010108947754] </code></pre> <p>How many do you need? Is...
4
2010-04-08T22:51:46Z
[ "python", "linux", "performance", "guid", "uuid" ]
Pre-generating GUIDs for use in python?
2,603,951
<p>I have a python program that needs to generate several guids and hand them back with some other data to a client over the network. It may be hit with a lot of requests in a short time period and I would like the latency to be as low as reasonably possible.</p> <p>Ideally, rather than generating new guids on the fly...
2
2010-04-08T22:43:49Z
2,604,101
<p>Suppose you have a thread to keep topping up a pool of uuid's.</p> <p>Here is a very simple version</p> <pre><code>import uuid,threading,time class UUID_Pool(threading.Thread): pool_size=10000 def __init__(self): super(UUID_Pool,self).__init__() self.daemon=True self.uuid_pool=set(...
0
2010-04-08T23:19:14Z
[ "python", "linux", "performance", "guid", "uuid" ]
Can we have assignment in a condition?
2,603,956
<p>Is it possible to have assignment in a condition?</p> <p>For ex.</p> <pre><code>if (a=some_func()): # Use a </code></pre>
19
2010-04-08T22:45:49Z
2,603,966
<p>Why not try it out?</p> <pre><code>&gt;&gt;&gt; def some_func(): ... return 2 ... &gt;&gt;&gt; a = 2 &gt;&gt;&gt; if (a = some_func()): File "&lt;stdin&gt;", line 1 if (a = some_func()): ^ SyntaxError: invalid syntax &gt;&gt;&gt; </code></pre> <p>So, no.</p>
42
2010-04-08T22:47:47Z
[ "python" ]
Can we have assignment in a condition?
2,603,956
<p>Is it possible to have assignment in a condition?</p> <p>For ex.</p> <pre><code>if (a=some_func()): # Use a </code></pre>
19
2010-04-08T22:45:49Z
2,603,981
<p>No. Assignment in Python is a statement, not an expression.</p>
2
2010-04-08T22:50:25Z
[ "python" ]
Can we have assignment in a condition?
2,603,956
<p>Is it possible to have assignment in a condition?</p> <p>For ex.</p> <pre><code>if (a=some_func()): # Use a </code></pre>
19
2010-04-08T22:45:49Z
2,604,036
<p><a href="http://docs.python.org/tutorial/datastructures.html">http://docs.python.org/tutorial/datastructures.html</a></p> <blockquote> <p>Note that in Python, unlike C, assignment cannot occur inside expressions. C programmers may grumble about this, but it avoids a common class of problems encountered in...
7
2010-04-08T23:02:58Z
[ "python" ]
Can we have assignment in a condition?
2,603,956
<p>Is it possible to have assignment in a condition?</p> <p>For ex.</p> <pre><code>if (a=some_func()): # Use a </code></pre>
19
2010-04-08T22:45:49Z
2,604,121
<p>Nope, the BDFL didn't like that feature.</p> <p>From where I sit, Guido van Rossum, "Benevolent Dictator For Life”, has fought hard to keep Python as simple as it can be. We can quibble with some of the decisions he's made -- I'd have preferred he said 'No' more often. But the fact that there hasn't been a commit...
23
2010-04-08T23:26:14Z
[ "python" ]
Can we have assignment in a condition?
2,603,956
<p>Is it possible to have assignment in a condition?</p> <p>For ex.</p> <pre><code>if (a=some_func()): # Use a </code></pre>
19
2010-04-08T22:45:49Z
2,604,842
<p>Not directly, per <a href="http://code.activestate.com/recipes/66061-assign-and-test/" rel="nofollow">this old recipe of mine</a> -- but as the recipe says it's easy to build the semantic equivalent, e.g. if you need to transliterate directly from a C-coded reference algorithm (before refactoring to more-idiomatic P...
4
2010-04-09T02:54:21Z
[ "python" ]
Can we have assignment in a condition?
2,603,956
<p>Is it possible to have assignment in a condition?</p> <p>For ex.</p> <pre><code>if (a=some_func()): # Use a </code></pre>
19
2010-04-08T22:45:49Z
19,911,464
<p>One of the reasons why assignments are illegal in conditions is that it's easier to make a mistake and assign True or False:</p> <pre><code>some_variable = 5 # This does not work # if True = some_variable: # do_something() # This only works in Python 2.x True = some_variable print True # returns 5 </code></pr...
1
2013-11-11T16:40:55Z
[ "python" ]
Obtaining IP addresses in Bittorrent
2,604,153
<p>I am trying to get a list of IP addresses serving or downloading a file. What I did was to contact a tracker like openbittorrent.com to get the following (as part of the scrape file):</p> <pre><code>B%00%00%0C%5F%B1%B1l%CAGa%84S%CB%B0%9BG%84%3BE:0:1 </code></pre> <p>Now, the long string in the beginning is the inf...
2
2010-04-08T23:35:40Z
2,604,257
<p>That's not a torrent file, that's an announce response. They're both bencode (use <a href="http://pypi.python.org/pypi/BitTorrent-bencode" rel="nofollow">bencode</a> to decode them), but the announce response contains only peer information. That's not enough information to be able to download the contents of the tor...
2
2010-04-09T00:01:36Z
[ "python", "language-agnostic", "prototype", "p2p", "bittorrent" ]
Why don't these class attributes register?
2,604,230
<p>I have a factory method that generates django form classes like so:</p> <pre><code>def get_indicator_form(indicator, patient): class IndicatorForm(forms.Form): #These don't work! indicator_id = forms.IntegerField(initial=indicator.id, widget=forms.HiddenInput()) patient_id = forms.Intege...
0
2010-04-08T23:55:32Z
2,604,602
<p>Try this:</p> <pre><code>def get_indicator_form(indicator, patient): class IndicatorForm(forms.Form): indicator_id = forms.IntegerField(initial=indicator.id, widget=forms.HiddenInput()) patient_id = forms.IntegerField(initial=patient.id, widget=forms.HiddenInput()) def __init__(self, *a...
1
2010-04-09T01:47:14Z
[ "python", "django", "django-forms" ]
Why does easy_install extract some python eggs and not others?
2,604,600
<p>Looking in my /usr/local/lib/python.../dist-package directory, I have <code>.egg</code> directories and <code>.egg</code> files. </p> <p>Why does the installer choose to extra packages to the <code>.egg</code> directory, yet leave other files with <code>.egg</code> extensions? </p>
13
2010-04-09T01:45:33Z
2,604,612
<p>I can't explain why some eggs are zipped (the files) and some are directories, but I can offer this: if you hate zipped eggs (like I do) put this in the <code>[easy_install]</code> section of your <code>~/.pydistutils.cfg</code>:</p> <pre> zip_ok = false </pre>
4
2010-04-09T01:48:51Z
[ "python", "egg" ]
Why does easy_install extract some python eggs and not others?
2,604,600
<p>Looking in my /usr/local/lib/python.../dist-package directory, I have <code>.egg</code> directories and <code>.egg</code> files. </p> <p>Why does the installer choose to extra packages to the <code>.egg</code> directory, yet leave other files with <code>.egg</code> extensions? </p>
13
2010-04-09T01:45:33Z
2,604,694
<p>If the package contains only pure-Python code, it can stay as just an egg file. The Python interpreter can load the Python modules directly from the egg. If the package contains modules written in C or other data, then egg needs to be extracted so the C modules and/or data can be accessed. That's the default beha...
24
2010-04-09T02:09:08Z
[ "python", "egg" ]
functional-style datatypes in Python
2,604,666
<p>For anyone who's spent some time with sml, ocaml, haskell, etc. when you go back to using C, Python, Java, etc. you start to notice things you never knew were missing. I'm doing some stuff in Python and I realized what I really want is a functional-style datatype like (for example)</p> <pre><code>datatype phoneme =...
3
2010-04-09T01:58:44Z
2,604,702
<p>You could create classes that contain the attributes you need.</p> <pre><code>class Phoneme: # ... class Consonant(Phoneme): def __init__(self, voice, place, manner): self.voice = voice self.place = place self.manner = manner # ... h = Consonant('Voiceless', 'Glottal', 'Fricati...
0
2010-04-09T02:12:03Z
[ "python", "types", "functional-programming" ]
functional-style datatypes in Python
2,604,666
<p>For anyone who's spent some time with sml, ocaml, haskell, etc. when you go back to using C, Python, Java, etc. you start to notice things you never knew were missing. I'm doing some stuff in Python and I realized what I really want is a functional-style datatype like (for example)</p> <pre><code>datatype phoneme =...
3
2010-04-09T01:58:44Z
2,604,712
<p>For the simple enumerations like <code>voice</code>, <code>place</code> and <code>manner</code> you could use a class like this:</p> <pre><code>class Enum(object): def __init__(self, *values): self._values = set(values) for value in values: setattr(self, value, value) def __iter__(self): ...
1
2010-04-09T02:13:58Z
[ "python", "types", "functional-programming" ]
functional-style datatypes in Python
2,604,666
<p>For anyone who's spent some time with sml, ocaml, haskell, etc. when you go back to using C, Python, Java, etc. you start to notice things you never knew were missing. I'm doing some stuff in Python and I realized what I really want is a functional-style datatype like (for example)</p> <pre><code>datatype phoneme =...
3
2010-04-09T01:58:44Z
2,605,654
<p>As sth indicated, your voice, place, and manner types are just enumerated types. There are a number of ways to implement those, such as</p> <pre><code>class voice(object): Voiced, Voiceless = range(2) </code></pre> <p>Then you can refer to voice.Voiced and voice.Voiceless, and so forth.</p> <p>The problem is ty...
1
2010-04-09T07:08:53Z
[ "python", "types", "functional-programming" ]
How to correctly relay TCP traffic between sockets?
2,604,740
<p>I'm trying to write some Python code that will establish an invisible relay between two TCP sockets. My current technique is to set up two threads, each one reading and subsequently writing 1kb of data at a time in a particular direction (i.e. 1 thread for A to B, 1 thread for B to A).</p> <p>This works for some ap...
4
2010-04-09T02:24:21Z
2,604,794
<p>I don't think that's likely to be your problem. </p> <p>In general, the sending application can't tell when the receiving application actually calls recv() to read the data: the sender's send() may have completed, but the TCP implementations in the source &amp; destination OS will be doing buffering, flow control, ...
1
2010-04-09T02:40:39Z
[ "python", "sockets", "tcp", "portforwarding" ]
How to correctly relay TCP traffic between sockets?
2,604,740
<p>I'm trying to write some Python code that will establish an invisible relay between two TCP sockets. My current technique is to set up two threads, each one reading and subsequently writing 1kb of data at a time in a particular direction (i.e. 1 thread for A to B, 1 thread for B to A).</p> <p>This works for some ap...
4
2010-04-09T02:24:21Z
2,604,804
<blockquote> <p>Is it possible to only read from socket A when we know that B is ready to receive data?</p> </blockquote> <p>Sure: use <a href="http://docs.python.org/library/select.html?highlight=select#select.select">select.select</a> on both sockets A and B (if it returns saying only one of them is ready, use...
5
2010-04-09T02:43:18Z
[ "python", "sockets", "tcp", "portforwarding" ]
How to correctly relay TCP traffic between sockets?
2,604,740
<p>I'm trying to write some Python code that will establish an invisible relay between two TCP sockets. My current technique is to set up two threads, each one reading and subsequently writing 1kb of data at a time in a particular direction (i.e. 1 thread for A to B, 1 thread for B to A).</p> <p>This works for some ap...
4
2010-04-09T02:24:21Z
2,609,442
<p>Perhaps the application you're proxying is poorly written.</p> <p>For instance, if I call <code>recv(fd, buf, 4096, 0);</code> I'm not promised 4096 bytes. The system makes a best-effort to provide it.</p> <p>If 1k isn't a multiple of your application's <code>recv</code> or <code>send</code> sizes, and the applic...
1
2010-04-09T17:12:17Z
[ "python", "sockets", "tcp", "portforwarding" ]
Website stress test in Python - Django
2,604,747
<p>I'm trying to build a small stress test script to test how quickly a set of requests gets done.</p> <p>Need to measure speed for 100 requests.</p> <p>Problem is that I wouldn't know how to implement it, as it would require parallel url requests to be called. Any ideas?</p>
10
2010-04-09T02:26:27Z
2,604,755
<p>Why build it?</p> <p>There are several available.</p> <ol> <li>For a single url and many requests try <a href="http://httpd.apache.org/docs/2.0/programs/ab.html">ab</a></li> <li>For multiple urls and random tests try <a href="http://freshmeat.net/projects/siege/">siege</a></li> </ol>
8
2010-04-09T02:30:20Z
[ "python", "django", "http", "testing", "load" ]
Website stress test in Python - Django
2,604,747
<p>I'm trying to build a small stress test script to test how quickly a set of requests gets done.</p> <p>Need to measure speed for 100 requests.</p> <p>Problem is that I wouldn't know how to implement it, as it would require parallel url requests to be called. Any ideas?</p>
10
2010-04-09T02:26:27Z
2,604,756
<p>I'm not sure if this exactly the type of testing you were looking for but <a href="http://browsermob.com/performance-testing" rel="nofollow">BrowserMob</a> uses <a href="http://wiki.openqa.org/display/SEL/Home" rel="nofollow">Selenium</a> to do browser load testing. It works as if many browsers were pounding on your...
0
2010-04-09T02:30:25Z
[ "python", "django", "http", "testing", "load" ]
Website stress test in Python - Django
2,604,747
<p>I'm trying to build a small stress test script to test how quickly a set of requests gets done.</p> <p>Need to measure speed for 100 requests.</p> <p>Problem is that I wouldn't know how to implement it, as it would require parallel url requests to be called. Any ideas?</p>
10
2010-04-09T02:26:27Z
2,606,022
<p>If you want to stay within the Python framework you might try Corey Goldberg's <a href="http://www.pylot.org/" rel="nofollow">Pylot</a> or its successor <a href="http://testutils.org/multi-mechanize/" rel="nofollow">multi-mechanize</a>.</p>
11
2010-04-09T08:39:52Z
[ "python", "django", "http", "testing", "load" ]
Website stress test in Python - Django
2,604,747
<p>I'm trying to build a small stress test script to test how quickly a set of requests gets done.</p> <p>Need to measure speed for 100 requests.</p> <p>Problem is that I wouldn't know how to implement it, as it would require parallel url requests to be called. Any ideas?</p>
10
2010-04-09T02:26:27Z
13,639,264
<p>Although this question is quite old, I'd like to point out a nifty tool about this problem. The tool is <a href="http://funkload.nuxeo.org/" rel="nofollow">funkload</a>, and this is the typical <a href="http://funkload.nuxeo.org/report-example/test_seam_java6/" rel="nofollow">detailed report</a> it generates.</p>
4
2012-11-30T04:57:52Z
[ "python", "django", "http", "testing", "load" ]
Website stress test in Python - Django
2,604,747
<p>I'm trying to build a small stress test script to test how quickly a set of requests gets done.</p> <p>Need to measure speed for 100 requests.</p> <p>Problem is that I wouldn't know how to implement it, as it would require parallel url requests to be called. Any ideas?</p>
10
2010-04-09T02:26:27Z
16,429,317
<p>Also, there is an awesome open-source pure-python distributed and scaleable <a href="http://locust.io/">locust</a> framework that uses <a href="http://greenlet.readthedocs.org/en/latest/">greenlets</a>. It's great at simulating enormous amount of simultaneous users.</p>
14
2013-05-07T22:04:24Z
[ "python", "django", "http", "testing", "load" ]
Django: reverse lookup URL of feeds?
2,604,823
<p>I am having trouble doing a reverse URL lookup for Django-generated feeds.</p> <p>I have the following setup in <code>urls.py</code>:</p> <pre><code>feeds = { 'latest': LatestEntries, } urlpatterns = patterns('', # ... # enable feeds (RSS) url(r'^feeds/(?P&lt;url&gt;.*)/$', 'django.contrib.syndica...
2
2010-04-09T02:48:30Z
2,604,849
<p>You're using keyword arguments so you should pass them as such :) Try this:</p> <pre><code>&lt;a href="{% url feeds_view url="latest" %}"&gt;RSS feeds&lt;/a&gt; </code></pre>
1
2010-04-09T02:56:28Z
[ "python", "django", "django-templates", "django-urls" ]
Django: reverse lookup URL of feeds?
2,604,823
<p>I am having trouble doing a reverse URL lookup for Django-generated feeds.</p> <p>I have the following setup in <code>urls.py</code>:</p> <pre><code>feeds = { 'latest': LatestEntries, } urlpatterns = patterns('', # ... # enable feeds (RSS) url(r'^feeds/(?P&lt;url&gt;.*)/$', 'django.contrib.syndica...
2
2010-04-09T02:48:30Z
2,605,561
<p>Unfortunately, URL reversing is not really possible with the current feed framework. The good news is that the feed framework has been completely refactored and can seamlessly integrate with Django's URL resolving mechanisms. This refactored feed framework will be delivered with Django 1.2, which should arrive at th...
3
2010-04-09T06:48:24Z
[ "python", "django", "django-templates", "django-urls" ]
ImportError: No Module named simplejson
2,604,841
<p>I'm trying to run a command to install bespinclient on my Windows laptop but every time I execute the command <code>python bootstrap.py --no-site-packages</code>, I get an error saying:</p> <blockquote> <p>ImportError: No module named simplejson</p> </blockquote> <p>I'm using Mozilla build tools to run these L...
31
2010-04-09T02:53:52Z
2,604,855
<p>That means you must install <a href="http://pypi.python.org/pypi/simplejson/"><code>simplejson</code></a>. On newer versions of python, it was included by default into python's distribution, and renamed to <code>json</code>. So if you are on python 2.6+ you should change all instances of <code>simplejson</code> to <...
75
2010-04-09T02:58:20Z
[ "python", "unix" ]
ImportError: No Module named simplejson
2,604,841
<p>I'm trying to run a command to install bespinclient on my Windows laptop but every time I execute the command <code>python bootstrap.py --no-site-packages</code>, I get an error saying:</p> <blockquote> <p>ImportError: No module named simplejson</p> </blockquote> <p>I'm using Mozilla build tools to run these L...
31
2010-04-09T02:53:52Z
2,605,098
<p>@noskio is correct... it just means that <code>simplejson</code> isn't found on your system and you need to install it for Python older than 2.6. one way is to use the <a href="http://pypi.python.org/pypi/setuptools">setuptools</a> <code>easy_install</code> tool. with it, you can install it as easily as: <code>easy_...
8
2010-04-09T04:34:21Z
[ "python", "unix" ]
ImportError: No Module named simplejson
2,604,841
<p>I'm trying to run a command to install bespinclient on my Windows laptop but every time I execute the command <code>python bootstrap.py --no-site-packages</code>, I get an error saying:</p> <blockquote> <p>ImportError: No module named simplejson</p> </blockquote> <p>I'm using Mozilla build tools to run these L...
31
2010-04-09T02:53:52Z
5,645,465
<p>On Ubuntu/Debian, you can install it with <code>apt-get install python-simplejson</code></p>
4
2011-04-13T06:52:27Z
[ "python", "unix" ]
Enable PyGTK Eventbox motion-notify-event while is a Layout child
2,604,846
<p>I noticed when a Eventbox is added into a Layout some events are missed, this does not happend for example adding it to a Fixed (very similar widget), I tried to restore the event mask in this way with no sucess:</p> <pre><code>import pygtk import gtk def foo(widget, event): print event pygtk.require('2.0'...
1
2010-04-09T02:55:57Z
2,604,863
<p>The code you pasted works fine for me. When I press button 1 on the mouse and drag on the window, it generates and prints motion events to the terminal.</p> <p>I've even removed the <code>eventbox.set_events(...)</code> call and it still works.</p> <p>So what's the problem?</p>
1
2010-04-09T03:01:14Z
[ "python", "gtk", "pygtk", "gnome" ]
Accessing a dictionary value by custom object value in Python?
2,604,897
<p>So I have a square that's made up of a series of points. At every point there is a corresponding value.</p> <p>What I want to do is build a dictionary like this:</p> <pre><code>class Point: def __init__(self, x, y): self._x = x self._y = y square = {} for x in range(0, 5): for y i...
6
2010-04-09T03:12:12Z
2,604,908
<p>Define <a href="http://docs.python.org/reference/datamodel.html#object.__hash__"><code>Point.__hash__()</code></a> and <a href="http://docs.python.org/reference/datamodel.html#object.__eq__"><code>Point.__eq__()</code></a> so that they can be compared properly within dicts.</p> <p>And while you're at it, consider d...
11
2010-04-09T03:15:46Z
[ "python", "dictionary", "object" ]
Accessing a dictionary value by custom object value in Python?
2,604,897
<p>So I have a square that's made up of a series of points. At every point there is a corresponding value.</p> <p>What I want to do is build a dictionary like this:</p> <pre><code>class Point: def __init__(self, x, y): self._x = x self._y = y square = {} for x in range(0, 5): for y i...
6
2010-04-09T03:12:12Z
2,604,912
<p>Yes, define the <code>__eq__</code> and <code>__hash__</code> methods on your Point class.</p> <pre><code>class Point: def __init__(self, x, y): self._x = x self._y = y def __eq__(self, other): return self._x == other._x and self._y == other._y def __hash__(self): #This...
5
2010-04-09T03:17:14Z
[ "python", "dictionary", "object" ]
Accessing a dictionary value by custom object value in Python?
2,604,897
<p>So I have a square that's made up of a series of points. At every point there is a corresponding value.</p> <p>What I want to do is build a dictionary like this:</p> <pre><code>class Point: def __init__(self, x, y): self._x = x self._y = y square = {} for x in range(0, 5): for y i...
6
2010-04-09T03:12:12Z
2,604,950
<p>Any reason not to just use a tuple:</p> <pre><code>&gt;&gt;&gt; s={} &gt;&gt;&gt; s[1,2]=5 &gt;&gt;&gt; s {(1, 2): 5} &gt;&gt;&gt; s[1,2] 5 </code></pre>
2
2010-04-09T03:32:22Z
[ "python", "dictionary", "object" ]
Accessing a dictionary value by custom object value in Python?
2,604,897
<p>So I have a square that's made up of a series of points. At every point there is a corresponding value.</p> <p>What I want to do is build a dictionary like this:</p> <pre><code>class Point: def __init__(self, x, y): self._x = x self._y = y square = {} for x in range(0, 5): for y i...
6
2010-04-09T03:12:12Z
30,458,349
<p>Steps : Implement a custom key class and override hash and equality function.</p> <p>e.g.</p> <pre><code>class CustomDictKey(object): def __init__(self, param1, param2): self._param1 = param1 self._param2 = param2 # overriding hash and equality function does t...
2
2015-05-26T12:16:51Z
[ "python", "dictionary", "object" ]
Scraping a page from a secure URL which is possibly using a session ID
2,604,914
<p>How to scrape a page like this.</p> <p><a href="https://www.procom.ca/JobList.aspx?keywords=&amp;Cities=&amp;reference=&amp;JobType=0" rel="nofollow">https://www.procom.ca/JobList.aspx?keywords=&amp;Cities=&amp;reference=&amp;JobType=0</a></p> <p>It is secure, and requires a referrer? I can't get anything using wg...
2
2010-04-09T03:17:22Z
2,605,060
<p>What data are you sending in POST or Get, I would recommend look thru the POST/GET messages in Firebug Net Panel, in that page there are many hidden values which I think are time dependent and changes on each page load and may be valid once so load page , get those values and send them with POST messages e.g. see th...
0
2010-04-09T04:21:05Z
[ "python", "screen-scraping", "mechanize", "referrer", "scrapy" ]
Scraping a page from a secure URL which is possibly using a session ID
2,604,914
<p>How to scrape a page like this.</p> <p><a href="https://www.procom.ca/JobList.aspx?keywords=&amp;Cities=&amp;reference=&amp;JobType=0" rel="nofollow">https://www.procom.ca/JobList.aspx?keywords=&amp;Cities=&amp;reference=&amp;JobType=0</a></p> <p>It is secure, and requires a referrer? I can't get anything using wg...
2
2010-04-09T03:17:22Z
2,605,733
<p>As you suspect, it requires a referer. This works:</p> <pre><code> import urllib2 urlopen = urllib2.urlopen Request = urllib2.Request url = 'https://www.procom.ca/JobList.aspx?keywords=&amp;Cities=&amp;reference=&amp;JobType=0' headers = {'Referer' : 'http://www.stackoverflow.com'} req = Request(u...
3
2010-04-09T07:26:41Z
[ "python", "screen-scraping", "mechanize", "referrer", "scrapy" ]
Issue with making python program executable
2,604,917
<p>I'm trying to make a program so that I can run it through the command line with the following format:</p> <pre><code>./myProgram </code></pre> <p>I made it executable and put <code>#!/usr/bin/env python</code> in the header, but it's giving me the following error. </p> <pre><code>env: python\r: No such file or di...
2
2010-04-09T03:19:11Z
2,604,921
<p>Your line endings are wrong. Use <code>dos2unix</code> to fix them.</p>
14
2010-04-09T03:20:38Z
[ "python" ]