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
mod_python req.subprocess_env not "seeing" PythonOptions
1,663,291
<p>I'm having trouble getting an environmental variable out of apache config. (don't ask why it's being done this way, I didn't originally code it)</p> <p>This is what I have in the apache config.</p> <pre><code>&lt;Location "/var/www"&gt; SetHandler python-program PythonHandler mod_python.publisher Pytho...
0
2009-11-02T19:50:50Z
1,663,349
<pre><code>os.environ["MYSQL_PWD"] = req.get_options()["MYSQL_PWD"] </code></pre> <p>See <a href="http://www.modpython.org/live/current/doc-html/dir-other-po.html" rel="nofollow">docs on PythonOption</a> for more details</p>
0
2009-11-02T20:01:33Z
[ "python", "apache2", "debian", "mod-python" ]
How to keep help strings the same when applying decorators?
1,663,568
<p>How can I keep help strings in functions to be visible after applying a decorator?</p> <p>Right now the doc string is (partially) replaced with that of the inner function of the decorator.</p> <pre><code>def deco(fn): def x(*args, **kwargs): return fn(*args, **kwargs) x.func_doc = fn.func_doc x...
2
2009-11-02T20:43:06Z
1,663,669
<p>give the <a href="http://pypi.python.org/pypi/decorator" rel="nofollow">decorator</a> module a peek. i believe it does exactly what you want.</p> <pre><code>In [1]: from decorator import decorator In [2]: @decorator ...: def say_hello(f, *args, **kwargs): ...: print "Hello!" ...: return f(*args, *...
5
2009-11-02T21:02:10Z
[ "python", "documentation", "decorator" ]
How to keep help strings the same when applying decorators?
1,663,568
<p>How can I keep help strings in functions to be visible after applying a decorator?</p> <p>Right now the doc string is (partially) replaced with that of the inner function of the decorator.</p> <pre><code>def deco(fn): def x(*args, **kwargs): return fn(*args, **kwargs) x.func_doc = fn.func_doc x...
2
2009-11-02T20:43:06Z
1,663,955
<p>What you're requesting is very hard to do "properly", because <code>help</code> gets the function signature from <a href="http://docs.python.org/library/inspect.html?highlight=getargspec#inspect.getargspec" rel="nofollow"><code>inspect.getargspec</code></a> which in turn gets it from introspection which cannot direc...
1
2009-11-02T21:52:32Z
[ "python", "documentation", "decorator" ]
tokenizer errors with nltk
1,663,762
<p>I'm very new to Python, and am trying to learn in conjunction with using nltk.</p> <p>I've been following some examples and testing things out, but it seems I am very limited in what I can do due to errors being returned by python. </p> <p>I know nltk is installed and importing fine, because this code works </p> ...
0
2009-11-02T21:18:39Z
1,663,990
<p>Looks like the nltp package doesn't have a <code>tokenizer</code> package.</p> <p>A quick look on the NLTK website suggests that <code>from nltp.tokenize import *</code> is what you're after.</p>
3
2009-11-02T21:58:47Z
[ "python", "nltk" ]
tokenizer errors with nltk
1,663,762
<p>I'm very new to Python, and am trying to learn in conjunction with using nltk.</p> <p>I've been following some examples and testing things out, but it seems I am very limited in what I can do due to errors being returned by python. </p> <p>I know nltk is installed and importing fine, because this code works </p> ...
0
2009-11-02T21:18:39Z
1,664,176
<p>Adam's answer may well be correct for your immediate "tokenizer" problem. Here's some general advice:</p> <p>It helps when one is in unfamiliar territory to read the road signs e.g. this at the top of the Downloads page: """Although Python 3.0 is now available, many packages that NLTK requires do not have distribut...
0
2009-11-02T22:36:29Z
[ "python", "nltk" ]
Python, sending command to GPIB instrument
1,663,763
<p>I need to send a command to a GPIB instrument and I can do it like this: <code>power.write("volt 0.01")</code>.<br> This command sets the output of my power source to 0.01V, however, I'm trying to take an I-V curve and want to set the source to different values and take a measurement at each value. I basically need ...
0
2009-11-02T21:19:04Z
1,663,778
<p>Instead of <code>power.write("volt k")</code>, use:</p> <pre><code>power.write("volt " + str(k)) ^ observe space here! </code></pre> <p>If you want to control the output precision, you can use the following:</p> <pre><code>power.write("volt %0.2f" % k) </code></pre> <p>That is, if <cod...
6
2009-11-02T21:21:47Z
[ "python", "string-formatting", "gpib" ]
Python, sending command to GPIB instrument
1,663,763
<p>I need to send a command to a GPIB instrument and I can do it like this: <code>power.write("volt 0.01")</code>.<br> This command sets the output of my power source to 0.01V, however, I'm trying to take an I-V curve and want to set the source to different values and take a measurement at each value. I basically need ...
0
2009-11-02T21:19:04Z
1,663,849
<p>Instead of <code>power.write("volt k")</code>, use:</p> <pre><code>power.write("volt %0.2f" % k) </code></pre>
3
2009-11-02T21:31:27Z
[ "python", "string-formatting", "gpib" ]
Python urllib2: Reading content body even during HTTPError exception?
1,663,790
<p>I'm using urllib2 to fetch a a page via HTTP. Sometimes the resource throws a HTTP error 400 (Bad Request) when my request contains an error. However, that response also contains an XML element that gives a detailed error message. It would be very handy to be able to see that error rather than just the HTTPError ...
41
2009-11-02T21:23:28Z
1,663,809
<p>You can treat the error as a response.</p> <p><a href="http://www.voidspace.org.uk/python/articles/urllib2.shtml#httperror">http://www.voidspace.org.uk/python/articles/urllib2.shtml#httperror</a></p> <blockquote> <p>When an error is raised the server responds by returning an HTTP error code and an error page...
37
2009-11-02T21:26:40Z
[ "python" ]
Python urllib2: Reading content body even during HTTPError exception?
1,663,790
<p>I'm using urllib2 to fetch a a page via HTTP. Sometimes the resource throws a HTTP error 400 (Bad Request) when my request contains an error. However, that response also contains an XML element that gives a detailed error message. It would be very handy to be able to see that error rather than just the HTTPError ...
41
2009-11-02T21:23:28Z
1,664,074
<pre><code>import urllib2 try: request = urllib2.Request('http://www.somesite.com') response = urllib2.urlopen(req) except urllib2.HTTPError as e: error_message = e.read() print error_message </code></pre>
41
2009-11-02T22:15:13Z
[ "python" ]
How can I iterate through two lists in parallel in Python?
1,663,807
<p>I have two iterables in Python, and I want to go over them in pairs:</p> <pre><code>foo = (1, 2, 3) bar = (4, 5, 6) for (f, b) in some_iterator(foo, bar): print "f: ", f, "; b: ", b </code></pre> <p>It should result in:</p> <pre><code>f: 1; b: 4 f: 2; b: 5 f: 3; b: 6 </code></pre> <p><em>One</em> way to do ...
272
2009-11-02T21:26:24Z
1,663,818
<p>You want the <code>zip</code> function.</p> <pre><code>for (f,b) in zip(foo, bar): print "f: ", f ,"; b: ", b </code></pre>
23
2009-11-02T21:27:53Z
[ "python", "iterator" ]
How can I iterate through two lists in parallel in Python?
1,663,807
<p>I have two iterables in Python, and I want to go over them in pairs:</p> <pre><code>foo = (1, 2, 3) bar = (4, 5, 6) for (f, b) in some_iterator(foo, bar): print "f: ", f, "; b: ", b </code></pre> <p>It should result in:</p> <pre><code>f: 1; b: 4 f: 2; b: 5 f: 3; b: 6 </code></pre> <p><em>One</em> way to do ...
272
2009-11-02T21:26:24Z
1,663,821
<p>What you're looking for is called <a href="http://docs.python.org/library/functions.html?highlight=zip#zip"><code>zip</code></a>.</p>
6
2009-11-02T21:28:02Z
[ "python", "iterator" ]
How can I iterate through two lists in parallel in Python?
1,663,807
<p>I have two iterables in Python, and I want to go over them in pairs:</p> <pre><code>foo = (1, 2, 3) bar = (4, 5, 6) for (f, b) in some_iterator(foo, bar): print "f: ", f, "; b: ", b </code></pre> <p>It should result in:</p> <pre><code>f: 1; b: 4 f: 2; b: 5 f: 3; b: 6 </code></pre> <p><em>One</em> way to do ...
272
2009-11-02T21:26:24Z
1,663,823
<p>The builtin <code>zip</code> does exactly what you want. If you want the same over iterables instead of lists you could look at itertools.izip which does the same thing but gives results one at a time.</p>
10
2009-11-02T21:28:11Z
[ "python", "iterator" ]
How can I iterate through two lists in parallel in Python?
1,663,807
<p>I have two iterables in Python, and I want to go over them in pairs:</p> <pre><code>foo = (1, 2, 3) bar = (4, 5, 6) for (f, b) in some_iterator(foo, bar): print "f: ", f, "; b: ", b </code></pre> <p>It should result in:</p> <pre><code>f: 1; b: 4 f: 2; b: 5 f: 3; b: 6 </code></pre> <p><em>One</em> way to do ...
272
2009-11-02T21:26:24Z
1,663,826
<pre><code>for f, b in zip(foo, bar): print(f, b) </code></pre> <p><code>zip</code> stops when the shorter of <code>foo</code> or <code>bar</code> stops.</p> <p>In <strong>Python 2</strong>, <a href="https://docs.python.org/2/library/functions.html#zip"><code>zip</code></a> returns a list of tuples. This is fine ...
469
2009-11-02T21:28:27Z
[ "python", "iterator" ]
How to avoid writing request.GET.get() twice in order to print it?
1,663,995
<p>I come from a PHP background and would like to know if there's a way to do this in Python. </p> <p>In PHP you can kill 2 birds with one stone like this:</p> <p>Instead of:</p> <pre><code>if(getData()){ $data = getData(); echo $data; } </code></pre> <p>I can do this:</p> <pre><code>if($data = getData()){...
37
2009-11-02T21:59:42Z
1,664,010
<p>Probably not exactly what you were thinking, but...</p> <pre><code>q = request.GET.get('q') if q: print q </code></pre> <p>this?</p>
23
2009-11-02T22:02:14Z
[ "python", "if-statement", "dictionary" ]
How to avoid writing request.GET.get() twice in order to print it?
1,663,995
<p>I come from a PHP background and would like to know if there's a way to do this in Python. </p> <p>In PHP you can kill 2 birds with one stone like this:</p> <p>Instead of:</p> <pre><code>if(getData()){ $data = getData(); echo $data; } </code></pre> <p>I can do this:</p> <pre><code>if($data = getData()){...
37
2009-11-02T21:59:42Z
1,664,013
<p>See my 8-year-old recipe <a href="http://code.activestate.com/recipes/66061/">here</a> for just this task.</p> <pre><code># In Python, you can't code "if x=foo():" -- assignment is a statement, thus # you can't fit it into an expression, as needed for conditions of if and # while statements, &amp;c. No problem, if...
23
2009-11-02T22:03:18Z
[ "python", "if-statement", "dictionary" ]
How to avoid writing request.GET.get() twice in order to print it?
1,663,995
<p>I come from a PHP background and would like to know if there's a way to do this in Python. </p> <p>In PHP you can kill 2 birds with one stone like this:</p> <p>Instead of:</p> <pre><code>if(getData()){ $data = getData(); echo $data; } </code></pre> <p>I can do this:</p> <pre><code>if($data = getData()){...
37
2009-11-02T21:59:42Z
1,664,017
<p>Well, this would be one way</p> <pre><code>q = request.GET.get('q') if q: print q </code></pre> <p>A briefer (but not superior, due to the call to print of nothing) way would be</p> <pre><code>print request.GET.get('q') or '', </code></pre>
0
2009-11-02T22:04:04Z
[ "python", "if-statement", "dictionary" ]
How to avoid writing request.GET.get() twice in order to print it?
1,663,995
<p>I come from a PHP background and would like to know if there's a way to do this in Python. </p> <p>In PHP you can kill 2 birds with one stone like this:</p> <p>Instead of:</p> <pre><code>if(getData()){ $data = getData(); echo $data; } </code></pre> <p>I can do this:</p> <pre><code>if($data = getData()){...
37
2009-11-02T21:59:42Z
1,664,019
<pre><code>q = request.GET.get('q') if q: print q else: # q is None ... </code></pre> <p>There's no way of doing assignment and conditionals in one go...</p>
2
2009-11-02T22:04:22Z
[ "python", "if-statement", "dictionary" ]
How to avoid writing request.GET.get() twice in order to print it?
1,663,995
<p>I come from a PHP background and would like to know if there's a way to do this in Python. </p> <p>In PHP you can kill 2 birds with one stone like this:</p> <p>Instead of:</p> <pre><code>if(getData()){ $data = getData(); echo $data; } </code></pre> <p>I can do this:</p> <pre><code>if($data = getData()){...
37
2009-11-02T21:59:42Z
1,664,066
<p>If get() throws an exception when it's not there, you could do </p> <pre><code>try: q = request.GET.get('q') print q except : pass </code></pre>
2
2009-11-02T22:13:44Z
[ "python", "if-statement", "dictionary" ]
How to avoid writing request.GET.get() twice in order to print it?
1,663,995
<p>I come from a PHP background and would like to know if there's a way to do this in Python. </p> <p>In PHP you can kill 2 birds with one stone like this:</p> <p>Instead of:</p> <pre><code>if(getData()){ $data = getData(); echo $data; } </code></pre> <p>I can do this:</p> <pre><code>if($data = getData()){...
37
2009-11-02T21:59:42Z
1,806,338
<p>A variation on <a href="http://stackoverflow.com/questions/1663995/python-variable-assignment-and-if-statement/1664013#1664013">Alex's answer</a>:</p> <pre><code>class DataHolder: def __init__(self, value=None, attr_name='value'): self._attr_name = attr_name self.set(value) def __call__(self...
9
2009-11-27T01:03:20Z
[ "python", "if-statement", "dictionary" ]
How to avoid writing request.GET.get() twice in order to print it?
1,663,995
<p>I come from a PHP background and would like to know if there's a way to do this in Python. </p> <p>In PHP you can kill 2 birds with one stone like this:</p> <p>Instead of:</p> <pre><code>if(getData()){ $data = getData(); echo $data; } </code></pre> <p>I can do this:</p> <pre><code>if($data = getData()){...
37
2009-11-02T21:59:42Z
3,141,436
<pre><code>config_hash = {} tmp_dir = ([config_hash[x] for x in ["tmp_dir"] if config_hash.has_key(x)] or ["tmp"])[0] print tmp_dir config_hash["tmp_dir"] = "cat" tmp_dir = ([config_hash[x] for x in ["tmp_dir"] if config_hash.has_key(x)] or ["tmp"])[0] print tmp_dir </code></pre>
0
2010-06-29T14:06:20Z
[ "python", "if-statement", "dictionary" ]
How to avoid writing request.GET.get() twice in order to print it?
1,663,995
<p>I come from a PHP background and would like to know if there's a way to do this in Python. </p> <p>In PHP you can kill 2 birds with one stone like this:</p> <p>Instead of:</p> <pre><code>if(getData()){ $data = getData(); echo $data; } </code></pre> <p>I can do this:</p> <pre><code>if($data = getData()){...
37
2009-11-02T21:59:42Z
12,060,311
<p>a possible way to do it, without necessity to set the variable before, could be like:</p> <pre><code>if (lambda x: globals().update({'q':x}) or True if x else False)(request.GET.get('q')): print q </code></pre> <p>.. it's just for fun - this method should not be used, because it is ugly hack, difficult to unde...
0
2012-08-21T17:50:32Z
[ "python", "if-statement", "dictionary" ]
How to avoid writing request.GET.get() twice in order to print it?
1,663,995
<p>I come from a PHP background and would like to know if there's a way to do this in Python. </p> <p>In PHP you can kill 2 birds with one stone like this:</p> <p>Instead of:</p> <pre><code>if(getData()){ $data = getData(); echo $data; } </code></pre> <p>I can do this:</p> <pre><code>if($data = getData()){...
37
2009-11-02T21:59:42Z
30,416,590
<p>Simply try:</p> <pre><code>print(request.GET.get('q', '')) </code></pre> <p>which basically prints nothing if the first argument is not present (see <a href="https://docs.python.org/3/library/stdtypes.html#dict.get" rel="nofollow"><code>dict.get</code></a>).</p> <hr> <p>Alternative solution would be to use a con...
0
2015-05-23T19:10:35Z
[ "python", "if-statement", "dictionary" ]
bencoding binary data in Java strings
1,664,124
<p>I'm playing with bencoding and I would like to keep bencoded strings as Java strings, but they contain binary data, so blindly converting them to string will corrupt the data. What I am trying to accomplish is to have a conversion function that will keep the ASCII bytes as ASCII and encode non-ASCII chars in a rever...
2
2009-11-02T22:24:45Z
1,664,156
<p>Bencoded strings are byte strings. You can attempt to decode a byte string to unicode codepoints in Java with <code>String(byte[] bytes, Charset charset)</code>. Decoding with certain encodings such as ISO-8859-1 will always succeed, since any byte maps directly to a codepoint. With many of these encodings (includin...
1
2009-11-02T22:31:40Z
[ "java", "python", "encoding" ]
bencoding binary data in Java strings
1,664,124
<p>I'm playing with bencoding and I would like to keep bencoded strings as Java strings, but they contain binary data, so blindly converting them to string will corrupt the data. What I am trying to accomplish is to have a conversion function that will keep the ASCII bytes as ASCII and encode non-ASCII chars in a rever...
2
2009-11-02T22:24:45Z
1,664,328
<p>If <a href="http://en.wikipedia.org/wiki/Bencode" rel="nofollow">Wikipedia is accurate on Bencode</a>, the format seems straightforward enough. Parse the byte data directly:</p> <pre><code>while (true) { in.mark(1); int n = in.read(); if (n &lt; 0) { // end of input break; } in.reset(); // take ...
0
2009-11-02T23:11:21Z
[ "java", "python", "encoding" ]
siginterrupt() only works for the first signal? (Python)
1,664,195
<p>For some reason, siginterrupt() only seems to set the behaviour for the first signal received.</p> <p>In this example program, the first SIGQUIT appears to do nothing, but the second sigquit prints "SIGQUIT Handler" and s.accept() throws an Interrupted system call exception.</p> <pre><code>from signal import * fro...
7
2009-11-02T22:41:35Z
1,664,821
<p>Which <code>unix</code> are you using? At the <code>C</code> level, there are different implementations and semantics for signal handling on BSD vs System 5 (SYSV).</p> <p>My guess is that you are using SYSV, in which case the signal disposition is reset to SIG_DFL after the signal handler has returned (classical s...
2
2009-11-03T02:11:22Z
[ "python", "linux", "unix", "signals" ]
siginterrupt() only works for the first signal? (Python)
1,664,195
<p>For some reason, siginterrupt() only seems to set the behaviour for the first signal received.</p> <p>In this example program, the first SIGQUIT appears to do nothing, but the second sigquit prints "SIGQUIT Handler" and s.accept() throws an Interrupted system call exception.</p> <pre><code>from signal import * fro...
7
2009-11-02T22:41:35Z
6,182,996
<p>It's a <a href="http://bugs.python.org/issue8354" rel="nofollow">bug</a> of python. "siginterrupt with flag=False is reset when signal received", which has been fixed in later python2.6 release. (2.6.6+, 2.7+)</p> <p>For the second one, siginterrupt doesn't affect select(). </p> <p>see <a href="http://lkml.org/lkm...
3
2011-05-31T04:24:11Z
[ "python", "linux", "unix", "signals" ]
What does "evaluated only once" mean for chained comparisons in Python?
1,664,292
<p>A friend brought this to my attention, and after I pointed out an oddity, we're both confused.</p> <p>Python's docs, say, and have said since at least 2.5.1 (haven't checked further back:</p> <blockquote> <p>Comparisons can be chained arbitrarily, e.g., x &lt; y &lt;= z is equivalent to x &lt; y and y &lt;= z, e...
19
2009-11-02T23:01:45Z
1,664,307
<p>The 'expression' <code>y</code> is evaluated once. I.e., in the following expression, the function is executed only one time.</p> <pre><code>&gt;&gt;&gt; def five(): ... print 'returning 5' ... return 5 ... &gt;&gt;&gt; 1 &lt; five() &lt;= 5 returning 5 True </code></pre> <p>As opposed to:</p> <pre><code>&...
44
2009-11-02T23:06:57Z
[ "python" ]
What does "evaluated only once" mean for chained comparisons in Python?
1,664,292
<p>A friend brought this to my attention, and after I pointed out an oddity, we're both confused.</p> <p>Python's docs, say, and have said since at least 2.5.1 (haven't checked further back:</p> <blockquote> <p>Comparisons can be chained arbitrarily, e.g., x &lt; y &lt;= z is equivalent to x &lt; y and y &lt;= z, e...
19
2009-11-02T23:01:45Z
1,664,313
<p>In the context of y being evaluated, y is meant as an arbitrary expression that could have side-effects. For instance:</p> <pre><code>class Foo(object): @property def complain(self): print("Evaluated!") return 2 f = Foo() print(1 &lt; f.complain &lt; 3) # Prints evaluated once print(1 &lt; ...
8
2009-11-02T23:08:37Z
[ "python" ]
secure and efficient file uploader
1,664,597
<p>I am looking for a decent file uploader. I'm using django, but while i don't NEED a django file uploader, python is preferable. php would also be fine.</p> <p>can anyone point me in the direction of a good file uploader which is secure and efficient?</p> <p><strong>EDIT</strong>: I need the server-side handler of ...
1
2009-11-03T00:42:57Z
1,664,662
<p>I'm using <a href="http://www.uploadify.com/" rel="nofollow">uploadify</a> which is an upload plugin for jQuery with a flash progress bar. I use some basic php for the upload script. It can be made as secure as you need with a little investigating the forum.</p>
2
2009-11-03T01:13:54Z
[ "php", "python", "django", "upload" ]
secure and efficient file uploader
1,664,597
<p>I am looking for a decent file uploader. I'm using django, but while i don't NEED a django file uploader, python is preferable. php would also be fine.</p> <p>can anyone point me in the direction of a good file uploader which is secure and efficient?</p> <p><strong>EDIT</strong>: I need the server-side handler of ...
1
2009-11-03T00:42:57Z
1,664,806
<p>Agree with jeerose: <strong>Uploadify is a nice app.</strong></p> <p>I've made a simple Django wrapper for it as well if you're interested: <a href="http://wiki.github.com/tstone/django-uploadify" rel="nofollow">django-uploadify</a>. It basically gives you a template tag which renders uploadify and fires a Django...
2
2009-11-03T02:08:02Z
[ "php", "python", "django", "upload" ]
Django date filter by day of month
1,664,636
<p>I need to write a query that returns all object less that or equal to a certain day of a certain month. The year is not important. It's easy enough to get an object by a particular day/month (assume <code>now = datetime.datetime.now()</code>):</p> <pre><code>posts = TodaysObject.objects.filter(publish_date__day=now...
4
2009-11-03T00:58:35Z
1,664,681
<p>Try this:</p> <p>Option 1:</p> <pre><code>from django.db.models import Q datafilter = Q() for i in xrange(1, now.day+1): datafilter = datafilter | Q(publish_date__day=i) datafilter = datafilter &amp; Q(publish_date__month=now.month) posts = TodaysObject.objects.filter(datafilter) </code></pre> <p>Option 2:</...
7
2009-11-03T01:20:46Z
[ "python", "django" ]
Django date filter by day of month
1,664,636
<p>I need to write a query that returns all object less that or equal to a certain day of a certain month. The year is not important. It's easy enough to get an object by a particular day/month (assume <code>now = datetime.datetime.now()</code>):</p> <pre><code>posts = TodaysObject.objects.filter(publish_date__day=now...
4
2009-11-03T00:58:35Z
1,664,722
<p>it's not always portable from one database engine to another, but you may want to look into the <code>extra()</code> queryset method.</p> <p><a href="http://docs.djangoproject.com/en/dev/ref/models/querysets/#extra-select-none-where-none-params-none-tables-none-order-by-none-select-params-none" rel="nofollow">from ...
1
2009-11-03T01:38:50Z
[ "python", "django" ]
Can Python's distutils compile .S (assembly)?
1,664,812
<p>I wrote a small Python extension that bundles, compiles and statically links with a small C library with one optional .S (assembler) file. Distutils's Extension() doesn't recognize the .S by default. Is there a good way to compile that file, or should I just shell out to <code>make</code>? Right now I compile the C ...
2
2009-11-03T02:09:57Z
1,664,857
<p>As distributed, distutils don't know about assembly code, and I don't know of extensions to it that let it deal automatically with it. In a similar situation I've always built the library separately (with C and assembly as needed and feasible) and only used the resulting <code>.a</code> with setup.py.</p>
2
2009-11-03T02:19:38Z
[ "python", "distutils" ]
Can Python's distutils compile .S (assembly)?
1,664,812
<p>I wrote a small Python extension that bundles, compiles and statically links with a small C library with one optional .S (assembler) file. Distutils's Extension() doesn't recognize the .S by default. Is there a good way to compile that file, or should I just shell out to <code>make</code>? Right now I compile the C ...
2
2009-11-03T02:09:57Z
7,702,823
<p>There is an open feature request about this: <a href="http://bugs.python.org/issue2942" rel="nofollow">http://bugs.python.org/issue2942</a></p>
0
2011-10-09T10:21:18Z
[ "python", "distutils" ]
Python string interning and substrings
1,664,840
<p>Does python create a completely new string (copying the contents) when you do a substring operation like:</p> <pre><code>new_string = my_old_string[foo:bar] </code></pre> <p>Or does it use interning to point to the old data ?</p> <p>As a clarification, I'm curious if the underlying character buffer is shared as i...
4
2009-11-03T02:15:13Z
1,664,847
<p>In Python, strings are immutable. That means that you will always get a copy on any slice, concatenate, or other operations.</p> <p><a href="http://effbot.org/pyfaq/why-are-python-strings-immutable.htm" rel="nofollow">http://effbot.org/pyfaq/why-are-python-strings-immutable.htm</a> is a nice explanation for some o...
-2
2009-11-03T02:17:04Z
[ "python" ]
Python string interning and substrings
1,664,840
<p>Does python create a completely new string (copying the contents) when you do a substring operation like:</p> <pre><code>new_string = my_old_string[foo:bar] </code></pre> <p>Or does it use interning to point to the old data ?</p> <p>As a clarification, I'm curious if the underlying character buffer is shared as i...
4
2009-11-03T02:15:13Z
1,664,849
<p>It's a completely new string (so the old bigger one can be let go when feasible, rather than staying alive just because some tiny string's been sliced from it and it being kept around).</p> <p><code>intern</code> is a different thing, though.</p>
2
2009-11-03T02:17:44Z
[ "python" ]
Python string interning and substrings
1,664,840
<p>Does python create a completely new string (copying the contents) when you do a substring operation like:</p> <pre><code>new_string = my_old_string[foo:bar] </code></pre> <p>Or does it use interning to point to the old data ?</p> <p>As a clarification, I'm curious if the underlying character buffer is shared as i...
4
2009-11-03T02:15:13Z
1,664,880
<p>Looks like I can answer my own question, opened up the source and guess what I found:</p> <pre><code> static PyObject * string_slice(register PyStringObject *a, register Py_ssize_t i, register Py_ssize_t j) ... snip ... return PyString_FromStringAndSize(a-&gt;ob_sval + i, j-i); </code></pr...
0
2009-11-03T02:27:22Z
[ "python" ]
Python string interning and substrings
1,664,840
<p>Does python create a completely new string (copying the contents) when you do a substring operation like:</p> <pre><code>new_string = my_old_string[foo:bar] </code></pre> <p>Or does it use interning to point to the old data ?</p> <p>As a clarification, I'm curious if the underlying character buffer is shared as i...
4
2009-11-03T02:15:13Z
1,664,919
<p>Examining <a href="http://svn.python.org/view/python/trunk/Objects/stringobject.c?revision=75722&amp;view=markup">the source</a> reveals:</p> <p>When the slice indexes match the start and end of the original string, then the original string is returned.</p> <p>Otherwise, you get the result of the function <code>Py...
7
2009-11-03T02:40:32Z
[ "python" ]
Python string interning and substrings
1,664,840
<p>Does python create a completely new string (copying the contents) when you do a substring operation like:</p> <pre><code>new_string = my_old_string[foo:bar] </code></pre> <p>Or does it use interning to point to the old data ?</p> <p>As a clarification, I'm curious if the underlying character buffer is shared as i...
4
2009-11-03T02:15:13Z
1,664,990
<p>You may also be interested in islice which does provide a view of the original string</p> <pre><code>&gt;&gt;&gt; from sys import getrefcount &gt;&gt;&gt; from itertools import islice &gt;&gt;&gt; h="foobarbaz" &gt;&gt;&gt; getrefcount(h) 2 &gt;&gt;&gt; g=islice(h,3,6) &gt;&gt;&gt; getrefcount(h) 3 &gt;&gt;&gt; ""....
8
2009-11-03T03:05:32Z
[ "python" ]
How to create an image from a string in python
1,664,861
<p>I'm currently having trouble creating an image from a binary string of data in my Python program. I receive the binary data via a socket but when I try the methods I read about on <a href="http://effbot.org/imagingbook/introduction.htm">here</a> like this:</p> <pre><code>buff = StringIO.StringIO() #buffer where im...
16
2009-11-03T02:20:39Z
1,664,958
<p>I suspect that you're not <code>seek</code>-ing back to the beginning of the buffer before you pass the StringIO object to PIL. Here's some code the demonstrates the problem and solution:</p> <pre><code>&gt;&gt;&gt; buff = StringIO.StringIO() &gt;&gt;&gt; buff.write(open('map.png', 'rb').read()) &gt;&gt;&gt; &gt;&...
28
2009-11-03T02:56:27Z
[ "python", "string", "image", "sockets" ]
How to create an image from a string in python
1,664,861
<p>I'm currently having trouble creating an image from a binary string of data in my Python program. I receive the binary data via a socket but when I try the methods I read about on <a href="http://effbot.org/imagingbook/introduction.htm">here</a> like this:</p> <pre><code>buff = StringIO.StringIO() #buffer where im...
16
2009-11-03T02:20:39Z
1,665,591
<p>You have either call <code>buff.seek(0)</code> or, better, initialize memory buffer with data <code>StringIO.StringIO(data)</code>.</p>
6
2009-11-03T06:32:55Z
[ "python", "string", "image", "sockets" ]
Automatic string length in recarray
1,664,917
<p>If I create a recarray in this way:</p> <pre><code>In [29]: np.rec.fromrecords([(1,'hello'),(2,'world')],names=['a','b']) </code></pre> <p>The result looks fine:</p> <pre><code>Out[29]: rec.array([(1, 'hello'), (2, 'world')], dtype=[('a', '&lt;i8'), ('b', '|S5')]) </code></pre> <p>But if I want to specif...
3
2009-11-03T02:38:05Z
1,664,950
<p>I don't know how to ask numpy to determine for you some aspects of a dtype but not others, but couldn't you have, e.g.:</p> <pre><code>data = [(1,'hello'),(2,'world')] dlen = max(len(s) for i, s in data) st = '|S%d' % dlen np.rec.fromrecords(data, dtype=[('a',np.int8), ('b',st)]) </code></pre>
0
2009-11-03T02:52:29Z
[ "python", "numpy" ]
Automatic string length in recarray
1,664,917
<p>If I create a recarray in this way:</p> <pre><code>In [29]: np.rec.fromrecords([(1,'hello'),(2,'world')],names=['a','b']) </code></pre> <p>The result looks fine:</p> <pre><code>Out[29]: rec.array([(1, 'hello'), (2, 'world')], dtype=[('a', '&lt;i8'), ('b', '|S5')]) </code></pre> <p>But if I want to specif...
3
2009-11-03T02:38:05Z
1,767,115
<p>If you don't need to manipulate the strings as bytes, you may use the object data-type to represent them. This essentially stores a pointer instead of the actual bytes:</p> <pre><code>In [38]: np.array(data, dtype=[('a', np.uint8), ('b', np.object)]) Out[38]: array([(1, 'hello'), (2, 'world')], dtype=[('a'...
2
2009-11-19T22:45:10Z
[ "python", "numpy" ]
How to create queues of objects in Django?
1,664,952
<p>I am new to <strong>Django</strong> and I am trying to build a blog myself. I'm trying to create a feature I've seen implemented in <strong>Drupal</strong> using the <a href="http://drupal.org/project/nodequeue" rel="nofollow">nodequeue</a> module.</p> <p>What I want to do is to be able to create <strong>queues of ...
5
2009-11-03T02:53:32Z
1,664,987
<p>Here's one approach:</p> <pre><code>import collections, datetime, itertools class nodequeue(object): def __init__(self, N): self.data = collections.deque(N * [(None, None)]) def add(self, anobj): self.data.popleft() self.data.push((anobj, datetime.datetime.now()) def __iter__(self): it = iter...
5
2009-11-03T03:04:52Z
[ "python", "django", "django-models", "queue" ]
How to create queues of objects in Django?
1,664,952
<p>I am new to <strong>Django</strong> and I am trying to build a blog myself. I'm trying to create a feature I've seen implemented in <strong>Drupal</strong> using the <a href="http://drupal.org/project/nodequeue" rel="nofollow">nodequeue</a> module.</p> <p>What I want to do is to be able to create <strong>queues of ...
5
2009-11-03T02:53:32Z
1,665,194
<p>Alex's approach is great. I won't pretend to compete with his level of expertise, but for sake of completeness, here is another approach using the fantastic <a href="http://docs.python.org/library/queue.html" rel="nofollow"><code>Queue.Queue</code></a> class (bonus: thread-safe, but that's kinda useless to you base...
3
2009-11-03T04:09:59Z
[ "python", "django", "django-models", "queue" ]
How to create queues of objects in Django?
1,664,952
<p>I am new to <strong>Django</strong> and I am trying to build a blog myself. I'm trying to create a feature I've seen implemented in <strong>Drupal</strong> using the <a href="http://drupal.org/project/nodequeue" rel="nofollow">nodequeue</a> module.</p> <p>What I want to do is to be able to create <strong>queues of ...
5
2009-11-03T02:53:32Z
17,682,347
<p>You can use django-activity-stream. It doesn't have UI as Nodequeue has, but it can be used to create different queues of the objects.</p> <ul> <li><a href="https://github.com/justquick/django-activity-stream" rel="nofollow">https://github.com/justquick/django-activity-stream</a></li> <li><a href="http://www.slides...
0
2013-07-16T16:43:18Z
[ "python", "django", "django-models", "queue" ]
Is there a way to inspect the (differing) internal structures of Python objects that test as equal (==)?
1,665,176
<p>Yesterday I asked ("A case of outwardly equal lists of sets behaving differently under Python 2.5 (I think …)") why list W constructed as follows:</p> <pre><code>r_dim_1_based = range( 1, dim + 1) set_dim_1_based = set( r_dim_1_based) def listW_fill_func( val): if (val == 0): return set_dim_1_based ...
0
2009-11-03T04:04:11Z
1,665,233
<p>You're dealing with references in each case (more similar to pointers than to values). You can surely introspect your objects' references to your heart's contents -- for example, if you have a list and want to check if any items are identical references,</p> <pre><code>if len(thelist) != len(set(id(x) for x in the...
1
2009-11-03T04:24:03Z
[ "python", "list", "set", "inspection" ]
Verifying that an object in python adheres to a specific structure
1,665,260
<p>Is there some simple method that can check if an input object to some function adheres to a specific structure? For example, I want only a dictionary of string keys and values that are a list of integers.</p> <p>One method would be to write a recursive function that you pass in the object and you iterate over it, c...
2
2009-11-03T04:32:16Z
1,665,287
<p>Since Python emphasizes things just working, your best bet is to just <code>assert</code> as you go and trust the users of your library to feed you proper data. Let exceptions happen, if you must; that's on your clients for not reading your docstring.</p> <p>In your case, something like this:</p> <pre><code>def m...
0
2009-11-03T04:40:24Z
[ "python" ]
Verifying that an object in python adheres to a specific structure
1,665,260
<p>Is there some simple method that can check if an input object to some function adheres to a specific structure? For example, I want only a dictionary of string keys and values that are a list of integers.</p> <p>One method would be to write a recursive function that you pass in the object and you iterate over it, c...
2
2009-11-03T04:32:16Z
1,665,290
<p>Short answer, no, you have to create your own function.</p> <p>Long answer: its not pythonic to do what you're asking. There might be some special cases (e.g, marshalling a dict to xmlrpc), but by and large, assume the objects will act like what they're documented to be. If they don't, let the AttributeError bubb...
1
2009-11-03T04:40:40Z
[ "python" ]
Verifying that an object in python adheres to a specific structure
1,665,260
<p>Is there some simple method that can check if an input object to some function adheres to a specific structure? For example, I want only a dictionary of string keys and values that are a list of integers.</p> <p>One method would be to write a recursive function that you pass in the object and you iterate over it, c...
2
2009-11-03T04:32:16Z
1,665,291
<p>Why would you expect Python to provide an "elegant way" to check types, since the whole idea of type-checking is so utterly alien to the Pythonic way of conceiving the world and interacting with it?! Normally in Python you'd use duck typing -- so "an integer" might equally well be an int, a long, a gmpy.mpz -- type...
3
2009-11-03T04:40:41Z
[ "python" ]
Verifying that an object in python adheres to a specific structure
1,665,260
<p>Is there some simple method that can check if an input object to some function adheres to a specific structure? For example, I want only a dictionary of string keys and values that are a list of integers.</p> <p>One method would be to write a recursive function that you pass in the object and you iterate over it, c...
2
2009-11-03T04:32:16Z
1,665,441
<p>I will take a shot and propose a helper function that can do something like that for you in a more generic+elegant way:</p> <pre><code>def check_type(value, type_def): """ This validates an object instanct &lt;value&gt; against a type template &lt;type_def&gt; presented as a simplified object. E.g. ...
0
2009-11-03T05:36:24Z
[ "python" ]
Are there any examples of a Python PyGTK Pango editor toolbar?
1,665,288
<p>I am looking for an example application written in Python and PyGTK.</p> <p>There should be an editor out there somewhere that already does this.</p> <p>Some app with a text editor row of buttons: - Font - Bold/italic/underline - etc</p> <p>I am hoping to avoid reinventing the wheel on this one! thanks</p>
1
2009-11-03T04:40:39Z
1,684,397
<p>I couldn't find any pygtk programs that do what you want, but here is a good tutorial to using pango: <a href="http://zetcode.com/tutorials/pygtktutorial/pango/" rel="nofollow">http://zetcode.com/tutorials/pygtktutorial/pango/</a></p>
2
2009-11-05T23:30:25Z
[ "python", "pygtk", "pango" ]
Are there any examples of a Python PyGTK Pango editor toolbar?
1,665,288
<p>I am looking for an example application written in Python and PyGTK.</p> <p>There should be an editor out there somewhere that already does this.</p> <p>Some app with a text editor row of buttons: - Font - Bold/italic/underline - etc</p> <p>I am hoping to avoid reinventing the wheel on this one! thanks</p>
1
2009-11-03T04:40:39Z
1,772,990
<p>I found some related examples: KeepNote, which has a custom rich edit, and Rednotebook which implements KeepNote's richedit.</p>
2
2009-11-20T20:16:28Z
[ "python", "pygtk", "pango" ]
Python, Pygame, Pyro: How to send a surface over a network?
1,665,376
<p>I am working on a project in python using pygame and pyro. I can send data, functions, classes, and the like easily. However, I cannot send a surface across the wire without it dying on me in transit.</p> <p>The server makes a surface in the <code>def __init__</code> of the class being accessed across the wire:</p>...
2
2009-11-03T05:19:09Z
1,665,399
<p>Generally speaking, you don't want to send a Surface (I'm assuming that a Surface is a device-dependent display) across the network. Most of the time, your client will be responsible for managing the drawing on its local Surface, and your server is responsible for telling the client what it needs to draw. A server m...
1
2009-11-03T05:25:33Z
[ "python", "network-programming", "pygame", "pyro" ]
Python, Pygame, Pyro: How to send a surface over a network?
1,665,376
<p>I am working on a project in python using pygame and pyro. I can send data, functions, classes, and the like easily. However, I cannot send a surface across the wire without it dying on me in transit.</p> <p>The server makes a surface in the <code>def __init__</code> of the class being accessed across the wire:</p>...
2
2009-11-03T05:19:09Z
1,665,638
<p>A pygame Surface is a wrapper around an underlying SDL surface, which I suspect can't be serialized by Pyro. If you want to copy its contents across the wire, you would be better off doing something like this:</p> <ol> <li>on the server use Surface.get_buffer() to get access to the underlying pixels.</li> <li>make ...
5
2009-11-03T06:44:58Z
[ "python", "network-programming", "pygame", "pyro" ]
Python, Pygame, Pyro: How to send a surface over a network?
1,665,376
<p>I am working on a project in python using pygame and pyro. I can send data, functions, classes, and the like easily. However, I cannot send a surface across the wire without it dying on me in transit.</p> <p>The server makes a surface in the <code>def __init__</code> of the class being accessed across the wire:</p>...
2
2009-11-03T05:19:09Z
1,665,932
<p>Try pickling the object and send the file...</p>
0
2009-11-03T08:21:18Z
[ "python", "network-programming", "pygame", "pyro" ]
IDE for Python + Django Template Highlight + JQuery
1,665,468
<p>I try Netbeans 6.7 for python but don't have a good django template highlight and jquery code completion... i did find a project in google for django for netbeans but they don't explain how to do...</p> <p>Also I try eclipse with pydev, but have some problems with code competion on my class...</p> <p>I like to muc...
0
2009-11-03T05:44:40Z
1,666,418
<p>Aptana is great in HTML/CSS/Javascript editing.</p> <p>You may also refer to this question:</p> <p><a href="http://stackoverflow.com/questions/61470/which-text-editor-has-the-most-useful-autocomplete-for-web-page-editing">Which text editor has the most useful autocomplete for web page editing</a></p>
0
2009-11-03T10:14:34Z
[ "jquery", "python", "django-templates" ]
Python equivalent to atoi / atof
1,665,511
<p>Python loves raising exceptions, which is usually great. But I'm facing some strings I desperately want to convert to integers using C's atoi / atof semantics - e.g. atoi of "3 of 12", "3/12", "3 / 12", should all become 3; atof("3.14 seconds") should become 3.14; atoi(" -99 score") should become -99. Python of ...
10
2009-11-03T06:02:24Z
1,665,534
<p>Perhaps use a quick regex to grab only the first part of the string that can be considered numeric? Something like...</p> <pre><code>-?[0-9]+(?:\.[0-9]+)? </code></pre> <p>for floats and for ints just,</p> <pre><code>-?[0-9]+ </code></pre>
6
2009-11-03T06:09:06Z
[ "python" ]
Python equivalent to atoi / atof
1,665,511
<p>Python loves raising exceptions, which is usually great. But I'm facing some strings I desperately want to convert to integers using C's atoi / atof semantics - e.g. atoi of "3 of 12", "3/12", "3 / 12", should all become 3; atof("3.14 seconds") should become 3.14; atoi(" -99 score") should become -99. Python of ...
10
2009-11-03T06:02:24Z
1,665,550
<p>I think the iterative version is better than the recursive version</p> <pre><code># Iterative def atof(s): s,_,_=s.partition(' ') # eg. this helps by trimming off at the first space while s: try: return float(s) except: s=s[:-1] return 0.0 # Recursive def atof(s)...
7
2009-11-03T06:15:12Z
[ "python" ]
Python equivalent to atoi / atof
1,665,511
<p>Python loves raising exceptions, which is usually great. But I'm facing some strings I desperately want to convert to integers using C's atoi / atof semantics - e.g. atoi of "3 of 12", "3/12", "3 / 12", should all become 3; atof("3.14 seconds") should become 3.14; atoi(" -99 score") should become -99. Python of ...
10
2009-11-03T06:02:24Z
1,665,551
<p>If you're so keen on getting exactly the functionality of c's <code>atoi</code>, why not use it directly? E.g., on my Mac,</p> <pre><code>&gt;&gt;&gt; import ctypes, ctypes.util &gt;&gt;&gt; whereislib = ctypes.util.find_library('c') &gt;&gt;&gt; whereislib '/usr/lib/libc.dylib' &gt;&gt;&gt; clib = ctypes.cdll.Loa...
31
2009-11-03T06:15:55Z
[ "python" ]
Python equivalent to atoi / atof
1,665,511
<p>Python loves raising exceptions, which is usually great. But I'm facing some strings I desperately want to convert to integers using C's atoi / atof semantics - e.g. atoi of "3 of 12", "3/12", "3 / 12", should all become 3; atof("3.14 seconds") should become 3.14; atoi(" -99 score") should become -99. Python of ...
10
2009-11-03T06:02:24Z
1,665,561
<p>I think I will do it char by char:</p> <pre><code>def myatof(s): try: return float(s); except: last_result = None for i in range(1, len(s)): try: last_result = float(s[:i]) except: return last_result return last_result </code></pre>
0
2009-11-03T06:21:26Z
[ "python" ]
Python equivalent to atoi / atof
1,665,511
<p>Python loves raising exceptions, which is usually great. But I'm facing some strings I desperately want to convert to integers using C's atoi / atof semantics - e.g. atoi of "3 of 12", "3/12", "3 / 12", should all become 3; atof("3.14 seconds") should become 3.14; atoi(" -99 score") should become -99. Python of ...
10
2009-11-03T06:02:24Z
1,681,644
<p>It's pretty straightforward to do this with regular expressions:</p> <pre><code>&gt;&gt;&gt; import re &gt;&gt;&gt; p = re.compile(r'[^\d-]*(-?[\d]+(\.[\d]*)?([eE][+-]?[\d]+)?)') &gt;&gt;&gt; def test(seq): for s in seq: m = p.match(s) if m: result = m.groups()[0] ...
3
2009-11-05T16:12:19Z
[ "python" ]
Python equivalent to atoi / atof
1,665,511
<p>Python loves raising exceptions, which is usually great. But I'm facing some strings I desperately want to convert to integers using C's atoi / atof semantics - e.g. atoi of "3 of 12", "3/12", "3 / 12", should all become 3; atof("3.14 seconds") should become 3.14; atoi(" -99 score") should become -99. Python of ...
10
2009-11-03T06:02:24Z
18,520,298
<p>How about this?</p> <pre><code>num=int(q.join(re.findall(r'[\d-]',s))) </code></pre>
-1
2013-08-29T20:22:02Z
[ "python" ]
Python list filtering and transformation
1,665,667
<p>I have a list of library filenames that I need to filter against regular expression and then extract version number from those that match. This is the obvious way to do that:</p> <pre><code>libs = ['libIce.so.33', 'libIce.so.3.3.1', 'libIce.so.32', 'libIce.so.3.2.0'] versions = [] regex = re.compile('libIce.so\.([0...
9
2009-11-03T06:57:29Z
1,665,694
<p>How about a list comprehension?</p> <pre><code>In [5]: versions = [m.group(1) for m in [regex.match(lib) for lib in libs] if m] In [6]: versions Out[6]: ['3.3.1', '3.2.0'] </code></pre>
19
2009-11-03T07:05:11Z
[ "python", "list", "filtering", "transformation" ]
Python list filtering and transformation
1,665,667
<p>I have a list of library filenames that I need to filter against regular expression and then extract version number from those that match. This is the obvious way to do that:</p> <pre><code>libs = ['libIce.so.33', 'libIce.so.3.3.1', 'libIce.so.32', 'libIce.so.3.2.0'] versions = [] regex = re.compile('libIce.so\.([0...
9
2009-11-03T06:57:29Z
1,665,695
<p>You could do this:</p> <pre><code>versions = [m.group(1) for m in [regex.match(l) for l in libs] if m] </code></pre> <p>I don't think it's very readable, though...</p> <p>Maybe it's clearer done in two steps:</p> <pre><code>matches = [regex.match(l) for l in line] versions = [m.group(1) for m in matches if m] </...
5
2009-11-03T07:05:51Z
[ "python", "list", "filtering", "transformation" ]
Python list filtering and transformation
1,665,667
<p>I have a list of library filenames that I need to filter against regular expression and then extract version number from those that match. This is the obvious way to do that:</p> <pre><code>libs = ['libIce.so.33', 'libIce.so.3.3.1', 'libIce.so.32', 'libIce.so.3.2.0'] versions = [] regex = re.compile('libIce.so\.([0...
9
2009-11-03T06:57:29Z
1,665,699
<p>you don't really need to bother with regex for your simple case</p> <pre><code>&gt;&gt;&gt; libs = ['libIce.so.33', 'libIce.so.3.3.1', 'libIce.so.32', 'libIce.so.3.2.0'] &gt;&gt;&gt; libs ['libIce.so.33', 'libIce.so.3.3.1', 'libIce.so.32', 'libIce.so.3.2.0'] &gt;&gt;&gt; for i in libs: ... print i.split("so.") .....
0
2009-11-03T07:07:36Z
[ "python", "list", "filtering", "transformation" ]
Python list filtering and transformation
1,665,667
<p>I have a list of library filenames that I need to filter against regular expression and then extract version number from those that match. This is the obvious way to do that:</p> <pre><code>libs = ['libIce.so.33', 'libIce.so.3.3.1', 'libIce.so.32', 'libIce.so.3.2.0'] versions = [] regex = re.compile('libIce.so\.([0...
9
2009-11-03T06:57:29Z
1,665,704
<p>There's nothing that isn't pythonic about using a standard for loop. However, you can use the <a href="http://www.go4expert.com/forums/showthread.php?t=6251" rel="nofollow">map()</a> function to generate a new list based on the results from a function run against each item in the list.</p>
1
2009-11-03T07:09:47Z
[ "python", "list", "filtering", "transformation" ]
Python list filtering and transformation
1,665,667
<p>I have a list of library filenames that I need to filter against regular expression and then extract version number from those that match. This is the obvious way to do that:</p> <pre><code>libs = ['libIce.so.33', 'libIce.so.3.3.1', 'libIce.so.32', 'libIce.so.3.2.0'] versions = [] regex = re.compile('libIce.so\.([0...
9
2009-11-03T06:57:29Z
1,665,712
<p>How about this one:</p> <pre><code>import re def matches(regexp, list): 'Regexp, [str] -&gt; Iterable(Match or None)' return (regexp.match(s) for s in list) libs = ['libIce.so.33', 'libIce.so.3.3.1', 'libIce.so.32', 'libIce.so.3.2.0'] regexp = re.compile('libIce.so\.([0-9]+\.[0-9]+\.[0-9]+)') versions = [...
0
2009-11-03T07:11:55Z
[ "python", "list", "filtering", "transformation" ]
Python list filtering and transformation
1,665,667
<p>I have a list of library filenames that I need to filter against regular expression and then extract version number from those that match. This is the obvious way to do that:</p> <pre><code>libs = ['libIce.so.33', 'libIce.so.3.3.1', 'libIce.so.32', 'libIce.so.3.2.0'] versions = [] regex = re.compile('libIce.so\.([0...
9
2009-11-03T06:57:29Z
1,665,854
<p>One way I could think of was to combine 'map' and list comprehension.<br /> The solution looks as below: </p> <p><code></p> <pre><code>import re libs = ['libIce.so.33', 'libIce.so.3.3.1', 'libIce.so.32', 'libIce.so.3.2.0'] versions = [] regex = re.compile('libIce.so\.([0-9]+\.[0-9]+\.[0-9]+)') def matc...
0
2009-11-03T07:54:13Z
[ "python", "list", "filtering", "transformation" ]
Python list filtering and transformation
1,665,667
<p>I have a list of library filenames that I need to filter against regular expression and then extract version number from those that match. This is the obvious way to do that:</p> <pre><code>libs = ['libIce.so.33', 'libIce.so.3.3.1', 'libIce.so.32', 'libIce.so.3.2.0'] versions = [] regex = re.compile('libIce.so\.([0...
9
2009-11-03T06:57:29Z
1,666,113
<p>One more one-liner just to show other ways (I've also cleaned regexp a bit):</p> <pre><code>regex = re.compile(r'^libIce\.so\.([0-9]+\.[0-9]+\.[0-9]+)$') sum(map(regex.findall, libs), []) </code></pre> <p>But note, that your original version is more readable than all suggestions. Is it worth to change?</p>
8
2009-11-03T09:05:11Z
[ "python", "list", "filtering", "transformation" ]
CherryPy (or other Python framework) with FastCGI on shared host
1,665,742
<p>I am trying to configure the Python mini-framework CherryPy with FastCGI (actually fcgid) on Apache. I am on a shared host, so I don't have access to httpd.conf, just htaccess. I have followed these tutorials to no avail:</p> <ul> <li><a href="http://tools.cherrypy.org/wiki/FastCGIWSGI">http://tools.cherrypy.org/wi...
5
2009-11-03T07:22:03Z
1,668,126
<p>Apache + Bluehost + fastcgi + cherrypy + wsgi is unfortunately a lot of pieces. I wish I had a year to write the Definitive Guide for you, but alas. You might gain some insight from the <a href="http://groups.google.com/group/cherrypy-users/browse%5Ffrm/thread/a1522917362b41e9?tvc=1" rel="nofollow">rather long maili...
1
2009-11-03T15:40:24Z
[ "python", "fastcgi", "cherrypy", "mod-fcgid" ]
CherryPy (or other Python framework) with FastCGI on shared host
1,665,742
<p>I am trying to configure the Python mini-framework CherryPy with FastCGI (actually fcgid) on Apache. I am on a shared host, so I don't have access to httpd.conf, just htaccess. I have followed these tutorials to no avail:</p> <ul> <li><a href="http://tools.cherrypy.org/wiki/FastCGIWSGI">http://tools.cherrypy.org/wi...
5
2009-11-03T07:22:03Z
1,672,823
<p>An idea: make sure your .fcgi file has a reference to the correct python executable in the initial line:</p> <blockquote> <h1>#!/usr/bin/python</h1> </blockquote> <p>I had to get Django running with fcgi on Bluehost and apache using the wrong python environment was my problem (worked from the shell, but not from...
1
2009-11-04T10:13:59Z
[ "python", "fastcgi", "cherrypy", "mod-fcgid" ]
CherryPy (or other Python framework) with FastCGI on shared host
1,665,742
<p>I am trying to configure the Python mini-framework CherryPy with FastCGI (actually fcgid) on Apache. I am on a shared host, so I don't have access to httpd.conf, just htaccess. I have followed these tutorials to no avail:</p> <ul> <li><a href="http://tools.cherrypy.org/wiki/FastCGIWSGI">http://tools.cherrypy.org/wi...
5
2009-11-03T07:22:03Z
1,698,800
<p>In your webserver's log file, it should actually show what the output was that confused it. Are you sure you're looking in the error log as well as the access log?</p>
0
2009-11-09T02:25:21Z
[ "python", "fastcgi", "cherrypy", "mod-fcgid" ]
CherryPy (or other Python framework) with FastCGI on shared host
1,665,742
<p>I am trying to configure the Python mini-framework CherryPy with FastCGI (actually fcgid) on Apache. I am on a shared host, so I don't have access to httpd.conf, just htaccess. I have followed these tutorials to no avail:</p> <ul> <li><a href="http://tools.cherrypy.org/wiki/FastCGIWSGI">http://tools.cherrypy.org/wi...
5
2009-11-03T07:22:03Z
1,720,196
<p>The Bluehost article has been the best resource, but I didn't carefully read the part about getting the latest patches (the beginning of step 3). At the time of the article, and even now with CherryPy version 3.1.2, you can't do 'dynamic mode' fcgi (when apache spawns the process). more <a href="http://www.cherrypy....
1
2009-11-12T05:56:51Z
[ "python", "fastcgi", "cherrypy", "mod-fcgid" ]
Setting a lambda function as a property
1,665,789
<p>Consider these two classes:</p> <pre><code>class Test(int): difference = property(lambda self: self.__sub__) class Test2(int): difference=lambda self: self.__sub__ </code></pre> <p>Is there any difference between these two classes? <strong>New</strong>: If so, what is the purpose of using the property <em...
0
2009-11-03T07:35:39Z
1,665,803
<p>For Test1, you could use <code>.difference</code> - for Test2, you'd need to use <code>.difference()</code> instead.</p> <p>As for why you might use it, a potential use would be to replace something that was previously directly stored as a property with a dynamic calculation instead.</p> <p>For instance, if you us...
8
2009-11-03T07:40:55Z
[ "python" ]
Setting a lambda function as a property
1,665,789
<p>Consider these two classes:</p> <pre><code>class Test(int): difference = property(lambda self: self.__sub__) class Test2(int): difference=lambda self: self.__sub__ </code></pre> <p>Is there any difference between these two classes? <strong>New</strong>: If so, what is the purpose of using the property <em...
0
2009-11-03T07:35:39Z
1,665,808
<p>Yes, in one case difference is a property. If you are asking what a property is, you can see it as a method that gets automatically called.</p>
2
2009-11-03T07:42:02Z
[ "python" ]
Setting a lambda function as a property
1,665,789
<p>Consider these two classes:</p> <pre><code>class Test(int): difference = property(lambda self: self.__sub__) class Test2(int): difference=lambda self: self.__sub__ </code></pre> <p>Is there any difference between these two classes? <strong>New</strong>: If so, what is the purpose of using the property <em...
0
2009-11-03T07:35:39Z
1,665,838
<p>Yes, in one case difference is a property</p>
1
2009-11-03T07:50:11Z
[ "python" ]
Setting a lambda function as a property
1,665,789
<p>Consider these two classes:</p> <pre><code>class Test(int): difference = property(lambda self: self.__sub__) class Test2(int): difference=lambda self: self.__sub__ </code></pre> <p>Is there any difference between these two classes? <strong>New</strong>: If so, what is the purpose of using the property <em...
0
2009-11-03T07:35:39Z
1,667,062
<p>People have given there opinion without analyzing it, it can be better solved by python itself, below is the code to check the difference</p> <pre><code>import difflib from pprint import pprint s1 = """ class Test(int): difference=property(lambda self: self.__sub__) """ s2 = """ class Test(int): differenc...
3
2009-11-03T12:32:20Z
[ "python" ]
Setting a lambda function as a property
1,665,789
<p>Consider these two classes:</p> <pre><code>class Test(int): difference = property(lambda self: self.__sub__) class Test2(int): difference=lambda self: self.__sub__ </code></pre> <p>Is there any difference between these two classes? <strong>New</strong>: If so, what is the purpose of using the property <em...
0
2009-11-03T07:35:39Z
1,672,898
<p>Edit: Ah, I see. You are asking why anybody would do exactly the code above. It's not, in fact a question about why to make a lambda or a property at all, it's not a question of the differences between the two examples, and not even why you want to make a property out of a lambda.</p> <p>Your question is "Why would...
3
2009-11-04T10:25:31Z
[ "python" ]
Setting a lambda function as a property
1,665,789
<p>Consider these two classes:</p> <pre><code>class Test(int): difference = property(lambda self: self.__sub__) class Test2(int): difference=lambda self: self.__sub__ </code></pre> <p>Is there any difference between these two classes? <strong>New</strong>: If so, what is the purpose of using the property <em...
0
2009-11-03T07:35:39Z
1,673,035
<p>Purpose of property can be</p> <p>1. To provide get/set hooks while accessing an attribute<br> e.g. if you used to have class with attribute a, later on you want to do something else when it is set, you can convert that attribute to property without affecting the interface or how users use your class. So in the exa...
1
2009-11-04T10:52:17Z
[ "python" ]
How do I get the string representation of a variable in python?
1,665,833
<p>I have a variable x in python. How can i find the string 'x' from the variable. Here is my attempt:</p> <pre><code>def var(v,c): for key in c.keys(): if c[key] == v: return key def f(): x = '321' print 'Local var %s = %s'%(var(x,locals()),x) x = '123' print 'Global var %s = %s'%(var(x,locals())...
5
2009-11-03T07:49:04Z
1,665,864
<p>I believe the general form of what you want is <code>repr()</code> or the <code>__repr__()</code> method of an object.</p> <p>with regards to <code>__repr__()</code>:</p> <blockquote> <p>Called by the repr() built-in function and by string conversions (reverse quotes) to compute the “official” string r...
6
2009-11-03T07:58:17Z
[ "python", "introspection" ]
How do I get the string representation of a variable in python?
1,665,833
<p>I have a variable x in python. How can i find the string 'x' from the variable. Here is my attempt:</p> <pre><code>def var(v,c): for key in c.keys(): if c[key] == v: return key def f(): x = '321' print 'Local var %s = %s'%(var(x,locals()),x) x = '123' print 'Global var %s = %s'%(var(x,locals())...
5
2009-11-03T07:49:04Z
1,665,916
<p>Q: I have a variable x in python. How can i find the string 'x' from the variable.</p> <p>A: If I am understanding your question properly, you want to go from the value of a variable to its name. This is not really possible in Python.</p> <p>In Python, there really isn't any such thing as a "variable". What Pytho...
12
2009-11-03T08:15:11Z
[ "python", "introspection" ]
How do I get the string representation of a variable in python?
1,665,833
<p>I have a variable x in python. How can i find the string 'x' from the variable. Here is my attempt:</p> <pre><code>def var(v,c): for key in c.keys(): if c[key] == v: return key def f(): x = '321' print 'Local var %s = %s'%(var(x,locals()),x) x = '123' print 'Global var %s = %s'%(var(x,locals())...
5
2009-11-03T07:49:04Z
1,666,401
<p>There are three ways to get "the" string representation of an object in python: 1: str()</p> <pre><code>&gt;&gt;&gt; foo={"a":"z","b":"y"} &gt;&gt;&gt; str(foo) "{'a': 'z', 'b': 'y'}" </code></pre> <p>2: repr()</p> <pre><code>&gt;&gt;&gt; foo={"a":"z","b":"y"} &gt;&gt;&gt; repr(foo) "{'a': 'z', 'b': 'y'}" </code>...
0
2009-11-03T10:09:00Z
[ "python", "introspection" ]
How do I get the string representation of a variable in python?
1,665,833
<p>I have a variable x in python. How can i find the string 'x' from the variable. Here is my attempt:</p> <pre><code>def var(v,c): for key in c.keys(): if c[key] == v: return key def f(): x = '321' print 'Local var %s = %s'%(var(x,locals()),x) x = '123' print 'Global var %s = %s'%(var(x,locals())...
5
2009-11-03T07:49:04Z
1,668,411
<p>stevenha has a great answer to this question. But, if you actually do want to poke around in the namespace dictionaries anyway, you can get all the names for a given value in a particular scope / namespace like this:</p> <pre><code>def foo1(): x = 5 y = 4 z = x print names_of1(x, locals()) def nam...
3
2009-11-03T16:20:21Z
[ "python", "introspection" ]
Forwarding command line arguments to a process in Python
1,665,917
<p>I'm using a crude IDE (Microchip MPLAB) with C30 toolchain on Windows XP. The C compiler has a very noisy output that I'm unable to control, and it's very hard to spot actual warnings and errors in output window.</p> <p>I want to write a python script that would receive arguments for compiler, call the compiler wit...
3
2009-11-03T08:15:30Z
1,665,937
<p>Your shell is eating the quotes (the python script never even receives them) so I suppose it's not very easy to get them 'unaltered'.</p>
-1
2009-11-03T08:23:16Z
[ "python", "process", "arguments", "quotes", "command-line-arguments" ]
Forwarding command line arguments to a process in Python
1,665,917
<p>I'm using a crude IDE (Microchip MPLAB) with C30 toolchain on Windows XP. The C compiler has a very noisy output that I'm unable to control, and it's very hard to spot actual warnings and errors in output window.</p> <p>I want to write a python script that would receive arguments for compiler, call the compiler wit...
3
2009-11-03T08:15:30Z
1,665,980
<p>As ChristopheD said the shell removes the quotes.</p> <p>But you don't need to create the string yourself when using Popen: it can handle that for you automatically. You can do this instead:</p> <pre><code>import sys, subprocess process = subprocess.Popen(sys.argv[1:], executable=compiler_path, stdout=subprocess.P...
3
2009-11-03T08:35:45Z
[ "python", "process", "arguments", "quotes", "command-line-arguments" ]
Forwarding command line arguments to a process in Python
1,665,917
<p>I'm using a crude IDE (Microchip MPLAB) with C30 toolchain on Windows XP. The C compiler has a very noisy output that I'm unable to control, and it's very hard to spot actual warnings and errors in output window.</p> <p>I want to write a python script that would receive arguments for compiler, call the compiler wit...
3
2009-11-03T08:15:30Z
1,665,990
<p>Give the command arguments to Popen as a list:</p> <pre><code>arguments = sys.argv[1:] cmd = [compiler_path] + arguments process = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE) </code></pre>
4
2009-11-03T08:38:14Z
[ "python", "process", "arguments", "quotes", "command-line-arguments" ]
MOD_WSGI difficulties on Mac OS X Snow Leopard
1,665,994
<p>I've been trying to get MOD_WSGI working on Apache via XAMPP on my Mac OS X Snow Leopard all day today without any success. I've followed all the instructions, searched the internet for solutions, etc but no luck so far. Below are my <strong>exact</strong> steps and details. When I run localhost all I get is a white...
2
2009-11-03T08:38:54Z
1,666,486
<p>First off, run 'make distclean' and then redo configure/make/make install for mod_wsgi. Where you have 'Terminal "make" (message "make: Nothing to be done for `all'.")' indicates there were prior build results in directory and nothing got built for that execution of make.</p> <p>Next, use '.wsgi' extension instead ...
3
2009-11-03T10:28:02Z
[ "python", "apache", "osx", "xampp", "mod-wsgi" ]
What is the issubclass equivalent of isinstance in python?
1,666,079
<p>Given an object, how do I tell if it's a class, and a subclass of a given class Foo?</p> <p>e.g.</p> <pre><code>class Bar(Foo): pass isinstance(Bar(), Foo) # =&gt; True issubclass(Bar, Foo) # &lt;--- how do I do that? </code></pre>
8
2009-11-03T08:57:40Z
1,666,096
<p>It works exactly as one would expect it to work...</p> <pre><code>class Foo(): pass class Bar(Foo): pass class Bar2(): pass print issubclass(Bar, Foo) # True print issubclass(Bar2, Foo) # False </code></pre> <p>If you want to know if an <em>instance</em> of a class derived from a given base class, ...
22
2009-11-03T09:01:43Z
[ "python", "introspection" ]
Python: OAuth Library
1,666,415
<p>Is there a full flegged python library for oauth? I haven't found any that handle reissuing of oauth tokens once they expire (Step 5 on the <a href="http://developer.yahoo.com/oauth/guide/oauth-auth-flow.html">Yahoo OAuth flow</a>).</p> <p>So what is the most complete? I tried the one from <a href="http://oauth.goo...
17
2009-11-03T10:14:01Z
1,666,490
<p>I think Leah Culver's <a href="http://www.python-oauth.com/">python-oauth</a> (that you've already found) is the best starting point even though it's not complete.</p> <p>Leah has a mirror up on github which would make it easy to collaborate: <a href="http://github.com/leah/python-oauth/tree/master/oauth/">http://g...
12
2009-11-03T10:28:23Z
[ "python", "oauth", "yahoo" ]
Python: OAuth Library
1,666,415
<p>Is there a full flegged python library for oauth? I haven't found any that handle reissuing of oauth tokens once they expire (Step 5 on the <a href="http://developer.yahoo.com/oauth/guide/oauth-auth-flow.html">Yahoo OAuth flow</a>).</p> <p>So what is the most complete? I tried the one from <a href="http://oauth.goo...
17
2009-11-03T10:14:01Z
5,432,020
<p>Check out Mike Knapp's library on <a href="https://github.com/mikeknapp/AppEngine-OAuth-Library" rel="nofollow">GitHub</a>. Nice and simple, no install needed. And works on Google App Engine.</p>
2
2011-03-25T11:50:10Z
[ "python", "oauth", "yahoo" ]
Python: OAuth Library
1,666,415
<p>Is there a full flegged python library for oauth? I haven't found any that handle reissuing of oauth tokens once they expire (Step 5 on the <a href="http://developer.yahoo.com/oauth/guide/oauth-auth-flow.html">Yahoo OAuth flow</a>).</p> <p>So what is the most complete? I tried the one from <a href="http://oauth.goo...
17
2009-11-03T10:14:01Z
12,825,021
<p>Use Kenneth Reitz's awesome <a href="http://python-requests.org" rel="nofollow">requests</a> library along with the <a href="https://github.com/maraujop/requests-oauth" rel="nofollow">requests-oauth</a> plugin linked off of <a href="http://docs.python-requests.org/en/latest/community/out-there/" rel="nofollow">http:...
2
2012-10-10T17:30:30Z
[ "python", "oauth", "yahoo" ]
Python: OAuth Library
1,666,415
<p>Is there a full flegged python library for oauth? I haven't found any that handle reissuing of oauth tokens once they expire (Step 5 on the <a href="http://developer.yahoo.com/oauth/guide/oauth-auth-flow.html">Yahoo OAuth flow</a>).</p> <p>So what is the most complete? I tried the one from <a href="http://oauth.goo...
17
2009-11-03T10:14:01Z
16,180,228
<p><a href="https://rauth.readthedocs.org/en/latest/">Rauth</a> is the new best answer as far as I'm concerned. Wraps <a href="http://docs.python-requests.org/en/latest/">requests</a> library and it's well-maintained.</p>
11
2013-04-23T22:27:09Z
[ "python", "oauth", "yahoo" ]
Python: OAuth Library
1,666,415
<p>Is there a full flegged python library for oauth? I haven't found any that handle reissuing of oauth tokens once they expire (Step 5 on the <a href="http://developer.yahoo.com/oauth/guide/oauth-auth-flow.html">Yahoo OAuth flow</a>).</p> <p>So what is the most complete? I tried the one from <a href="http://oauth.goo...
17
2009-11-03T10:14:01Z
23,542,860
<p><a href="http://oauth.net/code/" rel="nofollow">OAuth</a> official website recommends both <a href="https://github.com/litl/rauth" rel="nofollow">rauth</a> and <a href="https://github.com/idan/oauthlib" rel="nofollow">oauthlib</a>. Quoting them regarding <strong>rauth</strong>:</p> <blockquote> <p>Max Countryman ...
2
2014-05-08T13:15:14Z
[ "python", "oauth", "yahoo" ]
A multithreaded queue in Python
1,666,441
<p>I need to perform time consuming tasks in an webapplication. Because the tasks can be so heavy that they run for minutes they have to run on multiple threads so the user won't have to look at a loading page for minutes.</p> <p>So I thought a multithreaded queue would be a good solution. Each instance of a object th...
2
2009-11-03T10:18:45Z
1,666,466
<p>You just need your elements to extend threading.Thread and use Conditions() to implement the <a href="http://en.wikipedia.org/wiki/Producer-consumer%5Fproblem" rel="nofollow">producer,consumer</a> system.</p> <p>I would maintain a thread pool with it's own concurrency control and an add() method, allowing some othe...
2
2009-11-03T10:23:35Z
[ "python", "multithreading", "queue" ]
A multithreaded queue in Python
1,666,441
<p>I need to perform time consuming tasks in an webapplication. Because the tasks can be so heavy that they run for minutes they have to run on multiple threads so the user won't have to look at a loading page for minutes.</p> <p>So I thought a multithreaded queue would be a good solution. Each instance of a object th...
2
2009-11-03T10:18:45Z
1,666,470
<p>I'd don't know much about python, but what you're describing sounds like a thread pool - this is from a quick google</p> <p><a href="http://pypi.python.org/pypi/threadpool/" rel="nofollow">http://pypi.python.org/pypi/threadpool/</a></p>
1
2009-11-03T10:24:11Z
[ "python", "multithreading", "queue" ]
A multithreaded queue in Python
1,666,441
<p>I need to perform time consuming tasks in an webapplication. Because the tasks can be so heavy that they run for minutes they have to run on multiple threads so the user won't have to look at a loading page for minutes.</p> <p>So I thought a multithreaded queue would be a good solution. Each instance of a object th...
2
2009-11-03T10:18:45Z
1,666,476
<p><a href="http://www.kamaelia.org/Home" rel="nofollow">kamaelia</a> provides tools for abstracting concurrency to threads or process etc.</p>
2
2009-11-03T10:25:37Z
[ "python", "multithreading", "queue" ]
A multithreaded queue in Python
1,666,441
<p>I need to perform time consuming tasks in an webapplication. Because the tasks can be so heavy that they run for minutes they have to run on multiple threads so the user won't have to look at a loading page for minutes.</p> <p>So I thought a multithreaded queue would be a good solution. Each instance of a object th...
2
2009-11-03T10:18:45Z
1,666,520
<p>The Python standard library <a href="http://docs.python.org/library/queue.html" rel="nofollow">Queue</a> module is already thread-safe and aware and should work for your requirements.</p> <p>Here's a nice paper <a href="http://docs.google.com/gview?a=v&amp;q=cache%3AXuLJl1ktTh0J%3Aparlab.eecs.berkeley.edu/wiki/%5Fm...
6
2009-11-03T10:33:53Z
[ "python", "multithreading", "queue" ]
A multithreaded queue in Python
1,666,441
<p>I need to perform time consuming tasks in an webapplication. Because the tasks can be so heavy that they run for minutes they have to run on multiple threads so the user won't have to look at a loading page for minutes.</p> <p>So I thought a multithreaded queue would be a good solution. Each instance of a object th...
2
2009-11-03T10:18:45Z
1,668,863
<p>I'd recommend you look at <a href="http://kr.github.com/beanstalkd/" rel="nofollow">beanstalkd</a> or <a href="http://gearman.org/" rel="nofollow">gearman</a>.</p> <p>Let your web server be a web server, and scale your long-running jobs independently and more safely by moving them through a queue to an external wor...
0
2009-11-03T17:22:43Z
[ "python", "multithreading", "queue" ]
A multithreaded queue in Python
1,666,441
<p>I need to perform time consuming tasks in an webapplication. Because the tasks can be so heavy that they run for minutes they have to run on multiple threads so the user won't have to look at a loading page for minutes.</p> <p>So I thought a multithreaded queue would be a good solution. Each instance of a object th...
2
2009-11-03T10:18:45Z
1,744,990
<p>I would recommend using <a href="http://docs.python.org/library/multiprocessing.html#module-multiprocessing.pool" rel="nofollow">process pools</a> from the multithreading library. This is a built in library and abstracts most of the implementaion you need anyway, especially since pools work on lists and your data is...
0
2009-11-16T21:32:34Z
[ "python", "multithreading", "queue" ]