title stringlengths 10 172 | question_id int64 469 40.1M | question_body stringlengths 22 48.2k | question_score int64 -44 5.52k | question_date stringlengths 20 20 | answer_id int64 497 40.1M | answer_body stringlengths 18 33.9k | answer_score int64 -38 8.38k | answer_date stringlengths 20 20 | tags list |
|---|---|---|---|---|---|---|---|---|---|
Why is python decode replacing more than the invalid bytes from an encoded string? | 2,547,262 | <p>Trying to decode an invalid encoded utf-8 html page gives different results in
python, firefox and chrome.</p>
<p>The invalid encoded fragment from test page looks like <code>'PREFIX\xe3\xabSUFFIX'</code></p>
<pre><code>>>> fragment = 'PREFIX\xe3\xabSUFFIX'
>>> fragment.decode('utf-8', 'strict')
... | 24 | 2010-03-30T17:33:46Z | 2,548,480 | <p>You know that your S is valid, with the benefit of both look-ahead and hindsight :-) Suppose there was originally a legal 3-byte UTF-8 sequence there, and the 3rd byte was corrupted in transmission ... with the change that you mention, you'd be complaining that a spurious S had not been replaced. There is no "right"... | 7 | 2010-03-30T20:31:45Z | [
"python",
"security",
"unicode",
"screen-scraping"
] |
Scipy.cluster.hierarchy.fclusterdata + distance measure | 2,547,391 | <p>1) I am using scipy's hcluster module.</p>
<p>so the variable that I have control over is the threshold variable.
How do I know my performance per threshold? i.e. In Kmeans, this performance will be the sum of all the points to their centroids. Of course, this has to be adjusted since more clusters = less distance... | 6 | 2010-03-30T17:53:34Z | 2,913,071 | <p>One can calculate average distances |x - cluster centre| for x in cluster, just as for K-means.
The following does this brute-force. (It must be a builtin
in scipy.cluster or scipy.spatial.distance but I can't find it either.)</p>
<p>On your question 2, pass. Any links to good tutorials on hierarchical clustering w... | 4 | 2010-05-26T12:50:52Z | [
"python",
"cluster-analysis",
"scipy"
] |
Why does a JRuby application on App Engine take so long to start (versus a Python app)? | 2,547,498 | <p>I'm considering using JRuby on App Engine but have heard that Juby app on App Engine have a long startup lag versus a Python app. Why is this? </p>
<p>Is it because the JRuby jar files are so large that a cold startup requires them to be loaded into memory before the app can start serving? That would be my guess b... | 4 | 2010-03-30T18:11:20Z | 2,547,521 | <p>That's basically it. When your app hasn't been used in a while, App Engine swaps it out until another request comes in.</p>
<p>When that happens, it loads all the JARs your app requires, which may take a very long time, upwards of 10-15+ seconds in some cases.</p>
<p>I don't have any experience with JRuby in parti... | 10 | 2010-03-30T18:15:12Z | [
"java",
"python",
"ruby",
"google-app-engine",
"jruby"
] |
Why does a JRuby application on App Engine take so long to start (versus a Python app)? | 2,547,498 | <p>I'm considering using JRuby on App Engine but have heard that Juby app on App Engine have a long startup lag versus a Python app. Why is this? </p>
<p>Is it because the JRuby jar files are so large that a cold startup requires them to be loaded into memory before the app can start serving? That would be my guess b... | 4 | 2010-03-30T18:11:20Z | 2,551,179 | <p><em>Disclaimer: I haven't benchmarked this myself</em></p>
<p>The difference between the Python version and JRuby in particular
probably have lots to do with the fact that JRuby is a language
implemented on top of another language. The Python engine on the other
hand is native, and much closer to CPython (some in-h... | 0 | 2010-03-31T07:35:44Z | [
"java",
"python",
"ruby",
"google-app-engine",
"jruby"
] |
Python unicode issues (2.6) | 2,547,517 | <p>I'm currently working on a irc bot for a multi-lingual channel, and I'm encountering some issues with unicode which are proving nearly impossible to solve. </p>
<p>No matter what configuration of unicode encoding I seem to try, the list function which the below code sits within just flat out does nothing (c.notice ... | 0 | 2010-03-30T18:14:33Z | 2,547,688 | <p>A few points:</p>
<ul>
<li>The bytes "天åÂ" are the UTF-8 encoding of "天å", so are you sure it's wrong that this is sent? Does the program/... that should process the data use UTF-8, or does it just interpret the input as a different encoding like Latin-1?</li>
<li><code>unicode(uk,"utf-8").encode("utf-8"... | 1 | 2010-03-30T18:35:32Z | [
"python",
"unicode",
"encoding",
"utf-8",
"irc"
] |
Python unicode issues (2.6) | 2,547,517 | <p>I'm currently working on a irc bot for a multi-lingual channel, and I'm encountering some issues with unicode which are proving nearly impossible to solve. </p>
<p>No matter what configuration of unicode encoding I seem to try, the list function which the below code sits within just flat out does nothing (c.notice ... | 0 | 2010-03-30T18:14:33Z | 2,549,294 | <p>Change this:</p>
<pre><code>u"Current list of faq entries: %s" % (uk)
</code></pre>
<p>into this:</p>
<pre><code>"Current list of faq entries: %s" % (uk)
</code></pre>
<p>and try again. Make sure that <code>uk</code> is already a UTF-8 encoded string (not unicode).</p>
<p>I assume that the c.notice method takes... | 0 | 2010-03-30T22:58:14Z | [
"python",
"unicode",
"encoding",
"utf-8",
"irc"
] |
Python unicode issues (2.6) | 2,547,517 | <p>I'm currently working on a irc bot for a multi-lingual channel, and I'm encountering some issues with unicode which are proving nearly impossible to solve. </p>
<p>No matter what configuration of unicode encoding I seem to try, the list function which the below code sits within just flat out does nothing (c.notice ... | 0 | 2010-03-30T18:14:33Z | 2,550,329 | <p>Turns out the issue was with the client I was using to test the output - it wasn't handling unicode properly itself!</p>
| 1 | 2010-03-31T03:31:52Z | [
"python",
"unicode",
"encoding",
"utf-8",
"irc"
] |
Official multiple Python versions on the same machine? | 2,547,554 | <p>Is there official documentation on the Python website somewhere, on how to install and run multiple versions of Python on the same machine on Linux?</p>
<p>I can find gazillions of blog posts and answers, but I want to know if there is a "standard" official way of doing this?</p>
<p>Or is this all dependent on OS?... | 40 | 2010-03-30T18:19:35Z | 2,547,576 | <p>It's most strongly dependent on the package distribution system you use. For example, with MacPorts, you can install multiple Python packages and use the <code>pyselect</code> utility to switch the default between them with ease. At all times, you're able to call the different Python interpreters by providing the f... | 0 | 2010-03-30T18:23:08Z | [
"python"
] |
Official multiple Python versions on the same machine? | 2,547,554 | <p>Is there official documentation on the Python website somewhere, on how to install and run multiple versions of Python on the same machine on Linux?</p>
<p>I can find gazillions of blog posts and answers, but I want to know if there is a "standard" official way of doing this?</p>
<p>Or is this all dependent on OS?... | 40 | 2010-03-30T18:19:35Z | 2,547,577 | <p>I think it is totally independent. Just install them, then you have the commands e.g. <code>/usr/bin/python2.5</code> and <code>/usr/bin/python2.6</code>. Link <code>/usr/bin/python</code> to the one you want to use as default. </p>
<p>All the libraries are in separate folders (named after the version) anyway.</p>
... | 42 | 2010-03-30T18:23:27Z | [
"python"
] |
Official multiple Python versions on the same machine? | 2,547,554 | <p>Is there official documentation on the Python website somewhere, on how to install and run multiple versions of Python on the same machine on Linux?</p>
<p>I can find gazillions of blog posts and answers, but I want to know if there is a "standard" official way of doing this?</p>
<p>Or is this all dependent on OS?... | 40 | 2010-03-30T18:19:35Z | 2,547,801 | <p>On Windows they get installed to separate folders, "C:\python26" and "C:\python31", but the executables have the same "python.exe" name. </p>
<p>I created another "C:\python" folder that contains "python.bat" and "python3.bat" that serve as wrappers to "python26" and "python31" respectively, and added "C:\python" ... | 16 | 2010-03-30T18:51:13Z | [
"python"
] |
Official multiple Python versions on the same machine? | 2,547,554 | <p>Is there official documentation on the Python website somewhere, on how to install and run multiple versions of Python on the same machine on Linux?</p>
<p>I can find gazillions of blog posts and answers, but I want to know if there is a "standard" official way of doing this?</p>
<p>Or is this all dependent on OS?... | 40 | 2010-03-30T18:19:35Z | 12,704,698 | <p>How to install different Python versions is indeed OS dependent.</p>
<p>However, if you're on linux, you can use a tool like <a href="https://github.com/utahta/pythonbrew" rel="nofollow">pythonbrew</a> or <a href="https://github.com/saghul/pythonz" rel="nofollow">pythonz</a> to help you easily manage and switch bet... | 3 | 2012-10-03T08:36:18Z | [
"python"
] |
Python: fetching SVG file using urllib is returning binary when I need ASCII | 2,547,937 | <p>I'm using urllib (in Python) to fetch an SVG file:</p>
<pre><code>import urllib
urllib.urlopen('http://alpha.vectors.cloudmade.com/BC9A493B41014CAABB98F0471D759707/-122.2487,37.87588,-122.265823,37.868054?styleid=1&viewport=400x231').read()
</code></pre>
<p>which produces output of the sort:</p>
<pre><code>x... | 2 | 2010-03-30T19:07:39Z | 2,547,996 | <p>It's gzip-compressed (check the <code>Content-Encoding</code> HTTP header). You can use the <a href="http://docs.python.org/library/gzip.html" rel="nofollow"><code>gzip</code></a> module to decompress it.</p>
| 2 | 2010-03-30T19:17:06Z | [
"python",
"ascii",
"urllib",
"binary-data"
] |
How to sort a dictionary having keys as a string of numbers in Python | 2,548,000 | <p>I have a dictionary:</p>
<pre><code>a = {'100':12,'6':5,'88':3,'test':34, '67':7,'1':64 }
</code></pre>
<p>I want to sort this dictionary with respect to key so it looks like:</p>
<pre><code>a = {'1':64,'6':5,'67':7,'88':3, '100':12,'test':34 }
</code></pre>
| 5 | 2010-03-30T19:17:30Z | 2,548,038 | <p>Dictionaries are unordered. You cannot sort one like you show because the resultant <code>a</code> is a dict, and dicts do not have order.</p>
<p>If you want, say, a list a list of the keys in sorted order, you can use code like</p>
<pre><code>>>> def my_key(dict_key):
... try:
... return int(... | 4 | 2010-03-30T19:23:17Z | [
"python"
] |
How to sort a dictionary having keys as a string of numbers in Python | 2,548,000 | <p>I have a dictionary:</p>
<pre><code>a = {'100':12,'6':5,'88':3,'test':34, '67':7,'1':64 }
</code></pre>
<p>I want to sort this dictionary with respect to key so it looks like:</p>
<pre><code>a = {'1':64,'6':5,'67':7,'88':3, '100':12,'test':34 }
</code></pre>
| 5 | 2010-03-30T19:17:30Z | 2,548,064 | <p>You cannot sort a <code>dict</code> in Python as the <code>dict</code> type is inherently unordered. What you can do is sort the items before you used them using the <code>sorted()</code> built in function. You will also need a helper function to distinguish between your numerical and string keys:</p>
<pre><code>de... | 5 | 2010-03-30T19:27:40Z | [
"python"
] |
How to sort a dictionary having keys as a string of numbers in Python | 2,548,000 | <p>I have a dictionary:</p>
<pre><code>a = {'100':12,'6':5,'88':3,'test':34, '67':7,'1':64 }
</code></pre>
<p>I want to sort this dictionary with respect to key so it looks like:</p>
<pre><code>a = {'1':64,'6':5,'67':7,'88':3, '100':12,'test':34 }
</code></pre>
| 5 | 2010-03-30T19:17:30Z | 2,548,078 | <p>9 years ago I posted a <a href="http://code.activestate.com/recipes/52306-to-sort-a-dictionary/">recipe</a> that <em>starts</em></p>
<blockquote>
<p>Dictionaries can't be sorted -- a
mapping has no ordering!</p>
</blockquote>
<p>and shows how to get sorted <strong>lists</strong> out of a dict's keys and values... | 4 | 2010-03-30T19:30:42Z | [
"python"
] |
How to sort a dictionary having keys as a string of numbers in Python | 2,548,000 | <p>I have a dictionary:</p>
<pre><code>a = {'100':12,'6':5,'88':3,'test':34, '67':7,'1':64 }
</code></pre>
<p>I want to sort this dictionary with respect to key so it looks like:</p>
<pre><code>a = {'1':64,'6':5,'67':7,'88':3, '100':12,'test':34 }
</code></pre>
| 5 | 2010-03-30T19:17:30Z | 2,548,121 | <p>If you install my <a href="http://pypi.python.org/pypi/blist" rel="nofollow">blist</a> package, it includes a <code>sorteddict</code> type. Then you could simply:</p>
<pre><code>from blist import sorteddict
def my_key(dict_key):
try:
return int(dict_key)
except ValueError:
... | 2 | 2010-03-30T19:39:41Z | [
"python"
] |
How to sort a dictionary having keys as a string of numbers in Python | 2,548,000 | <p>I have a dictionary:</p>
<pre><code>a = {'100':12,'6':5,'88':3,'test':34, '67':7,'1':64 }
</code></pre>
<p>I want to sort this dictionary with respect to key so it looks like:</p>
<pre><code>a = {'1':64,'6':5,'67':7,'88':3, '100':12,'test':34 }
</code></pre>
| 5 | 2010-03-30T19:17:30Z | 2,548,252 | <p>Like everyone else has pointed out, dictionaries have their own ordering and you can't just sort them like you would a list.</p>
<p>One thing I would like to add is that, if you just want to go through the elements of a dictionary in sorted order, that's just:</p>
<pre><code>for k in sorted(a):
print k, a[k] #... | 7 | 2010-03-30T19:58:19Z | [
"python"
] |
How do I get the "id" after INSERT into MySQL database with Python? | 2,548,493 | <p>I execute an INSERT INTO statement</p>
<pre><code>cursor.execute("INSERT INTO mytable(height) VALUES(%s)",(height))
</code></pre>
<p>and I want to get the primary key.</p>
<p>My table has 2 columns: </p>
<pre><code>id primary, auto increment
height this is the other column.
</code></pre>
<p>How do I get t... | 85 | 2010-03-30T20:33:32Z | 2,548,531 | <p>Use <code>cursor.lastrowid</code> to get the last row ID inserted on the cursor object, or <code>connection.insert_id()</code> to get the ID from the last insert on that connection.</p>
| 98 | 2010-03-30T20:37:02Z | [
"python",
"mysql",
"database"
] |
How do I get the "id" after INSERT into MySQL database with Python? | 2,548,493 | <p>I execute an INSERT INTO statement</p>
<pre><code>cursor.execute("INSERT INTO mytable(height) VALUES(%s)",(height))
</code></pre>
<p>and I want to get the primary key.</p>
<p>My table has 2 columns: </p>
<pre><code>id primary, auto increment
height this is the other column.
</code></pre>
<p>How do I get t... | 85 | 2010-03-30T20:33:32Z | 2,548,546 | <pre><code>SELECT @@IDENTITY AS 'Identity';
</code></pre>
<p>or</p>
<pre><code>SELECT last_insert_id();
</code></pre>
| 3 | 2010-03-30T20:39:29Z | [
"python",
"mysql",
"database"
] |
How do I get the "id" after INSERT into MySQL database with Python? | 2,548,493 | <p>I execute an INSERT INTO statement</p>
<pre><code>cursor.execute("INSERT INTO mytable(height) VALUES(%s)",(height))
</code></pre>
<p>and I want to get the primary key.</p>
<p>My table has 2 columns: </p>
<pre><code>id primary, auto increment
height this is the other column.
</code></pre>
<p>How do I get t... | 85 | 2010-03-30T20:33:32Z | 3,790,542 | <p>Also, <code>cursor.lastrowid</code> (a dbapi/PEP249 extension supported by MySQLdb):</p>
<pre><code>>>> import MySQLdb
>>> connection = MySQLdb.connect(user='root')
>>> cursor = connection.cursor()
>>> cursor.execute('INSERT INTO sometable VALUES (...)')
1L
>>> connectio... | 86 | 2010-09-24T19:59:58Z | [
"python",
"mysql",
"database"
] |
How do I get the "id" after INSERT into MySQL database with Python? | 2,548,493 | <p>I execute an INSERT INTO statement</p>
<pre><code>cursor.execute("INSERT INTO mytable(height) VALUES(%s)",(height))
</code></pre>
<p>and I want to get the primary key.</p>
<p>My table has 2 columns: </p>
<pre><code>id primary, auto increment
height this is the other column.
</code></pre>
<p>How do I get t... | 85 | 2010-03-30T20:33:32Z | 4,581,359 | <p>Python DBAPI spec also define 'lastrowid' attribute for cursor object, so...</p>
<pre><code>id = cursor.lastrowid
</code></pre>
<p>...should work too, and it's per-connection based obviously.</p>
| 29 | 2011-01-03T00:45:28Z | [
"python",
"mysql",
"database"
] |
working python xml | 2,548,659 | <p>my question is the following, which is the best way of working XML (kml) with python?, especially script serializable.</p>
<p>thanks for your attention and answers</p>
| 1 | 2010-03-30T20:56:43Z | 2,548,703 | <p>For Python and XML I routinely use <code>xml.etree</code> (see its <a href="http://docs.python.org/library/xml.etree.elementtree.html" rel="nofollow">documentation</a>). The good thing with <code>xml.etree</code> is that it's included in the Python standard library. I've heard good things about <a href="http://codes... | 4 | 2010-03-30T21:02:08Z | [
"python",
"xml",
"xml-serialization",
"kml"
] |
working python xml | 2,548,659 | <p>my question is the following, which is the best way of working XML (kml) with python?, especially script serializable.</p>
<p>thanks for your attention and answers</p>
| 1 | 2010-03-30T20:56:43Z | 2,549,093 | <p><a href="http://codespeak.net/lxml/" rel="nofollow">lxml</a> is very fast. With large data its best choice.</p>
<p>Edit: But "Note that lxml does not provide any thread-safety by itself (mainly for performance reasons), so you have to take care when you use parts of the API concurrently."</p>
| 3 | 2010-03-30T22:10:04Z | [
"python",
"xml",
"xml-serialization",
"kml"
] |
working python xml | 2,548,659 | <p>my question is the following, which is the best way of working XML (kml) with python?, especially script serializable.</p>
<p>thanks for your attention and answers</p>
| 1 | 2010-03-30T20:56:43Z | 2,549,393 | <p>For very small and simple things, <code>xml.dom.minidom</code> is the easiest route. If you're looking for something which can handle large files with very little memory usage then you'll want to use an <a href="http://docs.python.org/library/xml.sax.html" rel="nofollow">xml.sax</a> parser.</p>
| 1 | 2010-03-30T23:25:06Z | [
"python",
"xml",
"xml-serialization",
"kml"
] |
Does anyone have any feedback on using Psyco in a wsgi application? | 2,548,705 | <p>Have you tried Psyco in a wsgi application (custom, Pylons, Django...)?</p>
<p>What does your set up look like?</p>
<p>Did you get measurable results?</p>
| 2 | 2010-03-30T21:02:19Z | 2,553,516 | <p>The question you should ask is not did you get measurable results, but does it make your site noticeably faster? Most web applications are not CPU bound, so even if JIT makes them faster, you probably weren't fully utilizing your processor to begin with.</p>
<p>It has been a very long time since I played with psyc... | 2 | 2010-03-31T13:57:54Z | [
"python",
"wsgi"
] |
Does anyone have any feedback on using Psyco in a wsgi application? | 2,548,705 | <p>Have you tried Psyco in a wsgi application (custom, Pylons, Django...)?</p>
<p>What does your set up look like?</p>
<p>Did you get measurable results?</p>
| 2 | 2010-03-30T21:02:19Z | 9,439,466 | <p>Psyco is dead -- its successor is called PyPy. You are unlikely to get any speed increase with an I/O bound application however.</p>
| 1 | 2012-02-24T23:22:52Z | [
"python",
"wsgi"
] |
How to stringfy a swig matrix object in python | 2,548,779 | <p>I am using swig wrapper of <a href="http://openbabel.org/wiki/Developer%3aPython_Tutorial" rel="nofollow">openbabel</a> (written in C++, and supply a python wrapper through swig)</p>
<p>Below i just use it to read a molecule structure file and get the unitcell property of it. </p>
<pre><code>import pybel
for molec... | 4 | 2010-03-30T21:10:50Z | 2,548,966 | <p>Based on this openbabel documentation, it looks like there is a good reason the Python bindings don't come with a nice way to print a <code>matrix3x3 object</code>. The <code>matrix3x3</code> C++ class overloads the <code><<</code> operator, which SWIG will simply ignore:</p>
<p><a href="http://openbabel.org/... | 5 | 2010-03-30T21:42:31Z | [
"python",
"swig"
] |
How to stringfy a swig matrix object in python | 2,548,779 | <p>I am using swig wrapper of <a href="http://openbabel.org/wiki/Developer%3aPython_Tutorial" rel="nofollow">openbabel</a> (written in C++, and supply a python wrapper through swig)</p>
<p>Below i just use it to read a molecule structure file and get the unitcell property of it. </p>
<pre><code>import pybel
for molec... | 4 | 2010-03-30T21:10:50Z | 11,127,657 | <p>Further to the answer from @jhoon, it seems that SWIG doesn't recognise the <em>std::string</em> return type so change the function to return <em>const char*</em>. Also, since it is a function outside the class, you can't use self but you must use SWIG's <em>$self</em> variable.</p>
<p>So, in the SWIG <em>.i</em> f... | 0 | 2012-06-20T20:27:48Z | [
"python",
"swig"
] |
Design pattern for parsing data that will be grouped to two different ways and flipped | 2,548,790 | <p>I'm looking for an easily maintainable and extendable design model for a script to parse an excel workbook into two separate workbooks after pulling data from other locations like the command line, and a database. The high level details are as follows.</p>
<p>I need to parse an excel workbook containing a sheet tha... | 0 | 2010-03-30T21:13:10Z | 2,548,938 | <p>Not sure if I can help, but at the least, sympathy for you I do have :-)</p>
<p>Have you tried using <a href="http://en.wikipedia.org/wiki/Strategy_pattern" rel="nofollow">Strategies</a>? If haven't check out the link, there is even a simple Python example. If your types differ only in the way they handle the URLs,... | 1 | 2010-03-30T21:37:22Z | [
"python",
"design-patterns",
"oop"
] |
How hard is it to modify the Django Models? | 2,548,791 | <p>I am doing geolocation, and Django does not have a PointField. So, I am forced to writing in RAW SQL. GeoDjango, the Django library, does not support the following query for MYSQL databases (can someone verify that for me?)</p>
<pre><code> cursor.execute("SELECT id FROM l_tag WHERE\
(GLength(LineStr... | 1 | 2010-03-30T21:13:20Z | 2,548,827 | <p>Why don't you just extend a class that's already there? Just curious and wish I could help you specifically.</p>
| 0 | 2010-03-30T21:18:13Z | [
"python",
"mysql",
"database",
"django",
"geodjango"
] |
How hard is it to modify the Django Models? | 2,548,791 | <p>I am doing geolocation, and Django does not have a PointField. So, I am forced to writing in RAW SQL. GeoDjango, the Django library, does not support the following query for MYSQL databases (can someone verify that for me?)</p>
<pre><code> cursor.execute("SELECT id FROM l_tag WHERE\
(GLength(LineStr... | 1 | 2010-03-30T21:13:20Z | 2,613,930 | <p>GeoDjango does have a PointField. </p>
<p>It looks like you're trying to do a dwithin field lookup, which does not work on MySQL (as of April 2010), but does in Postgres:</p>
<p>class Tag(Model):
point = PointField()</p>
<p>Tag.objects.filter(point__dwithin=(point,D(mi=4)))</p>
<p>Careful with this kind of q... | 0 | 2010-04-10T15:50:22Z | [
"python",
"mysql",
"database",
"django",
"geodjango"
] |
How to find the filename of a script being run when it is executed from a symlink on linux | 2,548,936 | <p>If I have a python script that is executed via a symlink, is there a way that I can find the path to the script rather than the symlink? I've tried using the methods suggested in <a href="http://stackoverflow.com/questions/1296501/python-find-path-to-file-being-run">this</a> question, but they always return the pa... | 4 | 2010-03-30T21:36:54Z | 2,548,953 | <p><a href="http://docs.python.org/library/os.html#os.readlink" rel="nofollow"><code>os.readlink()</code></a> will resolve a symlink, and <a href="http://docs.python.org/library/os.path.html#os.path.islink" rel="nofollow"><code>os.path.islink()</code></a> will tell you if it's a symlink in the first place.</p>
| 3 | 2010-03-30T21:39:43Z | [
"python",
"linux",
"filenames",
"symlink"
] |
How to find the filename of a script being run when it is executed from a symlink on linux | 2,548,936 | <p>If I have a python script that is executed via a symlink, is there a way that I can find the path to the script rather than the symlink? I've tried using the methods suggested in <a href="http://stackoverflow.com/questions/1296501/python-find-path-to-file-being-run">this</a> question, but they always return the pa... | 4 | 2010-03-30T21:36:54Z | 2,548,964 | <p>You want the <code><a href="http://docs.python.org/library/os.path.html#os.path.realpath">os.path.realpath()</a></code> function.</p>
| 7 | 2010-03-30T21:42:24Z | [
"python",
"linux",
"filenames",
"symlink"
] |
How to find the filename of a script being run when it is executed from a symlink on linux | 2,548,936 | <p>If I have a python script that is executed via a symlink, is there a way that I can find the path to the script rather than the symlink? I've tried using the methods suggested in <a href="http://stackoverflow.com/questions/1296501/python-find-path-to-file-being-run">this</a> question, but they always return the pa... | 4 | 2010-03-30T21:36:54Z | 2,548,985 | <p>I believe you will need to check if the file is a symlink, and if so, get where it is linked to. For example...</p>
<pre><code>try:
print os.readlink(__file__)
except:
print "File is not a symlink"
</code></pre>
| 0 | 2010-03-30T21:44:58Z | [
"python",
"linux",
"filenames",
"symlink"
] |
Is there a Python package similar to Perl's Archive::Extract? | 2,549,134 | <p>I'm looking for a package that will automatically detect the type of and extract an archive (zip, tar.gz, etc). In Perl, this is easy - in Python, I can't find any simple package/class to do it...</p>
| 3 | 2010-03-30T22:19:01Z | 2,549,150 | <p>In Python you can use:</p>
<ul>
<li><a href="http://docs.python.org/library/zipfile.html" rel="nofollow">zipfile</a></li>
<li><a href="http://docs.python.org/library/tarfile.html" rel="nofollow">tarfile</a> - Note: Tarfile can also handle bz2ed and gzipped tar files.</li>
<li><a href="http://docs.python.org/library... | 1 | 2010-03-30T22:21:52Z | [
"python",
"zip",
"gzip",
"extract",
"archive"
] |
Is there a Python package similar to Perl's Archive::Extract? | 2,549,134 | <p>I'm looking for a package that will automatically detect the type of and extract an archive (zip, tar.gz, etc). In Perl, this is easy - in Python, I can't find any simple package/class to do it...</p>
| 3 | 2010-03-30T22:19:01Z | 2,549,598 | <p>Riding off of <a href="http://stackoverflow.com/questions/2549134/is-there-a-python-package-similar-to-perls-archiveextract/2549150#2549150">Mark Byers' response</a>, perhaps you can tie all of these together with <code>mimetypes</code> (also from the standard library). You could identify the type of file, and proc... | 1 | 2010-03-31T00:21:45Z | [
"python",
"zip",
"gzip",
"extract",
"archive"
] |
: in node causing Keyerror in xmlparsing using ElementTree | 2,549,211 | <p>Hi I'm using ElementTree to parse out an xml feed from Kuler. I'm only beginning in python but am stuck here.
The parsing works fine until I attempt to retrieve any nodes containing ':'
e.g kuler:swatchHexColor</p>
<p>Below is a cut down version of the full feed but same structure:</p>
<pre><code><rss xmlns:xs=... | 1 | 2010-03-30T22:38:24Z | 2,549,257 | <p>Based on this <a href="http://effbot.org/zone/element.htm#xml-namespaces" rel="nofollow">article</a> (and comments on this article) I think you have to substitute the namespace name with the actual URI (and remove the colon and put it in <code>{}</code>):</p>
<pre><code>namespace = 'http://kuler.adobe.com/kuler/API... | 1 | 2010-03-30T22:48:37Z | [
"python",
"xml",
"django",
"parsing",
"elementtree"
] |
Exit python program when argument is less than 0 | 2,549,300 | <p>I'd like the program to exit if the input number is less than 0, but sys.exit() isn't doing the trick. This is what I have now:</p>
<pre><code>if len( sys.argv ) > 1:
number = sys.argv[1]
if number <= 0:
print "Invalid number! Must be greater than 0"
sys.exit()
</code></pre>
| 3 | 2010-03-30T23:01:16Z | 2,549,311 | <p>Your test is failing because number is a string.</p>
<pre><code>>>> '-1' <= 0
False
</code></pre>
<p>You need to convert <code>number</code> to an integer:</p>
<pre><code>number = int(sys.argv[1])
</code></pre>
<p>Note that in Python 3.0 your code would have given an error, allowing you to find your ... | 10 | 2010-03-30T23:04:30Z | [
"python"
] |
How do I create a named temporary file on windows in Python? | 2,549,384 | <p>I've got a Python program that needs to create a named temporary file which will be opened and closed a couple times over the course of the program, and should be deleted when the program exits. Unfortunately, none of the options in <code>tempfile</code> seem to work:</p>
<ul>
<li><code>TemporaryFile</code> doesn'... | 9 | 2010-03-30T23:23:06Z | 2,549,537 | <p>If you don't care about the security what is wrong with this?</p>
<pre><code>tmpfile_name = tempfile.mktemp()
# do stuff
os.unlink(tmpfile_name)
</code></pre>
<p>You might be trying to over-engineer this. If you want to make sure that this file is always removed when the program exits, you could wrap your <code>m... | 1 | 2010-03-31T00:04:48Z | [
"python",
"windows",
"temporary-files"
] |
How do I create a named temporary file on windows in Python? | 2,549,384 | <p>I've got a Python program that needs to create a named temporary file which will be opened and closed a couple times over the course of the program, and should be deleted when the program exits. Unfortunately, none of the options in <code>tempfile</code> seem to work:</p>
<ul>
<li><code>TemporaryFile</code> doesn'... | 9 | 2010-03-30T23:23:06Z | 2,566,321 | <p>I have had exactly the same problem when I needed to save an uploaded file to the opened temporary file using the csv module. The most irritating thing was that the filename in WindowsError pointed to the temporary file, but saving the uploading file contents into the StringIO buffer and pushing the buffer data into... | 2 | 2010-04-02T11:14:54Z | [
"python",
"windows",
"temporary-files"
] |
How do I create a named temporary file on windows in Python? | 2,549,384 | <p>I've got a Python program that needs to create a named temporary file which will be opened and closed a couple times over the course of the program, and should be deleted when the program exits. Unfortunately, none of the options in <code>tempfile</code> seem to work:</p>
<ul>
<li><code>TemporaryFile</code> doesn'... | 9 | 2010-03-30T23:23:06Z | 5,422,943 | <p>I needed something similar to this today, and ended up writing my own. I'm using atexit.register() to register a function callback that removes the file when the program exits.</p>
<p>Note that the coding standards for this are slightly different from the typical Python coding standards (camelCase rather than using... | 4 | 2011-03-24T17:15:36Z | [
"python",
"windows",
"temporary-files"
] |
What is the difference between AF_INET and PF_INET constants? | 2,549,461 | <p>Looking at examples about socket programming, we can see that some people use <code>AF_INET</code> while others use <code>PF_INET</code>. In addition, sometimes <a href="http://stackoverflow.com/questions/2384562/double-udp-socket-binding-in-linux/2384605#2384605">both of them are used at the same example</a>. The q... | 26 | 2010-03-30T23:43:54Z | 2,549,477 | <p>I think the <a href="http://en.wikipedia.org/wiki/Berkeley_sockets#Protocol_and_address_families">Wikipedia notes on this</a> sum it up pretty well:</p>
<blockquote>
<p>The original design concept of the socket interface distinguished between protocol types (families) and the specific address types that each may ... | 19 | 2010-03-30T23:50:19Z | [
"python",
"c",
"unix",
"sockets"
] |
Django pagination | get current index of paginated item in page index, (not the page index range itself) | 2,549,549 | <p>I am trying to build a photo gallery with Django.</p>
<p>It is set up by category.</p>
<p>I have paginated the results of a category by n amount of images per page. I want to also use the paginator on the page that shows just the single image and have a prev/next button for the prev/next image in that category. <... | 0 | 2010-03-31T00:09:27Z | 2,550,289 | <p>I think the way you're describing it would work ok because behind the scenes I believe what Django is doing is using an SQL <code>LIMIT</code> to simply let the database do the heavy lifting of sorting out what and how much data to return. Because the database is optimized for doing this type of thing it's probably... | 0 | 2010-03-31T03:18:14Z | [
"python",
"django",
"pagination",
"django-pagination"
] |
Where did Pylons beautiful error handling go? Using Nginx + Paster + Flup#fcgi_thread | 2,549,611 | <p>I need to run my development through nginx due to some complicated subdomain routing rules in my pylons app that wouldn't be handled otherwise.</p>
<p>I had been using lighttpd + paster + Flup#scgi_thread and the nice error reporting by Pylons had been working fine in that environment.</p>
<p>Yesterday I recompile... | 1 | 2010-03-31T00:26:33Z | 2,620,095 | <p>It looks like you are not getting the trackback css from _debug/media/traceback.css You might want to see if you can view the actual CSS and investigate whether nginx should serve your static content directly.</p>
| 0 | 2010-04-12T05:47:52Z | [
"python",
"error-handling",
"nginx",
"pylons",
"paster"
] |
Where did Pylons beautiful error handling go? Using Nginx + Paster + Flup#fcgi_thread | 2,549,611 | <p>I need to run my development through nginx due to some complicated subdomain routing rules in my pylons app that wouldn't be handled otherwise.</p>
<p>I had been using lighttpd + paster + Flup#scgi_thread and the nice error reporting by Pylons had been working fine in that environment.</p>
<p>Yesterday I recompile... | 1 | 2010-03-31T00:26:33Z | 3,199,321 | <p>I would guess that you need to configure Flup to disable its own error handling, so that the nice one one used by Paster could pass through.</p>
| 2 | 2010-07-07T22:12:12Z | [
"python",
"error-handling",
"nginx",
"pylons",
"paster"
] |
How do I do this Database Model in Django? | 2,549,616 | <p>Django currently does not support the "Point" datatype in MySQL. That's why I created my own.</p>
<pre><code>class PointField(models.Field):
def db_type(self):
return 'Point'
class Tag(models.Model):
user = models.ForeignKey(User)
utm = PointField()
</code></pre>
<p>As you can see, this works,... | 1 | 2010-03-31T00:28:01Z | 2,552,104 | <p>Your question is a bit unclear - are you just asking how to calculate the distance between 2 points? Or are you hoping the ORM will give you some functionality to do it?</p>
<p>If the latter, then that's not going to happen without some external assistance; geometry and geography are beyond the remit of most typica... | 0 | 2010-03-31T10:34:29Z | [
"python",
"mysql",
"database",
"django"
] |
Django Form for date range | 2,549,655 | <p>I am trying to come up with a form that lets the user select a date range to generate a web query in Django. I am having errors getting the date to filter with in my view, I am unable to strip the date.</p>
<p>Here is my <code>forms.py</code>:</p>
<pre><code>class ReportFiltersForm(forms.Form):
start_date = fo... | 1 | 2010-03-31T00:35:16Z | 2,549,765 | <p>There are many mistakes you are making here.</p>
<p>First off, to fix your <code>TypeError</code>, you need to cast your data into <code>int</code> like so:</p>
<pre><code>...
sdy = int(request.POST['start_date_year'])
#Do the same with the other 5 fields
</code></pre>
<p>However, this is a really bad way of doin... | 3 | 2010-03-31T01:02:04Z | [
"python",
"django",
"django-forms"
] |
How to concat a string in Python | 2,549,672 | <pre><code>query = "SELECT * FROM mytable WHERE time=%s", (mytime)
</code></pre>
<p>Currently, I"m doing this, but I want to split it into 2 strings (so I can do them separately)</p>
<pre><code>cursor.execute("SELECT * FROM mytable WHERE time=%s",(mytime))
</code></pre>
<p>Then, I want to add a limit %s to it. How c... | 1 | 2010-03-31T00:41:33Z | 2,549,686 | <pre><code>cxn.execute("SELECT * FROM mytable WHERE time=%%s LIMIT %d" % (mylimit,), mytime)
</code></pre>
<p>Or:</p>
<pre><code>cxn.execute("SELECT * FROM mytable WHERE time=%s" + (" LIMIT %d" % (mylimit,)), mytime)
</code></pre>
| 1 | 2010-03-31T00:44:15Z | [
"python"
] |
How to concat a string in Python | 2,549,672 | <pre><code>query = "SELECT * FROM mytable WHERE time=%s", (mytime)
</code></pre>
<p>Currently, I"m doing this, but I want to split it into 2 strings (so I can do them separately)</p>
<pre><code>cursor.execute("SELECT * FROM mytable WHERE time=%s",(mytime))
</code></pre>
<p>Then, I want to add a limit %s to it. How c... | 1 | 2010-03-31T00:41:33Z | 2,550,224 | <p>Being wary of SQL injection, you can dynamically compose your query <a href="http://stackoverflow.com/questions/2549672/how-to-concat-a-string-in-python/2549686#2549686">as Ignacio suggests</a>.</p>
<pre><code>>>> qry = 'SELECT t.mycol FROM mytable t WHERE t.mycol = %%s %s' % 'LIMIT %s,%s'
</code></pre>
<... | 3 | 2010-03-31T03:04:08Z | [
"python"
] |
Intersections of 3D polygons in python | 2,549,708 | <p>Are there any open source tools or libraries (ideally in python) that are available for performing lots of intersections with 3D geometry read from an ESRI shapefile? Most of the tests will be simple line segments vs polygons.</p>
<p>I've looked into OGR 1.7.1 / GEOS 3.2.0, and whilst it loads the data correctly, t... | 3 | 2010-03-31T00:49:19Z | 4,652,154 | <p>A bit late on answer but my python optical ray tracing programme <a href="http://github.com/danieljfarrell/pvtrace" rel="nofollow">pvtrace</a> does exactly this. It would work like this: </p>
<p>1) Define polygon with a a list of points and make a Polygon object</p>
<pre><code>points = [[0,0,0],[0,0.1,0],[0.1,0.1,... | 4 | 2011-01-10T22:17:14Z | [
"python",
"geometry",
"intersection",
"shapefile"
] |
Python - CSV: Large file with rows of different lengths | 2,549,746 | <p>In short, I have a 20,000,000 line csv file that has different row lengths. This is due to archaic data loggers and proprietary formats. We get the end result as a csv file in the following format. MY goal is to insert this file into a postgres database. How Can I do the following:</p>
<ul>
<li>Keep the first 8 col... | 1 | 2010-03-31T00:56:59Z | 2,549,760 | <p>Read a row with <a href="http://docs.python.org/library/csv.html"><code>csv</code></a>, then:</p>
<pre><code>newrow = row[:8] + row[-2:]
</code></pre>
<p>then add your new field and write it out (also with <code>csv</code>).</p>
| 7 | 2010-03-31T01:00:55Z | [
"python",
"parsing",
"csv",
"etl"
] |
Python - CSV: Large file with rows of different lengths | 2,549,746 | <p>In short, I have a 20,000,000 line csv file that has different row lengths. This is due to archaic data loggers and proprietary formats. We get the end result as a csv file in the following format. MY goal is to insert this file into a postgres database. How Can I do the following:</p>
<ul>
<li>Keep the first 8 col... | 1 | 2010-03-31T00:56:59Z | 2,549,777 | <p>You can open the file as a textfile and read the lines one at a time. Are there quoted or escaped commas that don't "split fields"? If not, you can do</p>
<pre><code>with open('thebigfile.csv', 'r') as thecsv:
for line in thecsv:
fields = [f.strip() for f in thecsv.split(',')]
consist = fields... | 2 | 2010-03-31T01:06:35Z | [
"python",
"parsing",
"csv",
"etl"
] |
Python - CSV: Large file with rows of different lengths | 2,549,746 | <p>In short, I have a 20,000,000 line csv file that has different row lengths. This is due to archaic data loggers and proprietary formats. We get the end result as a csv file in the following format. MY goal is to insert this file into a postgres database. How Can I do the following:</p>
<ul>
<li>Keep the first 8 col... | 1 | 2010-03-31T00:56:59Z | 2,549,824 | <p>I would recommend using the <code>csv</code> module. Here's some code based off CSV processing that I've done elsewhere</p>
<pre><code>from __future__ import with_statement
import csv
def process( reader, writer):
for line in reader:
data = row[:8] + row[-2:]
writer.write( data )
def main( inf... | 1 | 2010-03-31T01:19:55Z | [
"python",
"parsing",
"csv",
"etl"
] |
Python - CSV: Large file with rows of different lengths | 2,549,746 | <p>In short, I have a 20,000,000 line csv file that has different row lengths. This is due to archaic data loggers and proprietary formats. We get the end result as a csv file in the following format. MY goal is to insert this file into a postgres database. How Can I do the following:</p>
<ul>
<li>Keep the first 8 col... | 1 | 2010-03-31T00:56:59Z | 2,551,604 | <p>Sorry, you will need to write some code with this one. When you have a huge file like this, it's worth checking all of it to be sure it's consistent with what you expect. If you let the unhappy data into your database, you will never get all of it out.</p>
<p>Remember oddities about CSV: it's a mishmash of a bun... | 1 | 2010-03-31T09:02:12Z | [
"python",
"parsing",
"csv",
"etl"
] |
python socket.recv/sendall call blocking | 2,549,788 | <p>This post is incorrectly tagged 'send' since I cannot create new tags.</p>
<p>I have a very basic question about this simple echo server. Here are some code snippets.</p>
<p>client</p>
<pre><code>while True:
data = raw_input("Enter data: ")
mySock.sendall(data)
echoedData = mySock.recv(1024)
if not echoedData... | 1 | 2010-03-31T01:09:43Z | 2,549,803 | <p>More like, the <code>sendall()</code> call does nothing (since there's no data to send), and thus the <code>recv()</code> call on the <em>client</em> blocks waiting for data, but since nothing was sent to the server, the server never sends any data back since it's also blocked on its initial <code>recv()</code>, and... | 3 | 2010-03-31T01:14:43Z | [
"python",
"sockets",
"send",
"recv"
] |
Converting a Doc object into a string in python | 2,549,789 | <p>I'm using minidom to parse through an xml document. I took the data with yum tags and stored them in a list and calculated the frequency of the words. However, its not storing or reading them as strings in the list. Is there another way to do it? Right now this is what I have:</p>
<pre><code>yumNodes = [node for no... | 0 | 2010-03-31T01:09:46Z | 2,549,905 | <p>Replace</p>
<pre><code>yumlist.append(t.data for t in node.childNodes if t.nodeType == t.TEXT_NODE)
</code></pre>
<p>with the following:</p>
<pre><code>yumlist.append(t.nodeValue for t in node.childNodes if t.nodeType == 3)
</code></pre>
| 0 | 2010-03-31T01:40:45Z | [
"python",
"minidom"
] |
Converting a Doc object into a string in python | 2,549,789 | <p>I'm using minidom to parse through an xml document. I took the data with yum tags and stored them in a list and calculated the frequency of the words. However, its not storing or reading them as strings in the list. Is there another way to do it? Right now this is what I have:</p>
<pre><code>yumNodes = [node for no... | 0 | 2010-03-31T01:09:46Z | 2,550,184 | <p>Not directly related to your question, but as a remark that could improve your code...the pattern</p>
<pre><code>freqDict = {}
...
if word not in freqDict:
freqDict[word] = 1
else:
freqDict[word] += 1
</code></pre>
<p>is usually replaced with</p>
<pre><code>import collections
freqDict = collections.defaul... | 1 | 2010-03-31T02:55:05Z | [
"python",
"minidom"
] |
Using ftplib for multithread uploads | 2,549,829 | <p>I'm trying to do multithread uploads, but get errors.
I guessed that maybe it's impossible to use multithreads with ftplib?</p>
<p>Here comes my code:</p>
<pre><code> class myThread (threading.Thread):
def __init__(self, threadID, src, counter, image_name):
self.threadID = threadID
self.src ... | 1 | 2010-03-31T01:20:41Z | 2,549,898 | <p>Have you tried to put the connection code inside the thread? </p>
<p>In other words, make each thread do their own separate connection with FTP.host() and FTP.login(). The server may not like multiple uploads at the same time on a single connection, because it may be parsing commands one at a time and can't handl... | 5 | 2010-03-31T01:39:32Z | [
"python",
"multithreading",
"ftplib"
] |
Populate a list from xml using python | 2,549,895 | <p>I have an xml file in the following format:</p>
<pre><code><food>
<desert>
cake
<desert>
</food>
<history>
currently in my belly
</history>
</code></pre>
<p>I want to create two list, food and text populated with cake and history in string format. Is there an easy way to do it i... | 1 | 2010-03-31T01:37:43Z | 2,549,901 | <p><a href="http://docs.python.org/library/xml.etree.elementtree.html" rel="nofollow">ElementTree</a> (and the faster compatible implementations in <code>cElementTree</code> and <code>lxml</code>) let you very easily extract information from XML -- as long as the XML is correct and your goals are well defined.</p>
<p>... | 1 | 2010-03-31T01:40:34Z | [
"python",
"xml"
] |
Populate a list from xml using python | 2,549,895 | <p>I have an xml file in the following format:</p>
<pre><code><food>
<desert>
cake
<desert>
</food>
<history>
currently in my belly
</history>
</code></pre>
<p>I want to create two list, food and text populated with cake and history in string format. Is there an easy way to do it i... | 1 | 2010-03-31T01:37:43Z | 2,549,909 | <p>You could <code>import xml.dom</code> and use it to create a DOM tree which you can then read like any other DOM tree</p>
| 0 | 2010-03-31T01:41:37Z | [
"python",
"xml"
] |
Get signal names from numbers in Python | 2,549,939 | <p>Is there a way to map a signal number (e.g. signal.SIGINT) to its respective name (i.e. "SIGINT")?</p>
<p>I'd like to be able to print the name of a signal in the log when I receive it, however I cannot find a map from signal numbers to names in Python, i.e.:</p>
<pre><code>import signal
def signal_handler(signum,... | 29 | 2010-03-31T01:51:47Z | 2,549,950 | <p>There is none, but if you don't mind a little hack, you can generate it like this:</p>
<pre><code>import signal
dict((k, v) for v, k in reversed(sorted(signal.__dict__.items()))
if v.startswith('SIG') and not v.startswith('SIG_'))
</code></pre>
| 21 | 2010-03-31T01:55:40Z | [
"python",
"signals"
] |
Get signal names from numbers in Python | 2,549,939 | <p>Is there a way to map a signal number (e.g. signal.SIGINT) to its respective name (i.e. "SIGINT")?</p>
<p>I'd like to be able to print the name of a signal in the log when I receive it, however I cannot find a map from signal numbers to names in Python, i.e.:</p>
<pre><code>import signal
def signal_handler(signum,... | 29 | 2010-03-31T01:51:47Z | 2,549,955 | <p>Well, <code>help(signal)</code> says at the bottom:</p>
<pre><code>DATA
NSIG = 23
SIGABRT = 22
SIGBREAK = 21
SIGFPE = 8
SIGILL = 4
SIGINT = 2
SIGSEGV = 11
SIGTERM = 15
SIG_DFL = 0
SIG_IGN = 1
</code></pre>
<p>So this should work:</p>
<pre><code>sig_names = {23:"NSIG", 22:"S... | 0 | 2010-03-31T01:56:36Z | [
"python",
"signals"
] |
Get signal names from numbers in Python | 2,549,939 | <p>Is there a way to map a signal number (e.g. signal.SIGINT) to its respective name (i.e. "SIGINT")?</p>
<p>I'd like to be able to print the name of a signal in the log when I receive it, however I cannot find a map from signal numbers to names in Python, i.e.:</p>
<pre><code>import signal
def signal_handler(signum,... | 29 | 2010-03-31T01:51:47Z | 5,596,664 | <p>I found this article when I was in the same situation and figured the handler is only handling one signal at a time, so I don't even need a whole dictionary, just the name of one signal:</p>
<pre><code>sig_name = tuple((v) for v, k in signal.__dict__.iteritems() if k == signum)[0]
</code></pre>
<p>there's probably... | 2 | 2011-04-08T14:34:10Z | [
"python",
"signals"
] |
Get signal names from numbers in Python | 2,549,939 | <p>Is there a way to map a signal number (e.g. signal.SIGINT) to its respective name (i.e. "SIGINT")?</p>
<p>I'd like to be able to print the name of a signal in the log when I receive it, however I cannot find a map from signal numbers to names in Python, i.e.:</p>
<pre><code>import signal
def signal_handler(signum,... | 29 | 2010-03-31T01:51:47Z | 8,527,643 | <p>The Python Standard Library By Example shows this function in the chapter on signals:</p>
<pre><code>SIGNALS_TO_NAMES_DICT = dict((getattr(signal, n), n) \
for n in dir(signal) if n.startswith('SIG') and '_' not in n )
</code></pre>
<p>You can then use it like this:</p>
<pre><code>print "Terminated by signal ... | 10 | 2011-12-15T22:39:19Z | [
"python",
"signals"
] |
Get signal names from numbers in Python | 2,549,939 | <p>Is there a way to map a signal number (e.g. signal.SIGINT) to its respective name (i.e. "SIGINT")?</p>
<p>I'd like to be able to print the name of a signal in the log when I receive it, however I cannot find a map from signal numbers to names in Python, i.e.:</p>
<pre><code>import signal
def signal_handler(signum,... | 29 | 2010-03-31T01:51:47Z | 35,996,948 | <p>With the addition of the <a href="https://docs.python.org/3/library/signal.html"><code>signal.Signals</code></a> <a href="https://docs.python.org/3/library/enum.html#enum.IntEnum"><code>enum</code></a> in Python 3.5 this is now as easy as:</p>
<pre><code>>>> import signal
>>> signal.SIGINT.name
'S... | 10 | 2016-03-14T20:00:56Z | [
"python",
"signals"
] |
Get signal names from numbers in Python | 2,549,939 | <p>Is there a way to map a signal number (e.g. signal.SIGINT) to its respective name (i.e. "SIGINT")?</p>
<p>I'd like to be able to print the name of a signal in the log when I receive it, however I cannot find a map from signal numbers to names in Python, i.e.:</p>
<pre><code>import signal
def signal_handler(signum,... | 29 | 2010-03-31T01:51:47Z | 36,516,025 | <p>Building on <a href="http://stackoverflow.com/a/35996948/2957469">another answer</a>:</p>
<pre><code>import signal
if hasattr(signal, "Signals"):
def _signal_name(signum):
try:
return signal.Signals(signum).name
except ValueError:
pass
else:
def _signal_name(signum):... | 1 | 2016-04-09T11:15:11Z | [
"python",
"signals"
] |
How do I properly unit test a Django session? | 2,550,078 | <p>The behavior of Django sessions changes between "standard" views code and test code, making it unclear how test code is written for sessions. Googling this yields two relevant discussions about this issue:</p>
<ol>
<li><p><a href="http://code.djangoproject.com/ticket/10899" rel="nofollow">Easier manipulation of ses... | 3 | 2010-03-31T02:30:51Z | 11,291,362 | <p>I don't quite understand what do you mean by saying the behavior changes between "standard" view and "test" code, maybe you should elaborate on that.</p>
<p>but regarding how to test the session, I do think there are approaches. </p>
<ol>
<li>you have to understand how django session works, read the unit test for ... | 1 | 2012-07-02T09:54:51Z | [
"python",
"django",
"unit-testing",
"session",
"django-sessions"
] |
How do I write this query in Django? | 2,550,164 | <p>Suppose I have a datetime column.</p>
<pre><code>"SELECT * FROM mytable WHERE thetime < INTERVAL 1 HOUR"
</code></pre>
<p>How do you write this in Django?</p>
| 1 | 2010-03-31T02:49:48Z | 2,550,215 | <pre><code>MyModel.objects.extra(where=['thetime < INTERVAL 1 HOUR'])
</code></pre>
| 0 | 2010-03-31T03:02:46Z | [
"python",
"mysql",
"database",
"django"
] |
Are there any libraries to allow Python or Ruby to get info from SVN? | 2,550,198 | <p>I'm looking for plugins that will allow my codebase to interact with, browse, and poll an SVN server for information about a repository.</p>
<p><a href="http://trac.edgewall.org/" rel="nofollow">Trac</a> can do this, but I was hoping there was an easy-to-use library available to accomplish the task, rather than tro... | 3 | 2010-03-31T02:58:35Z | 2,550,205 | <p><a href="http://pysvn.tigris.org/" rel="nofollow">pysvn</a></p>
| 3 | 2010-03-31T03:00:46Z | [
"python",
"ruby-on-rails",
"ruby",
"svn"
] |
Are there any libraries to allow Python or Ruby to get info from SVN? | 2,550,198 | <p>I'm looking for plugins that will allow my codebase to interact with, browse, and poll an SVN server for information about a repository.</p>
<p><a href="http://trac.edgewall.org/" rel="nofollow">Trac</a> can do this, but I was hoping there was an easy-to-use library available to accomplish the task, rather than tro... | 3 | 2010-03-31T02:58:35Z | 2,550,298 | <p>Apparently Subversion ships with Ruby bindings. There is some information on Ruby SVN bindings <a href="http://www.oneofthewolves.com/2007/03/06/ruby-subversion-bindings-finally-some-documentation/" rel="nofollow">here</a> and <a href="http://alistairisrael.wordpress.com/2007/09/19/using-the-subversion-ruby-bindings... | 2 | 2010-03-31T03:20:46Z | [
"python",
"ruby-on-rails",
"ruby",
"svn"
] |
figuring out objects created 30 min ago in django | 2,550,238 | <p>I have a DateTimeField called created in my model and I would like to get all the objects where created date is 30 min or more. How would query this using MyModel.objects(....) in django?</p>
| 1 | 2010-03-31T03:07:49Z | 2,550,275 | <p>Use this function:</p>
<pre><code>.filter(created__lte=datetime.datetime.now() - datetime.timedelta(seconds=60 * 30))
</code></pre>
| 1 | 2010-03-31T03:14:59Z | [
"python",
"django",
"django-models"
] |
figuring out objects created 30 min ago in django | 2,550,238 | <p>I have a DateTimeField called created in my model and I would like to get all the objects where created date is 30 min or more. How would query this using MyModel.objects(....) in django?</p>
| 1 | 2010-03-31T03:07:49Z | 2,550,282 | <p>Maybe something like:</p>
<pre><code>import datetime
created_time = datetime.datetime.now() - datetime.timedelta(minutes=30)
old_objects = MyModel.objects.filter(created__lte=created_time)
</code></pre>
<p>See <a href="http://docs.djangoproject.com/en/dev/topics/db/queries/" rel="nofollow">http://docs.djangoprojec... | 3 | 2010-03-31T03:15:35Z | [
"python",
"django",
"django-models"
] |
Purpose of SQLAlchemy over MySQLdb | 2,550,292 | <p>Why do people use SQLAlchemy instead of MySQLdb? What advantages does it offer?</p>
| 6 | 2010-03-31T03:19:34Z | 2,550,304 | <p>Easier portability among different DB engines (say that tomorrow you decide you want to move to sqlite, or PostgreSQL, or...), and higher level of abstraction (and thus potentially higher productivity).</p>
<p>Those are some of the <em>good</em> reasons. There are also some bad reasons for using an ORM, such as no... | 9 | 2010-03-31T03:22:16Z | [
"python",
"sql",
"mysql",
"sqlalchemy"
] |
Purpose of SQLAlchemy over MySQLdb | 2,550,292 | <p>Why do people use SQLAlchemy instead of MySQLdb? What advantages does it offer?</p>
| 6 | 2010-03-31T03:19:34Z | 2,550,364 | <p>You don't use SQLAlchemy instead of MySQLdbâyou use SQLAlchemy to access something like MySQLdb, oursql (another MySQL driver that I hear is nicer and has better performance), the sqlite3 module, psycopg2, or whatever other database driver you are using. </p>
<p>An ORM (like SQLAlchemy) helps abstract away the de... | 8 | 2010-03-31T03:43:47Z | [
"python",
"sql",
"mysql",
"sqlalchemy"
] |
Purpose of SQLAlchemy over MySQLdb | 2,550,292 | <p>Why do people use SQLAlchemy instead of MySQLdb? What advantages does it offer?</p>
| 6 | 2010-03-31T03:19:34Z | 2,550,578 | <p>In addition to what Alex said...</p>
<ol>
<li><p>"not wanting to learn SQL" is probably a bad thing, however, if you want to get more non-technical people involved as part of the development process, ORMs do a pretty good job at it because it does push this level of complexity down a level. One of the elements that... | 3 | 2010-03-31T04:55:37Z | [
"python",
"sql",
"mysql",
"sqlalchemy"
] |
how to write re-usable views in django? | 2,550,308 | <p>These are the techniques that I use regularly to make my views reusable:</p>
<ul>
<li>take the template_name as an argument with a default</li>
<li>take an optional extra_context which defaults to empty {}
<ul>
<li>right before the template is rendered the context is updated with the extra_context</li>
<li>for furt... | 0 | 2010-03-31T03:25:08Z | 2,550,339 | <p>I would think that doing all of those puts a large burden on your urlconf to get everything right. Perhaps making a function that takes all that and hardcoding your views to be a glorified wrapper around said function would be better.</p>
| 0 | 2010-03-31T03:35:33Z | [
"python",
"django",
"views"
] |
how to write re-usable views in django? | 2,550,308 | <p>These are the techniques that I use regularly to make my views reusable:</p>
<ul>
<li>take the template_name as an argument with a default</li>
<li>take an optional extra_context which defaults to empty {}
<ul>
<li>right before the template is rendered the context is updated with the extra_context</li>
<li>for furt... | 0 | 2010-03-31T03:25:08Z | 2,550,450 | <blockquote>
<p>whenever the view needs a particular object from the ORM, it attempts to fetch it using any "id" parameter in several ways (e.g. as a slug, as a database id) (this may be a bad practice...)</p>
</blockquote>
<p>So... why not just expect a model instance to be passed in as a parameter? Or a QuerySet ... | 0 | 2010-03-31T04:10:44Z | [
"python",
"django",
"views"
] |
Cheetah pre-compiled template usage | 2,550,323 | <p>For performance reason as suggested <a href="http://packages.python.org/Cheetah/recipes/precompiled.html" rel="nofollow">here</a>, I am studying how to used the pr-compiled template.</p>
<p>I edit <code>hello.tmpl</code> in template directory as</p>
<pre><code>#attr title = "This is my Template"
<html>
&... | 0 | 2010-03-31T03:30:13Z | 2,557,255 | <p>Your main problem is that in runner.py inside <code>myMethod()</code> instead of</p>
<pre><code>print tmpl
</code></pre>
<p>You need</p>
<pre><code>print results
</code></pre>
<p>Additionally, your code has some formatting problems:</p>
<ol>
<li>don't escape the ${title} with a backslash</li>
<li>you need <code... | 0 | 2010-03-31T23:45:06Z | [
"python",
"templates",
"cheetah"
] |
Correct way to put long function calls on multiple lines | 2,550,439 | <p>I have a long function, as seen below:</p>
<pre><code>hash_correct = hashlib.md5(salt + password)).digest().encode("base64")
</code></pre>
<p>I'd like to split it up into two lines but am not sure of the correct way to do this in Python?</p>
<p>Thanks.</p>
| 11 | 2010-03-31T04:07:44Z | 2,550,482 | <p>The coding guidelines limiting length of lines is there, in part, to make the code more readable. In your case of chained method calls, the meaning is not clear. You should pick some temporary variable names for the intermediate values so that a reader of the code can understand the chain easily.</p>
<p>One exam... | 19 | 2010-03-31T04:22:35Z | [
"python",
"multiline"
] |
Correct way to put long function calls on multiple lines | 2,550,439 | <p>I have a long function, as seen below:</p>
<pre><code>hash_correct = hashlib.md5(salt + password)).digest().encode("base64")
</code></pre>
<p>I'd like to split it up into two lines but am not sure of the correct way to do this in Python?</p>
<p>Thanks.</p>
| 11 | 2010-03-31T04:07:44Z | 2,550,510 | <p>Prefer Charles Merram's answer, but I thought this worth noting as working but ugly and to be discouraged. Because '.' is a lexical <a href="http://docs.python.org/reference/lexical_analysis.html#delimiters" rel="nofollow">delimiter</a>, the following worked:</p>
<pre><code>>>> 'abc def' . split()
['abc', ... | 3 | 2010-03-31T04:34:01Z | [
"python",
"multiline"
] |
How do I use Django to insert a Geometry Field into the database? | 2,550,506 | <pre><code>class LocationLog(models.Model):
user = models.ForeignKey(User)
utm = models.GeometryField(spatial_index=True)
</code></pre>
<p>This is my database model. I would like to insert a row.</p>
<p>I want to insert a circle at point -55, 333. With a radius of 10. How can I put this circle into the geomet... | 0 | 2010-03-31T04:32:07Z | 2,550,697 | <p>Solved.
I created a square.</p>
<pre><code>from django.contrib.gis.geos import Polygon
s = Polygon(( (x-rad,y+rad)
,(x+rad,y+rad)
,(x+rad,y-rad)
,(x-rad,y-rad)
,(x-rad,y+rad) )
)
Then you insert "s" into the database as a GeometryField.
</code></p... | 0 | 2010-03-31T05:29:25Z | [
"python",
"mysql",
"database",
"django",
"geometry"
] |
Cheetah with Cherrypy: how to load base templates, and do so automatically on change during development | 2,550,511 | <p>I am working on a cherrypy+cheetah app and would like to improve the development experience.</p>
<p>I have everything working when I manually compile templates beforehand. (Update: This is how things work for production: precompile, don't ship *.tmpl and load templates as regular python modules.) However, during de... | 2 | 2010-03-31T04:34:07Z | 2,550,739 | <p>Try this: </p>
<p>Replace <code>base.tmpl</code> with:</p>
<pre><code>#from Cheetah.Template import Template
#def body
#set $base = Template(file="templates/base.tmpl")
$base.body()
<br/>
This is the extended body
#end def
$body()
<br/>
This is from index
</code></pre>
| 1 | 2010-03-31T05:40:01Z | [
"python",
"template-engine",
"cherrypy",
"cheetah"
] |
Cheetah with Cherrypy: how to load base templates, and do so automatically on change during development | 2,550,511 | <p>I am working on a cherrypy+cheetah app and would like to improve the development experience.</p>
<p>I have everything working when I manually compile templates beforehand. (Update: This is how things work for production: precompile, don't ship *.tmpl and load templates as regular python modules.) However, during de... | 2 | 2010-03-31T04:34:07Z | 2,554,679 | <p>Looks like this question was kind of answered in another SO question. By using the <a href="http://stackoverflow.com/questions/919539/how-do-we-precompile-base-templates-in-cheetah-so-that-include-extends-and-im/933727#933727">cheetah_import</a> function, I can write my methods like this:</p>
<pre><code>@cherrypy.e... | 1 | 2010-03-31T16:30:47Z | [
"python",
"template-engine",
"cherrypy",
"cheetah"
] |
Simulate Network Presence in dbus | 2,550,523 | <p>Is there a way using Python to simulate the presence of an active network connection using dbus? If I call getstate() on the dbus, I'm able to get the current network state. I want to set the current state to 4 (Connection Present). This is because Network Manager is not able to connect using my modem and I use othe... | 0 | 2010-03-31T04:37:41Z | 2,550,541 | <p>Your options are to write something that mocks NetworkManager's D-Bus interface, or to write a module for NetworkManager that supports the tools you use.</p>
| 0 | 2010-03-31T04:42:23Z | [
"python",
"linux",
"dbus"
] |
Simulate Network Presence in dbus | 2,550,523 | <p>Is there a way using Python to simulate the presence of an active network connection using dbus? If I call getstate() on the dbus, I'm able to get the current network state. I want to set the current state to 4 (Connection Present). This is because Network Manager is not able to connect using my modem and I use othe... | 0 | 2010-03-31T04:37:41Z | 2,559,633 | <p>I'm pretty sure that both Pidgin and Empathy assume you're online if you disable NM by right-clicking the Network Manager tray icon and untick <em>Enable Networking</em>. So you can do this when you're connecting via a non-NM mechanism. No code necessary!</p>
<p>(You could write an application which implements the ... | 1 | 2010-04-01T10:17:52Z | [
"python",
"linux",
"dbus"
] |
Python script to get the data from the flex application | 2,550,637 | <p>I am making a simple Python CGI script that collects data(in xml format) from a flex application and I want to insert it into the mysql database . </p>
<p>In perl The script is looks like the following...</p>
<pre><code>my @samplexml=$cgi->param("Items");
my $data=$xml->XMLin("@samplexml");
foreach my $e(@... | 0 | 2010-03-31T05:15:57Z | 2,551,380 | <p>It should be fairly easy to convert this to a Python script. Setting the stage:</p>
<ol>
<li>Python has the <a href="http://docs.python.org/library/cgi.html" rel="nofollow">cgi</a> module.</li>
<li>Get the <a href="http://pypi.python.org/pypi/MySQL-python/1.2.3c1" rel="nofollow">Python-MySQL</a> library (or an equi... | 0 | 2010-03-31T08:16:57Z | [
"python",
"flex",
"cgi"
] |
Python script to get the data from the flex application | 2,550,637 | <p>I am making a simple Python CGI script that collects data(in xml format) from a flex application and I want to insert it into the mysql database . </p>
<p>In perl The script is looks like the following...</p>
<pre><code>my @samplexml=$cgi->param("Items");
my $data=$xml->XMLin("@samplexml");
foreach my $e(@... | 0 | 2010-03-31T05:15:57Z | 2,563,543 | <p>If you're not bound to XML, you can consider pyAMF and flex's remoteobjects or other remoting facilities.</p>
| 0 | 2010-04-01T20:44:11Z | [
"python",
"flex",
"cgi"
] |
Python - List and Loop in one def | 2,550,642 | <p>I'm trying to get the def wfsc_pod1 and wfsc_ip into the same def. I'm not quite sure how to approach the problem. I want wfsc_pod1 to display all the information for name, subnet and gateway. Then wfsc_ip shows the ip addresses below it. I also get a None value when I run it as it. Not sure why. Anything more pytho... | 0 | 2010-03-31T05:17:59Z | 2,550,668 | <p><code>OutageAddress.wfsc_ip</code> returns <code>None</code> because it has no return statement.</p>
| 0 | 2010-03-31T05:24:03Z | [
"python"
] |
Python - List and Loop in one def | 2,550,642 | <p>I'm trying to get the def wfsc_pod1 and wfsc_ip into the same def. I'm not quite sure how to approach the problem. I want wfsc_pod1 to display all the information for name, subnet and gateway. Then wfsc_ip shows the ip addresses below it. I also get a None value when I run it as it. Not sure why. Anything more pytho... | 0 | 2010-03-31T05:17:59Z | 2,550,670 | <p>You get a <code>None</code> because that is what <code>wfsc_ip</code> returns. Functions/methods that don't return anything else return <code>None</code>.</p>
| 0 | 2010-03-31T05:24:15Z | [
"python"
] |
Python - List and Loop in one def | 2,550,642 | <p>I'm trying to get the def wfsc_pod1 and wfsc_ip into the same def. I'm not quite sure how to approach the problem. I want wfsc_pod1 to display all the information for name, subnet and gateway. Then wfsc_ip shows the ip addresses below it. I also get a None value when I run it as it. Not sure why. Anything more pytho... | 0 | 2010-03-31T05:17:59Z | 2,550,671 | <p>You get <code>None</code> from <code>print network.wfsc_ip()</code> because <code>wfsc_ip</code> doesn't <strong>return</strong> anything, which is the same thing as returning <code>None</code> -- what <strong>else</strong> did you expect to get from printing the value of a function that just doesn't return anything... | 0 | 2010-03-31T05:24:32Z | [
"python"
] |
Python - List and Loop in one def | 2,550,642 | <p>I'm trying to get the def wfsc_pod1 and wfsc_ip into the same def. I'm not quite sure how to approach the problem. I want wfsc_pod1 to display all the information for name, subnet and gateway. Then wfsc_ip shows the ip addresses below it. I also get a None value when I run it as it. Not sure why. Anything more pytho... | 0 | 2010-03-31T05:17:59Z | 2,550,693 | <p>First of all, you probably meant to write <code>wfsc_pod1</code> like this:</p>
<pre><code>def wfsc_pod1(self):
return "%s\t%s\t%s" % (self.name[0], self.subnet[0], self.gateway[0])
</code></pre>
<p>and call <code>wfsc_ip</code> like this:</p>
<pre><code>network.wfsc_ip() # no print
</code></pre>
<p>If you w... | 1 | 2010-03-31T05:28:31Z | [
"python"
] |
Python: List of Modules (>>> help('modules') not working) | 2,550,667 | <p>I wanted a list of my modules and was told:</p>
<pre><code>>>> help('modules')
</code></pre>
<p>Would do the trick. But I just get </p>
<blockquote>
<p>Please wait a moment while I gather a
list of all available modules...</p>
</blockquote>
<p>For over 10 minutes before I killed it.</p>
<p>Anyone ... | 3 | 2010-03-31T05:23:56Z | 2,550,694 | <p>If you want to see the modules you have *<em>import</em>*ed (directly or indirectly),</p>
<pre><code>>>> import sys
>>> print sys.modules
</code></pre>
<p><code>help('modules')</code> is about all modules that are <em>available</em> -- i.e. ones you *<em>could</em> import if you wished. It doesn... | 1 | 2010-03-31T05:28:59Z | [
"python",
"ubuntu",
"module"
] |
Python: List of Modules (>>> help('modules') not working) | 2,550,667 | <p>I wanted a list of my modules and was told:</p>
<pre><code>>>> help('modules')
</code></pre>
<p>Would do the trick. But I just get </p>
<blockquote>
<p>Please wait a moment while I gather a
list of all available modules...</p>
</blockquote>
<p>For over 10 minutes before I killed it.</p>
<p>Anyone ... | 3 | 2010-03-31T05:23:56Z | 2,550,705 | <p>Make sure that you can import the module. </p>
<pre><code>import modules
</code></pre>
<p>For which module do you want help? Is it your own module or third-party?</p>
| 0 | 2010-03-31T05:31:50Z | [
"python",
"ubuntu",
"module"
] |
Python: List of Modules (>>> help('modules') not working) | 2,550,667 | <p>I wanted a list of my modules and was told:</p>
<pre><code>>>> help('modules')
</code></pre>
<p>Would do the trick. But I just get </p>
<blockquote>
<p>Please wait a moment while I gather a
list of all available modules...</p>
</blockquote>
<p>For over 10 minutes before I killed it.</p>
<p>Anyone ... | 3 | 2010-03-31T05:23:56Z | 2,551,200 | <p>Install ipython</p>
<pre><code>$ sudo apt-get install ipython
</code></pre>
<p>Then run ipython and type <code>import <tab></code> where <em><tab></em> is the tab key</p>
<p>If you've installed the python-pygraphviz package, you can use</p>
<pre><code>import pygraphviz
</code></pre>
| 1 | 2010-03-31T07:40:41Z | [
"python",
"ubuntu",
"module"
] |
Python: List of Modules (>>> help('modules') not working) | 2,550,667 | <p>I wanted a list of my modules and was told:</p>
<pre><code>>>> help('modules')
</code></pre>
<p>Would do the trick. But I just get </p>
<blockquote>
<p>Please wait a moment while I gather a
list of all available modules...</p>
</blockquote>
<p>For over 10 minutes before I killed it.</p>
<p>Anyone ... | 3 | 2010-03-31T05:23:56Z | 34,274,444 | <p><code>help("modules")</code> can take a long time, because it has to import each module before it can search that module's path for sub-modules. This can be a problem if any module has code outside of an <code>if __name__ == "__main__":</code> guard, and if that code expects user input or enters an infinite loop or ... | 2 | 2015-12-14T18:50:16Z | [
"python",
"ubuntu",
"module"
] |
How do I write this insert statement in Django? | 2,550,806 | <pre><code>newthing = Link(user=request.user,last_updated=datetime.datetime.now())
</code></pre>
<p>However, this uses datetime , not the MYSQL "now()".</p>
<p>How can I use mysql's now()?</p>
| 0 | 2010-03-31T05:58:09Z | 2,550,853 | <p>I'm not sure if this uses the MySQL <code>now()</code> call, but the right way to do this in Django is to use the <a href="http://docs.djangoproject.com/en/dev/ref/models/fields/#django.db.models.DateField.auto_now_add" rel="nofollow"><code>auto_now_add</code></a> or <a href="http://docs.djangoproject.com/en/dev/ref... | 2 | 2010-03-31T06:11:45Z | [
"python",
"mysql",
"database",
"django"
] |
In Python, how would I do this Datetime? | 2,550,812 | <pre><code>right_now = datetime.datetime.now()
one_hour_before = ?????
</code></pre>
<p>How can I use right_now to get one_hour_before?</p>
| 0 | 2010-03-31T06:01:59Z | 2,550,824 | <pre><code>right_now = datetime.datetime.now()
one_hour_before = right_now - datetime.timedelta(hours=1)
</code></pre>
| 7 | 2010-03-31T06:05:20Z | [
"python",
"datetime"
] |
In Python, how would I do this Datetime? | 2,550,812 | <pre><code>right_now = datetime.datetime.now()
one_hour_before = ?????
</code></pre>
<p>How can I use right_now to get one_hour_before?</p>
| 0 | 2010-03-31T06:01:59Z | 2,550,826 | <p>You need to use <a href="http://docs.python.org/library/datetime.html#timedelta-objects" rel="nofollow"><code>datetime.timedelta</code></a> like so:</p>
<pre><code>right_now = datetime.datetime.now()
one_hour_before = right_now - datetime.timedelta(hours = 1)
</code></pre>
| 1 | 2010-03-31T06:06:01Z | [
"python",
"datetime"
] |
dictionary interface for large data sets | 2,550,980 | <p>I have a set of key/values (all text) that is too large to load in memory at once. I would like to interact with this data via a Python dictionary-like interface. </p>
<p>Does such a module already exist? </p>
<p>Reading key values should be efficient and values compressed on disk to save space.</p>
<p>Edit:</p>
... | 2 | 2010-03-31T06:51:59Z | 2,550,988 | <p>Assuming you are on a *nix platform, you are just BEGGING for tokyo-cabinet... It has a native set of ruby bindings... You can more information at 1978th.net...</p>
| 0 | 2010-03-31T06:53:59Z | [
"python",
"dictionary",
"dataset",
"large-files"
] |
dictionary interface for large data sets | 2,550,980 | <p>I have a set of key/values (all text) that is too large to load in memory at once. I would like to interact with this data via a Python dictionary-like interface. </p>
<p>Does such a module already exist? </p>
<p>Reading key values should be efficient and values compressed on disk to save space.</p>
<p>Edit:</p>
... | 2 | 2010-03-31T06:51:59Z | 2,551,049 | <p>Take a look at the <a href="http://docs.python.org/library/shelve.html" rel="nofollow">shelve</a> module. It provides dictionaries with various backing database systems include BerkleyDB and dbm.</p>
| 2 | 2010-03-31T07:09:55Z | [
"python",
"dictionary",
"dataset",
"large-files"
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.