title
stringlengths
10
172
question_id
int64
469
40.1M
question_body
stringlengths
22
48.2k
question_score
int64
-44
5.52k
question_date
stringlengths
20
20
answer_id
int64
497
40.1M
answer_body
stringlengths
18
33.9k
answer_score
int64
-38
8.38k
answer_date
stringlengths
20
20
tags
listlengths
1
5
pylint not recognizing some of the standard library
1,316,334
<p>I'm using pylint + pydev, with python 2.6. I have a module with just this line of code</p> <pre><code>from email import Message </code></pre> <p>Now when I try to run this module it runs fine. But pylint reports an error:</p> <pre><code>ID: E0611 No name 'Message' in module 'email' </code></pre> <p>Although it e...
9
2009-08-22T16:19:08Z
6,261,591
<p>realise this is an old question, but the correct answer is that the older ways of invoking what you need, which use the "import hackery" that Richie describes, have long been deprecated (despite still appearing in many tutorials). If you use the new ways, you'll be writing better code and <code>pylint</code> won't ...
10
2011-06-07T06:53:58Z
[ "python", "email", "import", "pydev", "pylint" ]
zlib decompression in python
1,316,357
<p>Okay so I have some data streams compressed by python's (2.6) zlib.compress() function. When I try to decompress them, some of them won't decompress (zlib error -5, which seems to be a "buffer error", no idea what to make of that). At first, I thought I was done, but I realized that all the ones I couldn't decompres...
4
2009-08-22T16:24:56Z
1,317,267
<p>According to <a href="http://www.ietf.org/rfc/rfc1950.txt">RFC 1950</a> , the difference between the "OK" 0x789C and the "bad" 0x78DA is in the FLEVEL bit-field:</p> <pre><code> FLEVEL (Compression level) These flags are available for use by specific compression methods. The "deflate" method (CM = 8) se...
22
2009-08-22T23:06:12Z
[ "python", "compression", "zlib", "corruption" ]
zlib decompression in python
1,316,357
<p>Okay so I have some data streams compressed by python's (2.6) zlib.compress() function. When I try to decompress them, some of them won't decompress (zlib error -5, which seems to be a "buffer error", no idea what to make of that). At first, I thought I was done, but I realized that all the ones I couldn't decompres...
4
2009-08-22T16:24:56Z
1,317,724
<p>Okay sorry I wasn't clear enough. This is win32, python 2.6.2. I'm afraid I can't find the zlib file, but its whatever is included in the win32 binary release. And I don't have access to the original data -- I've been compressing my log files, and I'd like to get them back. As far as other software, I've naievely tr...
0
2009-08-23T04:01:07Z
[ "python", "compression", "zlib", "corruption" ]
zlib decompression in python
1,316,357
<p>Okay so I have some data streams compressed by python's (2.6) zlib.compress() function. When I try to decompress them, some of them won't decompress (zlib error -5, which seems to be a "buffer error", no idea what to make of that). At first, I thought I was done, but I realized that all the ones I couldn't decompres...
4
2009-08-22T16:24:56Z
1,319,471
<p>Ok sorry about my last post, I didn't have everything. And I can't edit my post because I didn't use OpenID. Anyways, here's some data:</p> <p>1) Decompression traceback:</p> <pre><code>Traceback (most recent call last): File "&lt;my file&gt;", line 5, in &lt;module&gt; zlib.decompress(data) zlib.error: Erro...
0
2009-08-23T20:28:24Z
[ "python", "compression", "zlib", "corruption" ]
Downloading compressed content over HTTP using Python
1,316,517
<p>How do I take advantage of HTTP 1.1's compression when downloading web pages using Python?</p> <p>I am currently using the built-in <a href="http://docs.python.org/library/urllib.html" rel="nofollow"><strong>urllib</strong></a> module for downloading web content. Reading through the documentation I couldn't find a...
3
2009-08-22T17:25:05Z
1,316,546
<p><a href="http://code.google.com/p/httplib2/" rel="nofollow">httplib2</a> supports 'deflate' and 'gzip' compression. </p> <p><strong>Example</strong></p> <pre><code>import httplib2 h = httplib2.Http(".cache") resp, content = h.request("http://example.org/", "GET") </code></pre> <p>The content is decompressed as ne...
6
2009-08-22T17:39:59Z
[ "python", "http", "compression", "gzip", "httplib2" ]
Django URL.py and the index
1,316,682
<p>I want to know what is the best way to write in the <code>URL.py</code>. I am trying to get the index in this way: <code>www.example.com</code> with <code>(r'',index)</code>. But when I try <code>r''</code>, all pages in the website are going to the home page.</p> <p>Part of my <code>url.py</code>:</p> <pre><code>...
9
2009-08-22T18:35:01Z
1,316,696
<p>Like this:</p> <pre><code> #... (r'^$', index), #... </code></pre>
23
2009-08-22T18:41:43Z
[ "python", "django", "django-urls" ]
Django URL.py and the index
1,316,682
<p>I want to know what is the best way to write in the <code>URL.py</code>. I am trying to get the index in this way: <code>www.example.com</code> with <code>(r'',index)</code>. But when I try <code>r''</code>, all pages in the website are going to the home page.</p> <p>Part of my <code>url.py</code>:</p> <pre><code>...
9
2009-08-22T18:35:01Z
1,316,709
<p>Django URL matching is very powerful if not always as convenient as it could be. As Brian says, you need to use the pattern r'^$' to force your pattern to match the entire string. With r'', you are looking for an empty string anywhere in the URL, which is true for every URL.</p> <p>Django URL patterns nearly alwa...
3
2009-08-22T18:47:11Z
[ "python", "django", "django-urls" ]
How can I explicitly free memory in Python?
1,316,767
<p>I wrote a Python program that acts on a large input file to create a few million objects representing triangles. The algorithm is:</p> <ol> <li>read an input file</li> <li>process the file and create a list of triangles, represented by their vertices</li> <li>output the vertices in the OFF format: a list of vertic...
123
2009-08-22T19:10:35Z
1,316,779
<p>Python is garbage-collected, so if you reduce the size of your list, it will reclaim memory. You can also use the "del" statement to get rid of a variable completely:</p> <pre><code>biglist = [blah,blah,blah] #... del biglist </code></pre>
11
2009-08-22T19:14:30Z
[ "python", "memory", "memory-management" ]
How can I explicitly free memory in Python?
1,316,767
<p>I wrote a Python program that acts on a large input file to create a few million objects representing triangles. The algorithm is:</p> <ol> <li>read an input file</li> <li>process the file and create a list of triangles, represented by their vertices</li> <li>output the vertices in the OFF format: a list of vertic...
123
2009-08-22T19:10:35Z
1,316,788
<p>The <code>del</code> statement might be of use, but IIRC <strong>it isn't guaranteed to free the memory</strong>. The <a href="http://docs.python.org/reference/simple%5Fstmts.html">docs are here</a> ... and a <a href="http://effbot.org/pyfaq/why-doesnt-python-release-the-memory-when-i-delete-a-large-object.htm">why ...
13
2009-08-22T19:16:12Z
[ "python", "memory", "memory-management" ]
How can I explicitly free memory in Python?
1,316,767
<p>I wrote a Python program that acts on a large input file to create a few million objects representing triangles. The algorithm is:</p> <ol> <li>read an input file</li> <li>process the file and create a list of triangles, represented by their vertices</li> <li>output the vertices in the OFF format: a list of vertic...
123
2009-08-22T19:10:35Z
1,316,790
<p>You can't explicitly free memory. What you need to do is to make sure you don't keep references to objects. They will then be garbage collected, freeing the memory.</p> <p>In your case, when you need large lists, you typically need to reorganize the code, typically using generators/iterators instead. That way you d...
13
2009-08-22T19:16:44Z
[ "python", "memory", "memory-management" ]
How can I explicitly free memory in Python?
1,316,767
<p>I wrote a Python program that acts on a large input file to create a few million objects representing triangles. The algorithm is:</p> <ol> <li>read an input file</li> <li>process the file and create a list of triangles, represented by their vertices</li> <li>output the vertices in the OFF format: a list of vertic...
123
2009-08-22T19:10:35Z
1,316,793
<p>According to <a href="http://docs.python.org/library/gc.html">Python Official Documentation</a>, you can force the Garbage Collector to release unreferenced memory with <code>gc.collect()</code></p>
108
2009-08-22T19:18:27Z
[ "python", "memory", "memory-management" ]
How can I explicitly free memory in Python?
1,316,767
<p>I wrote a Python program that acts on a large input file to create a few million objects representing triangles. The algorithm is:</p> <ol> <li>read an input file</li> <li>process the file and create a list of triangles, represented by their vertices</li> <li>output the vertices in the OFF format: a list of vertic...
123
2009-08-22T19:10:35Z
1,316,799
<p>Unfortunately (depending on your version and release of Python) some types of objects use "free lists" which are a neat local optimization but may cause memory fragmentation, specifically by making more and more memory "earmarked" for only objects of a certain type and thereby unavailable to the "general fund".</p> ...
68
2009-08-22T19:21:21Z
[ "python", "memory", "memory-management" ]
How can I explicitly free memory in Python?
1,316,767
<p>I wrote a Python program that acts on a large input file to create a few million objects representing triangles. The algorithm is:</p> <ol> <li>read an input file</li> <li>process the file and create a list of triangles, represented by their vertices</li> <li>output the vertices in the OFF format: a list of vertic...
123
2009-08-22T19:10:35Z
1,316,811
<p>If you don't care about vertex reuse, you could have two output files--one for vertices and one for triangles. Then append the triangle file to the vertex file when you are done.</p>
2
2009-08-22T19:29:19Z
[ "python", "memory", "memory-management" ]
How can I explicitly free memory in Python?
1,316,767
<p>I wrote a Python program that acts on a large input file to create a few million objects representing triangles. The algorithm is:</p> <ol> <li>read an input file</li> <li>process the file and create a list of triangles, represented by their vertices</li> <li>output the vertices in the OFF format: a list of vertic...
123
2009-08-22T19:10:35Z
1,316,865
<p>Others have posted some ways that you might be able to "coax" the Python interpreter into freeing the memory (or otherwise avoid having memory problems). Chances are you should try their ideas out first. However, I feel it important to give you a direct answer to your question. </p> <p>There isn't really any way...
5
2009-08-22T19:47:09Z
[ "python", "memory", "memory-management" ]
How can I explicitly free memory in Python?
1,316,767
<p>I wrote a Python program that acts on a large input file to create a few million objects representing triangles. The algorithm is:</p> <ol> <li>read an input file</li> <li>process the file and create a list of triangles, represented by their vertices</li> <li>output the vertices in the OFF format: a list of vertic...
123
2009-08-22T19:10:35Z
1,317,085
<p>Lists of numbers are much less memory-efficient than the format used by the standard array module or the third-party Numpy module. You would save memory by putting your vertices in a Numpy 3xN array and your triangles in an N-element array.</p>
7
2009-08-22T21:29:57Z
[ "python", "memory", "memory-management" ]
What is the most efficient string concatenation method in python?
1,316,887
<p>Is there any efficient mass string concatenation method in Python (like <em>StringBuilder</em> in C# or <em>StringBuffer</em> in Java)? I found following methods <a href="http://skymind.com/~ocrow/python_string/">here</a>:</p> <ul> <li>Simple concatenation using <code>+</code></li> <li>Using string list and <code>j...
75
2009-08-22T19:53:41Z
1,316,891
<p><code>''.join(sequenceofstrings)</code> is what usually works best -- simplest and fastest.</p>
42
2009-08-22T19:55:58Z
[ "python", "string" ]
What is the most efficient string concatenation method in python?
1,316,887
<p>Is there any efficient mass string concatenation method in Python (like <em>StringBuilder</em> in C# or <em>StringBuffer</em> in Java)? I found following methods <a href="http://skymind.com/~ocrow/python_string/">here</a>:</p> <ul> <li>Simple concatenation using <code>+</code></li> <li>Using string list and <code>j...
75
2009-08-22T19:53:41Z
1,316,959
<p>You may be interested in this: <a href="http://www.python.org/doc/essays/list2str/">An optimization anecdote</a> by Guido. Although it is worth remembering also that this is an old article and it predates the existence of things like <code>''.join</code> (although I guess <code>string.joinfields</code> is more-or-l...
72
2009-08-22T20:26:59Z
[ "python", "string" ]
What is the most efficient string concatenation method in python?
1,316,887
<p>Is there any efficient mass string concatenation method in Python (like <em>StringBuilder</em> in C# or <em>StringBuffer</em> in Java)? I found following methods <a href="http://skymind.com/~ocrow/python_string/">here</a>:</p> <ul> <li>Simple concatenation using <code>+</code></li> <li>Using string list and <code>j...
75
2009-08-22T19:53:41Z
1,316,982
<p>It depends on what you're doing.</p> <p>After Python 2.5, string concatenation with the + operator is pretty fast. If you're just concatenating a couple of values, using the + operator works best:</p> <pre><code>&gt;&gt;&gt; x = timeit.Timer(stmt="'a' + 'b'") &gt;&gt;&gt; x.timeit() 0.039999961853027344 &gt;&gt;&...
23
2009-08-22T20:36:58Z
[ "python", "string" ]
What is the most efficient string concatenation method in python?
1,316,887
<p>Is there any efficient mass string concatenation method in Python (like <em>StringBuilder</em> in C# or <em>StringBuffer</em> in Java)? I found following methods <a href="http://skymind.com/~ocrow/python_string/">here</a>:</p> <ul> <li>Simple concatenation using <code>+</code></li> <li>Using string list and <code>j...
75
2009-08-22T19:53:41Z
1,317,432
<p>this url has the comparisons of the different approaches along with some benchmarking:</p> <p><a href="http://skymind.com/~ocrow/python_string/" rel="nofollow">http://skymind.com/~ocrow/python_string/</a></p> <p><hr /> <strong>Please Note:</strong> This is a very old comparison from pre-2009 based on Python 2.2, a...
6
2009-08-23T00:40:20Z
[ "python", "string" ]
What is the most efficient string concatenation method in python?
1,316,887
<p>Is there any efficient mass string concatenation method in Python (like <em>StringBuilder</em> in C# or <em>StringBuffer</em> in Java)? I found following methods <a href="http://skymind.com/~ocrow/python_string/">here</a>:</p> <ul> <li>Simple concatenation using <code>+</code></li> <li>Using string list and <code>j...
75
2009-08-22T19:53:41Z
12,321,184
<p>I ran into a situation where I needed to have an appendable string of unknown size. These are the benchmark results (python 2.7.3):</p> <pre><code>$ python -m timeit -s 's=""' 's+="a"' 10000000 loops, best of 3: 0.176 usec per loop $ python -m timeit -s 's=[]' 's.append("a")' 10000000 loops, best of 3: 0.196 usec ...
2
2012-09-07T15:32:45Z
[ "python", "string" ]
What is the most efficient string concatenation method in python?
1,316,887
<p>Is there any efficient mass string concatenation method in Python (like <em>StringBuilder</em> in C# or <em>StringBuffer</em> in Java)? I found following methods <a href="http://skymind.com/~ocrow/python_string/">here</a>:</p> <ul> <li>Simple concatenation using <code>+</code></li> <li>Using string list and <code>j...
75
2009-08-22T19:53:41Z
14,610,440
<p>Inspired by @JasonBaker's benchmarks, here's a simple one comparing 10 <code>"abcdefghijklmnopqrstuvxyz"</code> strings, showing that <code>.join()</code> is faster; even with this tiny increase in variables:</p> <h3>Catenation</h3> <pre><code>&gt;&gt;&gt; x = timeit.Timer(stmt='"abcdefghijklmnopqrstuvxyz" + "abcd...
0
2013-01-30T17:48:46Z
[ "python", "string" ]
What is the most efficient string concatenation method in python?
1,316,887
<p>Is there any efficient mass string concatenation method in Python (like <em>StringBuilder</em> in C# or <em>StringBuffer</em> in Java)? I found following methods <a href="http://skymind.com/~ocrow/python_string/">here</a>:</p> <ul> <li>Simple concatenation using <code>+</code></li> <li>Using string list and <code>j...
75
2009-08-22T19:53:41Z
22,356,177
<p>it pretty much depends on the relative sizes of the new string after every new concatenation. With the <code>+</code> operator, for every concatenation a new string is made. If the intermediary strings are relatively long, the <code>+</code> becomes increasingly slower because the new intermediary string is being st...
4
2014-03-12T15:26:31Z
[ "python", "string" ]
What is the most efficient string concatenation method in python?
1,316,887
<p>Is there any efficient mass string concatenation method in Python (like <em>StringBuilder</em> in C# or <em>StringBuffer</em> in Java)? I found following methods <a href="http://skymind.com/~ocrow/python_string/">here</a>:</p> <ul> <li>Simple concatenation using <code>+</code></li> <li>Using string list and <code>j...
75
2009-08-22T19:53:41Z
24,718,551
<p>As per John Fouhy's answer, don't optimize unless you have to, but if you're here and asking this question, it may be precisely because you <em>have to</em>. In my case, I needed assemble some URLs from string variables... fast. I noticed no one (so far) seems to be considering the string format method, so I thought...
2
2014-07-13T00:39:59Z
[ "python", "string" ]
What is the most efficient string concatenation method in python?
1,316,887
<p>Is there any efficient mass string concatenation method in Python (like <em>StringBuilder</em> in C# or <em>StringBuffer</em> in Java)? I found following methods <a href="http://skymind.com/~ocrow/python_string/">here</a>:</p> <ul> <li>Simple concatenation using <code>+</code></li> <li>Using string list and <code>j...
75
2009-08-22T19:53:41Z
33,981,580
<p>One Year later, let's test mkoistinen's answer with python 3.4.3:</p> <ul> <li>plus 0.963564149000 (95.83% as fast)</li> <li>join 0.923408469000 (100.00% as fast)</li> <li>form 1.501130934000 (61.51% as fast)</li> <li>intp 1.019677452000 (90.56% as fast)</li> </ul> <p>Nothing changed. Join is still the fastest met...
2
2015-11-29T10:08:17Z
[ "python", "string" ]
What is the most efficient string concatenation method in python?
1,316,887
<p>Is there any efficient mass string concatenation method in Python (like <em>StringBuilder</em> in C# or <em>StringBuffer</em> in Java)? I found following methods <a href="http://skymind.com/~ocrow/python_string/">here</a>:</p> <ul> <li>Simple concatenation using <code>+</code></li> <li>Using string list and <code>j...
75
2009-08-22T19:53:41Z
38,362,140
<p>Python 3.6 is going to change this for strings that have known components with <a href="https://www.python.org/dev/peps/pep-0498/">Literal String Interpolation</a>.</p> <p>Given the test case from <a href="http://stackoverflow.com/a/24718551/918959">mkoistinen's answer</a>, having strings</p> <pre><code>domain = '...
9
2016-07-13T21:38:41Z
[ "python", "string" ]
sqlalchemy flush() and get inserted id?
1,316,952
<p>I want to do something like this:</p> <pre><code>f = Foo(bar='x') session.add(f) session.flush() # do additional queries using f.id before commit() print f.id # should be not None session.commit() </code></pre> <p>But f.id is None when I try it. How can I get this to work?</p> <p>-Dan</p>
40
2009-08-22T20:21:42Z
1,317,382
<p>You should try using <code>session.save_or_update(f)</code> instead of <code>session.add(f)</code>. </p>
-6
2009-08-23T00:04:07Z
[ "python", "sqlalchemy" ]
sqlalchemy flush() and get inserted id?
1,316,952
<p>I want to do something like this:</p> <pre><code>f = Foo(bar='x') session.add(f) session.flush() # do additional queries using f.id before commit() print f.id # should be not None session.commit() </code></pre> <p>But f.id is None when I try it. How can I get this to work?</p> <p>-Dan</p>
40
2009-08-22T20:21:42Z
1,325,560
<p>your sample code should be providing a value for <code>f.id</code>, assuming its an autogenerating primary key column. primary key attributes are populated immediately within the flush() process as they are generated and no call to commit() should be required. So the answer here lies in the details of your mapping...
26
2009-08-25T01:06:33Z
[ "python", "sqlalchemy" ]
sqlalchemy flush() and get inserted id?
1,316,952
<p>I want to do something like this:</p> <pre><code>f = Foo(bar='x') session.add(f) session.flush() # do additional queries using f.id before commit() print f.id # should be not None session.commit() </code></pre> <p>But f.id is None when I try it. How can I get this to work?</p> <p>-Dan</p>
40
2009-08-22T20:21:42Z
5,083,472
<p>I've just run across the same problem, and after testing I have found that NONE of these answers are sufficient. </p> <p>Currently, or as of sqlalchemy .6+, there is a very simple solution (I don't know if this exists in prior version, though I imagine it does):</p> <p><strong>session.refresh()</strong></p> <p>So...
72
2011-02-22T20:21:13Z
[ "python", "sqlalchemy" ]
sqlalchemy flush() and get inserted id?
1,316,952
<p>I want to do something like this:</p> <pre><code>f = Foo(bar='x') session.add(f) session.flush() # do additional queries using f.id before commit() print f.id # should be not None session.commit() </code></pre> <p>But f.id is None when I try it. How can I get this to work?</p> <p>-Dan</p>
40
2009-08-22T20:21:42Z
26,260,822
<p>unlike the answer given by dpb, a refresh is not necessary. once you flush, you can access the id field, sqlalchemy automatically refreshes the id which is auto generated at the backend</p> <p>I encountered this problem and figured the exact reason after some investigation, my model was created with id as integerfi...
2
2014-10-08T15:33:02Z
[ "python", "sqlalchemy" ]
sqlalchemy flush() and get inserted id?
1,316,952
<p>I want to do something like this:</p> <pre><code>f = Foo(bar='x') session.add(f) session.flush() # do additional queries using f.id before commit() print f.id # should be not None session.commit() </code></pre> <p>But f.id is None when I try it. How can I get this to work?</p> <p>-Dan</p>
40
2009-08-22T20:21:42Z
28,721,063
<p>I once had a problem with having assigned <code>0</code> to id before calling <code>session.add</code> method. The id was correctly assigned by the database but the correct id was not retrieved from the session after <code>session.flush()</code>.</p>
1
2015-02-25T14:06:22Z
[ "python", "sqlalchemy" ]
Arbitrary number of positional arguments in django inclusion tag?
1,316,968
<p>I'm trying to write a django inclusion tag that takes an arbitrary number of arguments:</p> <pre><code>@register.inclusion_tag('so.html') def table_field(*args): fields = [] for arg in args: fields.append(arg) return { 'fields': fields, } </code></pre> <p>However, when I call this from django's template engine:</...
3
2009-08-22T20:29:28Z
1,317,095
<p>You'll have to write your own template tag i guess.</p>
1
2009-08-22T21:35:27Z
[ "python", "django" ]
Arbitrary number of positional arguments in django inclusion tag?
1,316,968
<p>I'm trying to write a django inclusion tag that takes an arbitrary number of arguments:</p> <pre><code>@register.inclusion_tag('so.html') def table_field(*args): fields = [] for arg in args: fields.append(arg) return { 'fields': fields, } </code></pre> <p>However, when I call this from django's template engine:</...
3
2009-08-22T20:29:28Z
1,317,731
<p>Re: I'm trying to write a django inclusion tag that takes an arbitrary number of arguments</p> <p>I think you should pass the arbitrary number of arguments in from the view as a single argument, as some sort of collection.</p> <p>Based on the <a href="http://docs.djangoproject.com/en/dev/howto/custom-template-tags...
2
2009-08-23T04:08:06Z
[ "python", "django" ]
Arbitrary number of positional arguments in django inclusion tag?
1,316,968
<p>I'm trying to write a django inclusion tag that takes an arbitrary number of arguments:</p> <pre><code>@register.inclusion_tag('so.html') def table_field(*args): fields = [] for arg in args: fields.append(arg) return { 'fields': fields, } </code></pre> <p>However, when I call this from django's template engine:</...
3
2009-08-22T20:29:28Z
1,349,853
<p>This is another limitation of django's inclusion tags. Currently, in django's trunk version, this cannot be done.</p>
0
2009-08-28T23:22:31Z
[ "python", "django" ]
Arbitrary number of positional arguments in django inclusion tag?
1,316,968
<p>I'm trying to write a django inclusion tag that takes an arbitrary number of arguments:</p> <pre><code>@register.inclusion_tag('so.html') def table_field(*args): fields = [] for arg in args: fields.append(arg) return { 'fields': fields, } </code></pre> <p>However, when I call this from django's template engine:</...
3
2009-08-22T20:29:28Z
3,527,961
<p>As of 1.2.1 you can pass arguments to inclusion tags.</p> <p>Here is an example from my mods to django voting templatetags</p> <pre><code>@register.inclusion_tag("voting/vote_form.html", takes_context=True) def vote_form(context, vote_object, vote_dict, score_dict): if isinstance(vote_dict, dict): </code></pre...
3
2010-08-20T03:22:04Z
[ "python", "django" ]
Arbitrary number of positional arguments in django inclusion tag?
1,316,968
<p>I'm trying to write a django inclusion tag that takes an arbitrary number of arguments:</p> <pre><code>@register.inclusion_tag('so.html') def table_field(*args): fields = [] for arg in args: fields.append(arg) return { 'fields': fields, } </code></pre> <p>However, when I call this from django's template engine:</...
3
2009-08-22T20:29:28Z
7,800,625
<p>The current development version does provide a variable number of arguments for the inclusion tag. The patch is described here: </p> <p><a href="https://code.djangoproject.com/ticket/13956" rel="nofollow">https://code.djangoproject.com/ticket/13956</a></p> <p>It will be released with 1.4, see <a href="https://docs...
1
2011-10-17T23:03:07Z
[ "python", "django" ]
use python to access mysql
1,317,103
<p>i am finally starting with python. i wanted to ask if i use the mysql db with python, how should i expect python to connect to the db? what i mean is, i have mysql installed in xampp and have my database created in mysql through php myadmin. now my python is in C:\python25\ and my *.py files would be in the same fo...
0
2009-08-22T21:37:04Z
1,317,108
<p>If you simply cut and pasted, you have the wrong kind of quotes.</p> <p>You've got some kind of asymmetric quote.</p> <p>Use simple apostrophes <code>'</code> or simple quotes <code>"</code>. </p> <p>Do not use <strong>’</strong> .</p>
2
2009-08-22T21:40:27Z
[ "python", "mysql" ]
use python to access mysql
1,317,103
<p>i am finally starting with python. i wanted to ask if i use the mysql db with python, how should i expect python to connect to the db? what i mean is, i have mysql installed in xampp and have my database created in mysql through php myadmin. now my python is in C:\python25\ and my *.py files would be in the same fo...
0
2009-08-22T21:37:04Z
1,317,128
<p>the basics is</p> <pre><code>import MySQLdb conn = MySQLdb.connect(host="localhost", user="root", passwd="nobodyknow", db="amit") cursor = conn.cursor() stmt = "SELECT * FROM overflows" cursor.execute(stmt) # Fetch and output result = cursor.fetchall() print result # get the number of rows numrows = int(cursor....
4
2009-08-22T21:48:39Z
[ "python", "mysql" ]
Finding matching keys in two large dictionaries and doing it fast
1,317,410
<p>I am trying to find corresponding keys in two different dictionaries. Each has about 600k entries.</p> <p>Say for example:</p> <pre><code> myRDP = { 'Actinobacter': 'GATCGA...TCA', 'subtilus sp.': 'ATCGATT...ACT' } myNames = { 'Actinobacter': '8924342' } </code></pre> <p>I want to print out the value for ...
10
2009-08-23T00:27:34Z
1,317,411
<p>You could do this:</p> <pre><code>for key in myRDP: if key in myNames: print key, myNames[key] </code></pre> <p>Your first attempt was slow because you were comparing <em>every</em> key in myRDP with <em>every</em> key in myNames. In algorithmic jargon, if myRDP has <strong>n</strong> elements and myN...
33
2009-08-23T00:30:01Z
[ "python", "bioinformatics" ]
Finding matching keys in two large dictionaries and doing it fast
1,317,410
<p>I am trying to find corresponding keys in two different dictionaries. Each has about 600k entries.</p> <p>Say for example:</p> <pre><code> myRDP = { 'Actinobacter': 'GATCGA...TCA', 'subtilus sp.': 'ATCGATT...ACT' } myNames = { 'Actinobacter': '8924342' } </code></pre> <p>I want to print out the value for ...
10
2009-08-23T00:27:34Z
1,317,412
<pre><code>for key in myRDP: name = myNames.get(key, None) if name: print key, name </code></pre> <p><code>dict.get</code> returns the default value you give it (in this case, <code>None</code>) if the key doesn't exist.</p>
8
2009-08-23T00:30:47Z
[ "python", "bioinformatics" ]
Finding matching keys in two large dictionaries and doing it fast
1,317,410
<p>I am trying to find corresponding keys in two different dictionaries. Each has about 600k entries.</p> <p>Say for example:</p> <pre><code> myRDP = { 'Actinobacter': 'GATCGA...TCA', 'subtilus sp.': 'ATCGATT...ACT' } myNames = { 'Actinobacter': '8924342' } </code></pre> <p>I want to print out the value for ...
10
2009-08-23T00:27:34Z
1,317,414
<p>Use the <code>get</code> method instead:</p> <pre><code> for key in myRDP: value = myNames.get(key) if value != None: print key, "=", value </code></pre>
2
2009-08-23T00:31:06Z
[ "python", "bioinformatics" ]
Finding matching keys in two large dictionaries and doing it fast
1,317,410
<p>I am trying to find corresponding keys in two different dictionaries. Each has about 600k entries.</p> <p>Say for example:</p> <pre><code> myRDP = { 'Actinobacter': 'GATCGA...TCA', 'subtilus sp.': 'ATCGATT...ACT' } myNames = { 'Actinobacter': '8924342' } </code></pre> <p>I want to print out the value for ...
10
2009-08-23T00:27:34Z
1,317,415
<p>Copy both dictionaries into <strong>one</strong> dictionary/array. This makes sense as you have 1:1 related values. Then you need only one search, no comparison loop, and can access the related value directly.</p> <p>Example Resulting Dictionary/Array:</p> <p><code></p> <pre><code>[Name][Value1][Value2] [Actinob...
0
2009-08-23T00:31:43Z
[ "python", "bioinformatics" ]
Finding matching keys in two large dictionaries and doing it fast
1,317,410
<p>I am trying to find corresponding keys in two different dictionaries. Each has about 600k entries.</p> <p>Say for example:</p> <pre><code> myRDP = { 'Actinobacter': 'GATCGA...TCA', 'subtilus sp.': 'ATCGATT...ACT' } myNames = { 'Actinobacter': '8924342' } </code></pre> <p>I want to print out the value for ...
10
2009-08-23T00:27:34Z
1,317,416
<p>Use sets, because they have a built-in <code>intersection</code> method which ought to be quick:</p> <pre><code>myRDP = { 'Actinobacter': 'GATCGA...TCA', 'subtilus sp.': 'ATCGATT...ACT' } myNames = { 'Actinobacter': '8924342' } rdpSet = set(myRDP) namesSet = set(myNames) for name in rdpSet.intersection(namesSet):...
21
2009-08-23T00:32:07Z
[ "python", "bioinformatics" ]
Finding matching keys in two large dictionaries and doing it fast
1,317,410
<p>I am trying to find corresponding keys in two different dictionaries. Each has about 600k entries.</p> <p>Say for example:</p> <pre><code> myRDP = { 'Actinobacter': 'GATCGA...TCA', 'subtilus sp.': 'ATCGATT...ACT' } myNames = { 'Actinobacter': '8924342' } </code></pre> <p>I want to print out the value for ...
10
2009-08-23T00:27:34Z
1,317,423
<p>You could start by finding the common keys and then iterating over them. Set operations should be fast because they are implemented in C, at least in modern versions of Python.</p> <pre><code>common_keys = set(myRDP).intersection(myNames) for key in common_keys: print key, myNames[key] </code></pre>
4
2009-08-23T00:34:51Z
[ "python", "bioinformatics" ]
Finding matching keys in two large dictionaries and doing it fast
1,317,410
<p>I am trying to find corresponding keys in two different dictionaries. Each has about 600k entries.</p> <p>Say for example:</p> <pre><code> myRDP = { 'Actinobacter': 'GATCGA...TCA', 'subtilus sp.': 'ATCGATT...ACT' } myNames = { 'Actinobacter': '8924342' } </code></pre> <p>I want to print out the value for ...
10
2009-08-23T00:27:34Z
1,317,594
<p>Here is my code for doing intersections, unions, differences, and other set operations on dictionaries:</p> <pre><code>class DictDiffer(object): """ Calculate the difference between two dictionaries as: (1) items added (2) items removed (3) keys same in both but changed values (4) keys same ...
0
2009-08-23T02:24:02Z
[ "python", "bioinformatics" ]
Dealing with dynamic urls
1,317,541
<p>Let's say my main controller 'hotels' has a pattern for the url, such as:</p> <p>/hotels/colorado/aspen/hotel-name/</p> <p>How should I program my controller ( keep in mind I'm still learning MVC ) to handle this variable?</p> <p>I know that I have to probably check if anything after /hotels/ is set, otherwise sh...
0
2009-08-23T01:53:38Z
1,318,011
<p>It's perfectly valid to have separate methods to get the state, city and hotel name.</p> <p>An alternative, if your templating language support it, is to have a hotel_info() method that returns a dictionary, so that you in the template do "info/state", info/city", etc.</p> <p>I do however think you should look int...
0
2009-08-23T07:42:34Z
[ "php", "python", "url-routing" ]
Dealing with dynamic urls
1,317,541
<p>Let's say my main controller 'hotels' has a pattern for the url, such as:</p> <p>/hotels/colorado/aspen/hotel-name/</p> <p>How should I program my controller ( keep in mind I'm still learning MVC ) to handle this variable?</p> <p>I know that I have to probably check if anything after /hotels/ is set, otherwise sh...
0
2009-08-23T01:53:38Z
1,318,251
<p>Usually this is solved with Object Dispatch. You can also create nested Controllers to handle this. An advantage is, that you can follow a major OOP principle, namely encapsulation, as you group all functionality that only concerns Hotels generally in the Hotel controller (for example adding a new one)</p> <p>Anoth...
1
2009-08-23T10:33:18Z
[ "php", "python", "url-routing" ]
Converting a float to a string without rounding it
1,317,558
<p>I'm making a program that, for reasons not needed to be explained, requires a float to be converted into a string to be counted with len(). However, str(float(x)) results in x being rounded when converted to a string, which throws the entire thing off. Does anyone know of a fix for it? Here's the code being used if ...
39
2009-08-23T02:03:07Z
1,317,563
<pre><code>len(repr(float(x)/3)) </code></pre> <p>However I must say that this isn't as reliable as you think.</p> <p>Floats are entered/displayed as decimal numbers, but your computer (in fact, your standard C library) stores them as binary. You get some side effects from this transition:</p> <pre><code>&gt;&gt;&gt...
8
2009-08-23T02:05:19Z
[ "python", "string", "floating-point", "rounding" ]
Converting a float to a string without rounding it
1,317,558
<p>I'm making a program that, for reasons not needed to be explained, requires a float to be converted into a string to be counted with len(). However, str(float(x)) results in x being rounded when converted to a string, which throws the entire thing off. Does anyone know of a fix for it? Here's the code being used if ...
39
2009-08-23T02:03:07Z
1,317,578
<p>Some form of rounding is often unavoidable when dealing with floating point numbers. This is because numbers that you can express exactly in base 10 cannot always be expressed exactly in base 2 (which your computer uses).</p> <p>For example:</p> <pre><code>&gt;&gt;&gt; .1 0.10000000000000001 </code></pre> <p>In ...
63
2009-08-23T02:10:13Z
[ "python", "string", "floating-point", "rounding" ]
Converting a float to a string without rounding it
1,317,558
<p>I'm making a program that, for reasons not needed to be explained, requires a float to be converted into a string to be counted with len(). However, str(float(x)) results in x being rounded when converted to a string, which throws the entire thing off. Does anyone know of a fix for it? Here's the code being used if ...
39
2009-08-23T02:03:07Z
1,318,207
<p>Other answers already pointed out that the representation of floating numbers is a thorny issue, to say the least.</p> <p>Since you don't give enough context in your question, I cannot know if the decimal module can be useful for your needs:</p> <p><a href="http://docs.python.org/library/decimal.html" rel="nofollo...
3
2009-08-23T10:09:22Z
[ "python", "string", "floating-point", "rounding" ]
Should I use "from package import utils, settings" or "from . import utils, settings"
1,317,624
<p>I'm developing a Python application; it has all its code in one package and runs inside this of course. The application's Python package is of no interest from the interpreter to the user, it's simply a GUI application.</p> <p>The question is, which style is preferred when importing modules inside the application p...
4
2009-08-23T02:43:54Z
1,317,642
<p>The <a href="http://www.python.org/dev/peps/pep-0008/" rel="nofollow">Python Style Guide</a> recommends explicitly against relative imports (the . style):</p> <blockquote> <p>Relative imports for intra-package imports are highly discouraged. Always use the absolute package path for all imports. Even now that ...
10
2009-08-23T02:57:34Z
[ "python" ]
How can I filter a date of a DateTimeField in Django?
1,317,714
<p>I am trying to filter a <code>DateTimeField</code> comparing with a date. I mean:</p> <pre><code>MyObject.objects.filter(datetime_attr=datetime.date(2009,8,22)) </code></pre> <p>I get an empty queryset list as an answer because (I think) I am not considering time, but I want "any time".</p> <p>Is there an easy wa...
112
2009-08-23T03:52:07Z
1,317,725
<pre><code>YourModel.objects.filter(datetime_published__year='2008', datetime_published__month='03', datetime_published__day='27') </code></pre> <p>// edit after comments</p> <pre><code>YourModel.objects.filter(datetime_published=datetime(2008, 03, 27)) </code></pre...
67
2009-08-23T04:02:35Z
[ "python", "django", "datetime", "filter", "django-queryset" ]
How can I filter a date of a DateTimeField in Django?
1,317,714
<p>I am trying to filter a <code>DateTimeField</code> comparing with a date. I mean:</p> <pre><code>MyObject.objects.filter(datetime_attr=datetime.date(2009,8,22)) </code></pre> <p>I get an empty queryset list as an answer because (I think) I am not considering time, but I want "any time".</p> <p>Is there an easy wa...
112
2009-08-23T03:52:07Z
1,317,737
<p>See the article <a href="http://www.djangoproject.com/documentation/models/lookup/" rel="nofollow">Django Documentation</a></p> <p>Its very similar to the JZ answer</p> <pre><code>ur_data_model.objects.filter(ur_date_field=datetime(2005, 7, 27) </code></pre>
0
2009-08-23T04:11:15Z
[ "python", "django", "datetime", "filter", "django-queryset" ]
How can I filter a date of a DateTimeField in Django?
1,317,714
<p>I am trying to filter a <code>DateTimeField</code> comparing with a date. I mean:</p> <pre><code>MyObject.objects.filter(datetime_attr=datetime.date(2009,8,22)) </code></pre> <p>I get an empty queryset list as an answer because (I think) I am not considering time, but I want "any time".</p> <p>Is there an easy wa...
112
2009-08-23T03:52:07Z
1,417,969
<pre><code>Model.objects.filter(datetime__year=2011, datetime__month=2, datetime__day=30) </code></pre>
0
2009-09-13T15:15:52Z
[ "python", "django", "datetime", "filter", "django-queryset" ]
How can I filter a date of a DateTimeField in Django?
1,317,714
<p>I am trying to filter a <code>DateTimeField</code> comparing with a date. I mean:</p> <pre><code>MyObject.objects.filter(datetime_attr=datetime.date(2009,8,22)) </code></pre> <p>I get an empty queryset list as an answer because (I think) I am not considering time, but I want "any time".</p> <p>Is there an easy wa...
112
2009-08-23T03:52:07Z
1,973,917
<p>Such lookups are implemented in <code>django.views.generic.date_based</code> as follows:</p> <pre><code>{'date_time_field__range': (datetime.datetime.combine(date, datetime.time.min), datetime.datetime.combine(date, datetime.time.max))} </code></pre> <p>Because it is quite verbose ther...
90
2009-12-29T10:23:03Z
[ "python", "django", "datetime", "filter", "django-queryset" ]
How can I filter a date of a DateTimeField in Django?
1,317,714
<p>I am trying to filter a <code>DateTimeField</code> comparing with a date. I mean:</p> <pre><code>MyObject.objects.filter(datetime_attr=datetime.date(2009,8,22)) </code></pre> <p>I get an empty queryset list as an answer because (I think) I am not considering time, but I want "any time".</p> <p>Is there an easy wa...
112
2009-08-23T03:52:07Z
2,262,766
<p>This produces the same results as using __year, __month, and __day and seems to work for me:</p> <pre><code>YourModel.objects.filter(your_datetime_field__startswith=datetime.date(2009,8,22)) </code></pre>
22
2010-02-14T21:05:12Z
[ "python", "django", "datetime", "filter", "django-queryset" ]
How can I filter a date of a DateTimeField in Django?
1,317,714
<p>I am trying to filter a <code>DateTimeField</code> comparing with a date. I mean:</p> <pre><code>MyObject.objects.filter(datetime_attr=datetime.date(2009,8,22)) </code></pre> <p>I get an empty queryset list as an answer because (I think) I am not considering time, but I want "any time".</p> <p>Is there an easy wa...
112
2009-08-23T03:52:07Z
2,918,306
<p>Hm.. My solution is working:</p> <pre><code>Mymodel.objects.filter(date_time_field__startswith=datetime.datetime(1986, 7, 28)) </code></pre>
1
2010-05-27T03:38:27Z
[ "python", "django", "datetime", "filter", "django-queryset" ]
How can I filter a date of a DateTimeField in Django?
1,317,714
<p>I am trying to filter a <code>DateTimeField</code> comparing with a date. I mean:</p> <pre><code>MyObject.objects.filter(datetime_attr=datetime.date(2009,8,22)) </code></pre> <p>I get an empty queryset list as an answer because (I think) I am not considering time, but I want "any time".</p> <p>Is there an easy wa...
112
2009-08-23T03:52:07Z
9,414,681
<pre><code>Mymodel.objects.filter(date_time_field__contains=datetime.date(1986, 7, 28)) </code></pre> <p>the above is what I've used. Not only does it work, it also has some inherent logical backing.</p>
22
2012-02-23T14:11:08Z
[ "python", "django", "datetime", "filter", "django-queryset" ]
How can I filter a date of a DateTimeField in Django?
1,317,714
<p>I am trying to filter a <code>DateTimeField</code> comparing with a date. I mean:</p> <pre><code>MyObject.objects.filter(datetime_attr=datetime.date(2009,8,22)) </code></pre> <p>I get an empty queryset list as an answer because (I think) I am not considering time, but I want "any time".</p> <p>Is there an easy wa...
112
2009-08-23T03:52:07Z
11,174,559
<p>Here are the results I got with ipython's timeit function:</p> <pre><code>from datetime import date today = date.today() timeit[Model.objects.filter(date_created__year=today.year, date_created__month=today.month, date_created__day=today.day)] 1000 loops, best of 3: 652 us per loop timeit[Model.objects.filter(date...
51
2012-06-24T02:31:03Z
[ "python", "django", "datetime", "filter", "django-queryset" ]
How can I filter a date of a DateTimeField in Django?
1,317,714
<p>I am trying to filter a <code>DateTimeField</code> comparing with a date. I mean:</p> <pre><code>MyObject.objects.filter(datetime_attr=datetime.date(2009,8,22)) </code></pre> <p>I get an empty queryset list as an answer because (I think) I am not considering time, but I want "any time".</p> <p>Is there an easy wa...
112
2009-08-23T03:52:07Z
12,042,566
<p>Here is an interesting technique-- I leveraged the startswith procedure as implemented with Django on MySQL to achieve the result of only looking up a datetime through only the date. Basically, when Django does the lookup in the database it has to do a string conversion for the DATETIME MySQL storage object, so you ...
2
2012-08-20T17:54:36Z
[ "python", "django", "datetime", "filter", "django-queryset" ]
How can I filter a date of a DateTimeField in Django?
1,317,714
<p>I am trying to filter a <code>DateTimeField</code> comparing with a date. I mean:</p> <pre><code>MyObject.objects.filter(datetime_attr=datetime.date(2009,8,22)) </code></pre> <p>I get an empty queryset list as an answer because (I think) I am not considering time, but I want "any time".</p> <p>Is there an easy wa...
112
2009-08-23T03:52:07Z
17,351,397
<p>assuming active_on is a date object, increment it by 1 day then do range </p> <pre><code>next_day = active_on + datetime.timedelta(1) queryset = queryset.filter(date_created__range=(active_on, next_day) ) </code></pre>
6
2013-06-27T19:14:04Z
[ "python", "django", "datetime", "filter", "django-queryset" ]
How can I filter a date of a DateTimeField in Django?
1,317,714
<p>I am trying to filter a <code>DateTimeField</code> comparing with a date. I mean:</p> <pre><code>MyObject.objects.filter(datetime_attr=datetime.date(2009,8,22)) </code></pre> <p>I get an empty queryset list as an answer because (I think) I am not considering time, but I want "any time".</p> <p>Is there an easy wa...
112
2009-08-23T03:52:07Z
32,271,398
<p>Now Django has <a href="https://docs.djangoproject.com/en/dev/ref/models/querysets/#date">__date</a> queryset filter to query datetime objects against dates in development version. Thus, it will be available in 1.9 soon.</p>
7
2015-08-28T12:44:37Z
[ "python", "django", "datetime", "filter", "django-queryset" ]
How can I filter a date of a DateTimeField in Django?
1,317,714
<p>I am trying to filter a <code>DateTimeField</code> comparing with a date. I mean:</p> <pre><code>MyObject.objects.filter(datetime_attr=datetime.date(2009,8,22)) </code></pre> <p>I get an empty queryset list as an answer because (I think) I am not considering time, but I want "any time".</p> <p>Is there an easy wa...
112
2009-08-23T03:52:07Z
33,221,142
<p>There's a fantastic blogpost that covers this here: <a href="http://blog.zdsmith.com/comparing-dates-and-datetimes-in-the-django-orm.html" rel="nofollow">Comparing Dates and Datetimes in the Django ORM</a></p> <p>The best solution posted for Django>1.7,&lt;1.9 is to register a transform:</p> <pre class="lang-py pr...
0
2015-10-19T18:12:09Z
[ "python", "django", "datetime", "filter", "django-queryset" ]
How can I filter a date of a DateTimeField in Django?
1,317,714
<p>I am trying to filter a <code>DateTimeField</code> comparing with a date. I mean:</p> <pre><code>MyObject.objects.filter(datetime_attr=datetime.date(2009,8,22)) </code></pre> <p>I get an empty queryset list as an answer because (I think) I am not considering time, but I want "any time".</p> <p>Is there an easy wa...
112
2009-08-23T03:52:07Z
36,462,961
<p>As of Django 1.9, the way to do this is by using <a href="https://docs.djangoproject.com/en/1.9/ref/models/querysets/#date" rel="nofollow"><code>__date</code></a> on a datetime object.</p> <p>For example: <code>MyObject.objects.filter(datetime_attr__date=datetime.date(2009,8,22))</code></p>
2
2016-04-06T21:47:07Z
[ "python", "django", "datetime", "filter", "django-queryset" ]
How can I filter a date of a DateTimeField in Django?
1,317,714
<p>I am trying to filter a <code>DateTimeField</code> comparing with a date. I mean:</p> <pre><code>MyObject.objects.filter(datetime_attr=datetime.date(2009,8,22)) </code></pre> <p>I get an empty queryset list as an answer because (I think) I am not considering time, but I want "any time".</p> <p>Is there an easy wa...
112
2009-08-23T03:52:07Z
36,714,403
<p>In Django 1.7.6 works:</p> <pre><code>MyObject.objects.filter(datetime_attr__startswith=datetime.date(2009,8,22)) </code></pre>
0
2016-04-19T09:35:26Z
[ "python", "django", "datetime", "filter", "django-queryset" ]
How can I hide incompatible code from older Python versions?
1,317,946
<p>I'm writing unit tests for a function that takes both an <code>*args</code> and a <code>**kwargs</code> argument. A reasonable use-case for this function is using keyword arguments after the <code>*args</code> argment, i.e. of the form</p> <pre><code>def f(a, *b, **c): print a, b, c f(1, *(2, 3, 4), keyword=13...
3
2009-08-23T06:59:55Z
1,317,951
<p>One approach might be to use <a href="http://docs.python.org/library/functions.html#eval" rel="nofollow"><code>eval()</code></a> or <a href="http://docs.python.org/reference/simple%5Fstmts.html#the-exec-statement" rel="nofollow"><code>exec</code></a> along with a test for the current version of Python. This will def...
2
2009-08-23T07:03:25Z
[ "python", "unit-testing" ]
How can I hide incompatible code from older Python versions?
1,317,946
<p>I'm writing unit tests for a function that takes both an <code>*args</code> and a <code>**kwargs</code> argument. A reasonable use-case for this function is using keyword arguments after the <code>*args</code> argment, i.e. of the form</p> <pre><code>def f(a, *b, **c): print a, b, c f(1, *(2, 3, 4), keyword=13...
3
2009-08-23T06:59:55Z
1,317,965
<p>I don't think you should be testing whether Python works correctly; instead, focus on testing your own code. In doing so, it is perfectly possible to write the specific invocation in a way that works for all Python versions, namely:</p> <pre><code>f(1, *(2,3,4), **{'keyword':13}) </code></pre>
11
2009-08-23T07:09:44Z
[ "python", "unit-testing" ]
How can I hide incompatible code from older Python versions?
1,317,946
<p>I'm writing unit tests for a function that takes both an <code>*args</code> and a <code>**kwargs</code> argument. A reasonable use-case for this function is using keyword arguments after the <code>*args</code> argment, i.e. of the form</p> <pre><code>def f(a, *b, **c): print a, b, c f(1, *(2, 3, 4), keyword=13...
3
2009-08-23T06:59:55Z
1,318,050
<p>Why do you want to use such syntax? I mean, this 2.6 feature does not bring any real advantage other than shortcut.</p> <pre><code>a = [2,3,4] a.insert(0, 1) kw = {'keyword'='test'} f(*a, **kw) </code></pre>
1
2009-08-23T08:16:24Z
[ "python", "unit-testing" ]
How to do create_or_update in sqlobject?
1,318,001
<p>I'm using <a href="http://www.sqlobject.org/" rel="nofollow">SQLobject</a> and so far was not able to find a elegant solution for "update row in the db or vreate a new one if it doesn't exist.</p> <p>Currently I use following somewhat convoluted code:</p> <pre><code>args = dict(artnr=artnr, name=name, hersteller='...
2
2009-08-23T07:34:59Z
1,318,165
<p>I don't know of any special way to do it, when you really don't know in advance whether it's a create or update. There's certainly no special SQL syntax that can do this efficiently(*), so any implementation provided would essentially be doing the same as your code.</p> <p>(*: well, MySQL has the ON DUPLICATE KEY U...
1
2009-08-23T09:38:35Z
[ "python", "coding-style", "sqlobject" ]
Why is the Borg pattern better than the Singleton pattern in Python
1,318,406
<p>Why is the <a href="http://code.activestate.com/recipes/66531/">Borg pattern</a> better than the <a href="http://stackoverflow.com/questions/31875/is-there-a-simple-elegant-way-to-define-singletons-in-python">Singleton pattern</a>?</p> <p>I ask because I don't see them resulting in anything different.</p> <p>Borg:...
50
2009-08-23T12:01:43Z
1,318,426
<p>It is not. What is generally not recommended is a pattern like this in python:</p> <pre><code>class Singleton(object): _instance = None def __init__(self, ...): ... @classmethod def instance(cls): if cls._instance is None: cls._instance = cls(...) return cls._instance </code></pre> <p>where you use...
10
2009-08-23T12:13:06Z
[ "python", "singleton" ]
Why is the Borg pattern better than the Singleton pattern in Python
1,318,406
<p>Why is the <a href="http://code.activestate.com/recipes/66531/">Borg pattern</a> better than the <a href="http://stackoverflow.com/questions/31875/is-there-a-simple-elegant-way-to-define-singletons-in-python">Singleton pattern</a>?</p> <p>I ask because I don't see them resulting in anything different.</p> <p>Borg:...
50
2009-08-23T12:01:43Z
1,318,427
<p>A class basically describes how you can access (read/write) the internal state of your object.</p> <p>In the singleton pattern you can only have a single class, i.e. all your objects will give you the same access points to the shared state. This means that if you have to provide an extended API, you will need to wr...
5
2009-08-23T12:13:17Z
[ "python", "singleton" ]
Why is the Borg pattern better than the Singleton pattern in Python
1,318,406
<p>Why is the <a href="http://code.activestate.com/recipes/66531/">Borg pattern</a> better than the <a href="http://stackoverflow.com/questions/31875/is-there-a-simple-elegant-way-to-define-singletons-in-python">Singleton pattern</a>?</p> <p>I ask because I don't see them resulting in anything different.</p> <p>Borg:...
50
2009-08-23T12:01:43Z
1,318,444
<p>The real reason that borg is different comes down to subclassing.</p> <p>If you subclass a borg, the subclass' objects have the same state as their parents classes objects, unless you explicitly override the shared state in that subclass. Each subclass of the singleton pattern has its own state and therefore will p...
40
2009-08-23T12:22:22Z
[ "python", "singleton" ]
Why is the Borg pattern better than the Singleton pattern in Python
1,318,406
<p>Why is the <a href="http://code.activestate.com/recipes/66531/">Borg pattern</a> better than the <a href="http://stackoverflow.com/questions/31875/is-there-a-simple-elegant-way-to-define-singletons-in-python">Singleton pattern</a>?</p> <p>I ask because I don't see them resulting in anything different.</p> <p>Borg:...
50
2009-08-23T12:01:43Z
1,318,542
<p>It's only better in those few cases where you actually have a difference. Like when you subclass. The Borg pattern is extremely unusual, I've never needed it for real in ten years of Python programming.</p>
5
2009-08-23T13:24:43Z
[ "python", "singleton" ]
Why is the Borg pattern better than the Singleton pattern in Python
1,318,406
<p>Why is the <a href="http://code.activestate.com/recipes/66531/">Borg pattern</a> better than the <a href="http://stackoverflow.com/questions/31875/is-there-a-simple-elegant-way-to-define-singletons-in-python">Singleton pattern</a>?</p> <p>I ask because I don't see them resulting in anything different.</p> <p>Borg:...
50
2009-08-23T12:01:43Z
20,809,695
<p>In python if you want a unique "object" that you can access from anywhere just create a class <code>Unique</code> that only contains static attributes, <code>@staticmethod</code>s, and <code>@classmethod</code>s; you could call it the Unique Pattern. Here I implement and compare the 3 patterns:</p> <p>Unique</p> <...
11
2013-12-28T00:30:55Z
[ "python", "singleton" ]
In pdb how do you reset the list (l) command line count?
1,318,676
<p>From PDB</p> <pre><code>(Pdb) help l l(ist) [first [,last]] List source code for the current file. Without arguments, list 11 lines around the current line or continue the previous listing. With one argument, list 11 lines starting at that line. With two arguments, list the given range; if the second ar...
22
2009-08-23T14:13:40Z
1,318,787
<p>I don't think there is a way to turn it off. It's annoyed me enough that once I went looking in the pdb source to see if there was an undocumented syntax, but I didn't find any. </p> <p>There really needs to be a syntax that means, "List the lines near the current execution pointer."</p>
3
2009-08-23T15:11:03Z
[ "python", "pdb" ]
In pdb how do you reset the list (l) command line count?
1,318,676
<p>From PDB</p> <pre><code>(Pdb) help l l(ist) [first [,last]] List source code for the current file. Without arguments, list 11 lines around the current line or continue the previous listing. With one argument, list 11 lines starting at that line. With two arguments, list the given range; if the second ar...
22
2009-08-23T14:13:40Z
1,324,264
<p>You could <a href="http://en.wikipedia.org/wiki/Monkey%5Fpatch" rel="nofollow">monkey patch</a> it for the behavior you want. For example, here is a full script which adds a "reset_list" or "rl" command to pdb:</p> <pre><code>import pdb def Pdb_reset_list(self, arg): self.lineno = None print &gt;&gt;self.s...
3
2009-08-24T19:31:39Z
[ "python", "pdb" ]
In pdb how do you reset the list (l) command line count?
1,318,676
<p>From PDB</p> <pre><code>(Pdb) help l l(ist) [first [,last]] List source code for the current file. Without arguments, list 11 lines around the current line or continue the previous listing. With one argument, list 11 lines starting at that line. With two arguments, list the given range; if the second ar...
22
2009-08-23T14:13:40Z
2,336,019
<p>If you use <a href="http://bitbucket.org/dugan/epdb/" rel="nofollow" title="Enhanced Python DeBugger">epdb</a> instead of pdb, you can use "l" to go forward like in pdb, but then "l." goes back to the current line number, and "l-" goes backwards through the file. You can also use until # to continue until a given l...
4
2010-02-25T17:15:46Z
[ "python", "pdb" ]
In pdb how do you reset the list (l) command line count?
1,318,676
<p>From PDB</p> <pre><code>(Pdb) help l l(ist) [first [,last]] List source code for the current file. Without arguments, list 11 lines around the current line or continue the previous listing. With one argument, list 11 lines starting at that line. With two arguments, list the given range; if the second ar...
22
2009-08-23T14:13:40Z
11,848,010
<p>Late but hopefully still helpful. In pdb, make the following alias (which you can add to your .pdbrc file so it's always available): </p> <pre><code>alias ll u;;d;;l </code></pre> <p>Then whenever you type <code>ll</code>, pdb will list from the current position. It works by going up the stack and then down the st...
13
2012-08-07T14:18:25Z
[ "python", "pdb" ]
Ctypes pro and con
1,318,736
<p>I have heard that Ctypes can cause crashes (or stop errors) in Python and windows. Should I stay away from their use? Where did I hear? It was back when I tried to control various aspects of windows, automation, that sort of thing.</p> <p>I hear of swig, but I see Ctypes more often than not. Any danger here? If so,...
7
2009-08-23T14:45:21Z
1,318,740
<p>ctypes is a safe module to use, if you use it right.</p> <p>Some libraries provide a lower level access to things, some modules simply allow you to shoot yourself in the foot. So naturally some modules are more dangerous than others. This doesn't mean you should not use them though!</p> <p>You probably heard so...
5
2009-08-23T14:47:29Z
[ "python", "winapi", "ctypes" ]
Ctypes pro and con
1,318,736
<p>I have heard that Ctypes can cause crashes (or stop errors) in Python and windows. Should I stay away from their use? Where did I hear? It was back when I tried to control various aspects of windows, automation, that sort of thing.</p> <p>I hear of swig, but I see Ctypes more often than not. Any danger here? If so,...
7
2009-08-23T14:45:21Z
1,318,763
<p><code>ctypes</code> can indeed cause crashes, if the C library you're using can <em>already</em> cause crashes.</p> <p>If anything, <code>ctypes</code> can help reduce crashes, because you can enforce runtime type safety with <a href="http://docs.python.org/library/ctypes.html#specifying-the-required-argument-types...
3
2009-08-23T14:58:05Z
[ "python", "winapi", "ctypes" ]
Ctypes pro and con
1,318,736
<p>I have heard that Ctypes can cause crashes (or stop errors) in Python and windows. Should I stay away from their use? Where did I hear? It was back when I tried to control various aspects of windows, automation, that sort of thing.</p> <p>I hear of swig, but I see Ctypes more often than not. Any danger here? If so,...
7
2009-08-23T14:45:21Z
1,319,150
<p>In terms of robustness, I still think swig is somewhat superior to ctypes, because it's possible to have a C compiler check things more thoroughly for you; however, this is pretty moot by now (while it loomed larger in earlier ctypes versons), thanks to the <code>argtypes</code> feature @Mark already mentioned. Howe...
13
2009-08-23T18:00:05Z
[ "python", "winapi", "ctypes" ]
Ctypes pro and con
1,318,736
<p>I have heard that Ctypes can cause crashes (or stop errors) in Python and windows. Should I stay away from their use? Where did I hear? It was back when I tried to control various aspects of windows, automation, that sort of thing.</p> <p>I hear of swig, but I see Ctypes more often than not. Any danger here? If so,...
7
2009-08-23T14:45:21Z
1,319,638
<p>I highly suggest you look into reading this book:</p> <p><a href="http://rads.stackoverflow.com/amzn/click/1593271921" rel="nofollow">Gray Hat Python: Python Programming for Hackers and Reverse Engineers</a></p> <p>The book functions as an in-depth tutorial for the ctypes library, and shows you how to run incredib...
2
2009-08-23T21:38:12Z
[ "python", "winapi", "ctypes" ]
Django i18n and python locales (and dates)
1,318,744
<p>I've been playing with Django's i18n system and it seems to be mostly working. However, dates in model code seem to be causing a problem.</p> <p>I use datetime.strftime to populate a few CHOICES tuples which are then used in forms. </p> <p>From what I understood, django will set the locale to the user's choice so ...
5
2009-08-23T14:50:01Z
1,321,102
<p>Django does not set locale for translation, just loads translation catalog. To get desired effect you have either set locale (which is not a good option since it works process-wide) or use specialized library. I recommend <a href="http://babel.edgewall.org/" rel="nofollow">Babel</a> which has nice Django integration...
3
2009-08-24T08:23:50Z
[ "python", "django", "internationalization" ]
Django i18n and python locales (and dates)
1,318,744
<p>I've been playing with Django's i18n system and it seems to be mostly working. However, dates in model code seem to be causing a problem.</p> <p>I use datetime.strftime to populate a few CHOICES tuples which are then used in forms. </p> <p>From what I understood, django will set the locale to the user's choice so ...
5
2009-08-23T14:50:01Z
5,457,952
<p>I've recently faced similar problem but managed to solve the problem by using <a href="http://code.djangoproject.com/browser/django/trunk/django/utils/dateformat.py#L282" rel="nofollow">format</a> instead of the python <code>strftime</code></p>
1
2011-03-28T10:55:00Z
[ "python", "django", "internationalization" ]
Python list filtering: remove subsets from list of lists
1,318,935
<p>Using Python how do you reduce a list of lists by an ordered subset match <code>[[..],[..],..]</code>? </p> <p>In the context of this question a list L is a <strong><em>subset</em></strong> of list <code>M</code> if <code>M</code> contains all members of <code>L</code>, and in the same order. For example, the list ...
7
2009-08-23T16:23:20Z
1,318,955
<p>Edit: I really need to improve my reading comprehension. Here's the answer to what was actually asked. It exploits the fact that "<code>A is super of B</code>" implies "<code>len(A) &gt; len(B) or A == B</code>". </p> <pre><code>def advance_to(it, value): """Advances an iterator until it matches the given value...
0
2009-08-23T16:34:34Z
[ "python", "list" ]
Python list filtering: remove subsets from list of lists
1,318,935
<p>Using Python how do you reduce a list of lists by an ordered subset match <code>[[..],[..],..]</code>? </p> <p>In the context of this question a list L is a <strong><em>subset</em></strong> of list <code>M</code> if <code>M</code> contains all members of <code>L</code>, and in the same order. For example, the list ...
7
2009-08-23T16:23:20Z
1,319,048
<pre><code>list0=[[1, 2, 4, 8], [1, 2, 4, 5, 6], [1, 2, 3], [2, 3, 21], [1, 2, 3, 4], [1, 2, 3, 4, 5, 6, 7]] for list1 in list0[:]: for list2 in list0: if list2!=list1: len1=len(list1) c=0 for n in list2: if n==list1[c]: c+=1 ...
0
2009-08-23T17:18:17Z
[ "python", "list" ]
Python list filtering: remove subsets from list of lists
1,318,935
<p>Using Python how do you reduce a list of lists by an ordered subset match <code>[[..],[..],..]</code>? </p> <p>In the context of this question a list L is a <strong><em>subset</em></strong> of list <code>M</code> if <code>M</code> contains all members of <code>L</code>, and in the same order. For example, the list ...
7
2009-08-23T16:23:20Z
1,319,050
<p>This seems to work:</p> <pre><code>original=[[1, 2, 4, 8], [1, 2, 4, 5, 6], [1, 2, 3], [2, 3, 21], [1, 2, 3, 4], [1, 2, 3, 4, 5, 6, 7]] target=[[1, 2, 4, 8], [2, 3, 21], [1, 2, 3, 4, 5, 6, 7]] class SetAndList: def __init__(self,aList): self.list=aList self.set=set(aList) self.isUnique...
0
2009-08-23T17:18:24Z
[ "python", "list" ]
Python list filtering: remove subsets from list of lists
1,318,935
<p>Using Python how do you reduce a list of lists by an ordered subset match <code>[[..],[..],..]</code>? </p> <p>In the context of this question a list L is a <strong><em>subset</em></strong> of list <code>M</code> if <code>M</code> contains all members of <code>L</code>, and in the same order. For example, the list ...
7
2009-08-23T16:23:20Z
1,319,055
<p>I implemented a different <code>issubseq</code> because yours doesn't say that <code>[1, 2, 4, 5, 6]</code> is a subsequence of <code>[1, 2, 3, 4, 5, 6, 7]</code>, for example (besides being painfully slow). The solution I came up with looks like this:</p> <pre><code> def is_subseq(a, b): if len(a) &gt; len(b):...
0
2009-08-23T17:19:33Z
[ "python", "list" ]
Python list filtering: remove subsets from list of lists
1,318,935
<p>Using Python how do you reduce a list of lists by an ordered subset match <code>[[..],[..],..]</code>? </p> <p>In the context of this question a list L is a <strong><em>subset</em></strong> of list <code>M</code> if <code>M</code> contains all members of <code>L</code>, and in the same order. For example, the list ...
7
2009-08-23T16:23:20Z
1,319,083
<p>This code should be rather memory efficient. Beyond storing your initial list of lists, this code uses negligible extra memory (no temporary sets or copies of lists are created).</p> <pre><code>def is_subset(needle,haystack): """ Check if needle is ordered subset of haystack in O(n) """ if len(haystack) &lt...
4
2009-08-23T17:35:05Z
[ "python", "list" ]
Python list filtering: remove subsets from list of lists
1,318,935
<p>Using Python how do you reduce a list of lists by an ordered subset match <code>[[..],[..],..]</code>? </p> <p>In the context of this question a list L is a <strong><em>subset</em></strong> of list <code>M</code> if <code>M</code> contains all members of <code>L</code>, and in the same order. For example, the list ...
7
2009-08-23T16:23:20Z
1,319,109
<p>A list is a superlist if it is not a subset of any other list. It's a subset of another list if every element of the list can be found, in order, in another list.</p> <p>Here's my code:</p> <pre><code>def is_sublist_of_any_list(cand, lists): # Compare candidate to a single list def is_sublist_of_list(cand,...
1
2009-08-23T17:42:40Z
[ "python", "list" ]
Python list filtering: remove subsets from list of lists
1,318,935
<p>Using Python how do you reduce a list of lists by an ordered subset match <code>[[..],[..],..]</code>? </p> <p>In the context of this question a list L is a <strong><em>subset</em></strong> of list <code>M</code> if <code>M</code> contains all members of <code>L</code>, and in the same order. For example, the list ...
7
2009-08-23T16:23:20Z
1,319,127
<p>This could be simplified, but:</p> <pre><code>l = [[1, 2, 4, 8], [1, 2, 4, 5, 6], [1, 2, 3], [2, 3, 21], [1, 2, 3, 4], [1, 2, 3, 4, 5, 6, 7]] l2 = l[:] for m in l: for n in l: if set(m).issubset(set(n)) and m != n: l2.remove(m) break print l2 [[1, 2, 4, 8], [2, 3, 21], [1, 2, 3...
3
2009-08-23T17:49:14Z
[ "python", "list" ]
Python list filtering: remove subsets from list of lists
1,318,935
<p>Using Python how do you reduce a list of lists by an ordered subset match <code>[[..],[..],..]</code>? </p> <p>In the context of this question a list L is a <strong><em>subset</em></strong> of list <code>M</code> if <code>M</code> contains all members of <code>L</code>, and in the same order. For example, the list ...
7
2009-08-23T16:23:20Z
1,324,781
<p>Refined answer after new test case:</p> <pre><code>original= [[2, 16, 17], [1, 2, 3, 4, 5, 6, 7], [1], [1, 2, 3, 4], [1, 2], [17, 18, 19, 22, 41, 48], [2, 3], [1, 2, 3], [50, 69], [1, 2, 3], [2, 3, 21], [1, 2, 3], [1, 2, 4, 8], [1, 2, 4, 5, 6]] class SetAndList: def __init__(self,aList): self.list=aLis...
0
2009-08-24T21:04:03Z
[ "python", "list" ]
Python list filtering: remove subsets from list of lists
1,318,935
<p>Using Python how do you reduce a list of lists by an ordered subset match <code>[[..],[..],..]</code>? </p> <p>In the context of this question a list L is a <strong><em>subset</em></strong> of list <code>M</code> if <code>M</code> contains all members of <code>L</code>, and in the same order. For example, the list ...
7
2009-08-23T16:23:20Z
1,327,425
<p>Thanks to all who suggested solutions and coping with my sometimes erroneous data sets. Using <strong>@hughdbrown</strong> solution I modified it to what I wanted:</p> <p>The modification was to use a sliding window over the target to ensure the subset sequence was found. I think I should have used a more appropria...
0
2009-08-25T10:37:03Z
[ "python", "list" ]
Python list filtering: remove subsets from list of lists
1,318,935
<p>Using Python how do you reduce a list of lists by an ordered subset match <code>[[..],[..],..]</code>? </p> <p>In the context of this question a list L is a <strong><em>subset</em></strong> of list <code>M</code> if <code>M</code> contains all members of <code>L</code>, and in the same order. For example, the list ...
7
2009-08-23T16:23:20Z
1,331,312
<p>So what you really wanted was to know if a list was a substring, so to speak, of another, with all the matching elements consecutive. Here is code that converts the candidate and the target list to comma-separated strings and does a substring comparison to see if the candidate appears within the target list</p> <pr...
0
2009-08-25T22:10:04Z
[ "python", "list" ]
Python/GAE web request error handling
1,318,960
<p>I am developing an application on the Google App Engine using Python.</p> <p>I have a handler that can return a variety of outputs (html and json at the moment), I am testing for obvious errors in the system based on invalid parameters sent to the request handler.</p> <p>However what I am doing feels dirty (see be...
4
2009-08-23T16:35:41Z
1,319,122
<p>As least, you should refactor repetitive code such as:</p> <pre><code>if application is None: if output_type == "json": self.response.out.write(simplejson.dumps({ "errorCode" : "Application not found."})) self.set_status(404) return </code></pre> <p>into an auxiliary method:</p> <pre><...
0
2009-08-23T17:48:34Z
[ "python", "google-app-engine", "error-handling", "design-patterns" ]
Python/GAE web request error handling
1,318,960
<p>I am developing an application on the Google App Engine using Python.</p> <p>I have a handler that can return a variety of outputs (html and json at the moment), I am testing for obvious errors in the system based on invalid parameters sent to the request handler.</p> <p>However what I am doing feels dirty (see be...
4
2009-08-23T16:35:41Z
1,319,433
<p>There's a couple of handy methods here. The first is self.<a href="http://code.google.com/p/googleappengine/source/browse/trunk/python/google/appengine/ext/webapp/%5F%5Finit%5F%5F.py#353">error</a>(code). By default this method simply sets the status code and clears the output buffer, but you can override it to outp...
9
2009-08-23T20:12:58Z
[ "python", "google-app-engine", "error-handling", "design-patterns" ]
Parallel Python: What is a callback?
1,319,074
<p>In <a href="http://www.parallelpython.com/">Parallel Python</a> it has something in the <i>submit</i> function called a <i>callback</i> (<a href="http://www.parallelpython.com/content/view/15/30/">documentation</a>) however it doesn't seem to explain it too well. I've posted on their forum a couple days ago and I'v...
20
2009-08-23T17:30:50Z
1,319,104
<p>Looking at the link, just looks like a hook which is called.</p> <blockquote> <p>callback - callback function which will be called with argument list equal to callbackargs+(result,) as soon as calculation is done</p> </blockquote> <p>The "as soon as calculation is done" bit seems ambiguou...
3
2009-08-23T17:41:35Z
[ "python", "callback", "parallel-python" ]
Parallel Python: What is a callback?
1,319,074
<p>In <a href="http://www.parallelpython.com/">Parallel Python</a> it has something in the <i>submit</i> function called a <i>callback</i> (<a href="http://www.parallelpython.com/content/view/15/30/">documentation</a>) however it doesn't seem to explain it too well. I've posted on their forum a couple days ago and I'v...
20
2009-08-23T17:30:50Z
1,319,108
<p>The relevant spot in the docs:</p> <pre><code>callback - callback function which will be called with argument list equal to callbackargs+(result,) as soon as calculation is done callbackargs - additional arguments for callback function </code></pre> <p>So, if you want some code to be executed as ...
13
2009-08-23T17:42:35Z
[ "python", "callback", "parallel-python" ]
Parallel Python: What is a callback?
1,319,074
<p>In <a href="http://www.parallelpython.com/">Parallel Python</a> it has something in the <i>submit</i> function called a <i>callback</i> (<a href="http://www.parallelpython.com/content/view/15/30/">documentation</a>) however it doesn't seem to explain it too well. I've posted on their forum a couple days ago and I'v...
20
2009-08-23T17:30:50Z
1,319,110
<p>A callback is simply a function. In Python, functions are just more objects, and so the name of a function can be used as a variable, like so:</p> <pre><code>def func(): ... something(func) </code></pre> <p>Note that many functions which accept a callback as an argument usually require that the callback accep...
1
2009-08-23T17:42:47Z
[ "python", "callback", "parallel-python" ]
Parallel Python: What is a callback?
1,319,074
<p>In <a href="http://www.parallelpython.com/">Parallel Python</a> it has something in the <i>submit</i> function called a <i>callback</i> (<a href="http://www.parallelpython.com/content/view/15/30/">documentation</a>) however it doesn't seem to explain it too well. I've posted on their forum a couple days ago and I'v...
20
2009-08-23T17:30:50Z
1,319,118
<p>A <a href="http://en.wikipedia.org/wiki/Callback%5Ffunction" rel="nofollow">callback</a> is a function you define that's later called by a function you call.</p> <p>As an example, consider how AJAX works: you write code that calls a back-end server function. At some point in the future, it returns from that functio...
3
2009-08-23T17:44:09Z
[ "python", "callback", "parallel-python" ]
Parallel Python: What is a callback?
1,319,074
<p>In <a href="http://www.parallelpython.com/">Parallel Python</a> it has something in the <i>submit</i> function called a <i>callback</i> (<a href="http://www.parallelpython.com/content/view/15/30/">documentation</a>) however it doesn't seem to explain it too well. I've posted on their forum a couple days ago and I'v...
20
2009-08-23T17:30:50Z
1,319,135
<p>A callback is a function provided by the consumer of an API that the API can then turn around and invoke (calling you back). If I setup a Dr.'s appointment, I can give them my phone number, so they can call me the day before to confirm the appointment. A callback is like that, except instead of just being a phone nu...
83
2009-08-23T17:52:53Z
[ "python", "callback", "parallel-python" ]