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
Python and urllib
2,289,768
<p>I'm trying to download a zip file ("tl_2008_01001_edges.zip") from an ftp <a href="ftp://ftp2.census.gov/geo/tiger/TIGER2008/01_ALABAMA/01001_Autauga_County/" rel="nofollow">census</a> site using urllib. What form is the zip file in when I get it and how do I save it?</p> <p>I'm fairly new to Python and don't under...
4
2010-02-18T15:31:50Z
2,290,035
<p>Use <a href="http://docs.python.org/library/urllib2.html#urllib2.urlopen" rel="nofollow"><code>urllib2.urlopen()</code></a> for the zip file data <em>and</em> directory listing.</p> <p>To process zip files with the <a href="http://docs.python.org/library/zipfile.html#module-zipfile" rel="nofollow"><code>zipfile</co...
4
2010-02-18T16:04:55Z
[ "python", "urllib2", "urllib" ]
Disable class instance methods
2,289,797
<p>How can I quickly disable all methods in a class instance based on a condition? My naive solution is to override using the <code>__getattr__</code> but this is not called when the function name exists already.</p> <pre><code>class my(): def method1(self): print 'method1' def method2(self): p...
3
2010-02-18T15:34:11Z
2,289,840
<p>The equivalent of what you want to do is actually to override <code>__getattribute__</code>, which is going to be called for <strong>every</strong> attribute access. Besides it being very slow, take care: by definition of <strong>every</strong>, that includes e.g. the call to <code>self.isValid</code> within <code>...
5
2010-02-18T15:40:43Z
[ "python" ]
sort lines in text file, but only use the first N characters
2,289,870
<p>I have a text file with lines like this:</p> <pre><code>2010-02-18 11:46:46.1287 bla 2010-02-18 11:46:46.1333 foo 2010-02-18 11:46:46.1333 bar 2010-02-18 11:46:46.1467 bla </code></pre> <p>A simple sort would swap lines 2 and 3 (bar comes before foo), but I would like to keep lines (that have the same date/time) i...
9
2010-02-18T15:44:12Z
2,289,911
<pre><code>sorted(array, key=lambda x:x[:24]) </code></pre> <p>Example:</p> <pre><code>&gt;&gt;&gt; a = ["wxyz", "abce", "abcd", "bcde"] &gt;&gt;&gt; sorted(a) ['abcd', 'abce', 'bcde', 'wxyz'] &gt;&gt;&gt; sorted(a, key=lambda x:x[:3]) ['abce', 'abcd', 'bcde', 'wxyz'] </code></pre>
23
2010-02-18T15:48:27Z
[ "python", "datetime", "sorting" ]
sort lines in text file, but only use the first N characters
2,289,870
<p>I have a text file with lines like this:</p> <pre><code>2010-02-18 11:46:46.1287 bla 2010-02-18 11:46:46.1333 foo 2010-02-18 11:46:46.1333 bar 2010-02-18 11:46:46.1467 bla </code></pre> <p>A simple sort would swap lines 2 and 3 (bar comes before foo), but I would like to keep lines (that have the same date/time) i...
9
2010-02-18T15:44:12Z
2,290,046
<p>The built-in sort is stable, so you the effectively-equal values stay in order by default.</p> <pre><code>import operator with open('filename', 'r') as f: sorted_lines = sorted(f, key=operator.itemgetter(slice(0, 24))) </code></pre> <p>At this point <code>sorted_lines</code> will be a list of the sorted lines...
4
2010-02-18T16:06:59Z
[ "python", "datetime", "sorting" ]
Sudo equivalent for Django user profiles
2,289,917
<p>Is it possible to implement an equivalent of <code>sudo</code> for Django profiles ? I'm using the basic authentication system <code>django.contrib.auth</code>.</p> <p><strong>Usecase</strong>: Sometimes, users report bugs which are only reproductible in their profile, so, each time, I change their password, log i...
3
2010-02-18T15:49:11Z
2,290,109
<p>Djangosnippets.org is your friend: <a href="http://www.djangosnippets.org/snippets/1590/" rel="nofollow">http://www.djangosnippets.org/snippets/1590/</a></p>
3
2010-02-18T16:15:31Z
[ "python", "django", "authentication" ]
Sudo equivalent for Django user profiles
2,289,917
<p>Is it possible to implement an equivalent of <code>sudo</code> for Django profiles ? I'm using the basic authentication system <code>django.contrib.auth</code>.</p> <p><strong>Usecase</strong>: Sometimes, users report bugs which are only reproductible in their profile, so, each time, I change their password, log i...
3
2010-02-18T15:49:11Z
2,295,124
<p>I knocked up a user panel in the debug toolbar. It works well for flipping logged in users around . The fork is here. </p> <p><a href="http://github.com/mjbrownie/django-debug-toolbar" rel="nofollow">http://github.com/mjbrownie/django-debug-toolbar</a></p> <p>it also displays some basic user group permission info....
2
2010-02-19T09:18:03Z
[ "python", "django", "authentication" ]
Beginner extending C with Python (specifically Numpy)
2,290,007
<p>I am working on a real time audio processing dynamically linked library where I have a 2 dimensional C array of floating point data which represents the audio buffer. One dimension is time (samples) and the other is channel. I would like to pass this to a python script as a numpy array for the DSP processing and the...
6
2010-02-18T16:02:09Z
2,294,359
<p>You may be able to avoid dealing with the NumPy C API entirely. Python can call C code using the <code>ctypes</code> module, and you can access pointers into the numpy data using the array's ctypes attribute. </p> <p>Here's a minimal example showing the process for a 1d sum-of-squares function.</p> <h2>ctsquare.c<...
8
2010-02-19T05:53:47Z
[ "c++", "python", "c", "api", "numpy" ]
disabling "joining" when process shuts down
2,290,043
<p>Is there a way to stop the <code>multiprocessing</code> Python module from trying to call &amp; wait on <code>join()</code> on child processes of a parent process shutting down?</p> <p><code>2010-02-18 10:58:34,750 INFO calling join() for process procRx1</code></p> <p>I want the process to which I sent a <code>SIG...
1
2010-02-18T16:06:38Z
2,292,166
<p>Have you tried to explicitly using <a href="http://docs.python.org/library/multiprocessing.html#multiprocessing.pool.multiprocessing.Pool.terminate" rel="nofollow"><code>Process.terminate</code></a>?</p>
0
2010-02-18T21:01:30Z
[ "python", "multiprocessing", "fail-fast" ]
disabling "joining" when process shuts down
2,290,043
<p>Is there a way to stop the <code>multiprocessing</code> Python module from trying to call &amp; wait on <code>join()</code> on child processes of a parent process shutting down?</p> <p><code>2010-02-18 10:58:34,750 INFO calling join() for process procRx1</code></p> <p>I want the process to which I sent a <code>SIG...
1
2010-02-18T16:06:38Z
2,292,882
<p>You could try joining in a loop with a timeout (1 sec?) and checking if the thread is still alive, something like:</p> <pre><code>while True: a_thread.join(1) if not a_thread.isAlive(): break </code></pre> <p>Terminating the <code>a_thread</code> will trigger <code>break</code> clause.</p>
0
2010-02-18T22:58:25Z
[ "python", "multiprocessing", "fail-fast" ]
disabling "joining" when process shuts down
2,290,043
<p>Is there a way to stop the <code>multiprocessing</code> Python module from trying to call &amp; wait on <code>join()</code> on child processes of a parent process shutting down?</p> <p><code>2010-02-18 10:58:34,750 INFO calling join() for process procRx1</code></p> <p>I want the process to which I sent a <code>SIG...
1
2010-02-18T16:06:38Z
2,298,526
<p>Sounds like setting your subprocess' flag <code>Process.daemon = False</code> may be what you want:</p> <p><a href="http://docs.python.org/library/multiprocessing.html#multiprocessing.Process.daemon" rel="nofollow">Process.daemon</a>:</p> <p>The process’s daemon flag, a Boolean value. This must be set before sta...
0
2010-02-19T18:02:06Z
[ "python", "multiprocessing", "fail-fast" ]
How to set pythonpath (python2.6) for tkinter on Ubuntu 9.04 (to use nltk)?
2,290,375
<p>I'd like to use the nltk toolkit on my machine which runs Ubuntu 9.04. I installed python 2.6.4 and several additional packages (numpy, scipy, matplotlib and of course nltk). I can import nltk, but calling a few methods gives various error masseges, all contain "please install Tkinter library". Googling around I dis...
0
2010-02-18T16:46:35Z
2,290,400
<p>Sounds like you forgot to install the appropriate TkInter when you installed Python 2.6.4. Install it from the same source.</p>
3
2010-02-18T16:48:49Z
[ "python", "tkinter", "nltk", "pythonpath" ]
How to set pythonpath (python2.6) for tkinter on Ubuntu 9.04 (to use nltk)?
2,290,375
<p>I'd like to use the nltk toolkit on my machine which runs Ubuntu 9.04. I installed python 2.6.4 and several additional packages (numpy, scipy, matplotlib and of course nltk). I can import nltk, but calling a few methods gives various error masseges, all contain "please install Tkinter library". Googling around I dis...
0
2010-02-18T16:46:35Z
2,298,117
<p>Tkinter is usually included with the python standard libraries but Ubuntu left it out of the regular python package. You just need to install the <strong>python-tk</strong> package.</p> <pre><code>sudo apt-get install python-tk </code></pre>
1
2010-02-19T16:58:09Z
[ "python", "tkinter", "nltk", "pythonpath" ]
python more trouble importing modules
2,290,595
<p>I asked a similar question yesterday, but have acquired a really odd problem since then. With this directory structure:</p> <pre><code>app/ models/ __init__.py user.py other.py pages/ __init__.py pages.py </code></pre> <p>The models/__init__.py file has this line:</...
1
2010-02-18T17:09:41Z
2,290,620
<pre><code>import models.user </code></pre>
0
2010-02-18T17:13:46Z
[ "python", "python-module", "python-import" ]
python more trouble importing modules
2,290,595
<p>I asked a similar question yesterday, but have acquired a really odd problem since then. With this directory structure:</p> <pre><code>app/ models/ __init__.py user.py other.py pages/ __init__.py pages.py </code></pre> <p>The models/__init__.py file has this line:</...
1
2010-02-18T17:09:41Z
2,290,634
<p>There are two options, depending on where you want to be explicit and how much you want available "by default" (which also means forced).</p> <p>In those __init__ files you could use:</p> <pre><code># models/__init__.py shown: import user, other # ambiguous relative import from . import user, other...
2
2010-02-18T17:15:43Z
[ "python", "python-module", "python-import" ]
python more trouble importing modules
2,290,595
<p>I asked a similar question yesterday, but have acquired a really odd problem since then. With this directory structure:</p> <pre><code>app/ models/ __init__.py user.py other.py pages/ __init__.py pages.py </code></pre> <p>The models/__init__.py file has this line:</...
1
2010-02-18T17:09:41Z
2,290,713
<p>One thing that can be real helpful when you're learning python (or debugging), is to run interactively and use the <code>dir()</code> function to see what lives where: </p> <pre><code>&gt;&gt;&gt; dir() ['__builtins__', '__doc__', '__name__', '__package__'] &gt;&gt;&gt; import models &gt;&gt;&gt; dir(models) ['__al...
1
2010-02-18T17:25:33Z
[ "python", "python-module", "python-import" ]
Accessing a Variable from Within a Doubly Nested Function in Python
2,290,654
<p>The following code:</p> <pre><code>x = 0 print "Initialization: ", x def f1(): x = 1 print "In f1 before f2:", x def f2(): global x x = 2 print "In f2: ", x f2() print "In f1 after f2: ", x f1() print "Final: ", x </code></pre> <p>prints:</p> <pre><cod...
4
2010-02-18T17:18:01Z
2,290,703
<p>remove <code>global</code> statement:</p> <pre><code>&gt;&gt;&gt; x 0 &gt;&gt;&gt; def f1(): x = 1 print(x) def f2(): print(x) f2() print(x) &gt;&gt;&gt; f1() 1 1 1 </code></pre> <p>if you want to <strong>change</strong> variable <code>x</code> from <code>f1</code> then you need to us...
0
2010-02-18T17:24:34Z
[ "python", "global-variables", "nested-function" ]
Accessing a Variable from Within a Doubly Nested Function in Python
2,290,654
<p>The following code:</p> <pre><code>x = 0 print "Initialization: ", x def f1(): x = 1 print "In f1 before f2:", x def f2(): global x x = 2 print "In f2: ", x f2() print "In f1 after f2: ", x f1() print "Final: ", x </code></pre> <p>prints:</p> <pre><cod...
4
2010-02-18T17:18:01Z
2,290,708
<p>In Python 3, you can define x as <a href="http://docs.python.org/dev/3.0/reference/simple_stmts.html#the-nonlocal-statement">nonlocal</a> in f2.</p> <p>In Python 2, you can't assign directly to f1's x in f2. However, you can read its value and access its members. So this could be a workaround:</p> <pre><code>def f...
5
2010-02-18T17:25:11Z
[ "python", "global-variables", "nested-function" ]
Accessing a Variable from Within a Doubly Nested Function in Python
2,290,654
<p>The following code:</p> <pre><code>x = 0 print "Initialization: ", x def f1(): x = 1 print "In f1 before f2:", x def f2(): global x x = 2 print "In f2: ", x f2() print "In f1 after f2: ", x f1() print "Final: ", x </code></pre> <p>prints:</p> <pre><cod...
4
2010-02-18T17:18:01Z
2,290,711
<p>You can access the variables, the problem is the assignment. In Python 2 there is no way to rebind <code>x</code> to a new value. See <a href="http://www.python.org/dev/peps/pep-0227/" rel="nofollow">PEP 227</a> (nested scopes) for more on this.</p> <p>In Python 3 you can use the new <code>nonlocal</code> keyword i...
4
2010-02-18T17:25:24Z
[ "python", "global-variables", "nested-function" ]
Any utility function in python which returns value when passed object and attribute to it?
2,290,805
<p>Like we have in Java Beans util where you pass object and the property name it gives you the value do we have anything similar in python:</p> <pre><code>def attr(obj, attr) return obj.attr </code></pre>
0
2010-02-18T17:40:24Z
2,290,819
<p>You can use <code>getattr</code> for this purpose. From the <a href="http://docs.python.org/library/functions.html" rel="nofollow">built-in function documentation</a>:</p> <blockquote> <p>For example, <code>getattr(x, 'foobar')</code> is equivalent to <code>x.foobar</code>.</p> </blockquote>
6
2010-02-18T17:42:30Z
[ "python" ]
Google visualization api on app engine not working... (python)
2,290,827
<p>I'm trying to render the sortable table that's provided in Google visualization API in my app on app engine, but it's not working. The app is written in python and uses the django framework.</p> <p>When I copy the generated HTML/Javascript and save it as a plain html file locally, it works just fine. This leads me ...
-1
2010-02-18T17:44:27Z
2,299,377
<p>Wait, where are you doing the rendering? The visapi stuff goes in the client-side. Is that where you have it? (Sorry if that's obvious; it's really not entirely clear from the way you wrote the question.)</p> <p>More details would definitely help.</p>
0
2010-02-19T20:39:01Z
[ "python", "google-app-engine", "google-visualization" ]
Google visualization api on app engine not working... (python)
2,290,827
<p>I'm trying to render the sortable table that's provided in Google visualization API in my app on app engine, but it's not working. The app is written in python and uses the django framework.</p> <p>When I copy the generated HTML/Javascript and save it as a plain html file locally, it works just fine. This leads me ...
-1
2010-02-18T17:44:27Z
2,368,935
<p>In case anyone else has this issue - I messed up headers of the page generated by rendering with the same function I created for XML output.</p> <p>Including this killed it: handler.response.headers["Content-Type"] = "text/xml" </p>
0
2010-03-03T05:15:56Z
[ "python", "google-app-engine", "google-visualization" ]
gdb python scripting: where has `parse_and_eval` gone?
2,290,842
<p>I had some scripts in Python to help me debugging with GDB that used the function <a href="http://sourceware.org/gdb/current/onlinedocs/gdb/Basic-Python.html#Basic-Python" rel="nofollow"><code>gdb.parse_and_eval</code></a> (still documented) to get the inferior values from the arguments passed to a scripted command,...
2
2010-02-18T17:46:30Z
2,290,941
<p>I don't know where it went or why, but Qt implemented this workaround in <a href="http://qt.gitorious.org/qt-creator/qt-creator/commit/68bd4d2b95702046116a02b9fdc37a57983de011" rel="nofollow">their code</a>, which may be practically useful to you:</p> <pre><code>def parseAndEvaluate(exp): if gdb.VERSION.sta...
3
2010-02-18T18:02:01Z
[ "python", "gdb" ]
gdb python scripting: where has `parse_and_eval` gone?
2,290,842
<p>I had some scripts in Python to help me debugging with GDB that used the function <a href="http://sourceware.org/gdb/current/onlinedocs/gdb/Basic-Python.html#Basic-Python" rel="nofollow"><code>gdb.parse_and_eval</code></a> (still documented) to get the inferior values from the arguments passed to a scripted command,...
2
2010-02-18T17:46:30Z
2,299,987
<p><code>parse_and_eval</code> was checked in on the Archer branch, but has not been merged into mainline in time for 7.0 release. It has been merged now:</p> <pre><code>2009-12-03 Tom Tromey &lt;tromey@redhat.com&gt; * python/python.c (gdbpy_parse_and_eval): New function. (GdbMethods): Add "parse_a...
4
2010-02-19T22:11:23Z
[ "python", "gdb" ]
How to solve this using regex?
2,290,859
<p>Given that string:</p> <pre> \n \n text1\n \ttext2\n Message: 1st message\n some more text\n \n \n Message: 2dn message\n\n \t\t Message: 3rd message\n text3\n </pre> <p>I want to extract messages from a multiline string (token is 'Message: '). What regex expression should I use to capture those 3 groups:</p> ...
2
2010-02-18T17:49:21Z
2,290,883
<pre><code>&gt;&gt;&gt; re.findall('Message: (.+?)$', s, re.M) ['1st message', '2dn message', '3rd message'] </code></pre> <p><a href="http://docs.python.org/library/re.html#re.M" rel="nofollow"><code>re.M</code> flag gives special meaning to <code>^</code> and <code>$</code></a>:</p> <blockquote> <p>When specified...
9
2010-02-18T17:53:49Z
[ "python", "regex" ]
How to solve this using regex?
2,290,859
<p>Given that string:</p> <pre> \n \n text1\n \ttext2\n Message: 1st message\n some more text\n \n \n Message: 2dn message\n\n \t\t Message: 3rd message\n text3\n </pre> <p>I want to extract messages from a multiline string (token is 'Message: '). What regex expression should I use to capture those 3 groups:</p> ...
2
2010-02-18T17:49:21Z
2,293,380
<p>@OP,you don't need a regex. Assuming you don't care about the lines after <code>"Message:"</code>,</p> <pre><code>for line in mystring.split("\n") if "Message:" in line: print "found: ",line </code></pre>
0
2010-02-19T00:50:45Z
[ "python", "regex" ]
Python: how to get sorted count of items in a list?
2,290,962
<p>In Python, I've got a list of items like:</p> <pre><code>mylist = [a, a, a, a, b, b, b, d, d, d, c, c, e] </code></pre> <p>And I'd like to output something like:</p> <pre><code>a (4) b (3) d (3) c (2) e (1) </code></pre> <p>How can I output a count and leaderboard of items in a list? I'm not too bothered about e...
4
2010-02-18T18:06:40Z
2,290,995
<pre><code>from collections import defaultdict def leaders(xs, top=10): counts = defaultdict(int) for x in xs: counts[x] += 1 return sorted(counts.items(), reverse=True, key=lambda tup: tup[1])[:top] </code></pre> <p>So this function uses a <code>defaultdict</code> to count the number of each entr...
5
2010-02-18T18:11:14Z
[ "python" ]
Python: how to get sorted count of items in a list?
2,290,962
<p>In Python, I've got a list of items like:</p> <pre><code>mylist = [a, a, a, a, b, b, b, d, d, d, c, c, e] </code></pre> <p>And I'd like to output something like:</p> <pre><code>a (4) b (3) d (3) c (2) e (1) </code></pre> <p>How can I output a count and leaderboard of items in a list? I'm not too bothered about e...
4
2010-02-18T18:06:40Z
2,290,999
<p>A two-liner:</p> <pre><code>for count, elem in sorted(((mylist.count(e), e) for e in set(mylist)), reverse=True): print '%s (%d)' % (elem, count) </code></pre>
3
2010-02-18T18:11:45Z
[ "python" ]
Can I use XPCOM to create and manipulate a Firefox window as I would use win32 COM with IE?
2,291,034
<p>With win32 COM I create an Internet Explorer instance and control it almost fully from my python code (manipulate windows, DOM elements, etc). More specifically, using DispatchEx('InternetExplorer.Application'). Can I do the same using XPCOM and C++/python?</p> <p>I need to automate certain actions taken on the htm...
1
2010-02-18T18:16:37Z
2,291,233
<p>I don't know about programmatically creating and controlling full Firefox instances, but Mozilla can definitely be embedded using XPCOM.<br> The <a href="https://developer.mozilla.org/en/Mozilla_Embedding_FAQ/Embedding_Gecko#Can_I_embed_Mozilla_in_any_other_way.3f" rel="nofollow">Mozilla embedding FAQ</a>, <a href="...
1
2010-02-18T18:44:20Z
[ "c++", "python", "xul", "xpcom", "browser-automation" ]
Can I use XPCOM to create and manipulate a Firefox window as I would use win32 COM with IE?
2,291,034
<p>With win32 COM I create an Internet Explorer instance and control it almost fully from my python code (manipulate windows, DOM elements, etc). More specifically, using DispatchEx('InternetExplorer.Application'). Can I do the same using XPCOM and C++/python?</p> <p>I need to automate certain actions taken on the htm...
1
2010-02-18T18:16:37Z
2,556,443
<p>I have used the <a href="http://xulplanet.mozdev.org/references/xpcomref/nsIDOMXULElement.html" rel="nofollow">nsIDOMXULElement</a> to attach event listeners in my XPCOM C++ code. I haven't tried modifying the UI, but it will probably work as well.</p> <p>For an example on how to get an nsIDOMXULElement look at the...
1
2010-03-31T21:04:46Z
[ "c++", "python", "xul", "xpcom", "browser-automation" ]
is python variable assignment atomic?
2,291,069
<p>Let's say I am using a <code>signal</code> handler for handling an interval timer.</p> <pre><code>def _aHandler(signum, _): global SomeGlobalVariable SomeGlobalVariable=True </code></pre> <p>Can I set <code>SomeGlobalVariable</code> without worrying that, in an unlikely scenario that whilst setting <code>SomeG...
13
2010-02-18T18:20:59Z
2,291,137
<p>Simple assignment to simple variables is "atomic" AKA threadsafe (compound assignments such as <code>+=</code> or assignments to items or attributes of objects need not be, but your example is a simple assignment to a simple, albeit global, variable, thus safe).</p>
9
2010-02-18T18:30:09Z
[ "python", "signals" ]
is python variable assignment atomic?
2,291,069
<p>Let's say I am using a <code>signal</code> handler for handling an interval timer.</p> <pre><code>def _aHandler(signum, _): global SomeGlobalVariable SomeGlobalVariable=True </code></pre> <p>Can I set <code>SomeGlobalVariable</code> without worrying that, in an unlikely scenario that whilst setting <code>SomeG...
13
2010-02-18T18:20:59Z
2,291,207
<p>Compound assignment involves three steps: read-update-write. This is a race condition if another thread is run and writes a new value to the location after the read happens, but before the write. In this case a stale value is being updated and written back, which will clobber whatever new value was written by the ot...
1
2010-02-18T18:41:06Z
[ "python", "signals" ]
Interrupt method execution after arbitrary time in Python
2,291,129
<p>I have some method doA() that occasionally hangs for a while. Are there any common modules in Python that can control time of doA() execution and interrupt it? Of course, it may be implemented via threads, so simple wrapper around threading module may be good solution.</p> <p>In other words i'd like to have code li...
1
2010-02-18T18:28:48Z
2,291,160
<p>You can use a <a href="http://docs.python.org/library/threading.html?highlight=timer#threading.Timer">threading.Timer</a> to call <a href="http://docs.python.org/library/thread.html#thread.interrupt_main">thread.interrupt_main</a>, as long as you're running <code>doA</code> in the main thread. Note that the syntax ...
6
2010-02-18T18:33:57Z
[ "python", "asynchronous", "multithreading" ]
django, python and link encryption
2,291,176
<p>Hello I need to arrange some kind of encrpytion for generating user specific links. Users will be clicking this link and at some other view, related link with the crypted string will be decrypted and result will be returned.</p> <p>For this, I need some kind of encryption function that consumes a number(or a string...
4
2010-02-18T18:36:19Z
2,291,403
<p>There are no encryption algorithms, per se, built in to Python. However, you might want to look at the <a href="http://www.dlitz.net/software/pycrypto/">Python Cryptography Toolkit</a> (PyCrypt). I've only tinkered with it, but it's referenced in Python's documentation on <a href="http://docs.python.org/library/cr...
7
2010-02-18T19:05:58Z
[ "python", "django", "encryption" ]
django, python and link encryption
2,291,176
<p>Hello I need to arrange some kind of encrpytion for generating user specific links. Users will be clicking this link and at some other view, related link with the crypted string will be decrypted and result will be returned.</p> <p>For this, I need some kind of encryption function that consumes a number(or a string...
4
2010-02-18T18:36:19Z
23,873,403
<p>Django has features for this now. See <a href="https://docs.djangoproject.com/en/dev/topics/signing/" rel="nofollow">https://docs.djangoproject.com/en/dev/topics/signing/</a> </p> <p>Quoting that page: </p> <p>"Django provides both a low-level API for signing values and a high-level API for setting and reading ...
0
2014-05-26T15:28:44Z
[ "python", "django", "encryption" ]
MongoDB: Limiting results from a $gt query (from pymongo)
2,291,307
<p>I'm gathering some statistics from a web service, and storing it in a collection. The data looks similar to this (but with more fields):</p> <pre><code>{"downloads": 30, "dt": "2010-02-17T16:56:34.163000"} {"downloads": 30, "dt": "2010-02-17T17:56:34.163000"} {"downloads": 30, "dt": "2010-02-17T18:56:34.163000"} {"...
3
2010-02-18T18:54:36Z
2,294,045
<p>You can do this using <a href="http://www.mongodb.org/display/DOCS/Aggregation#Aggregation-Group" rel="nofollow">group</a>. In your example you'd need to supply a javascript function to compute the key (as well the reduce function), because you want only the date component of the datetime field. This should work:<...
1
2010-02-19T04:20:06Z
[ "python", "mongodb", "pymongo" ]
Django decorator getting a WSGIRequest and not the expected function argument
2,291,616
<p>I'm creating a decorator for Django views that will check permissions in a non-Django-managed database. Here is the decorator:</p> <pre><code>def check_ownership(failure_redirect_url='/', *args, **kwargs): def _check_ownership(view): def _wrapper(request, csi=None): try: opb_...
1
2010-02-18T19:35:11Z
2,292,921
<pre><code>@check_ownership def my_view(request, csi=None): ... </code></pre> <p>Translates into:</p> <pre><code>def my_view(request, csi=None): ... my_view = check_ownership(my_view) </code></pre> <p>but <code>check_ownership</code> does not accept a function, but <code>_check_ownership</code> does. This mi...
1
2010-02-18T23:06:21Z
[ "python", "django", "decorator" ]
Django decorator getting a WSGIRequest and not the expected function argument
2,291,616
<p>I'm creating a decorator for Django views that will check permissions in a non-Django-managed database. Here is the decorator:</p> <pre><code>def check_ownership(failure_redirect_url='/', *args, **kwargs): def _check_ownership(view): def _wrapper(request, csi=None): try: opb_...
1
2010-02-18T19:35:11Z
2,292,924
<p>So the issue has to do with how the decorator is being called. You get different behavior with these:</p> <pre><code>@my_decorator </code></pre> <p>versus</p> <pre><code>@my_decorator(someparam='someval') </code></pre> <p>In the first case, you get the callable passed directly to my_decorator. In the second cas...
0
2010-02-18T23:07:11Z
[ "python", "django", "decorator" ]
Why dictionaries appear to be reversed?
2,291,637
<p>Why dictionaries in python appears reversed?</p> <pre><code>&gt;&gt;&gt; a = {'one': '1', 'two': '2', 'three': '3', 'four': '4'} &gt;&gt;&gt; a {'four': '4', 'three': '3', 'two': '2', 'one': '1'} </code></pre> <p>How can I fix this?</p>
1
2010-02-18T19:38:01Z
2,291,650
<p>Dictionaries in python (and hash tables in general) are unordered. In python you can use the <code>sort()</code> method on the keys to sort them.</p>
16
2010-02-18T19:41:05Z
[ "python", "dictionary" ]
Why dictionaries appear to be reversed?
2,291,637
<p>Why dictionaries in python appears reversed?</p> <pre><code>&gt;&gt;&gt; a = {'one': '1', 'two': '2', 'three': '3', 'four': '4'} &gt;&gt;&gt; a {'four': '4', 'three': '3', 'two': '2', 'one': '1'} </code></pre> <p>How can I fix this?</p>
1
2010-02-18T19:38:01Z
2,291,651
<p>And what is the "standard order" you would be expecting? It is very much application dependent. A python dictionary doesn't guarantee key ordering anyways.</p> <p>In any case, you can iterate over a dictionary keys() the way you want.</p>
0
2010-02-18T19:41:26Z
[ "python", "dictionary" ]
Why dictionaries appear to be reversed?
2,291,637
<p>Why dictionaries in python appears reversed?</p> <pre><code>&gt;&gt;&gt; a = {'one': '1', 'two': '2', 'three': '3', 'four': '4'} &gt;&gt;&gt; a {'four': '4', 'three': '3', 'two': '2', 'one': '1'} </code></pre> <p>How can I fix this?</p>
1
2010-02-18T19:38:01Z
2,291,656
<p>Dictionaries have no intrinsic order. You'll have to either roll your own ordered dict implementation, use an <a href="http://stackoverflow.com/questions/2291637/why-dictionaries-appear-to-be-reversed/2291727#2291727">ordered <code>list</code> of <code>tuple</code>s</a> or use an <a href="http://www.voidspace.org.uk...
5
2010-02-18T19:42:49Z
[ "python", "dictionary" ]
Why dictionaries appear to be reversed?
2,291,637
<p>Why dictionaries in python appears reversed?</p> <pre><code>&gt;&gt;&gt; a = {'one': '1', 'two': '2', 'three': '3', 'four': '4'} &gt;&gt;&gt; a {'four': '4', 'three': '3', 'two': '2', 'one': '1'} </code></pre> <p>How can I fix this?</p>
1
2010-02-18T19:38:01Z
2,291,727
<p>Now you know dicts are unordered, here is how to convert them to a list which you <em>can</em> order</p> <pre><code>&gt;&gt;&gt; a = {'one': '1', 'two': '2', 'three': '3', 'four': '4'} &gt;&gt;&gt; a {'four': '4', 'three': '3', 'two': '2', 'one': '1'} </code></pre> <p><strong>sorted by key</strong></p> <pre><code...
2
2010-02-18T19:51:34Z
[ "python", "dictionary" ]
Why dictionaries appear to be reversed?
2,291,637
<p>Why dictionaries in python appears reversed?</p> <pre><code>&gt;&gt;&gt; a = {'one': '1', 'two': '2', 'three': '3', 'four': '4'} &gt;&gt;&gt; a {'four': '4', 'three': '3', 'two': '2', 'one': '1'} </code></pre> <p>How can I fix this?</p>
1
2010-02-18T19:38:01Z
2,291,758
<p>From the <a href="http://docs.python.org/tutorial/datastructures.html#dictionaries" rel="nofollow">Python Tutorial</a>:</p> <blockquote> <p>It is best to think of a dictionary as an unordered set of key: value pairs</p> </blockquote> <p>And from the <a href="http://docs.python.org/library/stdtypes.html#dict.it...
0
2010-02-18T19:57:28Z
[ "python", "dictionary" ]
Why dictionaries appear to be reversed?
2,291,637
<p>Why dictionaries in python appears reversed?</p> <pre><code>&gt;&gt;&gt; a = {'one': '1', 'two': '2', 'three': '3', 'four': '4'} &gt;&gt;&gt; a {'four': '4', 'three': '3', 'two': '2', 'one': '1'} </code></pre> <p>How can I fix this?</p>
1
2010-02-18T19:38:01Z
2,292,962
<p><strong>Python3.1</strong> has an <strong><code>OrderedDict</code></strong></p> <pre><code>&gt;&gt;&gt; from collections import OrderedDict &gt;&gt;&gt; o=OrderedDict([('one', '1'), ('two', '2'), ('three', '3'), ('four', '4')]) &gt;&gt;&gt; o OrderedDict([('one', '1'), ('two', '2'), ('three', '3'), ('four', '4')]) ...
5
2010-02-18T23:17:05Z
[ "python", "dictionary" ]
Who is throwing (and catching) this MySQL Exception?
2,291,714
<p>i'm using Python with MySQL and Django. I keep seeing this error and I can't figure out where the exception is being thrown:</p> <blockquote> <p><code>Exception _mysql_exceptions.ProgrammingError: (2014, "Commands out of sync; you can't run this command now") in &lt;bound method Cursor.__del__ of &lt;MySQLdb.cur...
7
2010-02-18T19:50:09Z
2,291,748
<p>This is a Python Error.</p> <p>See: <a href="http://eric.lubow.org/2009/python/pythons-mysqldb-2014-error-commands-out-of-sync/" rel="nofollow">http://eric.lubow.org/2009/python/pythons-mysqldb-2014-error-commands-out-of-sync/</a></p> <p>It looks like there is a problem with your MySQLdb Query.</p>
3
2010-02-18T19:55:49Z
[ "python", "mysql", "django", "exception" ]
Who is throwing (and catching) this MySQL Exception?
2,291,714
<p>i'm using Python with MySQL and Django. I keep seeing this error and I can't figure out where the exception is being thrown:</p> <blockquote> <p><code>Exception _mysql_exceptions.ProgrammingError: (2014, "Commands out of sync; you can't run this command now") in &lt;bound method Cursor.__del__ of &lt;MySQLdb.cur...
7
2010-02-18T19:50:09Z
2,292,145
<p>I believe this error can occur if you are using the same connection/cursor from multiple threads. However, I dont think the creators of Django has made such a mistake, but if you are doing something by yourself it can easily happen.</p>
2
2010-02-18T20:57:56Z
[ "python", "mysql", "django", "exception" ]
Who is throwing (and catching) this MySQL Exception?
2,291,714
<p>i'm using Python with MySQL and Django. I keep seeing this error and I can't figure out where the exception is being thrown:</p> <blockquote> <p><code>Exception _mysql_exceptions.ProgrammingError: (2014, "Commands out of sync; you can't run this command now") in &lt;bound method Cursor.__del__ of &lt;MySQLdb.cur...
7
2010-02-18T19:50:09Z
2,300,154
<p>After printing out a bunch of stuff and debugging, I figured out the problem I think. One of the libraries that I used didn't close the connection or the cursor. But this problem only shows up if I iterate through a large amount of data. The problem is also very intermittent and I still don't know who's throwing ...
2
2010-02-19T22:47:06Z
[ "python", "mysql", "django", "exception" ]
Who is throwing (and catching) this MySQL Exception?
2,291,714
<p>i'm using Python with MySQL and Django. I keep seeing this error and I can't figure out where the exception is being thrown:</p> <blockquote> <p><code>Exception _mysql_exceptions.ProgrammingError: (2014, "Commands out of sync; you can't run this command now") in &lt;bound method Cursor.__del__ of &lt;MySQLdb.cur...
7
2010-02-18T19:50:09Z
12,108,333
<p>I had exactly that error (using MySQLdb and Django) and discovered that the reason it was "ignored" was that it occurred in a <code>__del__</code> method. Exceptions in <code>__del__</code> are categorically ignored: <a href="http://docs.python.org/reference/datamodel.html#object.__del__" rel="nofollow"><code>object...
4
2012-08-24T11:14:45Z
[ "python", "mysql", "django", "exception" ]
Overloading embedded Python functions using PyArg_ParseTuple
2,291,740
<p>If I'm trying to overload an embedded Python function so that the second argument can be a long or an Object, is there a standard way to do it? Is this it?</p> <p>What I'm trying now (names changed to protect the innocent):</p> <pre><code> bool UseLongVar2 = true; if (!PyArg_ParseTuple(args, "ll:foo", &amp;Long...
1
2010-02-18T19:54:16Z
2,292,953
<p>What I normally do is have two C functions that take the different arguments. The "python-facing" function's job is to parse out the arguments, call the appropriate C function, and build the return value if any.</p> <p>This is pretty common when, for example, you want to allow both byte and Unicode strings.</p> <p...
2
2010-02-18T23:14:11Z
[ "python", "overloading", "embedded-language" ]
Virtual Serial Device in Python?
2,291,772
<p>I know that I can use e.g. pySerial to talk to serial devices, but what if I don't have a device right now but still need to write a client for it? How can I write a "virtual serial device" in Python and have pySerial talk to it, like I would, say, run a local web server? Maybe I'm just not searching well, but I've ...
21
2010-02-18T19:59:31Z
2,291,879
<p>It may be easier to using something like <a href="http://com0com.sourceforge.net/" rel="nofollow">com0com</a> (if you're on Windows) to set up a virtual serial port, and develop on that.</p>
3
2010-02-18T20:14:42Z
[ "python", "serial-port", "pyserial", "virtual-serial-port" ]
Virtual Serial Device in Python?
2,291,772
<p>I know that I can use e.g. pySerial to talk to serial devices, but what if I don't have a device right now but still need to write a client for it? How can I write a "virtual serial device" in Python and have pySerial talk to it, like I would, say, run a local web server? Maybe I'm just not searching well, but I've ...
21
2010-02-18T19:59:31Z
2,292,185
<p>It depends a bit on what you're trying to accomplish now...</p> <p>You could wrap access to the serial port in a class and write an implementation to use socket I/O or file I/O. Then write your serial I/O class to use the same interface and plug it in when the device is available. (This is actually a good design fo...
3
2010-02-18T21:05:15Z
[ "python", "serial-port", "pyserial", "virtual-serial-port" ]
Virtual Serial Device in Python?
2,291,772
<p>I know that I can use e.g. pySerial to talk to serial devices, but what if I don't have a device right now but still need to write a client for it? How can I write a "virtual serial device" in Python and have pySerial talk to it, like I would, say, run a local web server? Maybe I'm just not searching well, but I've ...
21
2010-02-18T19:59:31Z
5,045,353
<p>Maybe a loop device will do the job if you need to test your application without access to a device. It's included in pySerial 2.5 <a href="https://pythonhosted.org/pyserial/url_handlers.html#loop" rel="nofollow">https://pythonhosted.org/pyserial/url_handlers.html#loop</a> </p>
1
2011-02-18T18:53:54Z
[ "python", "serial-port", "pyserial", "virtual-serial-port" ]
Virtual Serial Device in Python?
2,291,772
<p>I know that I can use e.g. pySerial to talk to serial devices, but what if I don't have a device right now but still need to write a client for it? How can I write a "virtual serial device" in Python and have pySerial talk to it, like I would, say, run a local web server? Maybe I'm just not searching well, but I've ...
21
2010-02-18T19:59:31Z
15,095,449
<p>this is something I did and worked out for me so far:</p> <pre><code>import os, pty, serial master, slave = pty.openpty() s_name = os.ttyname(slave) ser = serial.Serial(s_name) # To Write to the device ser.write('Your text') # To read from the device os.read(master,1000) </code></pre> <p>If you create more vir...
18
2013-02-26T17:29:44Z
[ "python", "serial-port", "pyserial", "virtual-serial-port" ]
Virtual Serial Device in Python?
2,291,772
<p>I know that I can use e.g. pySerial to talk to serial devices, but what if I don't have a device right now but still need to write a client for it? How can I write a "virtual serial device" in Python and have pySerial talk to it, like I would, say, run a local web server? Maybe I'm just not searching well, but I've ...
21
2010-02-18T19:59:31Z
23,255,001
<p>If you are running Linux you can use the <a href="http://www.dest-unreach.org/socat/" rel="nofollow">socat</a> command for this, like so:</p> <pre><code>socat -d -d pty,raw,echo=0 pty,raw,echo=0 </code></pre> <p>When the command runs, it will inform you of which serial ports it has created. On my machine this look...
2
2014-04-23T20:55:57Z
[ "python", "serial-port", "pyserial", "virtual-serial-port" ]
Virtual Serial Device in Python?
2,291,772
<p>I know that I can use e.g. pySerial to talk to serial devices, but what if I don't have a device right now but still need to write a client for it? How can I write a "virtual serial device" in Python and have pySerial talk to it, like I would, say, run a local web server? Maybe I'm just not searching well, but I've ...
21
2010-02-18T19:59:31Z
37,450,382
<p>I was able to emulate an arbitrary serial port <code>./foo</code> using this code:</p> <p>SerialEmulator.py</p> <pre><code>import os, subprocess, serial, time # this script lets you emulate a serial device # the client program should use the serial port file specifed by client_port # if the port is a location th...
1
2016-05-26T02:03:39Z
[ "python", "serial-port", "pyserial", "virtual-serial-port" ]
Django. Retrieving and opening a zip file from HDD
2,291,913
<p>I have a path to a zip file. I don't know how to</p> <ul> <li>retrieve the file from the hard drive or</li> <li>open that zip file. Does anyone know?</li> </ul> <p>The zip file is a zip file, but it's really a .epub file.</p>
1
2010-02-18T20:20:42Z
2,291,935
<p>You don't need anything Django specific, just use the Python standard library, with the class <code>ZipFile(file_name[, mode[, compression[, allowZip64]]])</code> from the <a href="http://docs.python.org/library/zipfile.html" rel="nofollow"><code>zipfile</code></a> package.</p>
1
2010-02-18T20:24:39Z
[ "python", "django" ]
Django. Retrieving and opening a zip file from HDD
2,291,913
<p>I have a path to a zip file. I don't know how to</p> <ul> <li>retrieve the file from the hard drive or</li> <li>open that zip file. Does anyone know?</li> </ul> <p>The zip file is a zip file, but it's really a .epub file.</p>
1
2010-02-18T20:20:42Z
2,291,992
<p><a href="http://docs.python.org/library/zipfile.html" rel="nofollow">http://docs.python.org/library/zipfile.html</a></p> <pre><code>&gt;&gt;&gt; import zipfile &gt;&gt;&gt; path = "example/path.epub" &gt;&gt;&gt; epub = zipfile.ZipFile(open(path)) &gt;&gt;&gt; epub.namelist() ['some_file.txt'] &gt;&gt;&gt; file = ...
2
2010-02-18T20:30:59Z
[ "python", "django" ]
python timer mystery
2,292,054
<p>Well, at least a mystery to me. Consider the following:</p> <pre><code>import time import signal def catcher(signum, _): print "beat!" signal.signal(signal.SIGALRM, catcher) signal.setitimer(signal.ITIMER_REAL, 2, 2) while True: time.sleep(5) </code></pre> <p>Works as expected i.e. delivers a "beat!" m...
7
2010-02-18T20:43:06Z
2,292,088
<p>From my system's man setitimer (emphasis mine):</p> <blockquote> <p>The system provides each process with three interval timers, each decrementing in a <strong>distinct time domain</strong>. When any timer expires, a signal is sent to the process, and the timer (potentially) restarts.</p> <p>ITIMER_REAL ...
11
2010-02-18T20:48:58Z
[ "python", "timer", "signals" ]
python timer mystery
2,292,054
<p>Well, at least a mystery to me. Consider the following:</p> <pre><code>import time import signal def catcher(signum, _): print "beat!" signal.signal(signal.SIGALRM, catcher) signal.setitimer(signal.ITIMER_REAL, 2, 2) while True: time.sleep(5) </code></pre> <p>Works as expected i.e. delivers a "beat!" m...
7
2010-02-18T20:43:06Z
2,292,097
<p>The <code>signal.ITIMER_VIRTUAL</code> only counts down with the process is running. <code>time.sleep(5)</code> suspends the process so the timer doesn't decrement.</p>
3
2010-02-18T20:49:56Z
[ "python", "timer", "signals" ]
Blurring a picture (Python, Jython, picture editing)
2,292,233
<p>Trying to blur a picture in Jython. What I have does run but does not return a blurred picture. I'm kinda at a loss of what is wrong with it. </p> <p><strong>FINAL (WORKING) CODE EDITED IN BELOW. THANKS FOR HELP GUYS!</strong></p> <p>def main(): </p> <pre><code>pic= makePicture( pickAFile() ) show( pic ) blu...
0
2010-02-18T21:13:36Z
2,292,258
<p>Here is the simple way to do it:</p> <pre><code>import ImageFilter def filterBlur(im): im1 = im.filter(ImageFilter.BLUR) im1.save("BLUR" + ext) filterBlur(im1) </code></pre> <p>For a complete reference to the Image Library See: <a href="http://www.riisen.dk/dop/pil.html" rel="nofollow">http://www.riise...
1
2010-02-18T21:18:30Z
[ "python", "image-manipulation", "jython" ]
Blurring a picture (Python, Jython, picture editing)
2,292,233
<p>Trying to blur a picture in Jython. What I have does run but does not return a blurred picture. I'm kinda at a loss of what is wrong with it. </p> <p><strong>FINAL (WORKING) CODE EDITED IN BELOW. THANKS FOR HELP GUYS!</strong></p> <p>def main(): </p> <pre><code>pic= makePicture( pickAFile() ) show( pic ) blu...
0
2010-02-18T21:13:36Z
2,295,088
<p>The problem is that you are overwriting the variable <code>px</code> from the outer loop which is the pixel in the blurred image with a pixel value from the original image.<br> So just replace your inner loop with:</p> <pre><code>for i in range(0,blurAmount): origPx=getPixel(pic,x+i,y) rTotal=rTotal+getRed(...
3
2010-02-19T09:11:08Z
[ "python", "image-manipulation", "jython" ]
ID3 Decision Tree with Numeric Values
2,292,540
<p>I'm looking for a ID3 decision tree implementation in Python or any languages which takes a validation and a testing file as an input and returns predictions.</p> <p>I found <a href="http://seat.massey.ac.nz/personal/s.r.marsland/Code/6/dtree.py">this</a> and this but I couldn't adapt them to numeric values, e.g. t...
5
2010-02-18T22:00:36Z
2,292,637
<p>I have a similar algorithm C4.5 written in python. It work from console. If you are interested I put it here. </p> <p>Sorry for a post if you need not this.</p> <p>BTW, I have tested it on Iris data set :)</p> <p>Update:</p> <p>I have uploaded both: code and data:</p> <ul> <li>c4.5 - <a href="http://pastebin.ca...
2
2010-02-18T22:15:50Z
[ "python", "id3", "decision-tree" ]
How do you order Models with M2M relationship to avoid NameSpace errors?
2,292,608
<p>I can't figure out how I'm supposed to order these models that have a M2M relationship.</p> <p>When I try to syncdb, I can't because the Model related model is not in the namespace yet, so I get:</p> <blockquote> <p>NameError: name 'FavoriteQuestion' is not defined</p> </blockquote> <p>If I switch places, I get...
0
2010-02-18T22:11:10Z
2,292,669
<p>You don't need to create the favourite_question field on the UserProfile.</p> <p>As long as each FavouriteQuestion has a user associated with it the model instance API will give you access to a list of favourite questions for a user.</p>
0
2010-02-18T22:19:49Z
[ "python", "django", "django-models" ]
How do you order Models with M2M relationship to avoid NameSpace errors?
2,292,608
<p>I can't figure out how I'm supposed to order these models that have a M2M relationship.</p> <p>When I try to syncdb, I can't because the Model related model is not in the namespace yet, so I get:</p> <blockquote> <p>NameError: name 'FavoriteQuestion' is not defined</p> </blockquote> <p>If I switch places, I get...
0
2010-02-18T22:11:10Z
35,788,210
<p>Instead of passing in the the Class to the field constructor, pass in the string of the class name. Django will do the leg work of figuring out how to hook up the models without relying on the class definitions to exist at the point in the module where the other class is being defined. I would actually do this for a...
0
2016-03-04T04:50:01Z
[ "python", "django", "django-models" ]
how can i get the executable's current directory in py2exe?
2,292,703
<p>I use this bit of code in my script to pinpoint, in a cross-platform way, where exactly it's being run from:</p> <pre><code>SCRIPT_ROOT = os.path.dirname(os.path.realpath(__file__)) </code></pre> <p>Pretty simple. I then go on to use <code>SCRIPT_ROOT</code> in other areas of my script to make sure everything is p...
14
2010-02-18T22:24:54Z
2,292,755
<p>Try this:</p> <pre><code>import os import sys os.path.realpath(os.path.dirname(sys.argv[0])) </code></pre>
2
2010-02-18T22:35:22Z
[ "python", "py2exe" ]
how can i get the executable's current directory in py2exe?
2,292,703
<p>I use this bit of code in my script to pinpoint, in a cross-platform way, where exactly it's being run from:</p> <pre><code>SCRIPT_ROOT = os.path.dirname(os.path.realpath(__file__)) </code></pre> <p>Pretty simple. I then go on to use <code>SCRIPT_ROOT</code> in other areas of my script to make sure everything is p...
14
2010-02-18T22:24:54Z
2,293,106
<p>Here is the <a href="http://www.py2exe.org/index.cgi/Py2exeEnvironment">py2exe documentation reference</a> and here are the relevant items:</p> <ul> <li><code>sys.executable</code> is set to the full pathname of the exe-file. </li> <li>The first item in <code>sys.argv</code> is the full pathname of the executable,...
20
2010-02-18T23:47:33Z
[ "python", "py2exe" ]
how can i get the executable's current directory in py2exe?
2,292,703
<p>I use this bit of code in my script to pinpoint, in a cross-platform way, where exactly it's being run from:</p> <pre><code>SCRIPT_ROOT = os.path.dirname(os.path.realpath(__file__)) </code></pre> <p>Pretty simple. I then go on to use <code>SCRIPT_ROOT</code> in other areas of my script to make sure everything is p...
14
2010-02-18T22:24:54Z
17,467,196
<p>Py2exe does not define <code>__file__</code>: <a href="http://www.py2exe.org/index.cgi/Py2exeEnvironment" rel="nofollow">http://www.py2exe.org/index.cgi/Py2exeEnvironment</a></p> <p>The OP requested a py2exe friendly version of:</p> <pre><code>SCRIPT_ROOT = os.path.dirname(os.path.realpath(__file__)) </code></pre>...
6
2013-07-04T09:50:43Z
[ "python", "py2exe" ]
What Python/IronPython web development framework work on the Microsoft technology stack?
2,292,775
<p>I started learning Python using the IronPython implementation. I'd like to do some web development now. I'm looking for a python web development framework that works on the Microsoft technology stack (IIS + MS SQL Server). Django looks like an interesting framework but based on what I have read, getting it to work o...
6
2010-02-18T22:39:10Z
2,292,804
<p>Django does in theory run on Windows, but using Apache and MySQL. It's not possible (and certainly not recommended) to run it on IIS.</p> <p>I know you totally didn't ask this, but I have to advise that if you really want to get into Python web development then looking into a Linux technology stack is definitely th...
1
2010-02-18T22:43:29Z
[ "python", "ironpython" ]
What Python/IronPython web development framework work on the Microsoft technology stack?
2,292,775
<p>I started learning Python using the IronPython implementation. I'd like to do some web development now. I'm looking for a python web development framework that works on the Microsoft technology stack (IIS + MS SQL Server). Django looks like an interesting framework but based on what I have read, getting it to work o...
6
2010-02-18T22:39:10Z
2,292,848
<p>While perhaps not entirely mature, <a href="http://code.google.com/p/isapi-wsgi/" rel="nofollow">isapi-wsgi</a> looks like a promising way to run the WSGI intermediate layer on IIS (I have no hands-on experience with it, but seems worth a try!). Once you have WSGI running just about any Python web framework, includ...
3
2010-02-18T22:53:30Z
[ "python", "ironpython" ]
What Python/IronPython web development framework work on the Microsoft technology stack?
2,292,775
<p>I started learning Python using the IronPython implementation. I'd like to do some web development now. I'm looking for a python web development framework that works on the Microsoft technology stack (IIS + MS SQL Server). Django looks like an interesting framework but based on what I have read, getting it to work o...
6
2010-02-18T22:39:10Z
2,292,863
<p>Working with the full MS stack will be hard as not many FLOSS frameworks aim there. You'll have better luck with a WAMP (Windows/Apache/MySQL-PostgreSQL/Python) approach.</p> <p>That being said, Django works on Windows, and even <a href="http://code.djangoproject.com/wiki/DjangoOnWindowsWithIISAndSQLServer" rel="no...
7
2010-02-18T22:55:36Z
[ "python", "ironpython" ]
How to set cookies with redirect in Pylons
2,292,881
<p>In light of the cookie-handling bugs affecting Safari and Chrome (<a href="http://stackoverflow.com/questions/1621499/why-cant-i-set-a-cookie-and-redirect">see this thread</a>), and Pylons implementation of redirect_to as an exception, is it possible to reliably set a tracking cookie and redirect at the same time? I...
5
2010-02-18T22:58:10Z
2,487,474
<p>Drilling down a bit, the <a href="https://bugs.webkit.org/show_bug.cgi?id=3512" rel="nofollow">webkit folks say it's not their problem</a>, so the possible solutions aren't as pretty. One possible ugly solution: setting the tracking information in the beaker session (if you're using beaker?) and retrieving it from ...
1
2010-03-21T14:50:02Z
[ "python", "cookies", "redirect", "pylons" ]
the number of images, using "len()"
2,292,982
<p>I need to count the number of images (in this case 1 image). Apparently using "len()"?</p> <p>Here is HTML:</p> <pre><code>&lt;div class="detail-headline"&gt; Fotogal&amp;#233;ria &lt;/div&gt; &lt;div class="detail-indent"&gt; &lt;table id="ctl00_ctl00_ctl00_containerHolder_mainContentHolder_innner...
0
2010-02-18T23:20:27Z
2,292,993
<p>Your job will be easier if you use <a href="http://www.crummy.com/software/BeautifulSoup" rel="nofollow">BeautifulSoup</a></p> <p>Perhaps something like this</p> <pre><code>from BeautifulSoup import BeaufitulSoup def count_images(htmltext) soup=BeautifulSoup(htmltext) return len(soup.findAll('div',{'class'...
3
2010-02-18T23:23:44Z
[ "python", "parsing" ]
the number of images, using "len()"
2,292,982
<p>I need to count the number of images (in this case 1 image). Apparently using "len()"?</p> <p>Here is HTML:</p> <pre><code>&lt;div class="detail-headline"&gt; Fotogal&amp;#233;ria &lt;/div&gt; &lt;div class="detail-indent"&gt; &lt;table id="ctl00_ctl00_ctl00_containerHolder_mainContentHolder_innner...
0
2010-02-18T23:20:27Z
2,293,455
<p>Just for a lark, I tried a pyparsing approach. Pyparsing includes some methods to help construct matching patterns for HTML tags, which include matches for attributes, unexpected whitespace, single or double quotes, and other hard-to-predict HTML tag gotchas. Here is a pyparsing solution (assumes your HTML source ...
1
2010-02-19T01:11:09Z
[ "python", "parsing" ]
python script for robust multi-array average on microarray data
2,293,143
<p>I have tried google with no luck. I have seen some weak references to robust multi-array averaging done with python but no code. I am not so interested in reinventing the wheel. Any suggestions on a python module, script ....</p> <p>If I could find a nice explanation or example of the algorithm I would write a pyth...
3
2010-02-18T23:55:40Z
2,293,726
<p>You might want to consider using a python interface for R, which has gcrma packages for it. <a href="http://rpy.sourceforge.net/" rel="nofollow">RPy</a> is a module that allows you to use all R modules installed on your system. <a href="http://www.bioconductor.org/" rel="nofollow">Bioconductor</a> has a <a href="htt...
2
2010-02-19T02:31:56Z
[ "python", "arrays", "bioinformatics", "dna-sequence" ]
python script for robust multi-array average on microarray data
2,293,143
<p>I have tried google with no luck. I have seen some weak references to robust multi-array averaging done with python but no code. I am not so interested in reinventing the wheel. Any suggestions on a python module, script ....</p> <p>If I could find a nice explanation or example of the algorithm I would write a pyth...
3
2010-02-18T23:55:40Z
2,294,040
<p>I am a biologist working in genomics and contributed to 5-6 microarray projects. I am also quite fluent in Python and can make do pretty well in R.</p> <p>Python is a great language, but as of now, I am aware of no module that would suite your request easily. R, on the other hand, offers a large gamut of packages f...
0
2010-02-19T04:19:05Z
[ "python", "arrays", "bioinformatics", "dna-sequence" ]
python script for robust multi-array average on microarray data
2,293,143
<p>I have tried google with no luck. I have seen some weak references to robust multi-array averaging done with python but no code. I am not so interested in reinventing the wheel. Any suggestions on a python module, script ....</p> <p>If I could find a nice explanation or example of the algorithm I would write a pyth...
3
2010-02-18T23:55:40Z
35,689,760
<p>Even though this question was asked more than six years ago, when I asked myself the same question recently, I still couldn't find a good Python implementation of RMA. I therefore did a bunch of research into the methodology and wrote one myself:</p> <ul> <li>GitHub: <a href="https://github.com/flo-compbio/pyaffy" ...
2
2016-02-28T23:42:43Z
[ "python", "arrays", "bioinformatics", "dna-sequence" ]
How to generate code objects from modules in Python?
2,293,322
<p>I have a .pyc file with no corresponding Python source code. I want to see the disassembly of the module using dis. I can import my module just fine with</p> <pre><code>import dis import foo </code></pre> <p>But to call dis.dis on it, I can't use the module object. I need the corresponding code object which backs ...
2
2010-02-19T00:33:46Z
2,293,368
<p>See <a href="http://nedbatchelder.com/blog/200804/the_structure_of_pyc_files.html" rel="nofollow">http://nedbatchelder.com/blog/200804/the_structure_of_pyc_files.html</a></p>
3
2010-02-19T00:44:12Z
[ "python", "bytecode", "cpython", "bytecode-manipulation" ]
Django memory usage going up with every request
2,293,333
<p>I moved my first Django project from DjangoEurope to Webfaction, and that started an issue looking like a memory leak. With every single request memory usage of the server process goes up about 500kb. It never goes down. This goes on until Webfaction kills it for using too much memory.</p> <p>I can clearly see this...
20
2010-02-19T00:36:39Z
2,294,171
<p>I have the same problems with webfaction.</p> <p>The method I use, and which webfaction told me I should keep using, is run a cron job that checks the memory every 5 minutes or so, and restarts any apps that are getting out of control.</p> <p>Out of 4 python apps on webfaction, I average 4 restarts per day.</p>
1
2010-02-19T05:03:10Z
[ "python", "django", "memory-leaks", "mod-wsgi" ]
Django memory usage going up with every request
2,293,333
<p>I moved my first Django project from DjangoEurope to Webfaction, and that started an issue looking like a memory leak. With every single request memory usage of the server process goes up about 500kb. It never goes down. This goes on until Webfaction kills it for using too much memory.</p> <p>I can clearly see this...
20
2010-02-19T00:36:39Z
2,296,171
<p>I've had issues with memory on Webfaction too - they didn't really crop up until I added my fifth application though. I tried a few tweaks to my apache configs, but what finally worked for me was just switching over to mod_wsgi.</p>
0
2010-02-19T12:18:52Z
[ "python", "django", "memory-leaks", "mod-wsgi" ]
Django memory usage going up with every request
2,293,333
<p>I moved my first Django project from DjangoEurope to Webfaction, and that started an issue looking like a memory leak. With every single request memory usage of the server process goes up about 500kb. It never goes down. This goes on until Webfaction kills it for using too much memory.</p> <p>I can clearly see this...
20
2010-02-19T00:36:39Z
2,297,197
<ul> <li><p>Did you check these tips? -> <a href="http://blog.webfaction.com/tips-to-keep-your-django-mod-python-memory-usage-down" rel="nofollow">http://blog.webfaction.com/tips-to-keep-your-django-mod-python-memory-usage-down</a></p></li> <li><p>We have deploy an app in WebFaction and we are not having those issues.<...
0
2010-02-19T14:59:23Z
[ "python", "django", "memory-leaks", "mod-wsgi" ]
Django memory usage going up with every request
2,293,333
<p>I moved my first Django project from DjangoEurope to Webfaction, and that started an issue looking like a memory leak. With every single request memory usage of the server process goes up about 500kb. It never goes down. This goes on until Webfaction kills it for using too much memory.</p> <p>I can clearly see this...
20
2010-02-19T00:36:39Z
2,329,097
<p>I'd suggest not to guess.</p> <p>Take a look at <a href="http://code.google.com/p/django-dowser/" rel="nofollow">http://code.google.com/p/django-dowser/</a>, it is a very useful app for detecting memory leaks and figuring out what parts of your code are responsible for memory consumption.</p>
1
2010-02-24T20:07:41Z
[ "python", "django", "memory-leaks", "mod-wsgi" ]
Django memory usage going up with every request
2,293,333
<p>I moved my first Django project from DjangoEurope to Webfaction, and that started an issue looking like a memory leak. With every single request memory usage of the server process goes up about 500kb. It never goes down. This goes on until Webfaction kills it for using too much memory.</p> <p>I can clearly see this...
20
2010-02-19T00:36:39Z
2,338,953
<p>Are both mod_python and mod_wsgi modules loaded into apache?</p> <p>I know mod_wsgi doesn't like having mod_python in its building. Check its not loaded.</p>
0
2010-02-26T01:32:52Z
[ "python", "django", "memory-leaks", "mod-wsgi" ]
Django memory usage going up with every request
2,293,333
<p>I moved my first Django project from DjangoEurope to Webfaction, and that started an issue looking like a memory leak. With every single request memory usage of the server process goes up about 500kb. It never goes down. This goes on until Webfaction kills it for using too much memory.</p> <p>I can clearly see this...
20
2010-02-19T00:36:39Z
2,338,957
<p>Check if the in-process memory cache backend is enabled, if yes, that could be the problem (new cache entries at each request).</p>
1
2010-02-26T01:36:24Z
[ "python", "django", "memory-leaks", "mod-wsgi" ]
Django memory usage going up with every request
2,293,333
<p>I moved my first Django project from DjangoEurope to Webfaction, and that started an issue looking like a memory leak. With every single request memory usage of the server process goes up about 500kb. It never goes down. This goes on until Webfaction kills it for using too much memory.</p> <p>I can clearly see this...
20
2010-02-19T00:36:39Z
2,350,809
<p>I'm afraid I haven't got any definite answers. Graham Dumpleton's tips were most helpfull, but unfortunately he didn't make an answer (just comments), so there is no way to accept his response.</p> <p>Although I still haven't fully resolved the issue, here are some basic tips for other people having similar problem...
12
2010-02-28T10:50:55Z
[ "python", "django", "memory-leaks", "mod-wsgi" ]
Django memory usage going up with every request
2,293,333
<p>I moved my first Django project from DjangoEurope to Webfaction, and that started an issue looking like a memory leak. With every single request memory usage of the server process goes up about 500kb. It never goes down. This goes on until Webfaction kills it for using too much memory.</p> <p>I can clearly see this...
20
2010-02-19T00:36:39Z
4,675,046
<p>We had a similar issue on Webfaction, but it turned out it wasn't because of them at all. There's a bug in Django about high memory usage when using the sitemap with lots of elements: <a href="http://code.djangoproject.com/ticket/11572" rel="nofollow">http://code.djangoproject.com/ticket/11572</a></p> <p>When we re...
2
2011-01-12T23:03:55Z
[ "python", "django", "memory-leaks", "mod-wsgi" ]
Cookies and HTTP with Python
2,293,491
<p>I wish to "retrieve" the cookies sent by the client in my subclass of <code>BaseHTTPRequestHandler</code>.</p> <p>Firstly I'm unsure of the exact sequence of sending of headers, in a typical HTTP request and response this is my understanding of the sequence of events:</p> <ol> <li>Client sends request (method, pat...
0
2010-02-19T01:22:15Z
2,293,508
<p>HTTP is a request/response protocol, without overlap; the body of a POST comes as part of the request (when the verb is POST, of course).</p> <p>All headers also come as part of the request, including <code>Cookie:</code> <em>if any</em> (there might be no such header of course, e.g. when the browser is running wit...
2
2010-02-19T01:27:43Z
[ "python", "http", "cookies", "post" ]
How do I generate coverage xml report for a single package?
2,293,647
<p>I'm using <strong>nose</strong> and <strong>coverage</strong> to generate coverage reports. I only have one package right now, <em>ae</em>, so I specify to only cover that: </p> <pre><code>nosetests -w tests/unit --with-xunit --with-coverage --cover-package=ae </code></pre> <p>And here are the results, which look ...
3
2010-02-19T02:11:01Z
2,339,352
<p>Did you try:</p> <pre><code>coverage xml ae </code></pre>
-1
2010-02-26T03:44:57Z
[ "python", "code-coverage", "nose", "coverage.py" ]
How do I generate coverage xml report for a single package?
2,293,647
<p>I'm using <strong>nose</strong> and <strong>coverage</strong> to generate coverage reports. I only have one package right now, <em>ae</em>, so I specify to only cover that: </p> <pre><code>nosetests -w tests/unit --with-xunit --with-coverage --cover-package=ae </code></pre> <p>And here are the results, which look ...
3
2010-02-19T02:11:01Z
2,377,148
<p>I wasn't able to find the answer to this, so I'm stripping the unwanted package elements out after processing. This function takes the original XML file, the element name to check, its attribute to check, the pattern (or list of words) you'd like to KEEP, and a destination filepath for the new file. </p> <pre><code...
0
2010-03-04T05:47:49Z
[ "python", "code-coverage", "nose", "coverage.py" ]
How do I generate coverage xml report for a single package?
2,293,647
<p>I'm using <strong>nose</strong> and <strong>coverage</strong> to generate coverage reports. I only have one package right now, <em>ae</em>, so I specify to only cover that: </p> <pre><code>nosetests -w tests/unit --with-xunit --with-coverage --cover-package=ae </code></pre> <p>And here are the results, which look ...
3
2010-02-19T02:11:01Z
2,756,329
<p>I had a similar problem and solved it with the <code>--omit</code> option. This made it run much faster and reduced the size of coverage.xml from 2MB to 70kB.</p> <pre><code>--omit=PRE1,PRE2,... Omit files when their filename path starts with one of these prefixes. </code></pre> <p>I'm on Ma...
3
2010-05-03T05:49:53Z
[ "python", "code-coverage", "nose", "coverage.py" ]
How can I show a widget and all its parent containers?
2,293,672
<p>In my program, there is a point where all widgets are hidden. Is there a simple way to show a widget and all of its parent containers? I am not able to use <code>show_all()</code>, because that would show other widgets that I don't want shown. I could go down the containers and show them all, but I would prefer not ...
0
2010-02-19T02:20:11Z
2,293,798
<p>Other than iterating through <a href="http://www.pygtk.org/docs/pygtk/class-gtkwidget.html#method-gtkwidget--get-parent" rel="nofollow"><code>Widget.get_parent</code></a> and <code>show</code>ing them all, you can also set the <a href="http://library.gnome.org/devel/gtk/unstable/GtkWidget.html#GtkWidget--no-show-all...
1
2010-02-19T02:55:51Z
[ "python", "gtk", "pygtk", "widget", "containers" ]
PyQt4: Hide widget and resize window
2,293,708
<p>I'm working with several widgets but the solution just won't come out. What I have is a series of buttons in series of <code>QHBoxLayouts</code>. Some buttons are hidden by default, but they will appear when needed. To solve space issues, all buttons have a minimum and maximum size so they always look well packed. A...
0
2010-02-19T02:28:38Z
2,298,675
<p>The answer was quite lame... Just needed to change the <code>QVBoxLayout</code> for a <code>QGridLayout</code> and use <code>self.ui.layout().setSizeConstraint(QtGui.QLayout.SetFixedSize)</code></p>
3
2010-02-19T18:32:11Z
[ "python", "qt4", "pyqt4" ]
How can I replace double and single quotations in a string efficiently?
2,293,854
<p>I'm parsing a xml file and inserting it into database. However since some text containes double or single quotation I'm having problem with insertion. Currently I'm using the code shown below. But it seems it's inefficient.</p> <pre><code>s = s.replace('"', ' ') s = s.replace("'", ' ') </code></pre> <p>Is there an...
2
2010-02-19T03:19:17Z
2,293,886
<p>Why can't you insert strings containing quote marks into your database? Is there some weird data type that permits any character except a quote mark? Or are you building an <code>insert</code> statement with literal strings, rather than binding your strings to query parameters as you should be doing?</p> <p>If you'...
12
2010-02-19T03:28:53Z
[ "python", "database", "string" ]
How can I replace double and single quotations in a string efficiently?
2,293,854
<p>I'm parsing a xml file and inserting it into database. However since some text containes double or single quotation I'm having problem with insertion. Currently I'm using the code shown below. But it seems it's inefficient.</p> <pre><code>s = s.replace('"', ' ') s = s.replace("'", ' ') </code></pre> <p>Is there an...
2
2010-02-19T03:19:17Z
2,294,147
<p>You could try something like _mysql.escape_string():</p> <pre><code>&gt;&gt;&gt; import _mysql &gt;&gt;&gt; a = '''I said, "Don't do that"''' &gt;&gt;&gt; a 'I said, "Don\'t do that"' &gt;&gt;&gt; _mysql.escape_string(a) 'I said, \\"Don\\\'t do that\\"' </code></pre> <p>However, the manual recommends using <a href...
1
2010-02-19T04:56:14Z
[ "python", "database", "string" ]
How can I replace double and single quotations in a string efficiently?
2,293,854
<p>I'm parsing a xml file and inserting it into database. However since some text containes double or single quotation I'm having problem with insertion. Currently I'm using the code shown below. But it seems it's inefficient.</p> <pre><code>s = s.replace('"', ' ') s = s.replace("'", ' ') </code></pre> <p>Is there an...
2
2010-02-19T03:19:17Z
2,294,655
<p>you should use <strong><code>str.translate</code></strong> instead of doing two <code>replace()</code> calls </p> <pre><code>&gt;&gt;&gt; import string &gt;&gt;&gt; quotes_to_spaces=string.maketrans('"\''," ") &gt;&gt;&gt; s=s.translate(quotes_to_spaces) </code></pre>
2
2010-02-19T07:18:07Z
[ "python", "database", "string" ]
How do I define an array of custom types in WSDL?
2,293,873
<p>I'm very new to WSDL, but what I'm trying to do is very simple. I have gotten a web service working with python's ZSI library, but am stuck defining a service which returns an array of a custom type.</p> <p>In my WSDL I have the following:</p> <pre><code>&lt;xsd:element name="ArtPiece"&gt; &lt;xsd:complexType...
8
2010-02-19T03:25:44Z
2,294,967
<pre><code>&lt;xs:schema elementFormDefault="qualified" targetNamespace="http://schemas.datacontract.org/2004/07/Foo" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:tns="http://schemas.datacontract.org/2004/07/Foo"&gt; &lt;xs:complexType name="ArtPiece"&gt; &lt;xs:sequ...
20
2010-02-19T08:43:04Z
[ "c#", "python", "web-services", "soap", "wsdl" ]
Django: Using django.contrib.auth for SAAS ( Users, permissions, etc. )
2,293,924
<p>I'm making a SAAS and I've been asking a slew of questions on here related to the Auth system built in. I'm having trouble understanding the "why" and "how". Primarily I don't understand how it fits in with my SAAS.</p> <h3>I (do) know the following:</h3> <ol> <li>You can do this: <a href="http://docs.djangoprojec...
2
2010-02-19T03:42:51Z
2,294,228
<blockquote> <p>Somebody goes to a page and creates a <code>UserProfile</code> with a username and password, etc.</p> </blockquote> <p><code>UserProfile</code> doesn't have an username or password field. So it should be <em>somebody goes to a page and create an <code>User</code></em>. Then, it creates an <code>UserP...
3
2010-02-19T05:17:36Z
[ "python", "django" ]
How do I create a list or set object in a class in Python?
2,293,968
<p>For my project, the role of the Lecturer (defined as a class) is to offer projects to students. Project itself is also a class. I have some global dictionaries, keyed by the unique numeric id's for lecturers and projects that map to objects.</p> <p>Thus for the "lecturers" dictionary (currently): </p> <pre><code>...
2
2010-02-19T03:59:09Z
2,293,998
<p><code>set</code> is better since you don't care about order and have no duplicate.</p> <p>You can parse the file easily with the <a href="http://docs.python.org/library/csv.html?highlight=sv#module-csv" rel="nofollow">csv</a> module (with a <code>delimiter</code> of <code>' '</code>).</p> <p>Once you have the <cod...
4
2010-02-19T04:07:42Z
[ "python", "class", "dictionary" ]
How do I create a list or set object in a class in Python?
2,293,968
<p>For my project, the role of the Lecturer (defined as a class) is to offer projects to students. Project itself is also a class. I have some global dictionaries, keyed by the unique numeric id's for lecturers and projects that map to objects.</p> <p>Thus for the "lecturers" dictionary (currently): </p> <pre><code>...
2
2010-02-19T03:59:09Z
2,294,002
<p>Sets are useful when you want to guarantee you only have one instance of each item. They are also faster than a list at calculating whether an item is present in the collection.</p> <p>Lists are faster at adding items, and also have an ordering.</p> <p>This sounds like you would like a set. You sound like you are ...
1
2010-02-19T04:08:40Z
[ "python", "class", "dictionary" ]
How do I create a list or set object in a class in Python?
2,293,968
<p>For my project, the role of the Lecturer (defined as a class) is to offer projects to students. Project itself is also a class. I have some global dictionaries, keyed by the unique numeric id's for lecturers and projects that map to objects.</p> <p>Thus for the "lecturers" dictionary (currently): </p> <pre><code>...
2
2010-02-19T03:59:09Z
2,294,273
<p>Thanks for the help <a href="http://stackoverflow.com/users/95810/alex-martelli">Alex</a> and <a href="http://stackoverflow.com/users/8014/oddthinking">Oddthinking</a>! I think I've figured out what was going on: </p> <p>I modified the code snippet that I added to the question. Basically, every time it read the li...
0
2010-02-19T05:31:49Z
[ "python", "class", "dictionary" ]
Python Lambda behaviour
2,294,134
<p>I'm trying to get my head around lambda expressions, closures and scoping in Python. Why does the program not crash on the first line here?</p> <pre><code>&gt;&gt;&gt; foo = lambda x: x + a &gt;&gt;&gt; foo(2) Traceback (most recent call last): File "&lt;stdin&gt;", line 1, in &lt;module&gt; File "&lt;stdin&gt;...
4
2010-02-19T04:52:12Z
2,294,152
<p>Your lambda expression doesn't get evaluated until you call it.</p> <p>It does get parsed, which is why a syntax error would cause a traceback.</p> <pre><code>&gt;&gt;&gt; foo = lambda x : x + a &gt;&gt;&gt; bar = lambda y : print y SyntaxError: invalid syntax </code></pre>
2
2010-02-19T04:59:19Z
[ "python", "lambda" ]
Python Lambda behaviour
2,294,134
<p>I'm trying to get my head around lambda expressions, closures and scoping in Python. Why does the program not crash on the first line here?</p> <pre><code>&gt;&gt;&gt; foo = lambda x: x + a &gt;&gt;&gt; foo(2) Traceback (most recent call last): File "&lt;stdin&gt;", line 1, in &lt;module&gt; File "&lt;stdin&gt;...
4
2010-02-19T04:52:12Z
2,294,154
<p>The bodies of lambdas (and functions defined with def) in Python are not evaluated until they are called. Names are always looked up at runtime.</p>
0
2010-02-19T04:59:42Z
[ "python", "lambda" ]