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
what is the correct way to process 4 bits inside an octet in python
1,587,496
<p>I'm writing an application to parse certain network packets. A packet field contains the protocol version number in an octet, so that 4 high bits are the 'major' and low 4 are the 'minor' version. Currently I am parsing them as follows, but am wondering if there is a prettier or more 'pythonic' way of doing it:</p> ...
1
2009-10-19T08:18:26Z
1,587,576
<p>Well named functions are always a good way to hide ugliness and irrelevant complexity. This way the bit-fiddling is confined to small and easily proven correct functions while the higher level code can refer to the purpose of the fiddling.</p> <pre><code>def high_nibble(byte): """Get 4 high order bits from a by...
2
2009-10-19T08:43:32Z
[ "python", "bit-manipulation" ]
Django: How to model a MySQL VARBINARY HEX Field?
1,587,617
<p>I am trying to model a <code>VARBINARY</code> MySQL field in Django v1.1.1. The binary field stores a hexadecimal representation of data (i.e. one would use <code>INSERT INTO test(bin_val) VALUES X'4D7953514C'</code>)</p> <p>Reading the Django documentation[1] I came up with this sollution:</p> <pre><code>class My...
3
2009-10-19T08:57:49Z
1,588,794
<p>The same ticket you referred to also has <a href="http://code.djangoproject.com/attachment/ticket/2417/binaryfield.patch" rel="nofollow">a patch</a> which should give some pointers towards implementing this field.</p> <p>In any case whats your real problem to store it in a CharField?</p> <p>Even if you were to imp...
0
2009-10-19T13:51:17Z
[ "python", "mysql", "django", "model", "varbinary" ]
Django: How to model a MySQL VARBINARY HEX Field?
1,587,617
<p>I am trying to model a <code>VARBINARY</code> MySQL field in Django v1.1.1. The binary field stores a hexadecimal representation of data (i.e. one would use <code>INSERT INTO test(bin_val) VALUES X'4D7953514C'</code>)</p> <p>Reading the Django documentation[1] I came up with this sollution:</p> <pre><code>class My...
3
2009-10-19T08:57:49Z
1,590,063
<p>MySQL neither store hexadecimal representation for VARBINARY fields nor require it in INSERT statement. The only difference from VARCHAR is that MySQL uses binary collation for it. You can pass any 8-bit string as parameter for it.</p>
0
2009-10-19T17:39:43Z
[ "python", "mysql", "django", "model", "varbinary" ]
Django: How to model a MySQL VARBINARY HEX Field?
1,587,617
<p>I am trying to model a <code>VARBINARY</code> MySQL field in Django v1.1.1. The binary field stores a hexadecimal representation of data (i.e. one would use <code>INSERT INTO test(bin_val) VALUES X'4D7953514C'</code>)</p> <p>Reading the Django documentation[1] I came up with this sollution:</p> <pre><code>class My...
3
2009-10-19T08:57:49Z
26,690,218
<p>The problem was the way Django creates database tables and was also related to database collation.</p> <p>The way I solved it was the following:</p> <ul> <li>changed the table charset to <code>utf8</code> and the collation to <code>utf8_bin</code></li> <li>changed the binary field from <code>VARCHAR</code> to <cod...
1
2014-11-01T14:31:09Z
[ "python", "mysql", "django", "model", "varbinary" ]
Light-weight renderer HTML with CSS in Python
1,587,637
<p>Sorry, perhaps I haven't described the problem well first time. All your answers are interesting, but most of them are almost full-featured web browsers, my task is much simpler.</p> <p>I'm planning to write a GUI application using one of the available on linux GUI frameworks (I haven't yet chosen one). I shall use...
7
2009-10-19T09:03:32Z
1,587,703
<p>You should use a UI framework:</p> <ul> <li>Qt: The simplest class to use would be <a href="http://www.riverbankcomputing.co.uk/static/Docs/PyQt4/html/qwebview.html">QWebView</a></li> <li>Gtk: pywebkitgtk would be the best answer, but you can find <a href="http://faq.pygtk.org/index.py?file=faq19.001.htp&req=show">...
10
2009-10-19T09:21:37Z
[ "python", "html", "browser" ]
Light-weight renderer HTML with CSS in Python
1,587,637
<p>Sorry, perhaps I haven't described the problem well first time. All your answers are interesting, but most of them are almost full-featured web browsers, my task is much simpler.</p> <p>I'm planning to write a GUI application using one of the available on linux GUI frameworks (I haven't yet chosen one). I shall use...
7
2009-10-19T09:03:32Z
1,587,951
<p><a href="http://code.google.com/p/flying-saucer//" rel="nofollow">Flying Saucer Project</a> -- an XHTML renderer.</p> <p>No, it's not Python. It's -- however -- trivially called from Python.</p>
0
2009-10-19T10:27:16Z
[ "python", "html", "browser" ]
Light-weight renderer HTML with CSS in Python
1,587,637
<p>Sorry, perhaps I haven't described the problem well first time. All your answers are interesting, but most of them are almost full-featured web browsers, my task is much simpler.</p> <p>I'm planning to write a GUI application using one of the available on linux GUI frameworks (I haven't yet chosen one). I shall use...
7
2009-10-19T09:03:32Z
1,588,474
<p>Maybe <a href="http://wiki.laptop.org/go/HulaHop" rel="nofollow">HulaHop</a> could be interesting for you (can also be combined with <a href="http://pyjs.org/" rel="nofollow">Pyjamas</a>). The Mozilla <a href="http://labs.mozilla.com/prism/" rel="nofollow">Prism</a> Project might also be relevant.</p>
0
2009-10-19T12:40:45Z
[ "python", "html", "browser" ]
Using different versions of a python library in the same process
1,587,776
<p>We've got a python library that we're developing. During development, I'd like to use some parts of that library in testing the newer versions of it. That is, use the stable code in order to test the development code. Is there any way of doing this in python?</p> <p><strong>Edit:</strong> To be more specific, we've...
5
2009-10-19T09:42:13Z
1,587,801
<p>I am unsure of exactly how you need to set up your tests, but you may be able to use <a href="http://pypi.python.org/pypi/virtualenv" rel="nofollow">VirtualEnv</a> to get both instances running alongside eachother.</p>
0
2009-10-19T09:46:58Z
[ "python", "testing", "dependencies", "circular-dependency" ]
Using different versions of a python library in the same process
1,587,776
<p>We've got a python library that we're developing. During development, I'd like to use some parts of that library in testing the newer versions of it. That is, use the stable code in order to test the development code. Is there any way of doing this in python?</p> <p><strong>Edit:</strong> To be more specific, we've...
5
2009-10-19T09:42:13Z
1,588,164
<p>If you "test" libA-dev using libT which depends on libA (stable), then you are not really testing libA-dev as it would behave in a production environment. The only way to really test libA-dev is to take the full plunge and make libT depend on libA-dev. If this breaks your unit tests then that is a good thing -- it i...
1
2009-10-19T11:27:37Z
[ "python", "testing", "dependencies", "circular-dependency" ]
Using different versions of a python library in the same process
1,587,776
<p>We've got a python library that we're developing. During development, I'd like to use some parts of that library in testing the newer versions of it. That is, use the stable code in order to test the development code. Is there any way of doing this in python?</p> <p><strong>Edit:</strong> To be more specific, we've...
5
2009-10-19T09:42:13Z
1,588,192
<p>"We want to test LibA using LibT, but because LibT depends on LibA, we'd rather it to use a stable version of LibA, while testing LibT "</p> <p>It doesn't make sense to use T + A to test A. What does make sense is the following.</p> <p>LibA is really two things mashed together: A1 and A2.</p> <p>T depends on A1...
1
2009-10-19T11:36:01Z
[ "python", "testing", "dependencies", "circular-dependency" ]
Is it possible to access the GetLongPathName() Win32 API in Python?
1,587,816
<p>I need to convert paths in 8.3 convention to full path. In Perl, I can use <a href="http://search.cpan.org/perldoc/Win32#Win32%3a%3aGetLongPathName%28PATHNAME%29" rel="nofollow"><code>Win32::GetLongPathName()</code></a> as pointed out in <a href="http://stackoverflow.com/questions/770171/how-do-i-get-full-win32-path...
2
2009-10-19T09:49:38Z
1,587,924
<p>Use <code>ctypes</code> which is available in the Python standard without the need of using the <a href="http://docs.activestate.com/activepython/2.5/pywin32/win32api__GetShortPathName_meth.html" rel="nofollow">pywin32 API</a>. Like this:</p> <pre><code>from ctypes import * buf = create_unicode_buffer(260) GetLong...
6
2009-10-19T10:19:42Z
[ "python", "windows" ]
Is it possible to access the GetLongPathName() Win32 API in Python?
1,587,816
<p>I need to convert paths in 8.3 convention to full path. In Perl, I can use <a href="http://search.cpan.org/perldoc/Win32#Win32%3a%3aGetLongPathName%28PATHNAME%29" rel="nofollow"><code>Win32::GetLongPathName()</code></a> as pointed out in <a href="http://stackoverflow.com/questions/770171/how-do-i-get-full-win32-path...
2
2009-10-19T09:49:38Z
2,161,652
<p>Use the GetLongPathName function from <a href="http://docs.activestate.com/activepython/2.6/pywin32/win32file__GetLongPathName_meth.html" rel="nofollow">win32file</a></p>
2
2010-01-29T11:46:23Z
[ "python", "windows" ]
how to determine if webpage has been modified
1,587,902
<p>I have snapshots of multiple webpages taken at 2 times. What is a reliable method to determine which webpages have been modified? </p> <p>I can't rely on something like an RSS feed, and I need to ignore minor noise like date text.</p> <p>Ideally I am looking for a Python solution, but an intuitive algorithm would ...
6
2009-10-19T10:13:46Z
1,587,914
<p>Something like <a href="http://en.wikipedia.org/wiki/Levenshtein%5Fdistance" rel="nofollow">Levenshtein Distance</a> could come in handy if you set the threshold of the changes to a distance that ignored the right amount of noise for you.</p>
0
2009-10-19T10:18:06Z
[ "python", "diff", "webpage", "snapshot" ]
how to determine if webpage has been modified
1,587,902
<p>I have snapshots of multiple webpages taken at 2 times. What is a reliable method to determine which webpages have been modified? </p> <p>I can't rely on something like an RSS feed, and I need to ignore minor noise like date text.</p> <p>Ideally I am looking for a Python solution, but an intuitive algorithm would ...
6
2009-10-19T10:13:46Z
1,587,919
<p>Well, first you need to decide what is noise and what isn't. You can use a HTML parser like <a href="http://www.crummy.com/software/BeautifulSoup/">BeautifulSoup</a> to remove the noise, pretty-print the result, and compare it as a string.</p> <p>If you are looking for an automatic solution, you can use <a href="ht...
8
2009-10-19T10:19:21Z
[ "python", "diff", "webpage", "snapshot" ]
how to determine if webpage has been modified
1,587,902
<p>I have snapshots of multiple webpages taken at 2 times. What is a reliable method to determine which webpages have been modified? </p> <p>I can't rely on something like an RSS feed, and I need to ignore minor noise like date text.</p> <p>Ideally I am looking for a Python solution, but an intuitive algorithm would ...
6
2009-10-19T10:13:46Z
1,588,436
<p>The solution really depends if you are scraping a specific site, or are trying to create a program which will work for any site. </p> <p>You can see which areas change frequently doing something like this:</p> <pre><code> diff &lt;(curl http://stackoverflow.com/questions/) &lt;(sleep 15; curl http://stackoverflow...
3
2009-10-19T12:34:25Z
[ "python", "diff", "webpage", "snapshot" ]
how to determine if webpage has been modified
1,587,902
<p>I have snapshots of multiple webpages taken at 2 times. What is a reliable method to determine which webpages have been modified? </p> <p>I can't rely on something like an RSS feed, and I need to ignore minor noise like date text.</p> <p>Ideally I am looking for a Python solution, but an intuitive algorithm would ...
6
2009-10-19T10:13:46Z
1,588,461
<p>just take snapshots of the files with MD5 or SHA1...if the values differ the next time you check, then they are modified.</p>
-1
2009-10-19T12:38:28Z
[ "python", "diff", "webpage", "snapshot" ]
Caching system for dynamically created files?
1,587,991
<p>I have a web server that is dynamically creating various reports in several formats (pdf and doc files). The files require a fair amount of CPU to generate, and it is fairly common to have situations where two people are creating the same report with the same input.</p> <p>Inputs:</p> <ul> <li>raw data input as a ...
1
2009-10-19T10:42:57Z
1,588,007
<p>This is what Apache is for.</p> <p>Create a directory that will have the reports.</p> <p>Configure Apache to serve files from that directory.</p> <p>If the report exists, redirect to a URL that Apache will serve.</p> <p>Otherwise, the report doesn't exist, so create it. Then redirect to a URL that Apache will s...
2
2009-10-19T10:45:35Z
[ "python" ]
Caching system for dynamically created files?
1,587,991
<p>I have a web server that is dynamically creating various reports in several formats (pdf and doc files). The files require a fair amount of CPU to generate, and it is fairly common to have situations where two people are creating the same report with the same input.</p> <p>Inputs:</p> <ul> <li>raw data input as a ...
1
2009-10-19T10:42:57Z
1,588,045
<p>The usual thing is to use a reverse proxy like <a href="http://en.wikipedia.org/wiki/Squid%5F%28software%29" rel="nofollow">Squid</a> or <a href="http://en.wikipedia.org/wiki/Varnish%5F%28software%29" rel="nofollow">Varnish</a></p>
1
2009-10-19T10:56:26Z
[ "python" ]
Read two variables in a single line with Python
1,588,058
<p>I am familiar with the input() function, to read a single variable from user input. Is there a similar easy way to read two variables? </p> <p>I'm looking for the equivalent of:</p> <pre><code>scanf("%d%d", &amp;i, &amp;j); // accepts "10 20\n" </code></pre> <p>One way I am able to achieve this is to use <code>ra...
5
2009-10-19T11:00:21Z
1,588,071
<p>No, the usual way is <code>raw_input().split()</code></p> <p>In your case you might use <code>map(int, raw_input().split())</code> if you want them to be integers rather than strings</p> <p>Don't use <code>input()</code> for that. Consider what happens if the user enters </p> <blockquote> <p><code>import os;os...
21
2009-10-19T11:02:53Z
[ "python", "input" ]
Read two variables in a single line with Python
1,588,058
<p>I am familiar with the input() function, to read a single variable from user input. Is there a similar easy way to read two variables? </p> <p>I'm looking for the equivalent of:</p> <pre><code>scanf("%d%d", &amp;i, &amp;j); // accepts "10 20\n" </code></pre> <p>One way I am able to achieve this is to use <code>ra...
5
2009-10-19T11:00:21Z
1,590,189
<p>You can also read from sys.stdin</p> <pre><code>import sys a,b = map(int,sys.stdin.readline().split()) </code></pre>
5
2009-10-19T18:04:29Z
[ "python", "input" ]
Read two variables in a single line with Python
1,588,058
<p>I am familiar with the input() function, to read a single variable from user input. Is there a similar easy way to read two variables? </p> <p>I'm looking for the equivalent of:</p> <pre><code>scanf("%d%d", &amp;i, &amp;j); // accepts "10 20\n" </code></pre> <p>One way I am able to achieve this is to use <code>ra...
5
2009-10-19T11:00:21Z
27,749,093
<p>I am new at this stuff as well. Did a bit of research from the python.org website and a bit of hacking to get this to work. The <strong>raw_input</strong> function is back again, changed from <strong>input</strong>. This is what I came up with:</p> <pre><code>i,j = raw_input("Enter two values: ").split i = int(i) ...
3
2015-01-02T21:58:20Z
[ "python", "input" ]
Read two variables in a single line with Python
1,588,058
<p>I am familiar with the input() function, to read a single variable from user input. Is there a similar easy way to read two variables? </p> <p>I'm looking for the equivalent of:</p> <pre><code>scanf("%d%d", &amp;i, &amp;j); // accepts "10 20\n" </code></pre> <p>One way I am able to achieve this is to use <code>ra...
5
2009-10-19T11:00:21Z
28,778,397
<p>Firstly read the complete line into a string like </p> <pre><code> string = raw_input() </code></pre> <p>Then use a for loop like this </p> <pre><code> prev = 0 lst = [] index = 0 for letter in string : if item == ' ' or item == '\n' : lst.append(int(string[prev:index]) ...
1
2015-02-28T05:18:13Z
[ "python", "input" ]
Read two variables in a single line with Python
1,588,058
<p>I am familiar with the input() function, to read a single variable from user input. Is there a similar easy way to read two variables? </p> <p>I'm looking for the equivalent of:</p> <pre><code>scanf("%d%d", &amp;i, &amp;j); // accepts "10 20\n" </code></pre> <p>One way I am able to achieve this is to use <code>ra...
5
2009-10-19T11:00:21Z
35,036,763
<p>or you can do this</p> <pre><code>input_user=map(int,raw_input().strip().split(" ")) </code></pre>
0
2016-01-27T11:58:22Z
[ "python", "input" ]
Is there any possibilty to convert recarray to ndarray and change ndim?
1,588,224
<p>I am getting recarray from matplotlib.mlab.csv2rec function. My expectation was it would have 2 dimensions like 'x', but it has 1 dimension like 'y'. Is there any way to get x from y? </p> <pre><code>&gt;&gt;&gt; import numpy as np &gt;&gt;&gt; from datetime import date &gt;&gt;&gt; x=np.array([(date(2000,1,1),0,1)...
0
2009-10-19T11:44:08Z
1,588,483
<p>Sounds weird but... I can save to csv by using matplotlib.mlab.rec2csv, and then read to ndarray by using numpy.loadtxt. My case is simpler as I already have csv file. Here is an example how it works. </p> <pre><code>&gt;&gt;&gt; a = np.loadtxt( 'name.csv', skiprows=1, delimiter=',', converters = {0: lambda x: 0} )...
0
2009-10-19T12:42:30Z
[ "python", "numpy" ]
Is there any possibilty to convert recarray to ndarray and change ndim?
1,588,224
<p>I am getting recarray from matplotlib.mlab.csv2rec function. My expectation was it would have 2 dimensions like 'x', but it has 1 dimension like 'y'. Is there any way to get x from y? </p> <pre><code>&gt;&gt;&gt; import numpy as np &gt;&gt;&gt; from datetime import date &gt;&gt;&gt; x=np.array([(date(2000,1,1),0,1)...
0
2009-10-19T11:44:08Z
1,590,064
<p>Well, there might be a more efficient way than this, but here is one way:</p> <pre><code>#!/usr/bin/env python import numpy as np from datetime import date x=np.array([(date(2000,1,1),0,1), (date(2000,1,1),1,1), (date(2000,1,1),1,0), (date(2000,1,1),0,0), ]) ...
0
2009-10-19T17:39:50Z
[ "python", "numpy" ]
Is there any possibilty to convert recarray to ndarray and change ndim?
1,588,224
<p>I am getting recarray from matplotlib.mlab.csv2rec function. My expectation was it would have 2 dimensions like 'x', but it has 1 dimension like 'y'. Is there any way to get x from y? </p> <pre><code>&gt;&gt;&gt; import numpy as np &gt;&gt;&gt; from datetime import date &gt;&gt;&gt; x=np.array([(date(2000,1,1),0,1)...
0
2009-10-19T11:44:08Z
19,298,072
<p>You can do it via pandas:</p> <pre><code>import pandas as pd pd.DataFrame(y).values array([[2000-01-01, 0, 1], [2000-01-01, 1, 1], [2000-01-01, 1, 0], [2000-01-01, 0, 0]], dtype=object) </code></pre> <p>But I would consider doing my project in pandas if I were you. Support for named columns i...
2
2013-10-10T14:07:37Z
[ "python", "numpy" ]
How to prepare a django project for future changes
1,588,570
<p>As I work on my first django powered site, I am constantly learning new things and making all sorts of changes and additions to my apps as I go. I try to follow DRY and pythonic principles and be smart in my coding but eventually I will have to take the site live and am certain that not long after I do, something n...
8
2009-10-19T13:04:09Z
1,588,609
<p>Not sure how relevant this is outside of the wonderful world of Webfaction.</p> <p>Use Django checked out from Django's svn repository, rather than whatever your host installed for you when creating a Django app, so you can update Django to get security fixes by running <code>svn up</code>.</p> <p>I had to do this...
5
2009-10-19T13:14:53Z
[ "python", "database", "django" ]
How to prepare a django project for future changes
1,588,570
<p>As I work on my first django powered site, I am constantly learning new things and making all sorts of changes and additions to my apps as I go. I try to follow DRY and pythonic principles and be smart in my coding but eventually I will have to take the site live and am certain that not long after I do, something n...
8
2009-10-19T13:04:09Z
1,588,620
<p><strong>"something will come up and I'll wish I had implemented it earlier"</strong></p> <p>That's the definition of a good site. One that evolves and changes.</p> <p><strong>"future-ready as possible ?"</strong></p> <p>What can this possibly mean? What specific things are you worried about? Technology is alwa...
-2
2009-10-19T13:16:27Z
[ "python", "database", "django" ]
How to prepare a django project for future changes
1,588,570
<p>As I work on my first django powered site, I am constantly learning new things and making all sorts of changes and additions to my apps as I go. I try to follow DRY and pythonic principles and be smart in my coding but eventually I will have to take the site live and am certain that not long after I do, something n...
8
2009-10-19T13:04:09Z
1,588,702
<ul> <li>Deploy into a pure environment using <a href="http://pypi.python.org/pypi/virtualenv" rel="nofollow">virtualenv</a>.</li> <li>Document requirements using a <a href="http://pip.openplans.org/" rel="nofollow">pip</a> requirements file.</li> </ul> <p>I'm sure others will suggest their deployment strategies, but ...
8
2009-10-19T13:35:51Z
[ "python", "database", "django" ]
How to prepare a django project for future changes
1,588,570
<p>As I work on my first django powered site, I am constantly learning new things and making all sorts of changes and additions to my apps as I go. I try to follow DRY and pythonic principles and be smart in my coding but eventually I will have to take the site live and am certain that not long after I do, something n...
8
2009-10-19T13:04:09Z
1,590,806
<p>Learn and use South at the outset, so when you make major DB schema changes, you'll have a migration tool already in place. Otherwise, you'll find you end up running two versions side by side while trying to figure out how to port the data, and it gets very VERY messy.</p> <p><a href="http://south.aeracode.org/" re...
7
2009-10-19T20:06:32Z
[ "python", "database", "django" ]
How to prepare a django project for future changes
1,588,570
<p>As I work on my first django powered site, I am constantly learning new things and making all sorts of changes and additions to my apps as I go. I try to follow DRY and pythonic principles and be smart in my coding but eventually I will have to take the site live and am certain that not long after I do, something n...
8
2009-10-19T13:04:09Z
1,591,366
<p>Listen to James Bennett: Read Practical Django Projects, follow <a href="http://b-list.org/" rel="nofollow">http://b-list.org/</a>. Search youtube for his djangocon talk on reusable apps. Read his code (on bitbucket).</p> <p>An example of advice I've gotten from him: Dependency injection on your views will make y...
4
2009-10-19T21:56:42Z
[ "python", "database", "django" ]
AppEngine GeoPt Data Upload
1,588,633
<p>I'm writing a GAE app in Java and only using Python for the data upload. I'm trying to import a CSV file that looks like this:</p> <pre><code>POSTAL_CODE_ID,PostalCode,City,Province,ProvinceCode,CityType,Latitude,Longitude 1,A0E2Z0,Monkstown,Newfoundland,NL,D,47.150300000000001,-55.299500000000002 </code></pre> <p...
4
2009-10-19T13:21:25Z
1,588,696
<p>I don't know what your loader code but...</p> <pre><code># given this class PostalCode(db.Model): id = db.IntegerProperty() postal_code = db.PostalAddressProperty() city = db.StringProperty() province = db.StringProperty() province_code = db.StringProperty() city_type = db.StringProperty() geoLocation...
0
2009-10-19T13:34:40Z
[ "python", "google-app-engine", "upload", "csv" ]
AppEngine GeoPt Data Upload
1,588,633
<p>I'm writing a GAE app in Java and only using Python for the data upload. I'm trying to import a CSV file that looks like this:</p> <pre><code>POSTAL_CODE_ID,PostalCode,City,Province,ProvinceCode,CityType,Latitude,Longitude 1,A0E2Z0,Monkstown,Newfoundland,NL,D,47.150300000000001,-55.299500000000002 </code></pre> <p...
4
2009-10-19T13:21:25Z
1,589,500
<p>Avoid typecasting and instanceof-tests. I use both geopt and geohash http posted, rather similar where deafult values are recommended to get started:</p> <pre><code> geopt=db.GeoPtProperty(verbose_name="geopt") </code></pre> <p>...</p> <pre><code> article.geopt = db.GeoPt(self.request.POST.get('lat'),se...
0
2009-10-19T15:49:09Z
[ "python", "google-app-engine", "upload", "csv" ]
AppEngine GeoPt Data Upload
1,588,633
<p>I'm writing a GAE app in Java and only using Python for the data upload. I'm trying to import a CSV file that looks like this:</p> <pre><code>POSTAL_CODE_ID,PostalCode,City,Province,ProvinceCode,CityType,Latitude,Longitude 1,A0E2Z0,Monkstown,Newfoundland,NL,D,47.150300000000001,-55.299500000000002 </code></pre> <p...
4
2009-10-19T13:21:25Z
1,595,278
<p>Ok, I got my answer from Google Groups (thanks Takashi Matsuo and Mike Armstrong). The solution is to modify my CSV file and combine lat and lng in a double-quoted string. The comma within the double-quoted string will not be counted as a CSV delimiter.</p> <pre><code>POSTAL_CODE_ID,PostalCode,City,Province,Provinc...
3
2009-10-20T15:01:42Z
[ "python", "google-app-engine", "upload", "csv" ]
AppEngine GeoPt Data Upload
1,588,633
<p>I'm writing a GAE app in Java and only using Python for the data upload. I'm trying to import a CSV file that looks like this:</p> <pre><code>POSTAL_CODE_ID,PostalCode,City,Province,ProvinceCode,CityType,Latitude,Longitude 1,A0E2Z0,Monkstown,Newfoundland,NL,D,47.150300000000001,-55.299500000000002 </code></pre> <p...
4
2009-10-19T13:21:25Z
3,905,888
<p>You can define your own loader which merge two columns from cvs into one value and then write a converter function that parses this value into db.GeoPt. In this solution you don't need to change your csv file. Here is an example (assuming that csv file has only three columns - lat, lng and some name):</p> <pre><cod...
0
2010-10-11T11:48:56Z
[ "python", "google-app-engine", "upload", "csv" ]
AppEngine GeoPt Data Upload
1,588,633
<p>I'm writing a GAE app in Java and only using Python for the data upload. I'm trying to import a CSV file that looks like this:</p> <pre><code>POSTAL_CODE_ID,PostalCode,City,Province,ProvinceCode,CityType,Latitude,Longitude 1,A0E2Z0,Monkstown,Newfoundland,NL,D,47.150300000000001,-55.299500000000002 </code></pre> <p...
4
2009-10-19T13:21:25Z
4,505,047
<p>This question should be deleted/deprecated. Python isn't used for the bulkloader anymore. Now only yaml files are used. For the answer to this question using the modern bulkloader, see: <a href="http://stackoverflow.com/questions/3350193/importing-geopt-data-with-the-google-appengine-bulkloader-yaml">Importing GeoPt...
0
2010-12-21T23:52:24Z
[ "python", "google-app-engine", "upload", "csv" ]
What are the use cases for non relational datastores?
1,588,708
<p>I'm looking at using CouchDB for one project and the GAE app engine datastore in the other. For relational stuff I tend to use postgres, although I much prefer an ORM. </p> <p>Anyway, what use cases suit non relational datastores best?</p>
3
2009-10-19T13:36:49Z
1,588,748
<p>Consider the situation where you have many entity types but few instances of each entity. In this case you will have many tables each with a few records so a relational approach is not suitable. </p>
2
2009-10-19T13:43:31Z
[ "python", "google-app-engine", "couchdb" ]
What are the use cases for non relational datastores?
1,588,708
<p>I'm looking at using CouchDB for one project and the GAE app engine datastore in the other. For relational stuff I tend to use postgres, although I much prefer an ORM. </p> <p>Anyway, what use cases suit non relational datastores best?</p>
3
2009-10-19T13:36:49Z
1,588,758
<p>Here is a nice little article (spread over three pages) that covers the use-case for non-relational databases.</p> <p><a href="http://www.readwriteweb.com/enterprise/2009/02/is-the-relational-database-doomed.php">http://www.readwriteweb.com/enterprise/2009/02/is-the-relational-database-doomed.php</a></p> <p>In a n...
7
2009-10-19T13:44:25Z
[ "python", "google-app-engine", "couchdb" ]
What are the use cases for non relational datastores?
1,588,708
<p>I'm looking at using CouchDB for one project and the GAE app engine datastore in the other. For relational stuff I tend to use postgres, although I much prefer an ORM. </p> <p>Anyway, what use cases suit non relational datastores best?</p>
3
2009-10-19T13:36:49Z
1,589,186
<p>In some cases that are simply nice. ZODB is a Python-only object database, that is so well-integrated with Python that you can simply forget that it's there. You don't have to bother about it, most of the time.</p>
0
2009-10-19T14:59:23Z
[ "python", "google-app-engine", "couchdb" ]
Nested Function in Python
1,589,058
<p>What benefit or implications could we get with Python code like this:</p> <pre><code>class some_class(parent_class): def doOp(self, x, y): def add(x, y): return x + y return add(x, y) </code></pre> <p>I found this in an open-source project, doing something useful inside the nested f...
46
2009-10-19T14:40:51Z
1,589,162
<p>I can't image any good reason for code like that.</p> <p>Maybe there was a reason for the inner function in older revisions, like other Ops. </p> <p>For example, this makes <em>slightly</em> more sense:</p> <pre><code>class some_class(parent_class): def doOp(self, op, x, y): def add(x, y): ...
7
2009-10-19T14:55:37Z
[ "python", "nested-function" ]
Nested Function in Python
1,589,058
<p>What benefit or implications could we get with Python code like this:</p> <pre><code>class some_class(parent_class): def doOp(self, x, y): def add(x, y): return x + y return add(x, y) </code></pre> <p>I found this in an open-source project, doing something useful inside the nested f...
46
2009-10-19T14:40:51Z
1,589,173
<p>The idea behind local methods is similar to local variables: don't pollute the larger name space. Obviously the benefits are limited since most languages don't also provide such functionality directly.</p>
4
2009-10-19T14:57:24Z
[ "python", "nested-function" ]
Nested Function in Python
1,589,058
<p>What benefit or implications could we get with Python code like this:</p> <pre><code>class some_class(parent_class): def doOp(self, x, y): def add(x, y): return x + y return add(x, y) </code></pre> <p>I found this in an open-source project, doing something useful inside the nested f...
46
2009-10-19T14:40:51Z
1,589,188
<p>Are you sure the code was exactly like this? The normal reason for doing something like this is for creating a partial - a function with baked-in parameters. Calling the outer function returns a callable that needs no parameters, and so therefore can be stored and used somewhere it is impossible to pass parameters. ...
1
2009-10-19T14:59:37Z
[ "python", "nested-function" ]
Nested Function in Python
1,589,058
<p>What benefit or implications could we get with Python code like this:</p> <pre><code>class some_class(parent_class): def doOp(self, x, y): def add(x, y): return x + y return add(x, y) </code></pre> <p>I found this in an open-source project, doing something useful inside the nested f...
46
2009-10-19T14:40:51Z
1,589,209
<p>Aside from function generators, where internal function creation is almost the definition of a function generator, the reason I create nested functions is to improve readability. If I have a tiny function that will only be invoked by the outer function, then I inline the definition so you don't have to skip around ...
35
2009-10-19T15:03:11Z
[ "python", "nested-function" ]
Nested Function in Python
1,589,058
<p>What benefit or implications could we get with Python code like this:</p> <pre><code>class some_class(parent_class): def doOp(self, x, y): def add(x, y): return x + y return add(x, y) </code></pre> <p>I found this in an open-source project, doing something useful inside the nested f...
46
2009-10-19T14:40:51Z
1,589,606
<p>Normally you do it to make <em><a href="http://en.wikipedia.org/wiki/Closure%5F%28computer%5Fscience%29">closures</a></em>:</p> <pre><code>def make_adder(x): def add(y): return x + y return add plus5 = make_adder(5) print(plus5(12)) # prints 17 </code></pre> <p>Inner functions can access variable...
67
2009-10-19T16:05:56Z
[ "python", "nested-function" ]
Nested Function in Python
1,589,058
<p>What benefit or implications could we get with Python code like this:</p> <pre><code>class some_class(parent_class): def doOp(self, x, y): def add(x, y): return x + y return add(x, y) </code></pre> <p>I found this in an open-source project, doing something useful inside the nested f...
46
2009-10-19T14:40:51Z
13,397,600
<p>One potential benefit of using inner methods is that it allows you to use outer method local variables without passing them as arguments.</p> <pre><code>def helper(feature, resultBuffer): resultBuffer.print(feature) resultBuffer.printLine() resultBuffer.flush() def save(item, resultBuffer): helper(item.de...
17
2012-11-15T12:32:05Z
[ "python", "nested-function" ]
Python XMLRPC with concurrent requests
1,589,150
<p>I'm looking for a way to prevent multiple hosts from issuing simultaneous commands to a Python XMLRPC listener. The listener is responsible for running scripts to perform tasks on that system that would fail if multiple users tried to issue these commands at the same time. Is there a way I can block all incoming req...
5
2009-10-19T14:54:08Z
1,589,181
<p>Can you have another communication channel? If yes, then have a "call me back when it is my turn" protocol running between the server and the clients.</p> <p>In other words, each client would register its intention to issue requests to the server and the said server would "callback" the next-up client when it is re...
0
2009-10-19T14:58:33Z
[ "python", "xml-rpc" ]
Python XMLRPC with concurrent requests
1,589,150
<p>I'm looking for a way to prevent multiple hosts from issuing simultaneous commands to a Python XMLRPC listener. The listener is responsible for running scripts to perform tasks on that system that would fail if multiple users tried to issue these commands at the same time. Is there a way I can block all incoming req...
5
2009-10-19T14:54:08Z
1,589,936
<p>I think python SimpleXMLRPCServer module is what you want. I believe the default behavior of that model is blocking new requests when current request is processing. The default behavior gave me lots of trouble and I changed that behavior by mix in ThreadingMixIn class so that my xmlrpc server could respond multiple ...
11
2009-10-19T17:12:22Z
[ "python", "xml-rpc" ]
Python XMLRPC with concurrent requests
1,589,150
<p>I'm looking for a way to prevent multiple hosts from issuing simultaneous commands to a Python XMLRPC listener. The listener is responsible for running scripts to perform tasks on that system that would fail if multiple users tried to issue these commands at the same time. Is there a way I can block all incoming req...
5
2009-10-19T14:54:08Z
1,590,010
<p>There are several choices:</p> <ol> <li>Use single-process-single-thread server like <code>SimpleXMLRPCServer</code> to process requests subsequently.</li> <li>Use <code>threading.Lock()</code> in threaded server.</li> <li>You some external locking mechanism (like <code>lockfile</code> module or <code>GET_LOCK()</c...
0
2009-10-19T17:27:52Z
[ "python", "xml-rpc" ]
Why can't I do SHOW PROCESSLIST with QtSql (PyQT)?
1,589,231
<p>I am a Python and QT newbie. I am trying to do a little app with PyQT4 in order to supervise a home MySQL server of mine, so my first idea was to do the classic <code>SHOW PROCESSLIST</code>, parse it, and show in a pretty UI. Nothing big, really.</p> <p>But for some reason, the QtSql module doesn't return anything...
0
2009-10-19T15:07:11Z
1,589,604
<p>I don't know what is wrong, but in recent versions of MySQL you can work it around using <a href="http://dev.mysql.com/doc/refman/5.1/en/processlist-table.html" rel="nofollow">information_schema.processlist</a>:</p> <pre><code>SELECT * FROM INFORMATION_SCHEMA.PROCESSLIST </code></pre>
1
2009-10-19T16:05:43Z
[ "python", "mysql", "qt", "pyqt" ]
Why can't I do SHOW PROCESSLIST with QtSql (PyQT)?
1,589,231
<p>I am a Python and QT newbie. I am trying to do a little app with PyQT4 in order to supervise a home MySQL server of mine, so my first idea was to do the classic <code>SHOW PROCESSLIST</code>, parse it, and show in a pretty UI. Nothing big, really.</p> <p>But for some reason, the QtSql module doesn't return anything...
0
2009-10-19T15:07:11Z
6,200,259
<p>I don't know if you already tried this, but what about adding an ';'?</p> <pre><code>q.exec_("SHOW PROCESSLIST;") </code></pre> <p>I have never worked with QtSQL but some MySQL API's do have quite strange behavior and I've run into that problem before.</p> <p>(sry for bumping an old question, it came up when I wa...
0
2011-06-01T11:15:09Z
[ "python", "mysql", "qt", "pyqt" ]
Iterating over arbitrary dimension of numpy.array
1,589,706
<p>Is there function to get an iterator over an arbitrary dimension of a numpy array?</p> <p>Iterating over the first dimension is easy...</p> <pre><code>In [63]: c = numpy.arange(24).reshape(2,3,4) In [64]: for r in c : ....: print r ....: [[ 0 1 2 3] [ 4 5 6 7] [ 8 9 10 11]] [[12 13 14 15] [16...
21
2009-10-19T16:27:11Z
1,593,130
<p>What you propose is quite fast, but the legibility can be improved with the clearer forms:</p> <pre><code>for i in range(c.shape[-1]): print c[:,:,i] </code></pre> <p>or, better (faster and more explicit):</p> <pre><code>for i in range(c.shape[-1]): print c[...,i] </code></pre> <p>However, the first appr...
24
2009-10-20T08:13:50Z
[ "python", "numpy", "loops" ]
Iterating over arbitrary dimension of numpy.array
1,589,706
<p>Is there function to get an iterator over an arbitrary dimension of a numpy array?</p> <p>Iterating over the first dimension is easy...</p> <pre><code>In [63]: c = numpy.arange(24).reshape(2,3,4) In [64]: for r in c : ....: print r ....: [[ 0 1 2 3] [ 4 5 6 7] [ 8 9 10 11]] [[12 13 14 15] [16...
21
2009-10-19T16:27:11Z
1,594,884
<p>I guess there is no function. When I wrote my function, I ended up taking the iteration EOL also suggested. For future readers, here it is:</p> <pre><code>def iterdim(a, axis=0) : a = numpy.asarray(a); leading_indices = (slice(None),)*axis for i in xrange(a.shape[axis]) : yield a[leading_indices+(i,)] <...
1
2009-10-20T14:10:18Z
[ "python", "numpy", "loops" ]
Iterating over arbitrary dimension of numpy.array
1,589,706
<p>Is there function to get an iterator over an arbitrary dimension of a numpy array?</p> <p>Iterating over the first dimension is easy...</p> <pre><code>In [63]: c = numpy.arange(24).reshape(2,3,4) In [64]: for r in c : ....: print r ....: [[ 0 1 2 3] [ 4 5 6 7] [ 8 9 10 11]] [[12 13 14 15] [16...
21
2009-10-19T16:27:11Z
5,923,332
<p>I'd use the following:</p> <pre><code>c = numpy.arange(2 * 3 * 4) c.shape = (2, 3, 4) for r in numpy.rollaxis(c, 2): print(r) </code></pre> <p>The function <strong>rollaxis</strong> creates a new view on the array. In this case it's moving axis 2 to the front, equivalent to the operation <code>c.transpose(2, ...
10
2011-05-07T19:05:11Z
[ "python", "numpy", "loops" ]
Iterating over arbitrary dimension of numpy.array
1,589,706
<p>Is there function to get an iterator over an arbitrary dimension of a numpy array?</p> <p>Iterating over the first dimension is easy...</p> <pre><code>In [63]: c = numpy.arange(24).reshape(2,3,4) In [64]: for r in c : ....: print r ....: [[ 0 1 2 3] [ 4 5 6 7] [ 8 9 10 11]] [[12 13 14 15] [16...
21
2009-10-19T16:27:11Z
16,085,248
<p>So, one can iterate over the first dimension easily, as you've shown. Another way to do this for arbitrary dimension is to use numpy.rollaxis() to bring the given dimension to the first (the default behavior), and then use the returned array (which is a view, so this is fast) as an iterator.</p> <pre><code>In [1]:...
1
2013-04-18T14:07:13Z
[ "python", "numpy", "loops" ]
Google App Engine compatibility layer
1,589,743
<p>I'm planning an application running on Google App Engine. The only worry I would have is portability. Or just the option to have the app run on a local, private cluster. </p> <p>I expected an option for Google App Engine applications to run on other systems, a compatibility layer, to spring up. I could imagine a GA...
6
2009-10-19T16:33:42Z
1,589,889
<p>The appscale project is designed to do exactly this. See <a href="https://github.com/AppScale/appscale/wiki" rel="nofollow">https://github.com/AppScale/appscale/wiki</a></p>
6
2009-10-19T17:02:22Z
[ "python", "google-app-engine" ]
Google App Engine compatibility layer
1,589,743
<p>I'm planning an application running on Google App Engine. The only worry I would have is portability. Or just the option to have the app run on a local, private cluster. </p> <p>I expected an option for Google App Engine applications to run on other systems, a compatibility layer, to spring up. I could imagine a GA...
6
2009-10-19T16:33:42Z
1,589,931
<p>Another taken from this <a href="http://serverfault.com/questions/59322/google-app-engine-sdk-is-open-source-would-anyone-from-the-cloud-try-to-catch-it">question:</a></p> <p><a href="http://waxy.org/2008/04/exclusive%5Fgoogle%5Fapp%5Fengine%5Fported%5Fto%5Famazons%5Fec2/" rel="nofollow">Waxy</a></p>
1
2009-10-19T17:11:06Z
[ "python", "google-app-engine" ]
Google App Engine compatibility layer
1,589,743
<p>I'm planning an application running on Google App Engine. The only worry I would have is portability. Or just the option to have the app run on a local, private cluster. </p> <p>I expected an option for Google App Engine applications to run on other systems, a compatibility layer, to spring up. I could imagine a GA...
6
2009-10-19T16:33:42Z
1,590,088
<p><a href="http://code.google.com/p/typhoonae/" rel="nofollow">Typhoonae</a> Might be interesting to you, it is a new project to implement a full production server stack using exisiting technologies, capable of hosting AppEngine instances. It also aims to do this while staying compatable with the AppEngine API, to all...
2
2009-10-19T17:46:00Z
[ "python", "google-app-engine" ]
Google App Engine compatibility layer
1,589,743
<p>I'm planning an application running on Google App Engine. The only worry I would have is portability. Or just the option to have the app run on a local, private cluster. </p> <p>I expected an option for Google App Engine applications to run on other systems, a compatibility layer, to spring up. I could imagine a GA...
6
2009-10-19T16:33:42Z
1,590,847
<blockquote> <p>I could imagine a GAE compatible framework utilizing Amazon SimpleDB or CouchDB to offer near 100% compatibility</p> </blockquote> <p>GAE/J uses DataNucleus for persistence. DataNucleus also has plugins for RDBMS, LDAP, XML, Excel, ODF, OODBMS, HBase (HADOOP), and Amazon S3. Consequently the persi...
4
2009-10-19T20:14:34Z
[ "python", "google-app-engine" ]
Google App Engine compatibility layer
1,589,743
<p>I'm planning an application running on Google App Engine. The only worry I would have is portability. Or just the option to have the app run on a local, private cluster. </p> <p>I expected an option for Google App Engine applications to run on other systems, a compatibility layer, to spring up. I could imagine a GA...
6
2009-10-19T16:33:42Z
4,219,064
<p>If you develop with web2py your code will run GAE other architectures wihtout changes using any of the 10 supported relational databases. The compatibility layer covers database api (including blobs and listproperty), email, and fetching). </p>
0
2010-11-18T20:08:40Z
[ "python", "google-app-engine" ]
Must two SQLAlchemy declarative models share the same declarative_base()?
1,589,748
<p>Is it necessary for two SQLAlchemy models to inherit from the same instance of <code>declarative_base()</code> if they must participate in the same Session? This is likely to be the case when importing two or more modules that define SQLAlchemy models.</p> <pre><code>from sqlalchemy.ext.declarative import declarati...
4
2009-10-19T16:34:41Z
1,589,895
<p>Separate Base classes will work just fine.</p> <p>You'll have to be careful when they are using different database connections, in that case you can't use joins across the two databases - every query needs to go to one database.</p>
2
2009-10-19T17:03:32Z
[ "python", "orm", "sqlalchemy" ]
Must two SQLAlchemy declarative models share the same declarative_base()?
1,589,748
<p>Is it necessary for two SQLAlchemy models to inherit from the same instance of <code>declarative_base()</code> if they must participate in the same Session? This is likely to be the case when importing two or more modules that define SQLAlchemy models.</p> <pre><code>from sqlalchemy.ext.declarative import declarati...
4
2009-10-19T16:34:41Z
1,590,090
<p>I successfully use different declarative bases in single session. This can be useful when using several databases: each base is created with own metadata and each metadata is bound to separate database. Some of your declarative bases could define additional methods or they could use another metaclass to install exte...
4
2009-10-19T17:46:12Z
[ "python", "orm", "sqlalchemy" ]
Python: Difference between 'global' & globals().update(var)
1,589,968
<p>What is the difference between initializing a variable as <code>global var</code> or calling <code>globals().update(var)</code>.</p> <p>Thanks</p>
7
2009-10-19T17:19:12Z
1,590,016
<p>When you say</p> <pre><code>global var </code></pre> <p>you are telling Python that var is the same var that was defined in a global context. You would use it in the following way:</p> <pre><code>var=0 def f(): global var var=1 f() print(var) # 1 &lt;---- the var outside the "def f" block is affected by ...
16
2009-10-19T17:29:41Z
[ "python", "variables", "global" ]
How do I write a unix filter in python?
1,589,994
<p>I want to write a program that reads stdin (unbuffered) and writes stdout (unbuffered) doing some trivial char-by-char transformation. For the sake of the example let's say I want to remove all chars <code>x</code> from stdin.</p>
9
2009-10-19T17:24:43Z
1,590,013
<p>Read from <code>sys.stdin</code> and write to <code>sys.stdout</code> (or use <code>print</code>). Your example program:</p> <pre><code>import sys for line in sys.stdin: print line.replace("x", ""), </code></pre> <p>There isn't a standard way to make stdin unbuffered, and you don't want that. Let the OS buff...
13
2009-10-19T17:28:44Z
[ "python", "unix", "filter" ]
How do I write a unix filter in python?
1,589,994
<p>I want to write a program that reads stdin (unbuffered) and writes stdout (unbuffered) doing some trivial char-by-char transformation. For the sake of the example let's say I want to remove all chars <code>x</code> from stdin.</p>
9
2009-10-19T17:24:43Z
1,590,058
<p>I don't know exactly what you mean by buffered in this context, but it is pretty simple to do what you are asking...</p> <p>so_gen.py (generating a constant stream that we can watch):</p> <pre><code>import time import sys while True: for char in 'abcdefx': sys.stdout.write(char) sys.stdout.flus...
7
2009-10-19T17:38:29Z
[ "python", "unix", "filter" ]
How do I write a unix filter in python?
1,589,994
<p>I want to write a program that reads stdin (unbuffered) and writes stdout (unbuffered) doing some trivial char-by-char transformation. For the sake of the example let's say I want to remove all chars <code>x</code> from stdin.</p>
9
2009-10-19T17:24:43Z
1,590,069
<p>You can use the <a href="http://docs.python.org/library/fileinput.html"><code>fileinput</code> class</a>, which lets you process inputs like the Perl diamond operator would. From the docs:</p> <pre><code>import fileinput for line in fileinput.input(): process(line) </code></pre> <p>where process does somethin...
8
2009-10-19T17:40:43Z
[ "python", "unix", "filter" ]
How do I write a unix filter in python?
1,589,994
<p>I want to write a program that reads stdin (unbuffered) and writes stdout (unbuffered) doing some trivial char-by-char transformation. For the sake of the example let's say I want to remove all chars <code>x</code> from stdin.</p>
9
2009-10-19T17:24:43Z
1,590,122
<p>Use the -u switch for the python interpreter to make all reads and writes unbuffered. Similar to setting <code>$| = true;</code> in Perl. Then proceed as you would, reading a line modifying it and then printing it. sys.stdout.flush() not required.</p> <pre><code>#!/path/to/python -u import sys for line in sys.std...
2
2009-10-19T17:52:14Z
[ "python", "unix", "filter" ]
url builder for python
1,590,219
<p>I know about <code>urllib</code> and <code>urlparse</code>, but I want to make sure I wouldn't be reinventing the wheel.</p> <p>My problem is that I am going to be fetching a bunch of urls from the same domain via the <code>urllib</code> library. I basically want to be able to generate urls to use (as strings) with...
10
2009-10-19T18:10:32Z
1,590,317
<p>Are you proposing an extension to <a href="http://docs.python.org/library/urlparse.html#urlparse.urlunparse" rel="nofollow">http://docs.python.org/library/urlparse.html#urlparse.urlunparse</a> that would substitute into the 6-item tuple?</p> <p>Are you talking about something like this?</p> <pre><code>def myUnpars...
4
2009-10-19T18:31:41Z
[ "python", "url" ]
url builder for python
1,590,219
<p>I know about <code>urllib</code> and <code>urlparse</code>, but I want to make sure I wouldn't be reinventing the wheel.</p> <p>My problem is that I am going to be fetching a bunch of urls from the same domain via the <code>urllib</code> library. I basically want to be able to generate urls to use (as strings) with...
10
2009-10-19T18:10:32Z
1,590,700
<p>Still not quite sure what you're looking for... But I'll give it a shot. If you're just looking to make a class that will keep your default values and such, it's simple enough to make your own class and use Python magic like <strong>str</strong>. Here's a scratched-out example (suboptimal):</p> <pre><code>class Url...
3
2009-10-19T19:44:43Z
[ "python", "url" ]
url builder for python
1,590,219
<p>I know about <code>urllib</code> and <code>urlparse</code>, but I want to make sure I wouldn't be reinventing the wheel.</p> <p>My problem is that I am going to be fetching a bunch of urls from the same domain via the <code>urllib</code> library. I basically want to be able to generate urls to use (as strings) with...
10
2009-10-19T18:10:32Z
11,576,693
<p>You might want consider having a look at <a href="https://github.com/gruns/furl/" rel="nofollow">furl</a> because it might be an answer to your needs.</p>
4
2012-07-20T09:34:11Z
[ "python", "url" ]
url builder for python
1,590,219
<p>I know about <code>urllib</code> and <code>urlparse</code>, but I want to make sure I wouldn't be reinventing the wheel.</p> <p>My problem is that I am going to be fetching a bunch of urls from the same domain via the <code>urllib</code> library. I basically want to be able to generate urls to use (as strings) with...
10
2009-10-19T18:10:32Z
35,260,759
<p>I think you want <a href="http://pythonhosted.org/uritools/" rel="nofollow">http://pythonhosted.org/uritools/</a>.</p> <p>Example from the docs:</p> <pre><code>parts = urisplit('foo://user@example.com:8042/over/there?name=ferret#nose') orig_uri = uriunsplit(parts) </code></pre> <p>The split value is a named tupl...
1
2016-02-08T00:03:40Z
[ "python", "url" ]
Cache a django view that has URL parameters
1,590,372
<p>I have recently implemented Django's excellent cache framework. However from what I understand Django will not cache a view that is passed parameters in a get request. I have an Ajax view that is passed get parameters that I would like to cache for X seconds, what would be an easy way to do this?</p> <p>In psuedo c...
9
2009-10-19T18:41:59Z
1,590,735
<p>Right, vary headers is not the correct solution, it's used when you want to cache based on client request headers like user-agent etc. </p> <p>You'll need to use <a href="http://docs.djangoproject.com/en/dev/topics/cache/#the-low-level-cache-api">low-level API</a> or <a href="http://docs.djangoproject.com/en/dev/t...
12
2009-10-19T19:50:09Z
[ "python", "django", "memcached" ]
Cache a django view that has URL parameters
1,590,372
<p>I have recently implemented Django's excellent cache framework. However from what I understand Django will not cache a view that is passed parameters in a get request. I have an Ajax view that is passed get parameters that I would like to cache for X seconds, what would be an easy way to do this?</p> <p>In psuedo c...
9
2009-10-19T18:41:59Z
1,609,369
<p>a bit late, but you can use <a href="http://bitbucket.org/kmike/django-view-cache-utils/" rel="nofollow">django-view-cache-utils</a> for that.</p>
0
2009-10-22T19:13:49Z
[ "python", "django", "memcached" ]
Cache a django view that has URL parameters
1,590,372
<p>I have recently implemented Django's excellent cache framework. However from what I understand Django will not cache a view that is passed parameters in a get request. I have an Ajax view that is passed get parameters that I would like to cache for X seconds, what would be an easy way to do this?</p> <p>In psuedo c...
9
2009-10-19T18:41:59Z
1,640,573
<p>Yes, you can use django-view-cache-utils, here is code for your case:</p> <pre><code>from view_cache_utils import cache_page_with_prefix from django.utils.hashcompat import md5_constructor ... @cache_page_with_prefix(60*15, lambda request: md5_constructor(request.get_full_path()).hexdigest()) def my_view(request): ...
8
2009-10-28T22:34:01Z
[ "python", "django", "memcached" ]
Cache a django view that has URL parameters
1,590,372
<p>I have recently implemented Django's excellent cache framework. However from what I understand Django will not cache a view that is passed parameters in a get request. I have an Ajax view that is passed get parameters that I would like to cache for X seconds, what would be an easy way to do this?</p> <p>In psuedo c...
9
2009-10-19T18:41:59Z
5,446,363
<p>This should be no longer an issue in Django 1.3+. See: <a href="http://docs.djangoproject.com/en/1.3/topics/cache/#using-vary-headers" rel="nofollow">http://docs.djangoproject.com/en/1.3/topics/cache/#using-vary-headers</a></p>
2
2011-03-27T00:26:49Z
[ "python", "django", "memcached" ]
Cache a django view that has URL parameters
1,590,372
<p>I have recently implemented Django's excellent cache framework. However from what I understand Django will not cache a view that is passed parameters in a get request. I have an Ajax view that is passed get parameters that I would like to cache for X seconds, what would be an easy way to do this?</p> <p>In psuedo c...
9
2009-10-19T18:41:59Z
29,379,752
<p>It appears that you no longer need to do anything more complicated than placing @cache_page([length of time]) above your View function you are trying to cache, irrespective of whether you have parameters in the URL.</p> <p>For example, if you have a url like:</p> <pre><code>http://example.com/user/some_user_id </c...
1
2015-03-31T22:34:23Z
[ "python", "django", "memcached" ]
Scheduled tasks in Win32
1,590,474
<p>I have a Scheduled Task on a WinXP SP2 machine that is set up to run a python script:</p> <p><strong>Daily</strong></p> <p><strong>Start time:</strong> 12:03 AM</p> <p><strong>Schedule task daily:</strong> every 1 day</p> <p><strong>Start date:</strong> some time in the past</p> <p><strong>Repeat task:</strong>...
1
2009-10-19T19:03:48Z
1,590,512
<p>What version of Windows are you running?</p> <p>Did you check the "Settings" tab to make sure all of the options are de-selected?</p> <p>You might also consider a more feature rich scheduler such as <a href="http://www.splinterware.com/products/wincron.htm" rel="nofollow">System Scheduler from Splinterware Softwar...
0
2009-10-19T19:11:12Z
[ "python", "windows-xp", "scheduled-tasks" ]
Scheduled tasks in Win32
1,590,474
<p>I have a Scheduled Task on a WinXP SP2 machine that is set up to run a python script:</p> <p><strong>Daily</strong></p> <p><strong>Start time:</strong> 12:03 AM</p> <p><strong>Schedule task daily:</strong> every 1 day</p> <p><strong>Start date:</strong> some time in the past</p> <p><strong>Repeat task:</strong>...
1
2009-10-19T19:03:48Z
1,590,518
<p>On the first pane (labeled "Task") do you have "Run only if logged on" unchecked and "Enabled (scheduled task runs at specified time" checked?</p> <p>I've run python jobs via Windows scheduled task with settings very similar to what you show.</p>
1
2009-10-19T19:12:16Z
[ "python", "windows-xp", "scheduled-tasks" ]
Scheduled tasks in Win32
1,590,474
<p>I have a Scheduled Task on a WinXP SP2 machine that is set up to run a python script:</p> <p><strong>Daily</strong></p> <p><strong>Start time:</strong> 12:03 AM</p> <p><strong>Schedule task daily:</strong> every 1 day</p> <p><strong>Start date:</strong> some time in the past</p> <p><strong>Repeat task:</strong>...
1
2009-10-19T19:03:48Z
1,590,546
<p>you can schedule it from another script and kick this off once a day or after each reboot:</p> <pre><code>#!/usr/bin/env python import subprocess interval = 300 # secs while True: p = subprocess.Popen(['pythonw.exe', 'foo.py']) time.sleep(interval) </code></pre> <p>This way you can do sub-minute interv...
3
2009-10-19T19:15:42Z
[ "python", "windows-xp", "scheduled-tasks" ]
Scheduled tasks in Win32
1,590,474
<p>I have a Scheduled Task on a WinXP SP2 machine that is set up to run a python script:</p> <p><strong>Daily</strong></p> <p><strong>Start time:</strong> 12:03 AM</p> <p><strong>Schedule task daily:</strong> every 1 day</p> <p><strong>Start date:</strong> some time in the past</p> <p><strong>Repeat task:</strong>...
1
2009-10-19T19:03:48Z
1,590,558
<p>Also, for the past year or so I've seen a common bug where Scheduled Tasks on Server 2003 or XP do not run if either of the following checkboxes are on:</p> <ul> <li>"Don't start the task if the computer is running on batteries"</li> <li>"Stop the task if battery mode begins"</li> </ul> <p>It seems that Windows ge...
1
2009-10-19T19:17:08Z
[ "python", "windows-xp", "scheduled-tasks" ]
Scheduled tasks in Win32
1,590,474
<p>I have a Scheduled Task on a WinXP SP2 machine that is set up to run a python script:</p> <p><strong>Daily</strong></p> <p><strong>Start time:</strong> 12:03 AM</p> <p><strong>Schedule task daily:</strong> every 1 day</p> <p><strong>Start date:</strong> some time in the past</p> <p><strong>Repeat task:</strong>...
1
2009-10-19T19:03:48Z
1,590,857
<p>From what I know, Scheduled Tasks is horrible. You should use something with better control like </p> <p><a href="http://cronw.sourceforge.net/" rel="nofollow">http://cronw.sourceforge.net/</a> or any other implementation of cron for Windows.</p>
1
2009-10-19T20:16:23Z
[ "python", "windows-xp", "scheduled-tasks" ]
Scheduled tasks in Win32
1,590,474
<p>I have a Scheduled Task on a WinXP SP2 machine that is set up to run a python script:</p> <p><strong>Daily</strong></p> <p><strong>Start time:</strong> 12:03 AM</p> <p><strong>Schedule task daily:</strong> every 1 day</p> <p><strong>Start date:</strong> some time in the past</p> <p><strong>Repeat task:</strong>...
1
2009-10-19T19:03:48Z
1,590,873
<p>Until: Duration 24 hours</p> <p>That shuts it off at the end of the first day.</p> <p>Remove that, see if it keeps going. It should, and you shouldn't need to install Python in the process. :)</p>
1
2009-10-19T20:19:01Z
[ "python", "windows-xp", "scheduled-tasks" ]
Scheduled tasks in Win32
1,590,474
<p>I have a Scheduled Task on a WinXP SP2 machine that is set up to run a python script:</p> <p><strong>Daily</strong></p> <p><strong>Start time:</strong> 12:03 AM</p> <p><strong>Schedule task daily:</strong> every 1 day</p> <p><strong>Start date:</strong> some time in the past</p> <p><strong>Repeat task:</strong>...
1
2009-10-19T19:03:48Z
1,591,169
<p>At the risk of not answering your question, can I suggest that if what you have to run is important or even critical then Windows task-Scheduler is not the way to run it. </p> <p>There are so many awful flows when using the task-scheduler. Lets just start with the obvious ones:</p> <p>There is no logging. There is...
1
2009-10-19T21:09:32Z
[ "python", "windows-xp", "scheduled-tasks" ]
Python Deprecation Warnings with Monostate __new__ -- Can someone explain why?
1,590,477
<p>I have a basic Monostate with Python 2.6.</p> <pre><code>class Borg(object): __shared_state = {} def __new__(cls, *args, **kwargs): self = object.__new__(cls, *args, **kwargs) self.__dict__ = cls.__shared_state return self def __init__(self, *args, **kwargs): noSend = kw...
5
2009-10-19T19:04:28Z
1,590,517
<p>The warning comes from the fact that <code>__new__()</code> can HAVE args, but since they're ignored everywhere, passing args (other than cls) to it causes the warning. It's not actually (currently) an error to pass the extra args, but they have no effect. </p> <p>In py3k it will become an error to pass the args.</...
1
2009-10-19T19:12:15Z
[ "python", "deprecated", "monostate" ]
Python Deprecation Warnings with Monostate __new__ -- Can someone explain why?
1,590,477
<p>I have a basic Monostate with Python 2.6.</p> <pre><code>class Borg(object): __shared_state = {} def __new__(cls, *args, **kwargs): self = object.__new__(cls, *args, **kwargs) self.__dict__ = cls.__shared_state return self def __init__(self, *args, **kwargs): noSend = kw...
5
2009-10-19T19:04:28Z
1,590,586
<p>See <a href="http://stackoverflow.com/questions/1363839/python-singleton-object-instantiation">python-singleton-object-instantiation</a>, and note <a href="http://stackoverflow.com/users/95810/alex-martelli">Alex Martelli's</a> singleton example:</p> <pre><code>class Singleton(object): __instance = None d...
6
2009-10-19T19:22:52Z
[ "python", "deprecated", "monostate" ]
Is it possible to forward-declare a function in Python?
1,590,608
<p>Is it possible to forward-declare a function in Python? I want to sort a list using my own <code>cmp</code> function before it is declared. </p> <pre><code>print "\n".join([str(bla) for bla in sorted(mylist, cmp = cmp_configs)]) </code></pre> <p>I've organized my code to put the definition of <code>cmp_configs</...
80
2009-10-19T19:29:21Z
1,590,632
<p>"just reorganize my code so that I don't have this problem." Correct. Easy to do. Always works.</p> <p>You can always provide the function prior to it's reference.</p> <p>"However, there are cases when this is probably unavoidable, for instance when implementing some forms of recursion"</p> <p>Can't see how th...
0
2009-10-19T19:33:09Z
[ "python", "forward-declaration" ]
Is it possible to forward-declare a function in Python?
1,590,608
<p>Is it possible to forward-declare a function in Python? I want to sort a list using my own <code>cmp</code> function before it is declared. </p> <pre><code>print "\n".join([str(bla) for bla in sorted(mylist, cmp = cmp_configs)]) </code></pre> <p>I've organized my code to put the definition of <code>cmp_configs</...
80
2009-10-19T19:29:21Z
1,590,640
<p>If you kick-start your script through the following:</p> <pre><code>if __name__=="__main__": main() </code></pre> <p>then you probably do not have to worry about things like "forward declaration". You see, the interpreter would go loading up all your functions and then start your main() function. Of course, m...
45
2009-10-19T19:33:53Z
[ "python", "forward-declaration" ]
Is it possible to forward-declare a function in Python?
1,590,608
<p>Is it possible to forward-declare a function in Python? I want to sort a list using my own <code>cmp</code> function before it is declared. </p> <pre><code>print "\n".join([str(bla) for bla in sorted(mylist, cmp = cmp_configs)]) </code></pre> <p>I've organized my code to put the definition of <code>cmp_configs</...
80
2009-10-19T19:29:21Z
1,590,655
<p>What you can do is to wrap the invocation into a function of its own.</p> <p>So that</p> <pre><code>foo() def foo(): print "Hi!" </code></pre> <p>will break, but</p> <pre><code>def bar(): foo() def foo(): print "Hi!" bar() </code></pre> <p>will be working properly.</p> <p>General rule in <code>P...
47
2009-10-19T19:36:32Z
[ "python", "forward-declaration" ]
Is it possible to forward-declare a function in Python?
1,590,608
<p>Is it possible to forward-declare a function in Python? I want to sort a list using my own <code>cmp</code> function before it is declared. </p> <pre><code>print "\n".join([str(bla) for bla in sorted(mylist, cmp = cmp_configs)]) </code></pre> <p>I've organized my code to put the definition of <code>cmp_configs</...
80
2009-10-19T19:29:21Z
1,590,657
<p>If you don't want to define a function <em>before</em> it's used, and defining it <em>afterwards</em> is impossible, what about defining it in some other module?</p> <p>Technically you still define it first, but it's clean.</p> <p>You could create a recursion like the following:</p> <pre><code>def foo(): bar(...
42
2009-10-19T19:36:50Z
[ "python", "forward-declaration" ]
Is it possible to forward-declare a function in Python?
1,590,608
<p>Is it possible to forward-declare a function in Python? I want to sort a list using my own <code>cmp</code> function before it is declared. </p> <pre><code>print "\n".join([str(bla) for bla in sorted(mylist, cmp = cmp_configs)]) </code></pre> <p>I've organized my code to put the definition of <code>cmp_configs</...
80
2009-10-19T19:29:21Z
1,590,660
<p>No, I don't believe there is any way to forward-declare a function in Python.</p> <p>Imagine you are the Python interpreter. When you get to the line </p> <pre><code>print "\n".join([str(bla) for bla in sorted(mylist, cmp = cmp_configs)]) </code></pre> <p>either you know what cmp_configs is or you don't. In order...
7
2009-10-19T19:37:31Z
[ "python", "forward-declaration" ]
Is it possible to forward-declare a function in Python?
1,590,608
<p>Is it possible to forward-declare a function in Python? I want to sort a list using my own <code>cmp</code> function before it is declared. </p> <pre><code>print "\n".join([str(bla) for bla in sorted(mylist, cmp = cmp_configs)]) </code></pre> <p>I've organized my code to put the definition of <code>cmp_configs</...
80
2009-10-19T19:29:21Z
1,590,664
<p>If the call to cmp_configs is inside its own function definition, you should be fine. I'll give an example.</p> <pre><code>def a(): b() # b() hasn't been defined yet, but that's fine because at this point, we're not # actually calling it. We're just defining what should happen when a() is called. a() # ...
8
2009-10-19T19:38:52Z
[ "python", "forward-declaration" ]
Is it possible to forward-declare a function in Python?
1,590,608
<p>Is it possible to forward-declare a function in Python? I want to sort a list using my own <code>cmp</code> function before it is declared. </p> <pre><code>print "\n".join([str(bla) for bla in sorted(mylist, cmp = cmp_configs)]) </code></pre> <p>I've organized my code to put the definition of <code>cmp_configs</...
80
2009-10-19T19:29:21Z
1,590,687
<p>There is no such thing in python like forward declaration. You just have to make sure that your function is declared before it is needed. Note that the body of a function isn't interpreted until the function is executed.</p> <p>Consider the following example:</p> <pre><code>def a(): b() # won't be resolved unti...
5
2009-10-19T19:42:13Z
[ "python", "forward-declaration" ]
Is it possible to forward-declare a function in Python?
1,590,608
<p>Is it possible to forward-declare a function in Python? I want to sort a list using my own <code>cmp</code> function before it is declared. </p> <pre><code>print "\n".join([str(bla) for bla in sorted(mylist, cmp = cmp_configs)]) </code></pre> <p>I've organized my code to put the definition of <code>cmp_configs</...
80
2009-10-19T19:29:21Z
1,590,765
<p>Now wait a minute. When your module reaches the print statement in your example, before <code>cmp_configs</code> has been defined, what exactly is it that you expect it to do?</p> <p>If your posting of a question using print is really trying to represent something like this:</p> <pre><code>fn = lambda mylist:"\n"...
0
2009-10-19T19:56:39Z
[ "python", "forward-declaration" ]
Is it possible to forward-declare a function in Python?
1,590,608
<p>Is it possible to forward-declare a function in Python? I want to sort a list using my own <code>cmp</code> function before it is declared. </p> <pre><code>print "\n".join([str(bla) for bla in sorted(mylist, cmp = cmp_configs)]) </code></pre> <p>I've organized my code to put the definition of <code>cmp_configs</...
80
2009-10-19T19:29:21Z
1,592,524
<p>You can't forward-declare a function in Python. If you have logic executing before you've defined functions, you've probably got a problem anyways. Put your action in an <code>if __name__ == '__main__'</code> at the end of your script (by executing a function you name "main" if it's non-trivial) and your code will b...
2
2009-10-20T04:53:42Z
[ "python", "forward-declaration" ]
Is it possible to forward-declare a function in Python?
1,590,608
<p>Is it possible to forward-declare a function in Python? I want to sort a list using my own <code>cmp</code> function before it is declared. </p> <pre><code>print "\n".join([str(bla) for bla in sorted(mylist, cmp = cmp_configs)]) </code></pre> <p>I've organized my code to put the definition of <code>cmp_configs</...
80
2009-10-19T19:29:21Z
10,797,465
<p>Sometimes an algorithm is easiest to understand top-down, starting with the overall structure and drilling down into the details.</p> <p>You can do so without forward declarations:</p> <pre><code>def main(): make_omelet() eat() def make_omelet(): break_eggs() whisk() fry() def break_eggs(): for egg i...
5
2012-05-29T10:37:36Z
[ "python", "forward-declaration" ]
Is it possible to forward-declare a function in Python?
1,590,608
<p>Is it possible to forward-declare a function in Python? I want to sort a list using my own <code>cmp</code> function before it is declared. </p> <pre><code>print "\n".join([str(bla) for bla in sorted(mylist, cmp = cmp_configs)]) </code></pre> <p>I've organized my code to put the definition of <code>cmp_configs</...
80
2009-10-19T19:29:21Z
18,039,692
<p>One way is to create a handler function. Define the handler early on, and put the handler below all the methods you need to call. </p> <p>Then when you invoke the handler method to call your functions, they will always be available.</p> <p>The handler could take an argument <code>nameOfMethodToCall</code>. Then u...
-2
2013-08-04T04:24:25Z
[ "python", "forward-declaration" ]
Is it possible to forward-declare a function in Python?
1,590,608
<p>Is it possible to forward-declare a function in Python? I want to sort a list using my own <code>cmp</code> function before it is declared. </p> <pre><code>print "\n".join([str(bla) for bla in sorted(mylist, cmp = cmp_configs)]) </code></pre> <p>I've organized my code to put the definition of <code>cmp_configs</...
80
2009-10-19T19:29:21Z
21,949,524
<p>I apologize for reviving this thread, but there was a strategy not discussed here which may be applicable.</p> <p>Using reflection it is possible to do something akin to forward declaration. For instance lets say you have a section of code that looks like this:</p> <pre><code># We want to call a function called 'f...
3
2014-02-22T04:08:36Z
[ "python", "forward-declaration" ]
Is it possible to forward-declare a function in Python?
1,590,608
<p>Is it possible to forward-declare a function in Python? I want to sort a list using my own <code>cmp</code> function before it is declared. </p> <pre><code>print "\n".join([str(bla) for bla in sorted(mylist, cmp = cmp_configs)]) </code></pre> <p>I've organized my code to put the definition of <code>cmp_configs</...
80
2009-10-19T19:29:21Z
28,533,518
<p>Theres a hackish way to do it as follows:</p> <pre><code>bar = None def foo(): print "foo", bar() def bar(): print "bar" foo() </code></pre> <p>By declaring a null value (or really anything) for bar before hand, it now has an entry in the dictionary. Assuming you dont try and call foo before bar is dec...
2
2015-02-16T02:00:49Z
[ "python", "forward-declaration" ]
How to use twistedweb with django on windows
1,590,651
<p>I'm looking for a super easy way to deploy django application on windows.</p> <p>Basically my plan is to set up any python web server with my app on it and the boundle everything together using py2exe into a single executable.</p> <p>I've tried using cherrypy however the newest (3.1.2) server doesn't work with Win...
0
2009-10-19T19:35:49Z
1,591,690
<p>I would rather suggest <a href="http://en.wlmp-project.net/downloads.php?cat=lighty" rel="nofollow">Portable LightTPD</a> (i.e. the .zip) and <a href="http://www.portablepython.com/wiki/Download" rel="nofollow">Portable Python</a>. It is very easy to set up LightTPD for FastCGI, and very easy to set up sqlite and F...
0
2009-10-19T23:22:41Z
[ "python", "windows", "django", "twisted" ]
How to use twistedweb with django on windows
1,590,651
<p>I'm looking for a super easy way to deploy django application on windows.</p> <p>Basically my plan is to set up any python web server with my app on it and the boundle everything together using py2exe into a single executable.</p> <p>I've tried using cherrypy however the newest (3.1.2) server doesn't work with Win...
0
2009-10-19T19:35:49Z
1,593,040
<p>I've found quite nice <a href="http://blog.dreid.org/2009/03/twisted-django-it-wont-burn-down-your.html" rel="nofollow">blog entry</a> describing how to run django on twisted trunk.</p> <p>Here is an example that merge twisted with django app into one file so it can be used from file created by py2exe:</p> <pre><c...
0
2009-10-20T07:48:14Z
[ "python", "windows", "django", "twisted" ]
Python| How can I make this variable global without initializing it as 'global'
1,590,712
<p>I have this code here. The only part I can add code to is in main_____ AFTER the 'i=1' line. This script will be executing multiple times and will have some variable (might not be 'i', could be 'xy', 'var', anything), incrementing by 1 each time. I have gotten this to work by declaring 'i' as global above the method...
-3
2009-10-19T19:45:51Z
1,591,050
<p>If you want to use a global variable you have to declare it as global. What's wrong with that?</p> <p>If you need to store state between calls, you should be using a class</p> <pre><code>&gt;&gt;&gt; class F(): ... def __init__(self): ... self.i=0 ... def __call__(self): ... print self.i .....
1
2009-10-19T20:46:13Z
[ "python", "global" ]