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
listlengths
1
5
referencing class methods in class lists in Python
1,351,669
<p>I am writing a class in Python 2.6.2 that contains a lookup table. Most cases are simple enough that the table contains data. Some of the cases are more complex and I want to be able call a function. However, I'm running into some trouble referencing the function.</p> <p>Here's some sample code:</p> <pre><code...
1
2009-08-29T15:11:45Z
1,369,481
<p>Remember that there's no such thing as static, or constant, in Python. Just make it easy to read. Here's an example which generates a cached version of <code>lut</code> per object:</p> <pre><code>class A(object): def __init__(self): self.__cached_lut = None def spam0(self): return (some_cal...
1
2009-09-02T18:49:42Z
[ "python", "class", "reference" ]
How do I form a URL in Django for what I'm doing
1,352,073
<p>Desperate, please help. Will work for food :)</p> <p>I want to be able to have pages at the following URLs, and I want to be able to look them up by their URL (ie, If somebody goes to a certain URL, I want to be able to check for a page there).</p> <pre> mysite.com/somepage/somesubpage/somesubsubpage/ mysite.com/s...
1
2009-08-29T18:34:55Z
1,352,086
<p>You need to also store <code>level</code> and <code>parent</code> attributes, so that you can always get the right object.</p> <p>The requirement to store hierarchical data comes up very frequently, and I always recommend <a href="http://code.google.com/p/django-mptt/" rel="nofollow">django-mptt</a>. It's the Djang...
2
2009-08-29T18:40:10Z
[ "python", "regex", "django", "django-urls" ]
How do I form a URL in Django for what I'm doing
1,352,073
<p>Desperate, please help. Will work for food :)</p> <p>I want to be able to have pages at the following URLs, and I want to be able to look them up by their URL (ie, If somebody goes to a certain URL, I want to be able to check for a page there).</p> <pre> mysite.com/somepage/somesubpage/somesubsubpage/ mysite.com/s...
1
2009-08-29T18:34:55Z
1,352,174
<p>It sounds like you're looking for a CMS app. There's a <a href="http://code.djangoproject.com/wiki/CMSAppsComparison" rel="nofollow">comparison</a> of several Django-based CMS. If you want a full-featured CMS at the center of your project, <a href="http://github.com/digi604/django-cms-2.0/tree/master" rel="nofollow"...
0
2009-08-29T19:18:09Z
[ "python", "regex", "django", "django-urls" ]
suppress/redirect stderr when calling python webrowser
1,352,361
<p>I have a python program that opens several urls in seperate tabs in a new browser window, however when I run the program from the command line and open the browser using </p> <pre><code>webbrowser.open_new(url) </code></pre> <p>The stderr from firefox prints to bash. Looking at the docs I can't seem to find a way ...
6
2009-08-29T21:01:51Z
1,352,363
<p>What about sending the output to <code>/dev/null</code> instead of a temporary file?</p>
0
2009-08-29T21:03:52Z
[ "python", "browser", "stderr" ]
suppress/redirect stderr when calling python webrowser
1,352,361
<p>I have a python program that opens several urls in seperate tabs in a new browser window, however when I run the program from the command line and open the browser using </p> <pre><code>webbrowser.open_new(url) </code></pre> <p>The stderr from firefox prints to bash. Looking at the docs I can't seem to find a way ...
6
2009-08-29T21:01:51Z
1,352,392
<p>What is webbrowser.get() giving you?</p> <p>If you do</p> <pre><code> webbrowser.get('firefox').open(url) </code></pre> <p>then you shouldn't see any output. The webbrowser module choses to leave stderr for some browsers - in particular the text browsers, and then ones where it isn't certain. For all UnixBrowsers...
5
2009-08-29T21:14:34Z
[ "python", "browser", "stderr" ]
suppress/redirect stderr when calling python webrowser
1,352,361
<p>I have a python program that opens several urls in seperate tabs in a new browser window, however when I run the program from the command line and open the browser using </p> <pre><code>webbrowser.open_new(url) </code></pre> <p>The stderr from firefox prints to bash. Looking at the docs I can't seem to find a way ...
6
2009-08-29T21:01:51Z
1,352,478
<p>I think Martin is right about Unix systems, but it looks like things are different on Windows. Is this on a Windows system?</p> <p>On Windows it looks like webbrowser.py is either going to give you a webbrowser.WindowsDefault browser, which opens the url using</p> <pre><code>os.startfile(url) </code></pre> <p>or...
0
2009-08-29T21:50:51Z
[ "python", "browser", "stderr" ]
Why is Python's enumerate so slow?
1,352,497
<p>Why is "enumerate" slower than "xrange + lst[i]"?</p> <pre> <code> >>> from timeit import Timer >>> lst = [1,2,3,0,1,2]*1000 >>> setup = 'from __main__ import lst' >>> s1 = """ for i in range(len(lst)): elem = lst[i] """ >>> s2 = """ for i in xrange(len(lst)): elem = lst[i] """ >>> s3 = """ for i, v in enum...
3
2009-08-29T21:57:28Z
1,352,514
<p>Possibly because you have hobbled <code>enumerate</code>. Try this:</p> <pre><code>&gt;&gt;&gt; s3 = """ for i, elem in enumerate(lst): pass """ </code></pre> <p><strong>Update</strong> Two extra reasons for using <code>timeit</code> at the shell prompt that Alex didn't mention:</p> <p>(1) It does "best of N"...
5
2009-08-29T22:05:46Z
[ "python" ]
Why is Python's enumerate so slow?
1,352,497
<p>Why is "enumerate" slower than "xrange + lst[i]"?</p> <pre> <code> >>> from timeit import Timer >>> lst = [1,2,3,0,1,2]*1000 >>> setup = 'from __main__ import lst' >>> s1 = """ for i in range(len(lst)): elem = lst[i] """ >>> s2 = """ for i in xrange(len(lst)): elem = lst[i] """ >>> s3 = """ for i, v in enum...
3
2009-08-29T21:57:28Z
1,352,521
<p>If you measure properly you'll see there's essentially no difference (enumerate is microscopically faster than xrange in this example, but well within noise):</p> <pre><code>$ python -mtimeit -s'lst=[1,2,3,0,1,2]*1000' 'for i in xrange(len(lst)): elem=lst[i]' 1000 loops, best of 3: 480 usec per loop $ python -mtime...
14
2009-08-29T22:09:07Z
[ "python" ]
Why does ActivePython exist?
1,352,528
<p>What's ActivePython actually about? </p> <p>From <a href="http://www.activestate.com/activepython/features/">what I've read</a> it's just standard Python with openssl and pyWin32 (on Win). No big deal I guess, I could install them in matter of minutes, and most people don't need them anyway. All other mentioned lib...
63
2009-08-29T22:12:56Z
1,352,533
<p>The main feature is that you can buy a paid support contract for it.</p> <p>Why does Red Hat Enterprise Linux exist when you can compile everything yourself? 8-)</p> <p>For many businesses, the combination of proven Open Source software <em>and</em> a support contract from people who build, package and test that ...
28
2009-08-29T22:17:13Z
[ "python", "activestate", "activepython", "rationale" ]
Why does ActivePython exist?
1,352,528
<p>What's ActivePython actually about? </p> <p>From <a href="http://www.activestate.com/activepython/features/">what I've read</a> it's just standard Python with openssl and pyWin32 (on Win). No big deal I guess, I could install them in matter of minutes, and most people don't need them anyway. All other mentioned lib...
63
2009-08-29T22:12:56Z
1,352,539
<p>It's a packaging, or "distribution", of Python, with some extras -- not (anywhere) quite as "Sumo" as Enthought's HUGE distro of "Python plus everything", but still in a similar vein (and it first appeared much earlier).</p> <p>I don't think you're missing anything in particular, except perhaps the fact that David ...
42
2009-08-29T22:20:10Z
[ "python", "activestate", "activepython", "rationale" ]
Why does ActivePython exist?
1,352,528
<p>What's ActivePython actually about? </p> <p>From <a href="http://www.activestate.com/activepython/features/">what I've read</a> it's just standard Python with openssl and pyWin32 (on Win). No big deal I guess, I could install them in matter of minutes, and most people don't need them anyway. All other mentioned lib...
63
2009-08-29T22:12:56Z
1,352,541
<p>ActiveState has a long tradition contributing Windows support to Python, Tcl, and Perl: by hiring key developers (like Mark Hammond, for some time), by fixing bugs specific to Windows, and having employees contribute fixes back, and by being sponsors of the Python Software Foundation.</p> <p>While it is true that t...
31
2009-08-29T22:21:36Z
[ "python", "activestate", "activepython", "rationale" ]
Why does ActivePython exist?
1,352,528
<p>What's ActivePython actually about? </p> <p>From <a href="http://www.activestate.com/activepython/features/">what I've read</a> it's just standard Python with openssl and pyWin32 (on Win). No big deal I guess, I could install them in matter of minutes, and most people don't need them anyway. All other mentioned lib...
63
2009-08-29T22:12:56Z
1,354,126
<p>I've been using ActivePerl for years and when I made the switch to Python, I very naturally downloaded ActivePython. Never had any problems with the Active* distributions - they're robust, come with a few useful libraries that the vanilla core Python doesn't have. They also come bundled with a .CHM Python documentat...
8
2009-08-30T15:40:47Z
[ "python", "activestate", "activepython", "rationale" ]
Why does ActivePython exist?
1,352,528
<p>What's ActivePython actually about? </p> <p>From <a href="http://www.activestate.com/activepython/features/">what I've read</a> it's just standard Python with openssl and pyWin32 (on Win). No big deal I guess, I could install them in matter of minutes, and most people don't need them anyway. All other mentioned lib...
63
2009-08-29T22:12:56Z
1,401,911
<p>Here is an email to python-list I wrote on this a long while ago:</p> <p><a href="https://mail.python.org/pipermail/python-list/2007-July/456660.html" rel="nofollow">https://mail.python.org/pipermail/python-list/2007-July/456660.html</a> </p> <p>Mostly those details are still true. Also, all the other responses I...
5
2009-09-09T20:30:47Z
[ "python", "activestate", "activepython", "rationale" ]
Is there any way to make an asynchronous function call from Python [Django]?
1,352,678
<p>I am creating a Django application that does various long computations with uploaded files. I don't want to make the user wait for the file to be handled - I just want to show the user a page reading something like 'file is being parsed'.</p> <p>How can I make an asynchronous function call from a view?</p> <p>Some...
4
2009-08-29T23:59:53Z
1,352,686
<p>Unless you specifically need to use a separate process, which seems to be the gist of the other questions S.Lott is indicating as duplicate of yours, the <code>threading</code> module from the Python standard library (documented <a href="http://docs.python.org/library/threading.html" rel="nofollow">here</a>) may off...
0
2009-08-30T00:05:55Z
[ "python", "django", "asynchronous" ]
Is there any way to make an asynchronous function call from Python [Django]?
1,352,678
<p>I am creating a Django application that does various long computations with uploaded files. I don't want to make the user wait for the file to be handled - I just want to show the user a page reading something like 'file is being parsed'.</p> <p>How can I make an asynchronous function call from a view?</p> <p>Some...
4
2009-08-29T23:59:53Z
1,353,400
<p>Rather than trying to manage this via subprocesses or threads, I recommend you separate it out completely. There are two approaches: the first is to set a flag in a database table somewhere, and have a cron job running regularly that checks the flag and performs the required operation.</p> <p>The second option is t...
5
2009-08-30T08:02:16Z
[ "python", "django", "asynchronous" ]
Is there any way to make an asynchronous function call from Python [Django]?
1,352,678
<p>I am creating a Django application that does various long computations with uploaded files. I don't want to make the user wait for the file to be handled - I just want to show the user a page reading something like 'file is being parsed'.</p> <p>How can I make an asynchronous function call from a view?</p> <p>Some...
4
2009-08-29T23:59:53Z
1,355,722
<p>I have tried to do the same and failed after multiple attempt due of the nature of django and other asynchronous call.</p> <p>The solution I have come up which could be a bit over the top for you is to have another asynchronous server in the background processing messages queues from the web request and throwing so...
2
2009-08-31T03:57:50Z
[ "python", "django", "asynchronous" ]
Is there any way to make an asynchronous function call from Python [Django]?
1,352,678
<p>I am creating a Django application that does various long computations with uploaded files. I don't want to make the user wait for the file to be handled - I just want to show the user a page reading something like 'file is being parsed'.</p> <p>How can I make an asynchronous function call from a view?</p> <p>Some...
4
2009-08-29T23:59:53Z
4,665,597
<p>threading will break runserver if I'm not mistaken. I've had good luck with multiprocess in request handlers with mod_wsgi and runserver. Maybe someone can enlighten me as to why this is bad:</p> <pre><code>def _bulk_action(action, objs): # mean ponies here def bulk_action(request, t): ... objs = mo...
0
2011-01-12T05:22:45Z
[ "python", "django", "asynchronous" ]
Python script performance as a background process
1,352,760
<p>Im in the process of writing a python script to act as a "glue" between an application and some external devices. The script itself is quite straight forward and has three distinct processes:</p> <ol> <li>Request data (from a socket connection, via UDP)</li> <li>Receive response (from a socket connection, via UDP)<...
0
2009-08-30T00:58:11Z
1,352,773
<p><a href="http://twistedmatrix.com/trac/" rel="nofollow">Twisted</a> -- the best async framework for Python -- would allow you do perform these tasks with the minimal hogging of system resources, most especially though not exclusively if you want to process several devices "at once" rather than just round-robin among...
4
2009-08-30T01:07:20Z
[ "python", "performance", "process", "background" ]
Python script performance as a background process
1,352,760
<p>Im in the process of writing a python script to act as a "glue" between an application and some external devices. The script itself is quite straight forward and has three distinct processes:</p> <ol> <li>Request data (from a socket connection, via UDP)</li> <li>Receive response (from a socket connection, via UDP)<...
0
2009-08-30T00:58:11Z
1,352,777
<p>If you are using blocking I/O to your devices, then the script won't consume any processor while waiting for the data. How much processor you use depends on what sorts of computation you are doing with the data.</p>
5
2009-08-30T01:08:15Z
[ "python", "performance", "process", "background" ]
Optional get parameters in django?
1,352,834
<p>Can someone please explain how you can write a url pattern and view that allows optional parameters? I've done this successfully, but I always break the url template tag.</p> <p>Here's what I have currently:</p> <p><strong>Pattern</strong></p> <pre><code>(r'^so/(?P&lt;required&gt;\d+)/?(?P&lt;optional&gt;(.*))/?$...
22
2009-08-30T01:43:34Z
1,352,841
<p>I generally make two patterns with a <a href="http://docs.djangoproject.com/en/dev/topics/http/urls/#naming-url-patterns">named url</a>:</p> <pre><code>url(r'^so/(?P&lt;required&gt;\d+)/$', 'myapp.so', name='something'), url(r'^so/(?P&lt;required&gt;\d+)/(?P&lt;optional&gt;.*)/$', 'myapp.so', name='something_else')...
34
2009-08-30T01:48:34Z
[ "python", "regex", "django" ]
Optional get parameters in django?
1,352,834
<p>Can someone please explain how you can write a url pattern and view that allows optional parameters? I've done this successfully, but I always break the url template tag.</p> <p>Here's what I have currently:</p> <p><strong>Pattern</strong></p> <pre><code>(r'^so/(?P&lt;required&gt;\d+)/?(?P&lt;optional&gt;(.*))/?$...
22
2009-08-30T01:43:34Z
1,352,842
<p>Why not have two patterns:</p> <pre><code>(r'^so/(?P&lt;required&gt;\d+)/(?P&lt;optional&gt;.*)/$', view='myapp.so', name='optional'), (r'^so/(?P&lt;required&gt;\d+)/$', view='myapp.so', kwargs={'optional':None}, name='required'), </code></pre>
1
2009-08-30T01:49:33Z
[ "python", "regex", "django" ]
Optional get parameters in django?
1,352,834
<p>Can someone please explain how you can write a url pattern and view that allows optional parameters? I've done this successfully, but I always break the url template tag.</p> <p>Here's what I have currently:</p> <p><strong>Pattern</strong></p> <pre><code>(r'^so/(?P&lt;required&gt;\d+)/?(?P&lt;optional&gt;(.*))/?$...
22
2009-08-30T01:43:34Z
1,353,956
<p>Others have demonstrated the way to handle this with two separate named URL patterns. If the repetition of part of the URL pattern bothers you, it's possible to get rid of it by using include():</p> <pre><code>url(r'^so/(?P&lt;required&gt;\d+)/', include('myapp.required_urls')) </code></pre> <p>And then add a requ...
5
2009-08-30T14:10:49Z
[ "python", "regex", "django" ]
Optional get parameters in django?
1,352,834
<p>Can someone please explain how you can write a url pattern and view that allows optional parameters? I've done this successfully, but I always break the url template tag.</p> <p>Here's what I have currently:</p> <p><strong>Pattern</strong></p> <pre><code>(r'^so/(?P&lt;required&gt;\d+)/?(?P&lt;optional&gt;(.*))/?$...
22
2009-08-30T01:43:34Z
6,345,264
<p>in views.py you do simple thing.</p> <pre><code>def so(request, required, optional=None): </code></pre> <p>And when you dont get <strong>optional</strong> param in url string it will be None in your code. </p> <p>Simple and elegant :)</p>
-1
2011-06-14T14:36:02Z
[ "python", "regex", "django" ]
Optional get parameters in django?
1,352,834
<p>Can someone please explain how you can write a url pattern and view that allows optional parameters? I've done this successfully, but I always break the url template tag.</p> <p>Here's what I have currently:</p> <p><strong>Pattern</strong></p> <pre><code>(r'^so/(?P&lt;required&gt;\d+)/?(?P&lt;optional&gt;(.*))/?$...
22
2009-08-30T01:43:34Z
8,981,132
<p>Django urls are polymorphic:</p> <pre><code>url(r'^so/(?P&lt;required&gt;\d+)/$', 'myapp.so', name='sample_view'), url(r'^so/(?P&lt;required&gt;\d+)/(?P&lt;optional&gt;.*)/$', 'myapp.so', name='sample_view'), </code></pre> <p>its obious that you have to make your views like this:</p> <pre><code>def sample_view(re...
16
2012-01-24T01:46:59Z
[ "python", "regex", "django" ]
Optional get parameters in django?
1,352,834
<p>Can someone please explain how you can write a url pattern and view that allows optional parameters? I've done this successfully, but I always break the url template tag.</p> <p>Here's what I have currently:</p> <p><strong>Pattern</strong></p> <pre><code>(r'^so/(?P&lt;required&gt;\d+)/?(?P&lt;optional&gt;(.*))/?$...
22
2009-08-30T01:43:34Z
16,558,729
<p>For anyone who is still having this problem. I use Django 1.5 (updated: using 1.8) and it's still working fine. </p> <p>I use:</p> <blockquote> <p>urls.py url(r'^(?P\d+)/start/+(?P\d+)?', views.restart, name='restart')</p> </blockquote> <p>Then when I want to have the two urls</p> <blockquote> <p>/1/start/...
1
2013-05-15T07:00:18Z
[ "python", "regex", "django" ]
Optional get parameters in django?
1,352,834
<p>Can someone please explain how you can write a url pattern and view that allows optional parameters? I've done this successfully, but I always break the url template tag.</p> <p>Here's what I have currently:</p> <p><strong>Pattern</strong></p> <pre><code>(r'^so/(?P&lt;required&gt;\d+)/?(?P&lt;optional&gt;(.*))/?$...
22
2009-08-30T01:43:34Z
26,871,543
<p>Depending on your use case, you may simply want to pass a url parameter like so:</p> <pre><code>url/?parameter=foo </code></pre> <p>call this in your view:</p> <pre><code>request.REQUEST.get('parameter') </code></pre> <p>this will return 'foo'</p>
-2
2014-11-11T18:10:06Z
[ "python", "regex", "django" ]
Nice copying from Python Interpreter
1,352,886
<p>When I am working with a Python Interpreter, I always find it a pain to try and copy code from it because it inserts all of these >>> and ...</p> <p>Is there a Python interpreter that will let me copy code, without having to deal with this? Or alternatively, is there a way to clean the output.</p> <p>Additionally,...
6
2009-08-30T02:18:40Z
1,352,900
<p>Decent text editors such as Notepad++ can make global search and replace operations that can replace >>> with nothing.</p>
0
2009-08-30T02:23:43Z
[ "python" ]
Nice copying from Python Interpreter
1,352,886
<p>When I am working with a Python Interpreter, I always find it a pain to try and copy code from it because it inserts all of these >>> and ...</p> <p>Is there a Python interpreter that will let me copy code, without having to deal with this? Or alternatively, is there a way to clean the output.</p> <p>Additionally,...
6
2009-08-30T02:18:40Z
1,352,904
<p>WingIDE from <a href="http://www.wingware.com" rel="nofollow">Wingware</a> will let you evaluate any chunk of code in a separate interpreter window.</p>
3
2009-08-30T02:24:38Z
[ "python" ]
Nice copying from Python Interpreter
1,352,886
<p>When I am working with a Python Interpreter, I always find it a pain to try and copy code from it because it inserts all of these >>> and ...</p> <p>Is there a Python interpreter that will let me copy code, without having to deal with this? Or alternatively, is there a way to clean the output.</p> <p>Additionally,...
6
2009-08-30T02:18:40Z
1,352,909
<p><a href="http://ipython.scipy.org/moin/" rel="nofollow">IPython</a> will let you paste Python code with leading indents without giving you an IndentationError. You can also <a href="http://ipython.scipy.org/doc/manual/html/config/customization.html#fine-tuning-your-prompt" rel="nofollow">change your prompts</a> to ...
1
2009-08-30T02:27:43Z
[ "python" ]
Nice copying from Python Interpreter
1,352,886
<p>When I am working with a Python Interpreter, I always find it a pain to try and copy code from it because it inserts all of these >>> and ...</p> <p>Is there a Python interpreter that will let me copy code, without having to deal with this? Or alternatively, is there a way to clean the output.</p> <p>Additionally,...
6
2009-08-30T02:18:40Z
1,352,914
<p>I have a vim macro to "paste while cleaning interpreter prompts and sample output [[==stuff NOT preceded by prompts" and I'll be happy to share it if vim is what you're using. Any editor or IDE worth that name will of course be similarly easy to program for such purposes!</p>
1
2009-08-30T02:28:51Z
[ "python" ]
Nice copying from Python Interpreter
1,352,886
<p>When I am working with a Python Interpreter, I always find it a pain to try and copy code from it because it inserts all of these >>> and ...</p> <p>Is there a Python interpreter that will let me copy code, without having to deal with this? Or alternatively, is there a way to clean the output.</p> <p>Additionally,...
6
2009-08-30T02:18:40Z
1,352,991
<p>IPython lets you show, save and edit your command history, for example to show the first three commands of your session without line numbers you'd type <code>%hist -n 1 4</code>.</p>
4
2009-08-30T03:17:51Z
[ "python" ]
Why is '#!/usr/bin/env python' supposedly more correct than just '#!/usr/bin/python'?
1,352,922
<p>Anyone know this? I've never been able to find an answer.</p>
57
2009-08-30T02:30:30Z
1,352,927
<p>It finds 'python' also in /usr/local/bin, ~/bin, /opt/bin, ... or wherever it may hide.</p>
5
2009-08-30T02:31:52Z
[ "python", "bash" ]
Why is '#!/usr/bin/env python' supposedly more correct than just '#!/usr/bin/python'?
1,352,922
<p>Anyone know this? I've never been able to find an answer.</p>
57
2009-08-30T02:30:30Z
1,352,932
<p>You may find this post to be of interest: <a href="http://mail.python.org/pipermail/python-list/2008-May/661514.html" rel="nofollow">http://mail.python.org/pipermail/python-list/2008-May/661514.html</a></p> <p>This may be a better explanation: <a href="http://mail.python.org/pipermail/tutor/2007-June/054816.html" r...
3
2009-08-30T02:34:02Z
[ "python", "bash" ]
Why is '#!/usr/bin/env python' supposedly more correct than just '#!/usr/bin/python'?
1,352,922
<p>Anyone know this? I've never been able to find an answer.</p>
57
2009-08-30T02:30:30Z
1,352,938
<p>If you're prone to installing python in various and interesting places on your PATH (as in <code>$PATH</code> in typical Unix shells, <code>%PATH</code> on typical Windows ones), using <code>/usr/bin/env</code> will accomodate your whim (well, in Unix-like environments at least) while going directly to <code>/usr/bi...
60
2009-08-30T02:36:51Z
[ "python", "bash" ]
Why is '#!/usr/bin/env python' supposedly more correct than just '#!/usr/bin/python'?
1,352,922
<p>Anyone know this? I've never been able to find an answer.</p>
57
2009-08-30T02:30:30Z
1,352,939
<p>From <a href="http://en.wikipedia.org/wiki/Shebang_%28Unix%29">wikipedia</a></p> <blockquote> <p>Shebangs specify absolute paths to system executables; this can cause problems on systems which have non-standard file system layouts</p> <p>Often, the program /usr/bin/env can be used to circumvent this limi...
23
2009-08-30T02:36:53Z
[ "python", "bash" ]
Why is '#!/usr/bin/env python' supposedly more correct than just '#!/usr/bin/python'?
1,352,922
<p>Anyone know this? I've never been able to find an answer.</p>
57
2009-08-30T02:30:30Z
1,352,941
<p>it finds the python executable in your environment and uses that. it's more portable because python may not always be in /usr/bin/python. env is always located in /usr/bin.</p>
9
2009-08-30T02:37:13Z
[ "python", "bash" ]
Multiprocessing debug techniques
1,352,980
<p>I'm having trouble debugging a multi-process application (specifically using a process pool in python's multiprocessing module). I have an apparent deadlock and I do not know what is causing it. The stack trace is not sufficient to describe the issue, as it only displays code in the multiprocessing module.</p> <p>A...
15
2009-08-30T03:06:04Z
1,353,037
<p>Yah, debugging deadlocks is fun. You can set the logging level to be higher -- see <a href="http://docs.python.org/library/multiprocessing.html">the Python documentation</a> for a description of it, but really quickly:</p> <pre><code>import multiprocessing, logging logger = multiprocessing.log_to_stderr() logger.s...
28
2009-08-30T03:58:08Z
[ "python", "debugging", "deadlock", "multiprocessing" ]
Multiprocessing debug techniques
1,352,980
<p>I'm having trouble debugging a multi-process application (specifically using a process pool in python's multiprocessing module). I have an apparent deadlock and I do not know what is causing it. The stack trace is not sufficient to describe the issue, as it only displays code in the multiprocessing module.</p> <p>A...
15
2009-08-30T03:06:04Z
1,353,520
<p>In order to <em>avoid</em> deadlocks in the first place, learning good practices is useful, as parallel processing is indeed quite subtle. The (free) <a href="http://www.greenteapress.com/semaphores/" rel="nofollow">Little Book of Semaphores</a> can be a very enjoyable read!</p>
3
2009-08-30T09:46:54Z
[ "python", "debugging", "deadlock", "multiprocessing" ]
RPC for multiprocessing, design issues
1,353,055
<p>Hey everyone, what's a good way to do rpc across multiprocessing.Process'es ?</p> <p>I am also open to design advise on the following architecture: Process A * 10, Process B * 1. Each process A has to check with proces B on whether a particular item needs to be queried. </p> <p>So I was thinking of implementing m...
0
2009-08-30T04:09:23Z
1,353,089
<p>Personally, I always tend to lean towards socket-based RPC, because that frees me from the confine of a single node if and when I need to expand more. Twisted offers a great way to handle socket-based communications, but of course there are other alternatives too. HTTP 1.1 is a great "transport" layer to use for s...
6
2009-08-30T04:34:10Z
[ "python", "rpc", "multiprocessing" ]
RPC for multiprocessing, design issues
1,353,055
<p>Hey everyone, what's a good way to do rpc across multiprocessing.Process'es ?</p> <p>I am also open to design advise on the following architecture: Process A * 10, Process B * 1. Each process A has to check with proces B on whether a particular item needs to be queried. </p> <p>So I was thinking of implementing m...
0
2009-08-30T04:09:23Z
1,353,698
<p>I'm satisfied with using REST-ful transaction design.</p> <p>This means using HTTP instead of pipes.</p> <p>If Process B has a queue of things for the various Process A's to do, it would work like this.</p> <p>Process B is an HTTP server, with RESTful URI's that handle queries from process A's. B is implemented ...
1
2009-08-30T11:41:22Z
[ "python", "rpc", "multiprocessing" ]
RPC for multiprocessing, design issues
1,353,055
<p>Hey everyone, what's a good way to do rpc across multiprocessing.Process'es ?</p> <p>I am also open to design advise on the following architecture: Process A * 10, Process B * 1. Each process A has to check with proces B on whether a particular item needs to be queried. </p> <p>So I was thinking of implementing m...
0
2009-08-30T04:09:23Z
1,569,247
<p>Have you looked at MPI? <a href="http://en.wikipedia.org/wiki/Message%5FPassing%5FInterface" rel="nofollow">http://en.wikipedia.org/wiki/Message%5FPassing%5FInterface</a>.</p> <p>It is broadly available on UNIX/Linux/etc. I believe it can be had on Windows. Basically it provides all the plumbing that you'll have to...
0
2009-10-14T21:57:29Z
[ "python", "rpc", "multiprocessing" ]
Python+Django social network open source projects
1,353,097
<p>I'm looking for some open source, free to change and use project written on Pyton+Django with following features:</p> <ul> <li>Blog (for site, not for users)</li> <li>Users Registration</li> <li>User Profiles </li> <li>Adding friends, watching what friends added</li> <li>Award system for active users (carma, rating...
6
2009-08-30T04:37:35Z
1,353,112
<p>Django has <a href="http://docs.djangoproject.com/en/dev/topics/auth/">authentication</a> and <a href="http://docs.djangoproject.com/en/dev/ref/contrib/comments/">commenting</a> built in, but most of the rest is covered by <a href="http://pinaxproject.com/">Pinax</a>.</p>
10
2009-08-30T04:44:12Z
[ "python", "django", "project", "social-networking" ]
Python+Django social network open source projects
1,353,097
<p>I'm looking for some open source, free to change and use project written on Pyton+Django with following features:</p> <ul> <li>Blog (for site, not for users)</li> <li>Users Registration</li> <li>User Profiles </li> <li>Adding friends, watching what friends added</li> <li>Award system for active users (carma, rating...
6
2009-08-30T04:37:35Z
5,789,370
<p>There is an application that covers all of your requirements: <a href="http://www.vikuit.com" rel="nofollow">vikuit</a>.</p> <p>django, python, social network, profiles, rating, registration.... </p> <p>It's open source, so you can adapt or improve. I used their forums and SSO as a base for another app.</p>
3
2011-04-26T11:04:52Z
[ "python", "django", "project", "social-networking" ]
Encrypted Django Model Fields
1,353,128
<p>A client wants to ensure that I cannot read sensitive data from their site, which will still be administered by me. In practice, this means that I'll have database access, but it can't be possible for me to read the contents of certain Model Fields. Is there any way to make the data inaccessible to me, but still dec...
4
2009-08-30T04:55:01Z
1,353,174
<p>No, it's not possible to have data that is both in a form you can't decrypt it, and in a form where you can decrypt it to show it to the client simultaneously. The best you can do is a reversible encryption on the content so at least if your server is compromised their data is safe.</p>
4
2009-08-30T05:52:05Z
[ "python", "django", "encryption", "django-models" ]
Encrypted Django Model Fields
1,353,128
<p>A client wants to ensure that I cannot read sensitive data from their site, which will still be administered by me. In practice, this means that I'll have database access, but it can't be possible for me to read the contents of certain Model Fields. Is there any way to make the data inaccessible to me, but still dec...
4
2009-08-30T04:55:01Z
1,360,064
<p>You and your client could agree on them being obscured. A simple XOR operation or something similar will make the values unreadable in the admin and they can be decoded just in time they are needed in the site.</p> <p>This way you can safely administer the site without "accidentally" reading something.</p> <p>Make...
0
2009-09-01T00:40:52Z
[ "python", "django", "encryption", "django-models" ]
Encrypted Django Model Fields
1,353,128
<p>A client wants to ensure that I cannot read sensitive data from their site, which will still be administered by me. In practice, this means that I'll have database access, but it can't be possible for me to read the contents of certain Model Fields. Is there any way to make the data inaccessible to me, but still dec...
4
2009-08-30T04:55:01Z
2,882,398
<p>Take a look at <a href="http://github.com/svetlyak40wt/django-fields" rel="nofollow">Django-fields</a></p>
2
2010-05-21T13:22:40Z
[ "python", "django", "encryption", "django-models" ]
Encrypted Django Model Fields
1,353,128
<p>A client wants to ensure that I cannot read sensitive data from their site, which will still be administered by me. In practice, this means that I'll have database access, but it can't be possible for me to read the contents of certain Model Fields. Is there any way to make the data inaccessible to me, but still dec...
4
2009-08-30T04:55:01Z
9,006,291
<p>This is possible with public key encryption. I have done something similar before in PHP but the idea is the same for a Django app:</p> <p>All data on this website was stored encrypted using a private key held by the system software. The corresponding public key to decrypt the data was held by the client in a text ...
5
2012-01-25T16:31:02Z
[ "python", "django", "encryption", "django-models" ]
Encrypted Django Model Fields
1,353,128
<p>A client wants to ensure that I cannot read sensitive data from their site, which will still be administered by me. In practice, this means that I'll have database access, but it can't be possible for me to read the contents of certain Model Fields. Is there any way to make the data inaccessible to me, but still dec...
4
2009-08-30T04:55:01Z
22,415,648
<p>You might find <a href="https://github.com/defrex/django-encrypted-fields" rel="nofollow">Django Encrypted Fields</a> useful.</p>
0
2014-03-14T21:00:29Z
[ "python", "django", "encryption", "django-models" ]
Encrypted Django Model Fields
1,353,128
<p>A client wants to ensure that I cannot read sensitive data from their site, which will still be administered by me. In practice, this means that I'll have database access, but it can't be possible for me to read the contents of certain Model Fields. Is there any way to make the data inaccessible to me, but still dec...
4
2009-08-30T04:55:01Z
23,873,516
<p>Some other issues to consider are that the web application will then not be able to sort or easily query on the encrypted fields. It would be helpful to know what administrative functions the client wants you to have. Another approach would be to have a separate app / access channel that does not show the critical...
0
2014-05-26T15:35:41Z
[ "python", "django", "encryption", "django-models" ]
Issues with scoped_session in sqlalchemy - how does it work?
1,353,131
<p>I'm not really sure how scoped_session works, other than it seems to be a wrapper that hides several real sessions, keeping them separate for different requests. Does it do this with thread locals?</p> <p>Anyway the trouble is as follows:</p> <pre><code>S = elixir.session # = scoped_session(...) f = Foo(bar=1) S.a...
6
2009-08-30T04:57:08Z
1,353,153
<p>It turns out elixir sets save-on-init=True on the created mappers. This can be disabled by:</p> <pre><code>using_mapper_options(save_on_init=False) </code></pre> <p>This solves the problem. Kudos to stepz on #sqlalchemy for figuring out what was going on immediately. Although I am still curious how scoped_session ...
2
2009-08-30T05:25:37Z
[ "python", "sqlalchemy", "python-elixir" ]
Issues with scoped_session in sqlalchemy - how does it work?
1,353,131
<p>I'm not really sure how scoped_session works, other than it seems to be a wrapper that hides several real sessions, keeping them separate for different requests. Does it do this with thread locals?</p> <p>Anyway the trouble is as follows:</p> <pre><code>S = elixir.session # = scoped_session(...) f = Foo(bar=1) S.a...
6
2009-08-30T04:57:08Z
1,353,193
<p>Scoped session creates a proxy object that keeps a registry of (by default) per thread session objects created on demand from the passed session factory. When you access a session method such as <code>ScopedSession.add</code> it finds the session corresponding to the current thread and returns the <code>add</code> m...
7
2009-08-30T06:02:18Z
[ "python", "sqlalchemy", "python-elixir" ]
Custom/Owner draw control in PyQt?
1,353,181
<p>I am learning PyQt and wonder if one can create custom/owner draw control like one show in the figure below:</p> <blockquote> <p><img src="http://lh5.ggpht.com/%5F5XDoB4MglkY/SpoT51SXR1I/AAAAAAAAFcU/ZXjzmhRyDVA/s400/SearchBox.png" alt="alt text" /></p> </blockquote> <p>The search box has magnifier icon on its ri...
1
2009-08-30T05:57:23Z
1,353,231
<p>If you only need to show an icon, an easy way is to use <a href="http://doc.trolltech.com/4.5/stylesheet.html">style-sheets</a>:</p> <pre><code>lineedit = QtGui.QLineEdit() lineedit.setStyleSheet("""QLineEdit { background-image: url(:/images/magnifier.png); background-repeat: no-repeat; backgroun...
6
2009-08-30T06:25:40Z
[ "python", "user-interface", "qt", "pyqt", "ownerdrawn" ]
Custom/Owner draw control in PyQt?
1,353,181
<p>I am learning PyQt and wonder if one can create custom/owner draw control like one show in the figure below:</p> <blockquote> <p><img src="http://lh5.ggpht.com/%5F5XDoB4MglkY/SpoT51SXR1I/AAAAAAAAFcU/ZXjzmhRyDVA/s400/SearchBox.png" alt="alt text" /></p> </blockquote> <p>The search box has magnifier icon on its ri...
1
2009-08-30T05:57:23Z
1,813,358
<p>Antas Aasma - good anser! m3rLinEz Maybe its worth packing all buttons and text labels into one widget. In constructor of that widget connect all buttons. Expose only necessary signals and slots. Just to reduce code you write (and possibly increase reuse of this widget).</p>
0
2009-11-28T18:45:08Z
[ "python", "user-interface", "qt", "pyqt", "ownerdrawn" ]
I'm a .NET Programmer. What are specific uses of Python and/or Ruby for that will make me more productive?
1,353,211
<p>I recall when I first read Pragmatic Programmer that they suggested using scripting languages to make you a more productive programmer.</p> <p>I am in a quandary putting this into practice.</p> <p><strong>I want to know specific ways that using Python or Ruby can make me a more productive .NET developer.</strong><...
4
2009-08-30T06:13:28Z
1,353,220
<h2>Quick Prototyping - Both</h2> <p>In the simplest cases when firing a python interpreter and writing a line or two is way faster than creating a new project in visual studio.</p> <p>And you can use ruby to. Or lua, or evel perl, whatever. The point is implicit typing and light-weight feel.</p>
1
2009-08-30T06:18:53Z
[ ".net", "python", "ruby", "productivity" ]
I'm a .NET Programmer. What are specific uses of Python and/or Ruby for that will make me more productive?
1,353,211
<p>I recall when I first read Pragmatic Programmer that they suggested using scripting languages to make you a more productive programmer.</p> <p>I am in a quandary putting this into practice.</p> <p><strong>I want to know specific ways that using Python or Ruby can make me a more productive .NET developer.</strong><...
4
2009-08-30T06:13:28Z
1,353,225
<h2>IronPython / IronRuby</h2> <p><a href="http://www.manning.com/foord/" rel="nofollow">IronPython in Action</a> will do a better job explaining this (and exactly how best to use IronPython) that can possibly be accommodated in a SO answer. I'm biased -- I was a tech reviewer and am a friend of one of the authors -- ...
5
2009-08-30T06:22:08Z
[ ".net", "python", "ruby", "productivity" ]
I'm a .NET Programmer. What are specific uses of Python and/or Ruby for that will make me more productive?
1,353,211
<p>I recall when I first read Pragmatic Programmer that they suggested using scripting languages to make you a more productive programmer.</p> <p>I am in a quandary putting this into practice.</p> <p><strong>I want to know specific ways that using Python or Ruby can make me a more productive .NET developer.</strong><...
4
2009-08-30T06:13:28Z
1,353,228
<h2>Advanced Text Processing</h2> <p>Traditional strengths of awk and perl. You can just glue together a bunch of regular expressions to create a simple data-mining system on the go.</p>
2
2009-08-30T06:24:30Z
[ ".net", "python", "ruby", "productivity" ]
I'm a .NET Programmer. What are specific uses of Python and/or Ruby for that will make me more productive?
1,353,211
<p>I recall when I first read Pragmatic Programmer that they suggested using scripting languages to make you a more productive programmer.</p> <p>I am in a quandary putting this into practice.</p> <p><strong>I want to know specific ways that using Python or Ruby can make me a more productive .NET developer.</strong><...
4
2009-08-30T06:13:28Z
1,353,229
<h2>Less Code</h2> <p>I think productivity is direct result on how proficient you are in a specific language. That said the terseness of a language like Python might save some time on getting certain things done.</p> <p>If I compare how much less code I have to write for simple administration scripts (e.g. clean-up ...
4
2009-08-30T06:24:34Z
[ ".net", "python", "ruby", "productivity" ]
I'm a .NET Programmer. What are specific uses of Python and/or Ruby for that will make me more productive?
1,353,211
<p>I recall when I first read Pragmatic Programmer that they suggested using scripting languages to make you a more productive programmer.</p> <p>I am in a quandary putting this into practice.</p> <p><strong>I want to know specific ways that using Python or Ruby can make me a more productive .NET developer.</strong><...
4
2009-08-30T06:13:28Z
1,353,244
<h2>Cross platform</h2> <p>Compared to .NET a simple script Python is more easily ported to other platforms such as Linux. Although possible to achieve the same with the likes of Mono it simpler to run a Python script file on different platforms.</p>
1
2009-08-30T06:35:51Z
[ ".net", "python", "ruby", "productivity" ]
I'm a .NET Programmer. What are specific uses of Python and/or Ruby for that will make me more productive?
1,353,211
<p>I recall when I first read Pragmatic Programmer that they suggested using scripting languages to make you a more productive programmer.</p> <p>I am in a quandary putting this into practice.</p> <p><strong>I want to know specific ways that using Python or Ruby can make me a more productive .NET developer.</strong><...
4
2009-08-30T06:13:28Z
1,353,255
<h2>Processing received Email</h2> <p>Python has built-in support for POP3 and IMAP where the standard .NET framework doesn't. Useful for automating email triggered tasks.</p>
1
2009-08-30T06:40:17Z
[ ".net", "python", "ruby", "productivity" ]
I'm a .NET Programmer. What are specific uses of Python and/or Ruby for that will make me more productive?
1,353,211
<p>I recall when I first read Pragmatic Programmer that they suggested using scripting languages to make you a more productive programmer.</p> <p>I am in a quandary putting this into practice.</p> <p><strong>I want to know specific ways that using Python or Ruby can make me a more productive .NET developer.</strong><...
4
2009-08-30T06:13:28Z
1,353,273
<p>Learning a new language gives you knowledge that you can bring back to <em>any</em> programming language. Here are some things you'd learn.</p> <p>Add <a href="http://jonesbunch.com/articles/2008/ruby-singleton" rel="nofollow">functionality to your objects</a> on the fly. </p> <p><a href="http://juixe.com/techknow...
2
2009-08-30T06:52:17Z
[ ".net", "python", "ruby", "productivity" ]
I'm a .NET Programmer. What are specific uses of Python and/or Ruby for that will make me more productive?
1,353,211
<p>I recall when I first read Pragmatic Programmer that they suggested using scripting languages to make you a more productive programmer.</p> <p>I am in a quandary putting this into practice.</p> <p><strong>I want to know specific ways that using Python or Ruby can make me a more productive .NET developer.</strong><...
4
2009-08-30T06:13:28Z
1,353,301
<h2>Embedding a script engine</h2> <p>Use of IronPython for a scripting engine inside your .NET application. For example enabling end-users of your application to change customizable parts with a full fledge language such as Python.</p> <p>A possible example might be to expose custom logic to end-users for a work fl...
2
2009-08-30T07:08:56Z
[ ".net", "python", "ruby", "productivity" ]
Should I optimise my python code like C++? Does it matter?
1,353,715
<p>I had an argument with a colleague about writing python efficiently. He claimed that though you are programming python you still have to optimise the little bits of your software as much as possible, as if you are writing an efficient algorithm in C++.</p> <p>Things like:</p> <ul> <li>In an <code>if</code> stateme...
5
2009-08-30T11:49:35Z
1,353,722
<p>My answer to that would be :</p> <blockquote> <p>We should forget about small efficiencies, say about 97% of the time: premature optimization is the root of all evil.</p> </blockquote> <p><em>(Quoting Knuth, Donald. Structured Programming with go to Statements, ACM Journal Computing Surveys, Vol 6, No. 4, ...
14
2009-08-30T11:52:06Z
[ "python", "performance" ]
Should I optimise my python code like C++? Does it matter?
1,353,715
<p>I had an argument with a colleague about writing python efficiently. He claimed that though you are programming python you still have to optimise the little bits of your software as much as possible, as if you are writing an efficient algorithm in C++.</p> <p>Things like:</p> <ul> <li>In an <code>if</code> stateme...
5
2009-08-30T11:49:35Z
1,353,728
<blockquote> <p>I should also say that context of the code is not a super-efficient NOC or missile-guidance systems. We're mostly writing tests in python.</p> </blockquote> <p>Given this, I'd say that you should take your colleague's advice about writing efficient Python but ignore anything he says that goes against...
3
2009-08-30T11:55:53Z
[ "python", "performance" ]
Should I optimise my python code like C++? Does it matter?
1,353,715
<p>I had an argument with a colleague about writing python efficiently. He claimed that though you are programming python you still have to optimise the little bits of your software as much as possible, as if you are writing an efficient algorithm in C++.</p> <p>Things like:</p> <ul> <li>In an <code>if</code> stateme...
5
2009-08-30T11:49:35Z
1,353,732
<p>The answer is really simple :</p> <ul> <li>Follow Python best practices, not C++ best practices.</li> <li>Readability in Python is more important that speed.</li> <li>If performance becomes an issue, measure, then start optimizing.</li> </ul>
13
2009-08-30T11:57:23Z
[ "python", "performance" ]
Should I optimise my python code like C++? Does it matter?
1,353,715
<p>I had an argument with a colleague about writing python efficiently. He claimed that though you are programming python you still have to optimise the little bits of your software as much as possible, as if you are writing an efficient algorithm in C++.</p> <p>Things like:</p> <ul> <li>In an <code>if</code> stateme...
5
2009-08-30T11:49:35Z
1,353,773
<blockquote> <p>In an if statement with an or always put the condition most likely to fail first, so the second will not be checked.</p> </blockquote> <p>This is generally a good advice, and also depends on the logic of your program. If it makes sense that the second statement is not evaluated if the first ret...
2
2009-08-30T12:26:12Z
[ "python", "performance" ]
Should I optimise my python code like C++? Does it matter?
1,353,715
<p>I had an argument with a colleague about writing python efficiently. He claimed that though you are programming python you still have to optimise the little bits of your software as much as possible, as if you are writing an efficient algorithm in C++.</p> <p>Things like:</p> <ul> <li>In an <code>if</code> stateme...
5
2009-08-30T11:49:35Z
1,353,775
<p>This sort of premature micro-optimisation is usually a waste of time in my experience, even in C and C++. Write readable code first. If it's running too slowly, run it through a profiler, and if necessary, fix the hot-spots.</p> <p>Fundamentally, you need to think about return on investment. Is it worth the extra e...
10
2009-08-30T12:26:37Z
[ "python", "performance" ]
Should I optimise my python code like C++? Does it matter?
1,353,715
<p>I had an argument with a colleague about writing python efficiently. He claimed that though you are programming python you still have to optimise the little bits of your software as much as possible, as if you are writing an efficient algorithm in C++.</p> <p>Things like:</p> <ul> <li>In an <code>if</code> stateme...
5
2009-08-30T11:49:35Z
1,353,788
<p>I agree with others: readable code first ("Performance is not a problem until performance is a problem.").</p> <p>I only want to add that when you absolutely need to write some unreadable and/or non-intuitive code, you can generally isolate it in few specific methods, for which you can write detailed comments, and ...
4
2009-08-30T12:36:50Z
[ "python", "performance" ]
Should I optimise my python code like C++? Does it matter?
1,353,715
<p>I had an argument with a colleague about writing python efficiently. He claimed that though you are programming python you still have to optimise the little bits of your software as much as possible, as if you are writing an efficient algorithm in C++.</p> <p>Things like:</p> <ul> <li>In an <code>if</code> stateme...
5
2009-08-30T11:49:35Z
1,353,798
<p>Sure follow Python best-practices (and in fact I agree with the first two recommendations), but maintainability and efficiency are not opposites, they are mostly togethers (if that's a word).</p> <p>Statements like "always write your IF statements a certain way for performance" are a-priori, i.e. not based on knowl...
1
2009-08-30T12:42:44Z
[ "python", "performance" ]
Should I optimise my python code like C++? Does it matter?
1,353,715
<p>I had an argument with a colleague about writing python efficiently. He claimed that though you are programming python you still have to optimise the little bits of your software as much as possible, as if you are writing an efficient algorithm in C++.</p> <p>Things like:</p> <ul> <li>In an <code>if</code> stateme...
5
2009-08-30T11:49:35Z
1,354,718
<p>I think there are several related 'urban legends' here.</p> <ul> <li><p><strong>False</strong> Putting the more often-checked condition first in a conditional and similar optimizations save enough time for a typical program that it is worthy for a typical programmer.</p></li> <li><p><strong>True</strong> Some, but ...
2
2009-08-30T19:33:55Z
[ "python", "performance" ]
Should I optimise my python code like C++? Does it matter?
1,353,715
<p>I had an argument with a colleague about writing python efficiently. He claimed that though you are programming python you still have to optimise the little bits of your software as much as possible, as if you are writing an efficient algorithm in C++.</p> <p>Things like:</p> <ul> <li>In an <code>if</code> stateme...
5
2009-08-30T11:49:35Z
1,354,801
<p>Before introducing performance optimizations at the expense of readability, look into modules like psyco that will do some JIT-ish compiling of distinct functions, often with striking results, with no impairment of readability.</p> <p>Then if you really want to embark on the optimization path, you must first learn ...
2
2009-08-30T20:16:59Z
[ "python", "performance" ]
Should I optimise my python code like C++? Does it matter?
1,353,715
<p>I had an argument with a colleague about writing python efficiently. He claimed that though you are programming python you still have to optimise the little bits of your software as much as possible, as if you are writing an efficient algorithm in C++.</p> <p>Things like:</p> <ul> <li>In an <code>if</code> stateme...
5
2009-08-30T11:49:35Z
1,354,833
<p>My visceral reaction is this:</p> <p>I've worked with guys like your colleague and in general I wouldn't take advice from them.</p> <p>Ask him if he's ever even used a profiler.</p>
1
2009-08-30T20:29:55Z
[ "python", "performance" ]
Handling KeyboardInterrupt in a KDE Python application?
1,353,823
<p>I'm working on a PyKDE4/PyQt4 application, <a href="http://autokey.googlecode.com/" rel="nofollow">Autokey</a>, and I noticed that when I send the program a CTRL+C, the keyboard interrupt is not processed until I interact with the application, by ie. clicking on a menu item or changing a checkbox. </p> <pre><code>l...
2
2009-08-30T12:58:52Z
1,357,015
<p>Try doing this:</p> <pre><code>import signal signal.signal(signal.SIGINT, signal.SIG_DFL) </code></pre> <p>before invoking <code>a.main()</code>.</p> <p><strong>Update:</strong> Remember, Ctrl-C can be used for Copy in GUI applications. It's better to use Ctrl+\ in Qt, which will cause the event loop to terminate...
4
2009-08-31T11:31:07Z
[ "python", "pyqt", "keyboardinterrupt", "pykde", "autokey" ]
Creating SVGs using Python
1,353,976
<p>I'm building a set of SVG files that include an unfortunate number of hardcoded values (they must print with some elements sized in mm, while others must be scaled as a percent, and most of the values are defined relative to each other). Rather than managing those numbers by hand (heaven forbid I want to change some...
5
2009-08-30T14:19:45Z
1,354,013
<p>Since SVG is XML, maybe you could use XSLT to transform a source XML file containing your variables to SVG. In your XSLT style sheet, you would have templates corresponding to various elements of your SVG illustration, that change their output depending on the values found in the source XML file.</p> <p>Or you coul...
0
2009-08-30T14:34:32Z
[ "python", "xml", "graphics", "svg" ]
Creating SVGs using Python
1,353,976
<p>I'm building a set of SVG files that include an unfortunate number of hardcoded values (they must print with some elements sized in mm, while others must be scaled as a percent, and most of the values are defined relative to each other). Rather than managing those numbers by hand (heaven forbid I want to change some...
5
2009-08-30T14:19:45Z
1,354,057
<p>A markup based templating engine, such as <a href="http://genshi.edgewall.org/" rel="nofollow">genshi</a> might be useful. It would let you do most of the authoring using a SVG tool and do the customization in the template. I'd definitely prefer it to XSLT.</p>
4
2009-08-30T15:02:22Z
[ "python", "xml", "graphics", "svg" ]
How to implement a multiprocessing priority queue in Python?
1,354,204
<p>Anybody familiar with how I can implement a multiprocessing priority queue in python?</p>
4
2009-08-30T16:17:03Z
1,354,255
<p>There is a bug that prevents true FIFO.<br /> Read <a href="http://bugs.python.org/issue4999" rel="nofollow">here</a>.</p> <p>An alternate way to build a priority queue multiprocessing setup would be certainly be great!</p>
2
2009-08-30T16:37:12Z
[ "python", "multiprocessing", "priority-queue" ]
How to implement a multiprocessing priority queue in Python?
1,354,204
<p>Anybody familiar with how I can implement a multiprocessing priority queue in python?</p>
4
2009-08-30T16:17:03Z
1,354,295
<p>Alas, it's nowhere as simple as changing queueing discipline of a good old <code>Queue.Queue</code>: the latter is in fact designed to be subclassed according to a template-method pattern, and overriding just the hook methods <code>_put</code> and/or <code>_get</code> can easily allow changing the queueing disciplin...
5
2009-08-30T16:56:16Z
[ "python", "multiprocessing", "priority-queue" ]
How to implement a multiprocessing priority queue in Python?
1,354,204
<p>Anybody familiar with how I can implement a multiprocessing priority queue in python?</p>
4
2009-08-30T16:17:03Z
1,354,373
<p>While this isn't an answer, maybe it can help you develop an multiprocessing queue. </p> <p>Here's a simple <strong>priority queue</strong> class I wrote using Python's <strong>Array</strong>:</p> <pre><code>class PriorityQueue(): """A basic priority queue that dequeues items with the smallest priority number....
1
2009-08-30T17:21:32Z
[ "python", "multiprocessing", "priority-queue" ]
How to implement a multiprocessing priority queue in Python?
1,354,204
<p>Anybody familiar with how I can implement a multiprocessing priority queue in python?</p>
4
2009-08-30T16:17:03Z
1,359,108
<p>Depending on your requirements you could use the operating system and the file system in a number of ways. How large will the queue grow and how fast does it have to be? If the queue may be big but you are willing to open a couple files for every queue access you could use a BTree implementation to store the queue...
0
2009-08-31T19:49:54Z
[ "python", "multiprocessing", "priority-queue" ]
How to implement a multiprocessing priority queue in Python?
1,354,204
<p>Anybody familiar with how I can implement a multiprocessing priority queue in python?</p>
4
2009-08-30T16:17:03Z
1,750,166
<p>I had the same use case. But with a finite number of priorities.</p> <p>What I am ending up doing is creating one Queue per priority, and my Process workers will try to get the items from those queues, starting with the most important queue to the less important one (moving from one queue to the other is done when ...
1
2009-11-17T16:43:45Z
[ "python", "multiprocessing", "priority-queue" ]
How to implement a multiprocessing priority queue in Python?
1,354,204
<p>Anybody familiar with how I can implement a multiprocessing priority queue in python?</p>
4
2009-08-30T16:17:03Z
22,471,105
<p>Inspired by @user211505's suggestion, I put together something quick and dirty. </p> <p>Note that this is not a complete solution to the difficult problem of priority queues in multiprocessing production environments. However, if you're just messing around or need something for a short project, this will likely fi...
0
2014-03-18T05:30:07Z
[ "python", "multiprocessing", "priority-queue" ]
Using HTML Parser with HTTPResponse in Python 3.1
1,354,338
<p>The response data from HTTPResponse object is of type bytes. </p> <pre><code>conn = http.client.HTTPConnection(www.yahoo.com) conn.request("GET","/") response = conn.getresponse(); data = response.read() type(data) </code></pre> <p>The data is of type bytes.</p> <p>I would like to use the response along with the ...
0
2009-08-30T17:10:27Z
1,354,379
<blockquote> <p>Is there a reason why HTTP response does not return string?</p> </blockquote> <p>You nailed it yourself. A HTTP response isn't necessarily a string.</p> <p>It can be an image, for example, and even when it is a string it can't know the encoding. If you know the encoding (or have an encoding detect...
2
2009-08-30T17:25:01Z
[ "python", "html", "http" ]
Split Twitter RSS string using Python
1,354,415
<p>I am trying to parse Twitter RSS feeds and put the information in a sqlite database, using Python. Here's an example:</p> <pre><code>MiamiPete: today's "Last Call" is now up http://bit.ly/MGDzu #stocks #stockmarket #finance #money </code></pre> <p>What I want to do is create one column for the main content (<code>...
1
2009-08-30T17:38:25Z
1,354,515
<p>Twitter has an api that may be easier for you to use here, <a href="http://apiwiki.twitter.com/Twitter-API-Documentation" rel="nofollow">http://apiwiki.twitter.com/Twitter-API-Documentation</a>.</p> <p>You can get the results as JSON or XML and use one of the many Python libraries to parse the results.</p> <p>Or i...
1
2009-08-30T18:20:54Z
[ "python", "string", "sqlite", "split", "bit.ly" ]
Split Twitter RSS string using Python
1,354,415
<p>I am trying to parse Twitter RSS feeds and put the information in a sqlite database, using Python. Here's an example:</p> <pre><code>MiamiPete: today's "Last Call" is now up http://bit.ly/MGDzu #stocks #stockmarket #finance #money </code></pre> <p>What I want to do is create one column for the main content (<code>...
1
2009-08-30T17:38:25Z
1,354,517
<p>It seems like your data-driven design is rather flawed. Unless all your entries have a text part, an url and up to 4 tags, it's not going to work.</p> <p>You also need to separate saving to db from parsing. Parsing could be easily done with a regexep (or even string methods):</p> <pre><code>&gt;&gt;&gt; s = your_s...
4
2009-08-30T18:21:40Z
[ "python", "string", "sqlite", "split", "bit.ly" ]
Split Twitter RSS string using Python
1,354,415
<p>I am trying to parse Twitter RSS feeds and put the information in a sqlite database, using Python. Here's an example:</p> <pre><code>MiamiPete: today's "Last Call" is now up http://bit.ly/MGDzu #stocks #stockmarket #finance #money </code></pre> <p>What I want to do is create one column for the main content (<code>...
1
2009-08-30T17:38:25Z
1,354,577
<p>Also, you can parse your strings using regexps:</p> <pre><code>&gt;&gt;&gt; s = (u'MiamiPete: today\'s "Last Call" is now up http://bit.ly/MGDzu ' '#stocks #stockmarket #finance #money') &gt;&gt;&gt; re.match(r'(.*) (http://[^ ]+)', s).groups() (u'MiamiPete: today\'s "Last Call" is now up', u'http://bit.ly...
2
2009-08-30T18:41:51Z
[ "python", "string", "sqlite", "split", "bit.ly" ]
Split Twitter RSS string using Python
1,354,415
<p>I am trying to parse Twitter RSS feeds and put the information in a sqlite database, using Python. Here's an example:</p> <pre><code>MiamiPete: today's "Last Call" is now up http://bit.ly/MGDzu #stocks #stockmarket #finance #money </code></pre> <p>What I want to do is create one column for the main content (<code>...
1
2009-08-30T17:38:25Z
1,355,156
<p>I would highly recommend using the Twitter API. There are actually two APIs, one for the main twitter server and one for the search server. They are used for different things.</p> <p>You can find sample code, pytwitter on svn. Add simplejson and you can be doing very powerful things in a matter of minutes.</p> ...
1
2009-08-30T22:59:11Z
[ "python", "string", "sqlite", "split", "bit.ly" ]
Storing huge hash table in a file in Python
1,354,520
<p>Hey. I have a function I want to memoize, however, it has too many possible values. Is there any convenient way to store the values in a text file and make it read from them? For example, something like storing a pre-computed list of primes up to 10^9 in a text file? I know it's slow to read from a text file but the...
4
2009-08-30T18:24:09Z
1,354,533
<p>You can use the <a href="http://docs.python.org/library/shelve.html">shelve module</a> to store a dictionary like structure in a file. From the Python documentation:</p> <pre><code>import shelve d = shelve.open(filename) # open -- file may get suffix added by low-level # library d[key] =...
6
2009-08-30T18:27:40Z
[ "python", "file", "hashtable" ]
Storing huge hash table in a file in Python
1,354,520
<p>Hey. I have a function I want to memoize, however, it has too many possible values. Is there any convenient way to store the values in a text file and make it read from them? For example, something like storing a pre-computed list of primes up to 10^9 in a text file? I know it's slow to read from a text file but the...
4
2009-08-30T18:24:09Z
1,354,611
<p>You can also go one step down the ladder and use <a href="http://docs.python.org/library/pickle.html" rel="nofollow">pickle</a>. <a href="http://docs.python.org/library/shelve.html#module-shelve" rel="nofollow">Shelve</a> imports from pickle (<a href="http://groups.google.com/group/comp.lang.python/msg/2913f64bc43e8...
0
2009-08-30T18:52:06Z
[ "python", "file", "hashtable" ]
Storing huge hash table in a file in Python
1,354,520
<p>Hey. I have a function I want to memoize, however, it has too many possible values. Is there any convenient way to store the values in a text file and make it read from them? For example, something like storing a pre-computed list of primes up to 10^9 in a text file? I know it's slow to read from a text file but the...
4
2009-08-30T18:24:09Z
1,354,615
<p>For <a href="http://projecteuler.net/" rel="nofollow">Project Euler</a>, I stored a precomputed list of primes up to 10**8 in a text file just by writing them in comma separated format. It worked well for that size, but it doesn't scale well to going much larger.</p> <p>If your huge is not really that huge, I would...
1
2009-08-30T18:54:37Z
[ "python", "file", "hashtable" ]
Storing huge hash table in a file in Python
1,354,520
<p>Hey. I have a function I want to memoize, however, it has too many possible values. Is there any convenient way to store the values in a text file and make it read from them? For example, something like storing a pre-computed list of primes up to 10^9 in a text file? I know it's slow to read from a text file but the...
4
2009-08-30T18:24:09Z
1,354,619
<p>For a list of primes up to <code>10**9</code>, why do you need a hash? What would the KEYS be?! Sounds like a perfect opportunity for a simple, straightforward binary file! By the <a href="http://en.wikipedia.org/wiki/Prime%5Fnumber%5Ftheorem">Prime Number Theorem</a>, there's about <code>10**9/ln(10**9)</code> s...
10
2009-08-30T18:56:01Z
[ "python", "file", "hashtable" ]
Storing huge hash table in a file in Python
1,354,520
<p>Hey. I have a function I want to memoize, however, it has too many possible values. Is there any convenient way to store the values in a text file and make it read from them? For example, something like storing a pre-computed list of primes up to 10^9 in a text file? I know it's slow to read from a text file but the...
4
2009-08-30T18:24:09Z
1,354,632
<p>Let's see where the bottleneck is. When you're going to read a file, the hard drive has to turn enough to be able to read from it; then it reads a big block and caches the results.</p> <p>So you want some method that will guess exactly <em>what position in file you're going to read from</em> and then do it exactly ...
0
2009-08-30T18:59:23Z
[ "python", "file", "hashtable" ]
Storing huge hash table in a file in Python
1,354,520
<p>Hey. I have a function I want to memoize, however, it has too many possible values. Is there any convenient way to store the values in a text file and make it read from them? For example, something like storing a pre-computed list of primes up to 10^9 in a text file? I know it's slow to read from a text file but the...
4
2009-08-30T18:24:09Z
1,354,750
<p>Just naively sticking a hash table onto disk will result in about 5 orders of magnitude performance loss compared to an in memory implementation (or at least 3 if you have a SSD). When dealing with hard disks you'll want to extract every bit of data-locality and caching you can get.</p> <p>The correct choice will d...
1
2009-08-30T19:50:31Z
[ "python", "file", "hashtable" ]
Storing huge hash table in a file in Python
1,354,520
<p>Hey. I have a function I want to memoize, however, it has too many possible values. Is there any convenient way to store the values in a text file and make it read from them? For example, something like storing a pre-computed list of primes up to 10^9 in a text file? I know it's slow to read from a text file but the...
4
2009-08-30T18:24:09Z
1,354,864
<p>You could also just go with the ultimate brute force, and create a Python file with just a single statement in it:</p> <pre><code>seedprimes = [3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71,73, 79,83,89,97,101,103,107,109,113,127,131,137,139,149,151,157,163,167,173, ... </code></pre> <p>and then just impor...
3
2009-08-30T20:49:04Z
[ "python", "file", "hashtable" ]
python object to native c++ pointer
1,355,187
<p>Im toying around with the idea to use python as an embedded scripting language for a project im working on and have got most things working. However i cant seem to be able to convert a python extended object back into a native c++ pointer.</p> <p>So this is my class:</p> <pre><code>class CGEGameModeBase { public: ...
2
2009-08-30T23:17:28Z
1,356,618
<p>Well, I am not sure whether it will help you, but I had the same problem with scripts in Lua. We created objects from Lua and wanted some c++ code to handle the objects via pointers. We did the following:</p> <ul> <li>all object stuff was written in c++, including constructors, destructors and factory method;</li> ...
0
2009-08-31T09:22:47Z
[ "c++", "python", "boost", "embedded-language" ]
python object to native c++ pointer
1,355,187
<p>Im toying around with the idea to use python as an embedded scripting language for a project im working on and have got most things working. However i cant seem to be able to convert a python extended object back into a native c++ pointer.</p> <p>So this is my class:</p> <pre><code>class CGEGameModeBase { public: ...
2
2009-08-30T23:17:28Z
1,356,622
<p>May not be the answer you are looking for, but take a look at <a href="http://www.chaiscript.com/" rel="nofollow">ChaiScript</a> for embedding in your C++ application.</p> <p>According to their website,</p> <blockquote> <p>ChaiScript is the first and only scripting language designed from the ground up with C...
0
2009-08-31T09:23:25Z
[ "c++", "python", "boost", "embedded-language" ]
python object to native c++ pointer
1,355,187
<p>Im toying around with the idea to use python as an embedded scripting language for a project im working on and have got most things working. However i cant seem to be able to convert a python extended object back into a native c++ pointer.</p> <p>So this is my class:</p> <pre><code>class CGEGameModeBase { public: ...
2
2009-08-30T23:17:28Z
1,357,350
<p>Thanks to Stefan from the python c++ mailling list, i was missing </p> <pre><code>super(Alpha, self).__init__() </code></pre> <p>from the constructor call meaning it never made the parent class. Thought this would of been automatic :D</p> <p>Only other issue i had was saving the new class instance as a global var...
1
2009-08-31T13:00:16Z
[ "c++", "python", "boost", "embedded-language" ]
How to tell if a full-screen application is running?
1,355,206
<p>Is it possible in python to tell if a full screen application on linux is running? I have a feeling it might be possible using Xlib but I haven't found a way.</p> <p><strong>EDIT:</strong> By full screen I mean the WHOLE screen nothing else but the application, such as a full-screen game.</p>
6
2009-08-30T23:26:39Z
1,355,332
<p>If all Window Managers you're interested in running under support <a href="http://standards.freedesktop.org/wm-spec/1.3/index.html#id2463334" rel="nofollow">EWMH</a>, the Extended Window Manager Hints standard, there are elegant ways to perform this (speaking to Xlib via ctypes, for example). The <code>_NET_ACTIVE_W...
4
2009-08-31T00:36:33Z
[ "python", "linux", "x11" ]
How to tell if a full-screen application is running?
1,355,206
<p>Is it possible in python to tell if a full screen application on linux is running? I have a feeling it might be possible using Xlib but I haven't found a way.</p> <p><strong>EDIT:</strong> By full screen I mean the WHOLE screen nothing else but the application, such as a full-screen game.</p>
6
2009-08-30T23:26:39Z
1,360,522
<p>Found a solution:</p> <pre><code>import Xlib.display screen = Xlib.display.Display().screen() root_win = screen.root num_of_fs = 0 for window in root_win.query_tree()._data['children']: window_name = window.get_wm_name() width = window.get_geometry()._data["width"] height = window.get_geometry()._data...
3
2009-09-01T04:27:22Z
[ "python", "linux", "x11" ]
Python code to download a webpage using JavaScript
1,355,244
<p>Im trying to download share data from a stock exchange using python. The problem is that there is no direct download link, but rather a javascript to export the data.</p> <p>The data page url: </p> <pre><code>http://tase.co.il/TASE/Templates/Company/CompanyHistory.aspx?NRMODE=Published&amp;NRORIGINALURL=%2fTASEEn...
1
2009-08-30T23:52:45Z
1,355,294
<p>You could use <a href="http://seleniumhq.org/" rel="nofollow">Selenium</a> or other ways to automate a browser to take advantage of the browser's built-in Javascript interpreter -- to control Selenium with Python, see e.g. <a href="http://jimmyg.org/blog/2009/getting-started-with-selenium-and-python.html" rel="nofol...
1
2009-08-31T00:15:31Z
[ "javascript", "python" ]
Latin letters with acute : DjangoUnicodeDecodeError
1,355,285
<p>I have a problem reading a txt file to insert in the mysql db table, te sniped of this code:</p> <p>file contains the in first line: "<b>aclaración</b>"</p> <blockquote> <p>archivo = open('file.txt',"r") <br> for line in archivo.readlines():<br> ....body = body + line<br> model = MyModel(body=body)<br> ...
1
2009-08-31T00:11:44Z
1,355,303
<p>Judging from the <code>\xf3</code> code for 'ó', it does look like the data is encoded in ISO-8859-1 (or some close relative). So <code>body.decode('iso-8859-1')</code> should be a valid Unicode string (you don't specify what "without solution" means -- what error message do you get, and where?); if what you need ...
5
2009-08-31T00:20:06Z
[ "python", "django", "utf-8", "character-encoding" ]
Python classes -- mutability
1,355,555
<p>Im having a problem with python.. I have a binary tree node type:</p> <pre><code>class NODE: element = 0 leftchild = None rightchild = None </code></pre> <p>And I had to implement a function deletemin:</p> <pre><code>def DELETEMIN( A ): if A.leftchild == None: retva...
1
2009-08-31T02:26:42Z
1,355,568
<p>Python passes arguments by object-reference, just like java, not by variable-reference. When you assign to a local variable (including an argument) to a new value, you're changing only the local variable, nothing else (don't confuse that with calling mutators or assigning to ATTRIBUTES of objects: we're talking abou...
2
2009-08-31T02:31:26Z
[ "python", "class" ]