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 |
|---|---|---|---|---|---|---|---|---|---|
python 2.5 dated? | 787,849 | <p>I am just learning python on my ubuntu 8.04 machine which comes with
python 2.5 install. Is 2.5 too dated to continue learning? How much
of 2.5 version is still valid python code in the newer version?</p>
| 2 | 2009-04-24T23:45:06Z | 787,889 | <p>One thing to keep in mind about python 2.6 is that some libraries may not work. <a href="http://numpy.scipy.org/" rel="nofollow">Numpy</a> comes to mind..</p>
| 1 | 2009-04-25T00:02:52Z | [
"python"
] |
python 2.5 dated? | 787,849 | <p>I am just learning python on my ubuntu 8.04 machine which comes with
python 2.5 install. Is 2.5 too dated to continue learning? How much
of 2.5 version is still valid python code in the newer version?</p>
| 2 | 2009-04-24T23:45:06Z | 787,903 | <p>I don't have any statistics but my impression is that Python 2.5 is the version most in use today. It is certainly not "dated" - I still use Python 2.5 and I expect that I will be using it for weeks or months yet to come.</p>
<p>If you have Python 2.6 available, though, I would suggest upgrading, as it's still fai... | 3 | 2009-04-25T00:09:15Z | [
"python"
] |
python 2.5 dated? | 787,849 | <p>I am just learning python on my ubuntu 8.04 machine which comes with
python 2.5 install. Is 2.5 too dated to continue learning? How much
of 2.5 version is still valid python code in the newer version?</p>
| 2 | 2009-04-24T23:45:06Z | 787,995 | <p>Also, right now the 2.x branch is the most supported one, so I would also say that it's a good reason to start with that version.</p>
<p>And when the moment comes, you can always switch to Python 3. </p>
| 2 | 2009-04-25T00:55:39Z | [
"python"
] |
python 2.5 dated? | 787,849 | <p>I am just learning python on my ubuntu 8.04 machine which comes with
python 2.5 install. Is 2.5 too dated to continue learning? How much
of 2.5 version is still valid python code in the newer version?</p>
| 2 | 2009-04-24T23:45:06Z | 788,020 | <p>Python 2.5 is <em>fine.</em> There are still plenty of people on Python 2.4 and 2.3.</p>
| 2 | 2009-04-25T01:18:56Z | [
"python"
] |
What is the correct way to clean up when using PyOpenAL? | 787,850 | <p>I'm looking at PyOpenAL for some sound needs with Python (obviously). Documentation is sparse (consisting of a demo script, which doesn't work unmodified) but as far as I can tell, there are two layers. Direct wrapping of OpenAL calls and a lightweight 'pythonic' wrapper - it is the latter I'm concerned with. Specif... | 0 | 2009-04-24T23:45:17Z | 1,287,355 | <pre><code>#relese reference to l b and s
del l
del b
del s
#now the WaveBuffer and Source should be destroyed, so we could:
pyopenal.quit()
</code></pre>
<p>Probably de destructor of pyopenal calls <code>quit()</code> before exit so you dont need to call it yourself.</p>
| 1 | 2009-08-17T11:05:42Z | [
"python",
"openal"
] |
Python interface to PayPal - urllib.urlencode non-ASCII characters failing | 787,935 | <p>I am trying to implement PayPal IPN functionality. The basic protocol is as such:</p>
<ol>
<li>The client is redirected from my site to PayPal's site to complete payment. He logs into his account, authorizes payment.</li>
<li>PayPal calls a page on my server passing in details as POST. Details include a person's na... | 20 | 2009-04-25T00:24:09Z | 788,055 | <p>Try converting the params dictionary to utf-8 first... urlencode seems to like that better than unicode:</p>
<pre><code>params = urllib.urlencode(dict([k, v.encode('utf-8')] for k, v in params.items()))
</code></pre>
<p>Of course, this assumes your input is unicode. If your input is something other than unicode, y... | 41 | 2009-04-25T01:45:55Z | [
"python",
"unicode",
"paypal",
"urllib2",
"urllib"
] |
Python interface to PayPal - urllib.urlencode non-ASCII characters failing | 787,935 | <p>I am trying to implement PayPal IPN functionality. The basic protocol is as such:</p>
<ol>
<li>The client is redirected from my site to PayPal's site to complete payment. He logs into his account, authorizes payment.</li>
<li>PayPal calls a page on my server passing in details as POST. Details include a person's na... | 20 | 2009-04-25T00:24:09Z | 2,220,455 | <p>Instead of encoding to <code>utf-8</code>, one should encode to what ever the paypal is using for the post.
It is available under key 'charset' in the form paypal sends.</p>
<p>So the following code worked for me:</p>
<blockquote>
<p><code>data = dict([(k, v.encode(data['charset'])) for k, v in data.items()])</c... | 6 | 2010-02-08T09:03:21Z | [
"python",
"unicode",
"paypal",
"urllib2",
"urllib"
] |
Python interface to PayPal - urllib.urlencode non-ASCII characters failing | 787,935 | <p>I am trying to implement PayPal IPN functionality. The basic protocol is as such:</p>
<ol>
<li>The client is redirected from my site to PayPal's site to complete payment. He logs into his account, authorizes payment.</li>
<li>PayPal calls a page on my server passing in details as POST. Details include a person's na... | 20 | 2009-04-25T00:24:09Z | 3,282,990 | <p>I know it's a bit late to chime in here, but the best solution I found was to not even parse what they were giving back. In django (don't know what you're using) I was able to get the raw request they sent, which I passed back verbatim. Then it was just a matter of putting the cmd key onto that.</p>
<p>This way it ... | 3 | 2010-07-19T16:34:28Z | [
"python",
"unicode",
"paypal",
"urllib2",
"urllib"
] |
Web development with python and sql | 788,083 | <p>I need to build a web site with the following features:
1) user forum where we expect light daily traffic
2) database backend for users to create profiles, where they can log in
and upload media (pictures)
3) users can uses their profile to buy content from an online inventory
4) create web pages, shopping carts etc... | 1 | 2009-04-25T02:19:50Z | 788,088 | <p><a href="http://www.djangoproject.com/" rel="nofollow">Django</a> was made for this kind of thing. Check it out.</p>
<p>As far as hosting, <a href="http://www.djangofriendly.com" rel="nofollow">djangofriendly.com</a> is a great resource. I have used <a href="http://www.webfaction.com/?affiliate=paolob" rel="nofollo... | 8 | 2009-04-25T02:25:12Z | [
"python"
] |
Web development with python and sql | 788,083 | <p>I need to build a web site with the following features:
1) user forum where we expect light daily traffic
2) database backend for users to create profiles, where they can log in
and upload media (pictures)
3) users can uses their profile to buy content from an online inventory
4) create web pages, shopping carts etc... | 1 | 2009-04-25T02:19:50Z | 788,125 | <p>Your requirements make <a href="http://pinaxproject.com/" rel="nofollow">pinax</a> sound like a library you might want to look into if you go the django route.</p>
| 0 | 2009-04-25T02:48:37Z | [
"python"
] |
Web development with python and sql | 788,083 | <p>I need to build a web site with the following features:
1) user forum where we expect light daily traffic
2) database backend for users to create profiles, where they can log in
and upload media (pictures)
3) users can uses their profile to buy content from an online inventory
4) create web pages, shopping carts etc... | 1 | 2009-04-25T02:19:50Z | 788,163 | <p>You can try <a href="http://www.pylonshq.com/" rel="nofollow">Pylons</a> lightweight web framework.</p>
| 1 | 2009-04-25T03:12:48Z | [
"python"
] |
Web development with python and sql | 788,083 | <p>I need to build a web site with the following features:
1) user forum where we expect light daily traffic
2) database backend for users to create profiles, where they can log in
and upload media (pictures)
3) users can uses their profile to buy content from an online inventory
4) create web pages, shopping carts etc... | 1 | 2009-04-25T02:19:50Z | 789,282 | <p>Google App Engine will provide hosting for free as well as Django and a db..</p>
| 0 | 2009-04-25T16:37:33Z | [
"python"
] |
How can I optimize this Python code to generate all words with word-distance 1? | 788,084 | <p>Profiling shows this is the slowest segment of my code for a little word game I wrote:</p>
<pre><code>def distance(word1, word2):
difference = 0
for i in range(len(word1)):
if word1[i] != word2[i]:
difference += 1
return difference
def getchildren(word, wordlist):
return [ w for... | 31 | 2009-04-25T02:20:26Z | 788,090 | <p>Well you can start by having your loop break if the difference is 2 or more.</p>
<p>Also you can change</p>
<pre><code>for i in range(len(word1)):
</code></pre>
<p>to </p>
<pre><code>for i in xrange(len(word1)):
</code></pre>
<p>Because xrange generates sequences on demand instead of generating the whole range ... | 2 | 2009-04-25T02:27:44Z | [
"python",
"optimization",
"python-2.x",
"levenshtein-distance",
"word-diff"
] |
How can I optimize this Python code to generate all words with word-distance 1? | 788,084 | <p>Profiling shows this is the slowest segment of my code for a little word game I wrote:</p>
<pre><code>def distance(word1, word2):
difference = 0
for i in range(len(word1)):
if word1[i] != word2[i]:
difference += 1
return difference
def getchildren(word, wordlist):
return [ w for... | 31 | 2009-04-25T02:20:26Z | 788,093 | <p>I don't know if it will significantly affect your speed, but you could start by turning the list comprehension into a generator expression. It's still iterable so it shouldn't be much different in usage:</p>
<pre><code>def getchildren(word, wordlist):
return [ w for w in wordlist if distance(word, w) == 1 ]
</... | 0 | 2009-04-25T02:29:48Z | [
"python",
"optimization",
"python-2.x",
"levenshtein-distance",
"word-diff"
] |
How can I optimize this Python code to generate all words with word-distance 1? | 788,084 | <p>Profiling shows this is the slowest segment of my code for a little word game I wrote:</p>
<pre><code>def distance(word1, word2):
difference = 0
for i in range(len(word1)):
if word1[i] != word2[i]:
difference += 1
return difference
def getchildren(word, wordlist):
return [ w for... | 31 | 2009-04-25T02:20:26Z | 788,094 | <p>Your function <code>distance</code> is calculating the total distance, when you really only care about distance=1. The majority of cases you'll know it's >1 within a few characters, so you could return early and save a lot of time.</p>
<p>Beyond that, there might be a better algorithm, but I can't think of it.</p>
... | 10 | 2009-04-25T02:30:29Z | [
"python",
"optimization",
"python-2.x",
"levenshtein-distance",
"word-diff"
] |
How can I optimize this Python code to generate all words with word-distance 1? | 788,084 | <p>Profiling shows this is the slowest segment of my code for a little word game I wrote:</p>
<pre><code>def distance(word1, word2):
difference = 0
for i in range(len(word1)):
if word1[i] != word2[i]:
difference += 1
return difference
def getchildren(word, wordlist):
return [ w for... | 31 | 2009-04-25T02:20:26Z | 788,113 | <pre><code>from itertools import izip
def is_neighbors(word1,word2):
different = False
for c1,c2 in izip(word1,word2):
if c1 != c2:
if different:
return False
different = True
return different
</code></pre>
<p>Or maybe in-lining the <code>izip</code> code:</... | 6 | 2009-04-25T02:41:49Z | [
"python",
"optimization",
"python-2.x",
"levenshtein-distance",
"word-diff"
] |
How can I optimize this Python code to generate all words with word-distance 1? | 788,084 | <p>Profiling shows this is the slowest segment of my code for a little word game I wrote:</p>
<pre><code>def distance(word1, word2):
difference = 0
for i in range(len(word1)):
if word1[i] != word2[i]:
difference += 1
return difference
def getchildren(word, wordlist):
return [ w for... | 31 | 2009-04-25T02:20:26Z | 788,119 | <p>For such a simple function that has such a large performance implication, I would probably make a C library and call it using <a href="http://docs.python.org/library/ctypes.html" rel="nofollow">ctypes</a>. One of reddit's founders claims they made the website 2x as fast using this technique.</p>
<p>You can also us... | 1 | 2009-04-25T02:44:00Z | [
"python",
"optimization",
"python-2.x",
"levenshtein-distance",
"word-diff"
] |
How can I optimize this Python code to generate all words with word-distance 1? | 788,084 | <p>Profiling shows this is the slowest segment of my code for a little word game I wrote:</p>
<pre><code>def distance(word1, word2):
difference = 0
for i in range(len(word1)):
if word1[i] != word2[i]:
difference += 1
return difference
def getchildren(word, wordlist):
return [ w for... | 31 | 2009-04-25T02:20:26Z | 788,124 | <p>Try this:</p>
<pre><code>def distance(word1, word2):
return sum([not c1 == c2 for c1, c2 in zip(word1,word2)])
</code></pre>
<p>Also, do you have a link to your game? I like being destroyed by word games</p>
| 0 | 2009-04-25T02:48:35Z | [
"python",
"optimization",
"python-2.x",
"levenshtein-distance",
"word-diff"
] |
How can I optimize this Python code to generate all words with word-distance 1? | 788,084 | <p>Profiling shows this is the slowest segment of my code for a little word game I wrote:</p>
<pre><code>def distance(word1, word2):
difference = 0
for i in range(len(word1)):
if word1[i] != word2[i]:
difference += 1
return difference
def getchildren(word, wordlist):
return [ w for... | 31 | 2009-04-25T02:20:26Z | 788,168 | <p>How often is the distance function called with the same arguments? A simple to implement optimization would be to use <a href="http://code.activestate.com/recipes/466320/" rel="nofollow">memoization</a>. </p>
<p>You could probably also create some sort of dictionary with frozensets of letters and lists of words tha... | 3 | 2009-04-25T03:14:32Z | [
"python",
"optimization",
"python-2.x",
"levenshtein-distance",
"word-diff"
] |
How can I optimize this Python code to generate all words with word-distance 1? | 788,084 | <p>Profiling shows this is the slowest segment of my code for a little word game I wrote:</p>
<pre><code>def distance(word1, word2):
difference = 0
for i in range(len(word1)):
if word1[i] != word2[i]:
difference += 1
return difference
def getchildren(word, wordlist):
return [ w for... | 31 | 2009-04-25T02:20:26Z | 788,180 | <p>People are mainly going about this by trying to write a quicker function, but there might be another way..</p>
<blockquote>
<p>"distance" is called over 5 million times</p>
</blockquote>
<p>Why is this? Perhaps a better way to optimise is to try and reduce the number of calls to <code>distance</code>, rather tha... | 4 | 2009-04-25T03:25:37Z | [
"python",
"optimization",
"python-2.x",
"levenshtein-distance",
"word-diff"
] |
How can I optimize this Python code to generate all words with word-distance 1? | 788,084 | <p>Profiling shows this is the slowest segment of my code for a little word game I wrote:</p>
<pre><code>def distance(word1, word2):
difference = 0
for i in range(len(word1)):
if word1[i] != word2[i]:
difference += 1
return difference
def getchildren(word, wordlist):
return [ w for... | 31 | 2009-04-25T02:20:26Z | 788,256 | <p>First thing to occur to me:</p>
<pre><code>from operator import ne
def distance(word1, word2):
return sum(map(ne, word1, word2))
</code></pre>
<p>which has a decent chance of going faster than other functions people have posted, because it has no interpreted loops, just calls to Python primitives. And it's sh... | 0 | 2009-04-25T04:55:54Z | [
"python",
"optimization",
"python-2.x",
"levenshtein-distance",
"word-diff"
] |
How can I optimize this Python code to generate all words with word-distance 1? | 788,084 | <p>Profiling shows this is the slowest segment of my code for a little word game I wrote:</p>
<pre><code>def distance(word1, word2):
difference = 0
for i in range(len(word1)):
if word1[i] != word2[i]:
difference += 1
return difference
def getchildren(word, wordlist):
return [ w for... | 31 | 2009-04-25T02:20:26Z | 788,461 | <p>If your wordlist is very long, might it be more efficient to generate all possible 1-letter-differences from 'word', then check which ones are in the list? I don't know any Python but there should be a suitable data structure for the wordlist allowing for log-time lookups.</p>
<p>I suggest this because if your wor... | 24 | 2009-04-25T07:38:18Z | [
"python",
"optimization",
"python-2.x",
"levenshtein-distance",
"word-diff"
] |
How can I optimize this Python code to generate all words with word-distance 1? | 788,084 | <p>Profiling shows this is the slowest segment of my code for a little word game I wrote:</p>
<pre><code>def distance(word1, word2):
difference = 0
for i in range(len(word1)):
if word1[i] != word2[i]:
difference += 1
return difference
def getchildren(word, wordlist):
return [ w for... | 31 | 2009-04-25T02:20:26Z | 1,301,507 | <p>for this snippet:</p>
<pre><code>for x,y in zip (word1, word2):
if x != y:
difference += 1
return difference
</code></pre>
<p>i'd use this one:</p>
<pre><code>return sum(1 for i in xrange(len(word1)) if word1[i] == word2[i])
</code></pre>
<p>the same pattern would follow all around the provided code.... | 0 | 2009-08-19T17:41:47Z | [
"python",
"optimization",
"python-2.x",
"levenshtein-distance",
"word-diff"
] |
How can I optimize this Python code to generate all words with word-distance 1? | 788,084 | <p>Profiling shows this is the slowest segment of my code for a little word game I wrote:</p>
<pre><code>def distance(word1, word2):
difference = 0
for i in range(len(word1)):
if word1[i] != word2[i]:
difference += 1
return difference
def getchildren(word, wordlist):
return [ w for... | 31 | 2009-04-25T02:20:26Z | 40,051,831 | <p>Everyone else focused just on explicit distance-calculation without doing anything about constructing the distance-1 candidates.
You can improve by using a well-known data-structure called a <strong><a href="https://stackoverflow.com/search?q=%5Bpython%5D+trie">Trie</a></strong> to merge the <strong>implicit distanc... | 0 | 2016-10-14T20:54:28Z | [
"python",
"optimization",
"python-2.x",
"levenshtein-distance",
"word-diff"
] |
Blender- python | 788,102 | <p>How do I point Blender to the version of python I have installed</p>
| 2 | 2009-04-25T02:36:16Z | 788,143 | <p>Personally, I was setting my PATH environment variable so that Blender would find the most appropriate version of Python first.</p>
| 1 | 2009-04-25T03:01:19Z | [
"python",
"blender"
] |
Blender- python | 788,102 | <p>How do I point Blender to the version of python I have installed</p>
| 2 | 2009-04-25T02:36:16Z | 790,261 | <p>Mark, your version of Blender should be compiled with a specific version of Python interfaced to it -- and THAT is the version of Python you need to install on your machine. The same issue surfaced back when Python 2.5 was reasonably new and Blender was still distributed with 2.4 compiled in -- see <a href="http://w... | 7 | 2009-04-26T04:57:45Z | [
"python",
"blender"
] |
Blender- python | 788,102 | <p>How do I point Blender to the version of python I have installed</p>
| 2 | 2009-04-25T02:36:16Z | 7,134,809 | <p>Blender 2.5x now comes bundled with its own python, this is un-modified, only included to so users don't have to match their system versions of python.</p>
<p>If you remove this python/ directory blender will look for python on the system, matching the version it was compiled with. (3.2, 3.3 etc, minor point releas... | 5 | 2011-08-20T21:28:23Z | [
"python",
"blender"
] |
How to get publisher.authors when you have book.publisher and book.author? | 788,192 | <p>Fresh from the Djangobook tutorial using the Books app example, you have Book related to Author through a many-to-many relationship and Book related to Publisher. You can get a set of books associated with a publisher with p.book_set.all(), but what do you need to do to get a set of authors associated with a publish... | 1 | 2009-04-25T03:35:18Z | 788,242 | <p>Something like that:</p>
<pre><code>publisher = Publisher.objects.get(...)
authors = Author.objects.filter(book__publisher=publisher).distinct()
</code></pre>
| 4 | 2009-04-25T04:43:43Z | [
"python",
"django"
] |
Check to see if python script is running | 788,411 | <p>I have a python daemon running as a part of my web app/ How can I quickly check (using python) if my daemon is running and, if not, launch it?</p>
<p>I want to do it that way to fix any crashes of the daemon, and so the script does not have to be run manually, it will automatically run as soon as it is called and t... | 60 | 2009-04-25T06:59:10Z | 788,423 | <p>There are a myriad of options. One method is using system calls or python libraries that perform such calls for you. The other is simply to spawn out a process like:</p>
<pre><code>ps ax | grep processName
</code></pre>
<p>and parse the output. Many people choose this approach, it isn't necessarily a bad approach ... | 2 | 2009-04-25T07:05:50Z | [
"python"
] |
Check to see if python script is running | 788,411 | <p>I have a python daemon running as a part of my web app/ How can I quickly check (using python) if my daemon is running and, if not, launch it?</p>
<p>I want to do it that way to fix any crashes of the daemon, and so the script does not have to be run manually, it will automatically run as soon as it is called and t... | 60 | 2009-04-25T06:59:10Z | 788,436 | <p>There are very good packages for restarting processes on UNIX. One that has a great tutorial about building and configuring it is <a href="http://www.cyberciti.biz/tips/howto-monitor-and-restart-linux-unix-service.html">monit</a>. With some tweaking you can have a rock solid proven technology keeping up your daem... | 9 | 2009-04-25T07:16:06Z | [
"python"
] |
Check to see if python script is running | 788,411 | <p>I have a python daemon running as a part of my web app/ How can I quickly check (using python) if my daemon is running and, if not, launch it?</p>
<p>I want to do it that way to fix any crashes of the daemon, and so the script does not have to be run manually, it will automatically run as soon as it is called and t... | 60 | 2009-04-25T06:59:10Z | 789,383 | <p>Drop a pidfile somewhere (e.g. /tmp). Then you can check to see if the process is running by checking to see if the PID in the file exists. Don't forget to delete the file when you shut down cleanly, and check for it when you start up.</p>
<pre><code>#/usr/bin/env python
import os
import sys
pid = str(os.getpid()... | 59 | 2009-04-25T17:37:56Z | [
"python"
] |
Check to see if python script is running | 788,411 | <p>I have a python daemon running as a part of my web app/ How can I quickly check (using python) if my daemon is running and, if not, launch it?</p>
<p>I want to do it that way to fix any crashes of the daemon, and so the script does not have to be run manually, it will automatically run as soon as it is called and t... | 60 | 2009-04-25T06:59:10Z | 790,426 | <p>I'm a big fan of <a href="http://supervisord.org" rel="nofollow">Supervisor</a> for managing daemons. It's written in Python, so there are plenty of examples of how to interact with or extend it from Python. For your purposes the <a href="http://supervisord.org/manual/current/api.process-control.html" rel="nofollo... | 2 | 2009-04-26T07:36:54Z | [
"python"
] |
Check to see if python script is running | 788,411 | <p>I have a python daemon running as a part of my web app/ How can I quickly check (using python) if my daemon is running and, if not, launch it?</p>
<p>I want to do it that way to fix any crashes of the daemon, and so the script does not have to be run manually, it will automatically run as soon as it is called and t... | 60 | 2009-04-25T06:59:10Z | 4,291,218 | <p>Of course the example from Dan will not work as it should be.</p>
<p>Indeed, if the script crash, rise an exception, or does not clean pid file, the script will be run multiple times.</p>
<p>I suggest the following based from another website: </p>
<p>This is to check if there is already a lock file existing</p>
... | 9 | 2010-11-27T10:41:19Z | [
"python"
] |
Check to see if python script is running | 788,411 | <p>I have a python daemon running as a part of my web app/ How can I quickly check (using python) if my daemon is running and, if not, launch it?</p>
<p>I want to do it that way to fix any crashes of the daemon, and so the script does not have to be run manually, it will automatically run as soon as it is called and t... | 60 | 2009-04-25T06:59:10Z | 7,758,075 | <p>A technique that is handy on a Linux system is using domain sockets:</p>
<pre><code>import socket
import sys
import time
def get_lock(process_name):
# Without holding a reference to our socket somewhere it gets garbage
# collected when the function exits
get_lock._lock_socket = socket.socket(socket.AF_... | 98 | 2011-10-13T17:36:26Z | [
"python"
] |
Check to see if python script is running | 788,411 | <p>I have a python daemon running as a part of my web app/ How can I quickly check (using python) if my daemon is running and, if not, launch it?</p>
<p>I want to do it that way to fix any crashes of the daemon, and so the script does not have to be run manually, it will automatically run as soon as it is called and t... | 60 | 2009-04-25T06:59:10Z | 10,999,897 | <p>The other answers are great for things like cron jobs, but if you're running a daemon you should monitor it with something like <a href="http://cr.yp.to/daemontools.html" rel="nofollow">daemontools</a>.</p>
| 0 | 2012-06-12T15:31:37Z | [
"python"
] |
Check to see if python script is running | 788,411 | <p>I have a python daemon running as a part of my web app/ How can I quickly check (using python) if my daemon is running and, if not, launch it?</p>
<p>I want to do it that way to fix any crashes of the daemon, and so the script does not have to be run manually, it will automatically run as soon as it is called and t... | 60 | 2009-04-25T06:59:10Z | 11,458,278 | <p>Consider the following example to solve your problem:</p>
<pre><code>#!/usr/bin/python
# -*- coding: latin-1 -*-
import os, sys, time, signal
def termination_handler (signum,frame):
global running
global pidfile
print 'You have requested to terminate the application...'
sys.stdout.flush()
runn... | -1 | 2012-07-12T18:29:35Z | [
"python"
] |
Check to see if python script is running | 788,411 | <p>I have a python daemon running as a part of my web app/ How can I quickly check (using python) if my daemon is running and, if not, launch it?</p>
<p>I want to do it that way to fix any crashes of the daemon, and so the script does not have to be run manually, it will automatically run as soon as it is called and t... | 60 | 2009-04-25T06:59:10Z | 12,682,828 | <p>Try this other version</p>
<pre><code>def checkPidRunning(pid):
'''Check For the existence of a unix pid.
'''
try:
os.kill(pid, 0)
except OSError:
return False
else:
return True
# Entry point
if __name__ == '__main__':
pid = str(os.getpid())
pidfile = os.... | 3 | 2012-10-02T00:09:37Z | [
"python"
] |
Check to see if python script is running | 788,411 | <p>I have a python daemon running as a part of my web app/ How can I quickly check (using python) if my daemon is running and, if not, launch it?</p>
<p>I want to do it that way to fix any crashes of the daemon, and so the script does not have to be run manually, it will automatically run as soon as it is called and t... | 60 | 2009-04-25T06:59:10Z | 17,116,843 | <p>Using bash to look for a process with the current script's name. No extra file.</p>
<pre><code>import commands
import os
import time
import sys
def stop_if_already_running():
script_name = os.path.basename(__file__)
l = commands.getstatusoutput("ps aux | grep -e '%s' | grep -v grep | awk '{print $2}'| awk ... | -1 | 2013-06-14T20:35:09Z | [
"python"
] |
Check to see if python script is running | 788,411 | <p>I have a python daemon running as a part of my web app/ How can I quickly check (using python) if my daemon is running and, if not, launch it?</p>
<p>I want to do it that way to fix any crashes of the daemon, and so the script does not have to be run manually, it will automatically run as soon as it is called and t... | 60 | 2009-04-25T06:59:10Z | 22,103,022 | <pre><code>ps ax | grep processName
</code></pre>
<p>if yor debug script in pycharm always exit</p>
<pre><code>pydevd.py --multiproc --client 127.0.0.1 --port 33882 --file processName
</code></pre>
| 0 | 2014-02-28T18:27:36Z | [
"python"
] |
Check to see if python script is running | 788,411 | <p>I have a python daemon running as a part of my web app/ How can I quickly check (using python) if my daemon is running and, if not, launch it?</p>
<p>I want to do it that way to fix any crashes of the daemon, and so the script does not have to be run manually, it will automatically run as soon as it is called and t... | 60 | 2009-04-25T06:59:10Z | 25,662,978 | <p>Rather than developing your own PID file solution (which has more subtleties and corner cases than you might think), have a look at <a href="http://supervisord.org/" rel="nofollow">supervisord</a> -- this is a process control system that makes it easy to wrap job control and daemon behaviors around an existing Pytho... | 0 | 2014-09-04T10:21:17Z | [
"python"
] |
Check to see if python script is running | 788,411 | <p>I have a python daemon running as a part of my web app/ How can I quickly check (using python) if my daemon is running and, if not, launch it?</p>
<p>I want to do it that way to fix any crashes of the daemon, and so the script does not have to be run manually, it will automatically run as soon as it is called and t... | 60 | 2009-04-25T06:59:10Z | 33,044,420 | <p>The <a href="https://pypi.python.org/pypi/pid/" rel="nofollow">pid</a> library can do exactly this.</p>
<pre><code>from pid import PidFile
with PidFile():
do_something()
</code></pre>
<p>It will also automatically handle the case where the pidfile exists but the process is not running.</p>
| 4 | 2015-10-09T17:55:11Z | [
"python"
] |
Check to see if python script is running | 788,411 | <p>I have a python daemon running as a part of my web app/ How can I quickly check (using python) if my daemon is running and, if not, launch it?</p>
<p>I want to do it that way to fix any crashes of the daemon, and so the script does not have to be run manually, it will automatically run as soon as it is called and t... | 60 | 2009-04-25T06:59:10Z | 38,822,039 | <p>try this:
</p>
<pre><code>#/usr/bin/env python
import os, sys, atexit
try:
# Set PID file
def set_pid_file():
pid = str(os.getpid())
f = open('myCode.pid', 'w')
f.write(pid)
f.close()
def goodby():
pid = str('myCode.pid')
os.remove(pid)
atexit.regis... | 0 | 2016-08-08T05:48:24Z | [
"python"
] |
Check to see if python script is running | 788,411 | <p>I have a python daemon running as a part of my web app/ How can I quickly check (using python) if my daemon is running and, if not, launch it?</p>
<p>I want to do it that way to fix any crashes of the daemon, and so the script does not have to be run manually, it will automatically run as soon as it is called and t... | 60 | 2009-04-25T06:59:10Z | 39,633,989 | <p>Here is more useful code (with checking if exactly python executes the script):</p>
<pre><code>#! /usr/bin/env python
import os
from sys import exit
def checkPidRunning(pid):
global script_name
if pid<1:
print "Incorrect pid number!"
exit()
try:
os.kill(pid, 0)
except O... | 0 | 2016-09-22T08:30:38Z | [
"python"
] |
finding substrings in python | 788,699 | <p>Can you please help me to get the substrings between two characters at each occurrence</p>
<p>For example to get all the substrings between "Q" and "E" in the given example sequence in all occurrences:</p>
<pre><code>ex: QUWESEADFQDFSAEDFS
</code></pre>
<p>and to find the substring with minimum length.</p>
| 4 | 2009-04-25T11:02:51Z | 788,720 | <pre><code>import re
DATA = "QUWESEADFQDFSAEDFS"
# Get all the substrings between Q and E:
substrings = re.findall(r'Q([^E]+)E', DATA)
print "Substrings:", substrings
# Sort by length, then the first one is the shortest:
substrings.sort(key=lambda s: len(s))
print "Shortest substring:", substrings[0]
</code></pre>
| 16 | 2009-04-25T11:14:49Z | [
"python",
"regex",
"algorithm",
"substring"
] |
finding substrings in python | 788,699 | <p>Can you please help me to get the substrings between two characters at each occurrence</p>
<p>For example to get all the substrings between "Q" and "E" in the given example sequence in all occurrences:</p>
<pre><code>ex: QUWESEADFQDFSAEDFS
</code></pre>
<p>and to find the substring with minimum length.</p>
| 4 | 2009-04-25T11:02:51Z | 790,231 | <p>RichieHindle has it right, except that</p>
<pre><code>substrings.sort(key=len)
</code></pre>
<p>is a better way to express it than that redundant lambda;-). </p>
<p>If you're using Python 2.5 or later, min(substrings, key=len) will actually give you the one shortest string (the first one, if several strings tie ... | 7 | 2009-04-26T04:21:40Z | [
"python",
"regex",
"algorithm",
"substring"
] |
How do i interface with the MSN Protocol using Python? | 788,715 | <p>I am trying to connect to the MSN network using Python.. I've done some searching and it seems like <a href="http://blitiri.com.ar/p/msnlib/" rel="nofollow">http://blitiri.com.ar/p/msnlib/</a> and <a href="http://msnp.sourceforge.net/" rel="nofollow">http://msnp.sourceforge.net/</a> are the available libraries. Howe... | 0 | 2009-04-25T11:11:28Z | 788,735 | <p>I might be babbling here, but I think <a href="http://twistedmatrix.com" rel="nofollow">Python Twisted</a> has a protocol implementation of msn.</p>
| 2 | 2009-04-25T11:25:42Z | [
"python",
"msn"
] |
How do i interface with the MSN Protocol using Python? | 788,715 | <p>I am trying to connect to the MSN network using Python.. I've done some searching and it seems like <a href="http://blitiri.com.ar/p/msnlib/" rel="nofollow">http://blitiri.com.ar/p/msnlib/</a> and <a href="http://msnp.sourceforge.net/" rel="nofollow">http://msnp.sourceforge.net/</a> are the available libraries. Howe... | 0 | 2009-04-25T11:11:28Z | 788,738 | <p>libpurple at <a href="http://developer.pidgin.im/wiki/WhatIsLibpurple" rel="nofollow">http://developer.pidgin.im/wiki/WhatIsLibpurple</a></p>
<p>is the library that drives pidgin, and allows you to connect to MSN and others, not sure if there's a python wrapper for it.</p>
| 2 | 2009-04-25T11:28:29Z | [
"python",
"msn"
] |
Problem running twisted.words example using msn protocol | 788,902 | <p>I am currently trying to use the Twisted library specifically twisted words to try and interat with MSN. However when i run the sample script provided by twisted , i get an error. Specifically the error is found here <a href="http://i42.tinypic.com/wl945w.jpg" rel="nofollow">http://i42.tinypic.com/wl945w.jpg</a> . T... | 5 | 2009-04-25T13:16:29Z | 788,982 | <h2>What happened</h2>
<p>This exception you get is when you try to call an object that is None. Check this out :</p>
<pre><code>>>> a = str
>>> a() # it's ok, a string is a callable class
''
>>> a = None
>>> a() # it fails, None a special Singleton not meant to be called
Tracebac... | 2 | 2009-04-25T13:57:27Z | [
"python",
"twisted",
"msn",
"twisted.words"
] |
Problem running twisted.words example using msn protocol | 788,902 | <p>I am currently trying to use the Twisted library specifically twisted words to try and interat with MSN. However when i run the sample script provided by twisted , i get an error. Specifically the error is found here <a href="http://i42.tinypic.com/wl945w.jpg" rel="nofollow">http://i42.tinypic.com/wl945w.jpg</a> . T... | 5 | 2009-04-25T13:16:29Z | 788,989 | <p>Since MSN involves SSL connections, you must have pyOpenSSL installed in order to use it. It seems as though you probably do not. This isn't a very good way for Twisted to be reporting this missing dependency, though. I recommend filing a ticket in the Twisted issue tracker for improving this reporting.</p>
| 3 | 2009-04-25T13:59:35Z | [
"python",
"twisted",
"msn",
"twisted.words"
] |
How do I reverse the direction that my rectangles travel? | 788,966 | <p>I am very new at programming as it was only just introduced into my school as a subject and I need some help. I have been given the task to have an animation of three balls (rectangle images) bouncing around the screen and off each other. I have the three balls and the bouncing of the walls all down good, but I don'... | 1 | 2009-04-25T13:48:57Z | 788,996 | <p>When two objects 'collide' they basically exist in the same physical space and therefore you have to check for this. In 2d this is nice and easy, especially for rectangular shapes. Basically write a function called 'overlap' that returns a true value if two of the balls collide. For example:</p>
<pre><code>for (i =... | 3 | 2009-04-25T14:02:19Z | [
"python",
"collision-detection"
] |
How do I reverse the direction that my rectangles travel? | 788,966 | <p>I am very new at programming as it was only just introduced into my school as a subject and I need some help. I have been given the task to have an animation of three balls (rectangle images) bouncing around the screen and off each other. I have the three balls and the bouncing of the walls all down good, but I don'... | 1 | 2009-04-25T13:48:57Z | 789,003 | <p>Well you actually have some clues in the code that you provide. The way you are detecting if the ball bounces on the wall is to check if the top boundary of the ball is less than 0 meaning that it has touched the top boundary and needs to bounce so you change direction.</p>
<p>So the code:</p>
<pre><code>if ball_b... | 1 | 2009-04-25T14:06:40Z | [
"python",
"collision-detection"
] |
How do I reverse the direction that my rectangles travel? | 788,966 | <p>I am very new at programming as it was only just introduced into my school as a subject and I need some help. I have been given the task to have an animation of three balls (rectangle images) bouncing around the screen and off each other. I have the three balls and the bouncing of the walls all down good, but I don'... | 1 | 2009-04-25T13:48:57Z | 2,591,236 | <p>As my lecturer added to my particular assessment on this,</p>
<blockquote>
<p>Once a second ball is bouncing around the frame, add some code to change the directions of the balls if they collide. PyGame provides a function that allows you to detect if a collision has occurred between two Rect objects. The functio... | 1 | 2010-04-07T09:22:54Z | [
"python",
"collision-detection"
] |
How can I import the sqlite3 module into Python 2.4? | 789,030 | <p>The sqlite3 module is included in Python version 2.5+. However, I am stuck with version 2.4. I uploaded the sqlite3 module files, added the directory to sys.path, but I get the following error when I try to import it:</p>
<pre><code>Traceback (most recent call last):
File "<stdin>", line 1, in ?
File "sql... | 7 | 2009-04-25T14:29:03Z | 789,037 | <p>Did you install it? That often works better than messing with <code>sys.path</code>. </p>
<pre><code>python setup.py install
</code></pre>
<p>If so, you should then find it.</p>
<p>If, for some reason, you can't install it, set the <code>PYTHONPATH</code> environment variable. Do not make a habit of messing wi... | 1 | 2009-04-25T14:32:36Z | [
"python",
"sqlite"
] |
How can I import the sqlite3 module into Python 2.4? | 789,030 | <p>The sqlite3 module is included in Python version 2.5+. However, I am stuck with version 2.4. I uploaded the sqlite3 module files, added the directory to sys.path, but I get the following error when I try to import it:</p>
<pre><code>Traceback (most recent call last):
File "<stdin>", line 1, in ?
File "sql... | 7 | 2009-04-25T14:29:03Z | 789,048 | <p>You will need to install <a href="http://pypi.python.org/pypi/pysqlite/" rel="nofollow">pysqlite</a>. Notice, however, that this absolutely does require a compiler, unless you can find binaries for it (and Python 2.4) on the net. Using the 2.5 binaries will not be possible.</p>
| 1 | 2009-04-25T14:41:05Z | [
"python",
"sqlite"
] |
How can I import the sqlite3 module into Python 2.4? | 789,030 | <p>The sqlite3 module is included in Python version 2.5+. However, I am stuck with version 2.4. I uploaded the sqlite3 module files, added the directory to sys.path, but I get the following error when I try to import it:</p>
<pre><code>Traceback (most recent call last):
File "<stdin>", line 1, in ?
File "sql... | 7 | 2009-04-25T14:29:03Z | 955,647 | <p>I had same problem with CentOS and python 2.4</p>
<p>My solution:</p>
<pre><code>yum install python-sqlite2
</code></pre>
<p>and try following python code</p>
<pre><code>try:
import sqlite3
except:
from pysqlite2 import dbapi2 as sqlite3
</code></pre>
| 13 | 2009-06-05T12:48:01Z | [
"python",
"sqlite"
] |
How can I import the sqlite3 module into Python 2.4? | 789,030 | <p>The sqlite3 module is included in Python version 2.5+. However, I am stuck with version 2.4. I uploaded the sqlite3 module files, added the directory to sys.path, but I get the following error when I try to import it:</p>
<pre><code>Traceback (most recent call last):
File "<stdin>", line 1, in ?
File "sql... | 7 | 2009-04-25T14:29:03Z | 8,376,109 | <p>You must ensure your sqlite, sqlite-devel, python-sqlite are installed correctly first and then recompile Python.</p>
| -2 | 2011-12-04T14:52:07Z | [
"python",
"sqlite"
] |
How do I watch a serial port with QSocketNotifier (linux)? | 789,304 | <p>Could someone give me an example on how to setup QSocketNotifier to fire an event if something comes on <strong>/dev/ttyS0</strong> ? (preferably in python/pyqt4)</p>
| 2 | 2009-04-25T16:49:45Z | 789,983 | <p>Here's an example that just keeps reading from a file using QSocketNotifier. Simply replace that 'foo.txt' with '/dev/ttyS0' and you should be good to go.</p>
<pre><code>
import os
from PyQt4.QtCore import QCoreApplication, QSocketNotifier, SIGNAL
def readAllData(fd):
bufferSize = 1024
while True... | 5 | 2009-04-26T00:15:44Z | [
"python",
"qt",
"serial-port",
"pyqt4"
] |
Converting an ImageMagick FX operator to pure Python code with PIL | 789,401 | <p>I'm trying to port some image processing functionality from an Image Magick
command (using the <a href="http://www.imagemagick.org/script/fx.php" rel="nofollow">Fx Special Effects Image Operator</a>) to Python using <a href="http://www.pythonware.com/products/pil/" rel="nofollow">PIL</a>. My
issue is that I'm not e... | 1 | 2009-04-25T17:53:27Z | 866,369 | <p>I know it's been about a month and you might has already figured it out. But here is the answer.</p>
<p>From ImageMagicK documentation I was able to understand what the effect is actually doing.</p>
<pre><code>convert input.png gradient.png -fx "v.p{0,u*v.h}" output.png
v is the second image (gradient.png)
u is t... | 1 | 2009-05-14T23:25:31Z | [
"python",
"imagemagick",
"python-imaging-library"
] |
Handling Authorization in web frameworks | 789,468 | <p>I want to write a simple web framework myself using WSGI, Python. I am in study to understand the authorization system.</p>
<p>The system needs to be more modular and abstract enough to add new system into the project as a plug-in. User may use DB or distributed key/value pair, bigtable, etc to store their informat... | 0 | 2009-04-25T18:30:30Z | 789,671 | <blockquote>
<p>"Is it possible to work with 'identity' object at entire framework?"</p>
<p>"But it is really tough to define "Identity" as an object due to its complex nature. "</p>
</blockquote>
<p>Until you define identity, yes, it's difficult to work with.</p>
<p>Identity has to be positively specified. L... | 0 | 2009-04-25T20:27:44Z | [
"python"
] |
How to debug Google App Engine scripts with PyScripter | 789,558 | <p>The situation is as follows: I have downloaded the Google App Engine SDK. I have written my "helloworld" app that runs locally in my computer. I have to use PyScripter as IDE. I can't use Eclipse, that would not be a valid solution to my problem. </p>
<p>In PyScripter, I have set a "Run Configuration", so that ... | 3 | 2009-04-25T19:26:06Z | 954,825 | <p>I think this is a <a href="http://code.google.com/p/pyscripter/issues/detail?id=238" rel="nofollow">PyScripter's bug</a>. I tested in version 1.9.9.7 and the same problem is still there. </p>
| 2 | 2009-06-05T08:28:33Z | [
"python",
"debugging",
"google-app-engine",
"pyscripter"
] |
What is the easiest way to build Python26.zip for embedded distribution? | 789,598 | <p>I am using Python as a plug-in scripting language for an existing C++ application. I am able to embed the python interpreter as stated in the Python documentation. Everything works successfully with the initialization and de-initialization of the interpreter. I am, however, having trouble loading modules because I h... | 3 | 2009-04-25T19:48:00Z | 789,669 | <p>It shouldn't be too difficult to write a script for that. Check out the <code>zipfile.PyZipFile</code> class and it's <code>writepy</code> method.</p>
| 2 | 2009-04-25T20:26:30Z | [
"c++",
"python",
"distribution",
"embedded-language"
] |
What is the easiest way to build Python26.zip for embedded distribution? | 789,598 | <p>I am using Python as a plug-in scripting language for an existing C++ application. I am able to embed the python interpreter as stated in the Python documentation. Everything works successfully with the initialization and de-initialization of the interpreter. I am, however, having trouble loading modules because I h... | 3 | 2009-04-25T19:48:00Z | 789,692 | <p>I would probably use <a href="http://peak.telecommunity.com/DevCenter/setuptools" rel="nofollow">setuptools</a> to create an egg (basically a java jar for python). The setup.py would probably look something like this:</p>
<pre><code>from setuptools import setup, find_packages
setup(
name='python26_stdlib',
... | 2 | 2009-04-25T20:42:50Z | [
"c++",
"python",
"distribution",
"embedded-language"
] |
What are some successful methods for deploying a Django application on the desktop? | 789,673 | <p>I have a Django application that I would like to deploy to the desktop. I have read a little on this and see that one way is to use <a href="http://cx-freeze.sourceforge.net/" rel="nofollow">freeze</a>. I have used this with varying success in the past for Python applications, but am not convinced it is the best app... | 4 | 2009-04-25T20:30:08Z | 1,004,965 | <p>If you want a good solution, you should give up on making it cross platform. Your code should all be portable, but your deployment - almost by definition - needs to be platform-specific.</p>
<p>I would recommend using <a href="http://py2exe.org/" rel="nofollow"><code>py2exe</code></a> on Windows, <a href="http://p... | 3 | 2009-06-17T03:28:33Z | [
"python",
"django",
"web-applications"
] |
What are some successful methods for deploying a Django application on the desktop? | 789,673 | <p>I have a Django application that I would like to deploy to the desktop. I have read a little on this and see that one way is to use <a href="http://cx-freeze.sourceforge.net/" rel="nofollow">freeze</a>. I have used this with varying success in the past for Python applications, but am not convinced it is the best app... | 4 | 2009-04-25T20:30:08Z | 1,005,333 | <p>I did this a couple years ago for a Django app running as a local daemon. It was launched by Twisted and wrapped by py2app for Mac and py2exe for Windows. There was both a browser as well as an Air front-end hitting it. It worked pretty well for the most part but I didn't get to deploy it out in the wild because the... | 5 | 2009-06-17T05:57:08Z | [
"python",
"django",
"web-applications"
] |
What is the best way to redirect email to a Python script? | 789,685 | <p>I'd like to provide a functionality for users of my website to get assigned an email address upon registration (such as firstname.lastname@mydomain.com) but I don't really think it is feasible to actually support all these emails account normally through a webmail program. I am also not sure if my webhost would be c... | 2 | 2009-04-25T20:35:44Z | 789,699 | <blockquote>
<p>but I don't really think it is
feasible to actually support all these
emails account normally through a
webmail program</p>
</blockquote>
<p>I think that your base assumption here is incorrect. You see, most 'webmail' programs are just frontends (or clients) to the backend mail system (postfix ... | 0 | 2009-04-25T20:49:17Z | [
"python",
"django",
"email"
] |
What is the best way to redirect email to a Python script? | 789,685 | <p>I'd like to provide a functionality for users of my website to get assigned an email address upon registration (such as firstname.lastname@mydomain.com) but I don't really think it is feasible to actually support all these emails account normally through a webmail program. I am also not sure if my webhost would be c... | 2 | 2009-04-25T20:35:44Z | 789,781 | <p>Your question is similar to <a href="http://stackoverflow.com/questions/484940/achieving-emailing-between-website-users-without-mailing-server-configuring/">this question</a>.</p>
<p>Use a project like <a href="http://code.google.com/p/django-messages/" rel="nofollow">django-messages</a> to handle messaging between... | 0 | 2009-04-25T21:41:07Z | [
"python",
"django",
"email"
] |
What is the best way to redirect email to a Python script? | 789,685 | <p>I'd like to provide a functionality for users of my website to get assigned an email address upon registration (such as firstname.lastname@mydomain.com) but I don't really think it is feasible to actually support all these emails account normally through a webmail program. I am also not sure if my webhost would be c... | 2 | 2009-04-25T20:35:44Z | 790,237 | <p>To directly answer your questions:</p>
<p>1,2) Check out <a href="https://help.webfaction.com/index.php?%5Fm=knowledgebase&%5Fa=viewarticle&kbarticleid=136&nav=0,3" rel="nofollow">this FAQ</a> in the WebFaction website. It explains how to easily route incoming emails into the script of your choice. When... | 4 | 2009-04-26T04:32:51Z | [
"python",
"django",
"email"
] |
What is the best way to redirect email to a Python script? | 789,685 | <p>I'd like to provide a functionality for users of my website to get assigned an email address upon registration (such as firstname.lastname@mydomain.com) but I don't really think it is feasible to actually support all these emails account normally through a webmail program. I am also not sure if my webhost would be c... | 2 | 2009-04-25T20:35:44Z | 790,278 | <p>See <a href="http://stackoverflow.com/questions/730573/django-to-send-and-receive-email/731515#731515">my answer</a> to a similar question. It has all the basic code to get you started with an email parser for Django.</p>
<p><em>Edit</em>: On second thought, here's the code:</p>
<p>There's an app called <a href="h... | 2 | 2009-04-26T05:18:51Z | [
"python",
"django",
"email"
] |
Why builtin functions instead of root class methods? | 789,718 | <p>(I'm sure this is a FAQ, but also hard to google)</p>
<p>Why does Python use abs(x) instead of x.abs?</p>
<p>As far as I see everything abs() does besides calling <code>x.__abs__</code> could just as well be implemented in object.abs()</p>
<p>Is it historical, because there hasn't always been a root class?</p>
| 4 | 2009-04-25T21:02:33Z | 789,724 | <p>I think you are looking a typical example where a language designer decides that readability and terseness trump purist constructs.</p>
| 1 | 2009-04-25T21:05:08Z | [
"python",
"oop"
] |
Why builtin functions instead of root class methods? | 789,718 | <p>(I'm sure this is a FAQ, but also hard to google)</p>
<p>Why does Python use abs(x) instead of x.abs?</p>
<p>As far as I see everything abs() does besides calling <code>x.__abs__</code> could just as well be implemented in object.abs()</p>
<p>Is it historical, because there hasn't always been a root class?</p>
| 4 | 2009-04-25T21:02:33Z | 789,732 | <p>i think it involves how object oriented way python has been used, because the first parameter of method calls on object is the object itself, so x.abs() is in essential abs(x)</p>
<p>look at the follow <a href="http://mcsp.wartburg.edu/zelle/python/python-first.html" rel="nofollow">page</a> under chapter 3.2.3 Pyth... | -3 | 2009-04-25T21:08:53Z | [
"python",
"oop"
] |
Why builtin functions instead of root class methods? | 789,718 | <p>(I'm sure this is a FAQ, but also hard to google)</p>
<p>Why does Python use abs(x) instead of x.abs?</p>
<p>As far as I see everything abs() does besides calling <code>x.__abs__</code> could just as well be implemented in object.abs()</p>
<p>Is it historical, because there hasn't always been a root class?</p>
| 4 | 2009-04-25T21:02:33Z | 789,733 | <p>The official answer from Guido van Rossum, with additional explanation from Fredrik Lundh, is here: <a href="http://effbot.org/pyfaq/why-does-python-use-methods-for-some-functionality-e-g-list-index-but-functions-for-other-e-g-len-list.htm">http://effbot.org/pyfaq/why-does-python-use-methods-for-some-functionality-e... | 13 | 2009-04-25T21:10:10Z | [
"python",
"oop"
] |
Why builtin functions instead of root class methods? | 789,718 | <p>(I'm sure this is a FAQ, but also hard to google)</p>
<p>Why does Python use abs(x) instead of x.abs?</p>
<p>As far as I see everything abs() does besides calling <code>x.__abs__</code> could just as well be implemented in object.abs()</p>
<p>Is it historical, because there hasn't always been a root class?</p>
| 4 | 2009-04-25T21:02:33Z | 789,746 | <p>Python is a language that supports object oriented coding, but it deliberately isn't a pure OO language. As you correctly mention, Python classes, even user defined ones, haven't always derived from a single base class.</p>
<p>Functions are the basic unit of functionality in Python, so it makes sense for the core o... | 0 | 2009-04-25T21:17:52Z | [
"python",
"oop"
] |
Turning on debug output for python 3 urllib | 789,856 | <p>In python 2, it was possible to get debug output from urllib by doing</p>
<pre><code>import httplib
import urllib
httplib.HTTPConnection.debuglevel = 1
response = urllib.urlopen('http://example.com').read()
</code></pre>
<p>However, in python 3 it looks like this has been moved to </p>
<pre><code>http.client.HTTP... | 13 | 2009-04-25T22:31:58Z | 790,011 | <p>You were right the first time. You can simply add the line <code>http.client.HTTPConnection.debuglevel = 1</code> at the start of your file to turn on HTTP debugging application-wide. <code>urllib.request</code> still uses <code>http.client</code>.</p>
<p>It seems that there's also a way to set the debuglevel for a... | 12 | 2009-04-26T00:34:27Z | [
"python",
"http",
"debugging",
"python-3.x",
"urllib"
] |
django on Google Appengine | 789,902 | <p>I came across 2 different modules for porting django to appengine.</p>
<p><a href="http://code.google.com/p/app-engine-patch/">http://code.google.com/p/app-engine-patch/</a></p>
<p><a href="http://code.google.com/p/google-app-engine-django/">http://code.google.com/p/google-app-engine-django/</a></p>
<p>Both seem ... | 5 | 2009-04-25T23:01:59Z | 790,169 | <p>Well, I got it myself. I used python 2.6, and it seem problmatic for app-engine. Starting with python2.5 solved it.
See <a href="http://www.google.co.il/url?sa=t&source=web&ct=res&cd=3&url=http%3A%2F%2Fcode.google.com%2Fp%2Fgoogleappengine%2Fissues%2Fdetail%3Fid%3D1159&ei=dNDzSez9OcaC%5FQb71NFW&... | 0 | 2009-04-26T03:10:59Z | [
"python",
"django",
"google-app-engine"
] |
django on Google Appengine | 789,902 | <p>I came across 2 different modules for porting django to appengine.</p>
<p><a href="http://code.google.com/p/app-engine-patch/">http://code.google.com/p/app-engine-patch/</a></p>
<p><a href="http://code.google.com/p/google-app-engine-django/">http://code.google.com/p/google-app-engine-django/</a></p>
<p>Both seem ... | 5 | 2009-04-25T23:01:59Z | 808,851 | <p>It's a bit late to answer, but the problem I've had so far with app-engine-patch is that, while it's a generally feature-complete port of Django 1.0, it discards Django models in favor of AppEngine's db.Model.</p>
<p>It's understandable, given the differences between the two, but it can require quite a bit of effor... | 1 | 2009-04-30T20:23:04Z | [
"python",
"django",
"google-app-engine"
] |
django on Google Appengine | 789,902 | <p>I came across 2 different modules for porting django to appengine.</p>
<p><a href="http://code.google.com/p/app-engine-patch/">http://code.google.com/p/app-engine-patch/</a></p>
<p><a href="http://code.google.com/p/google-app-engine-django/">http://code.google.com/p/google-app-engine-django/</a></p>
<p>Both seem ... | 5 | 2009-04-25T23:01:59Z | 968,639 | <p><a href="http://code.google.com/p/app-engine-patch/" rel="nofollow">App Engine Patch</a> is the right way to go.</p>
| 0 | 2009-06-09T07:23:28Z | [
"python",
"django",
"google-app-engine"
] |
django on Google Appengine | 789,902 | <p>I came across 2 different modules for porting django to appengine.</p>
<p><a href="http://code.google.com/p/app-engine-patch/">http://code.google.com/p/app-engine-patch/</a></p>
<p><a href="http://code.google.com/p/google-app-engine-django/">http://code.google.com/p/google-app-engine-django/</a></p>
<p>Both seem ... | 5 | 2009-04-25T23:01:59Z | 2,883,648 | <p>At the moment, the App Engine Patch is outdated.</p>
<p>Djangoappengine and Django-Nonrel provide "Native Django on App Engine":
<a href="http://www.allbuttonspressed.com/blog/django/2010/01/Native-Django-on-App-Engine" rel="nofollow">http://www.allbuttonspressed.com/blog/django/2010/01/Native-Django-on-App-Engine... | 6 | 2010-05-21T16:05:11Z | [
"python",
"django",
"google-app-engine"
] |
Locales and temperature/length conversion | 789,953 | <p>Do locales contain information about preferred units for temperature, lengths, etc. on Unix/Linux? Is it possible to access these properties from Python? I checked out the "locales" module, but didn't find anything suitable.</p>
<p>I'd like my application to automatically convert values into the most suitable unit.... | 1 | 2009-04-25T23:49:40Z | 789,969 | <p>No, that's not possible.</p>
<p>I think <a href="http://lamar.colostate.edu/~hillger/internat.htm" rel="nofollow">every country in the world</a> is on the metric system, with the dubious exceptions of the United States and a few others. With that said, you can be confident about choosing metric.</p>
<p>You'd want... | 3 | 2009-04-25T23:59:45Z | [
"python",
"localization"
] |
Locales and temperature/length conversion | 789,953 | <p>Do locales contain information about preferred units for temperature, lengths, etc. on Unix/Linux? Is it possible to access these properties from Python? I checked out the "locales" module, but didn't find anything suitable.</p>
<p>I'd like my application to automatically convert values into the most suitable unit.... | 1 | 2009-04-25T23:49:40Z | 790,078 | <p>For what it's worth, KDE offers a choice of "Metric" or "Imperial" as the standard unit system, so I would presume that it's possible to access that information through Python somehow. Gnome might have a similar setting, I'm not sure... but I don't think there's any equivalent for a generic UNIX/Linux system.</p>
... | 0 | 2009-04-26T01:25:52Z | [
"python",
"localization"
] |
cannot run appengine-admin on dev_server | 790,001 | <p>I've decided to try out this project:</p>
<p><a href="http://code.google.com/p/appengine-admin/wiki/QuickStart" rel="nofollow">http://code.google.com/p/appengine-admin/wiki/QuickStart</a></p>
<p>For the sake of the experiment, I took the demo guest-book shipped with app-engine. The import park look like this:</p>... | 4 | 2009-04-26T00:26:49Z | 790,234 | <p>You appear to be using Python 2.6 (given that some of the messages are from files in /usr/lib/python2.6 ...!), but Google App Engine needs Python 2.5 (any 2.5.x will do for any versions of x), so you should install and use that to run the App Engine SDK.</p>
| 4 | 2009-04-26T04:28:38Z | [
"python",
"google-app-engine"
] |
cannot run appengine-admin on dev_server | 790,001 | <p>I've decided to try out this project:</p>
<p><a href="http://code.google.com/p/appengine-admin/wiki/QuickStart" rel="nofollow">http://code.google.com/p/appengine-admin/wiki/QuickStart</a></p>
<p>For the sake of the experiment, I took the demo guest-book shipped with app-engine. The import park look like this:</p>... | 4 | 2009-04-26T00:26:49Z | 823,085 | <p>It wired that I have been using GAE with python2.6(probably 2.6.1), and every thing worked fine.</p>
<p>But now I get the same _multiprocess import error.(python2.6.2).</p>
| 0 | 2009-05-05T02:42:49Z | [
"python",
"google-app-engine"
] |
cannot run appengine-admin on dev_server | 790,001 | <p>I've decided to try out this project:</p>
<p><a href="http://code.google.com/p/appengine-admin/wiki/QuickStart" rel="nofollow">http://code.google.com/p/appengine-admin/wiki/QuickStart</a></p>
<p>For the sake of the experiment, I took the demo guest-book shipped with app-engine. The import park look like this:</p>... | 4 | 2009-04-26T00:26:49Z | 824,270 | <p>just do the following at the top of your something.py </p>
<p>import logging
logging.logMultiprocessing = 0</p>
| 1 | 2009-05-05T10:28:23Z | [
"python",
"google-app-engine"
] |
cannot run appengine-admin on dev_server | 790,001 | <p>I've decided to try out this project:</p>
<p><a href="http://code.google.com/p/appengine-admin/wiki/QuickStart" rel="nofollow">http://code.google.com/p/appengine-admin/wiki/QuickStart</a></p>
<p>For the sake of the experiment, I took the demo guest-book shipped with app-engine. The import park look like this:</p>... | 4 | 2009-04-26T00:26:49Z | 873,357 | <pre><code>import logging
logging.logMultiprocessing = 0
</code></pre>
<p>Worked for me</p>
| 1 | 2009-05-16T21:26:49Z | [
"python",
"google-app-engine"
] |
cannot run appengine-admin on dev_server | 790,001 | <p>I've decided to try out this project:</p>
<p><a href="http://code.google.com/p/appengine-admin/wiki/QuickStart" rel="nofollow">http://code.google.com/p/appengine-admin/wiki/QuickStart</a></p>
<p>For the sake of the experiment, I took the demo guest-book shipped with app-engine. The import park look like this:</p>... | 4 | 2009-04-26T00:26:49Z | 951,296 | <pre><code>import logging
logging.logMultiprocessing = 0
</code></pre>
<p>Worked for me too. Before uploading to GAE, comment those lines.</p>
| 0 | 2009-06-04T15:30:55Z | [
"python",
"google-app-engine"
] |
cannot run appengine-admin on dev_server | 790,001 | <p>I've decided to try out this project:</p>
<p><a href="http://code.google.com/p/appengine-admin/wiki/QuickStart" rel="nofollow">http://code.google.com/p/appengine-admin/wiki/QuickStart</a></p>
<p>For the sake of the experiment, I took the demo guest-book shipped with app-engine. The import park look like this:</p>... | 4 | 2009-04-26T00:26:49Z | 1,225,771 | <p>Google App Engine only supports Python 2.5, and you're on a newer version.</p>
<p>By the look of your directories, you might be on a Linux (or is it a Mac?). On, say, Ubuntu you can "sudo apt-get install python2.5" (it won't affect your Python 2.6 at all), and then rather than:</p>
<pre><code><path-to-gae>/d... | 3 | 2009-08-04T04:44:46Z | [
"python",
"google-app-engine"
] |
cannot run appengine-admin on dev_server | 790,001 | <p>I've decided to try out this project:</p>
<p><a href="http://code.google.com/p/appengine-admin/wiki/QuickStart" rel="nofollow">http://code.google.com/p/appengine-admin/wiki/QuickStart</a></p>
<p>For the sake of the experiment, I took the demo guest-book shipped with app-engine. The import park look like this:</p>... | 4 | 2009-04-26T00:26:49Z | 1,372,538 | <p>To make this work on my local machine (with 2.6) and on GAE, I used:</p>
<pre><code>import sys, logging
if sys.version[:3] == "2.6": logging.logMultiprocessing = 0
</code></pre>
| 2 | 2009-09-03T10:03:03Z | [
"python",
"google-app-engine"
] |
cannot run appengine-admin on dev_server | 790,001 | <p>I've decided to try out this project:</p>
<p><a href="http://code.google.com/p/appengine-admin/wiki/QuickStart" rel="nofollow">http://code.google.com/p/appengine-admin/wiki/QuickStart</a></p>
<p>For the sake of the experiment, I took the demo guest-book shipped with app-engine. The import park look like this:</p>... | 4 | 2009-04-26T00:26:49Z | 1,736,651 | <p>As others have said, this problem occurs in Python 2.6. I used the fix proposed in <a href="http://code.google.com/p/googleappengine/issues/detail?id=1504#c7" rel="nofollow">this comment in the App Engine issue tracker</a>:</p>
<pre><code>A quickfix is to create a file in your app's root named `_multiprocessing.py... | 3 | 2009-11-15T05:10:18Z | [
"python",
"google-app-engine"
] |
How do I return a CSV from a Pylons app? | 790,019 | <p>I'm trying to return a CSV from an action in my webapp, and give the user a prompt to download the file or open it from a spreadsheet app. I can get the CSV to spit out onto the screen, but how do I change the type of the file so that the browser recognizes that this isn't supposed to be displayed as HTML? Can I use... | 11 | 2009-04-26T00:36:32Z | 790,033 | <p>To tell the browser the type of content you're giving it, you need to set the <code>Content-type</code> header to 'text/csv'. In your Pylons function, the following should do the job:</p>
<p><code>response.headers['Content-type'] = 'text/csv'</code></p>
| 12 | 2009-04-26T00:45:28Z | [
"python",
"csv",
"pylons"
] |
How do I return a CSV from a Pylons app? | 790,019 | <p>I'm trying to return a CSV from an action in my webapp, and give the user a prompt to download the file or open it from a spreadsheet app. I can get the CSV to spit out onto the screen, but how do I change the type of the file so that the browser recognizes that this isn't supposed to be displayed as HTML? Can I use... | 11 | 2009-04-26T00:36:32Z | 790,140 | <p>PAG is correct, but furthermore if you want to suggest a name for the downloaded file you can also set <code>response.headers['Content-disposition'] = 'attachment; filename=suggest.csv'</code></p>
| 9 | 2009-04-26T02:29:20Z | [
"python",
"csv",
"pylons"
] |
How do I return a CSV from a Pylons app? | 790,019 | <p>I'm trying to return a CSV from an action in my webapp, and give the user a prompt to download the file or open it from a spreadsheet app. I can get the CSV to spit out onto the screen, but how do I change the type of the file so that the browser recognizes that this isn't supposed to be displayed as HTML? Can I use... | 11 | 2009-04-26T00:36:32Z | 1,441,002 | <p>Yes, you can use the csv module for this:</p>
<pre><code>import csv
from cStringIO import StringIO
</code></pre>
<p>...</p>
<pre><code>def results_csv(self):
response.headers['Content-Type'] = 'text/csv'
s = StringIO()
writer = csv.writer(s)
writer.writerow(['header', 'header', 'header'])
writ... | 7 | 2009-09-17T19:56:02Z | [
"python",
"csv",
"pylons"
] |
Is it possible to call a Python module from ObjC? | 790,103 | <p>Using PyObjC, is it possible to import a Python module, call a function and get the result as (say) a NSString?</p>
<p>For example, doing the equivalent of the following Python code:</p>
<pre><code>import mymodule
result = mymodule.mymethod()
</code></pre>
<p>..in pseudo-ObjC:</p>
<pre><code>PyModule *mypymod = ... | 6 | 2009-04-26T01:52:07Z | 790,133 | <p>Not quite, AFAIK, but you can do it "the C way", as suggested for example in <a href="http://lists.apple.com/archives/Cocoa-dev/2004/Jan/msg00598.html" rel="nofollow">http://lists.apple.com/archives/Cocoa-dev/2004/Jan/msg00598.html</a> -- or "the Pyobjc way" as per <a href="http://osdir.com/ml/python.pyobjc.devel/20... | 3 | 2009-04-26T02:24:26Z | [
"python",
"objective-c",
"pyobjc"
] |
Is it possible to call a Python module from ObjC? | 790,103 | <p>Using PyObjC, is it possible to import a Python module, call a function and get the result as (say) a NSString?</p>
<p>For example, doing the equivalent of the following Python code:</p>
<pre><code>import mymodule
result = mymodule.mymethod()
</code></pre>
<p>..in pseudo-ObjC:</p>
<pre><code>PyModule *mypymod = ... | 6 | 2009-04-26T01:52:07Z | 791,077 | <p>As mentioned in Alex Martelli's answer (although the link in the mailing-list message was broken, it should be <a href="https://docs.python.org/extending/embedding.html#pure-embedding" rel="nofollow">https://docs.python.org/extending/embedding.html#pure-embedding</a>).. The C way of calling.. </p>
<pre><code>print ... | 12 | 2009-04-26T15:45:38Z | [
"python",
"objective-c",
"pyobjc"
] |
Is there a replacement for Paste.Template? | 790,534 | <p>I have grown tired of all the little issues with paste template, it's horrible to maintain the templates, it has no way of updating an old project and it's very hard to test. </p>
<p>I'm wondering if someone knows of an alternative for quickstart generators as they have proven to be useful.</p>
| 1 | 2009-04-26T09:14:44Z | 790,555 | <p>I haven't used paste templates, so I'm not sure how it compares, but <a href="http://www.makotemplates.org/" rel="nofollow">Mako</a> seems like a fairly good system.</p>
<p>A snippet of the template language from their front page:</p>
<pre><code><%inherit file="base.html"/>
<%
rows = [[v for v in rang... | -1 | 2009-04-26T09:33:49Z | [
"python",
"templates",
"generator"
] |
Object class override or modify | 790,560 | <p>Is it possible to add a method to an object class, and use it on all objects?</p>
| 4 | 2009-04-26T09:36:41Z | 790,574 | <pre>
>>> object.test = "Test"
Traceback (most recent call last):
File "", line 1, in
TypeError: can't set attributes of built-in/extension type 'object'
</pre>
<p>Doesn't look like it. (Python 2.5.1)</p>
| 0 | 2009-04-26T09:48:28Z | [
"python"
] |
Object class override or modify | 790,560 | <p>Is it possible to add a method to an object class, and use it on all objects?</p>
| 4 | 2009-04-26T09:36:41Z | 790,588 | <p>In Python attributes are implemented using a dictionary :</p>
<pre><code>>>> t = test()
>>> t.__dict__["foo"] = "bla"
>>> t.foo
'bla'
</code></pre>
<p>But for "object", it uses a 'dictproxy' as an interface to prevent such assignement :</p>
<pre><code>>>> object.__dict__["test"... | 8 | 2009-04-26T10:04:12Z | [
"python"
] |
Object class override or modify | 790,560 | <p>Is it possible to add a method to an object class, and use it on all objects?</p>
| 4 | 2009-04-26T09:36:41Z | 791,093 | <p>No, Python's internals take great care to make built-in types NOT mutable -- very different design choices from Ruby's. It's not possible to make object "monkeypatchable" without deeply messing with the C-coded internals and recompiling the Python runtime to make a very different version (this is for the classic CP... | 5 | 2009-04-26T16:07:06Z | [
"python"
] |
Using Python set type to implement ACL | 790,613 | <p>Currently I have tables like: <code>Pages, Groups, GroupPage, Users, UserGroup</code>. With pickled sets I can implement the same thing with only 3 tables: <code>Pages, Groups, Users</code>.</p>
<p><code>set</code> seems a natural choice for implementing ACL, as group and permission related operations can be expres... | 1 | 2009-04-26T10:37:33Z | 790,662 | <p>You need to consider what it is that a DBMS provides you with, and which of those features you'll need to reimplement.
The issue of concurrency is a big one. There are a few race conditions to be considered (such as multiple writes taking place in different threads and processes and overwriting the new data), perfor... | 2 | 2009-04-26T11:18:04Z | [
"python",
"set",
"acl",
"pickle"
] |
Using Python set type to implement ACL | 790,613 | <p>Currently I have tables like: <code>Pages, Groups, GroupPage, Users, UserGroup</code>. With pickled sets I can implement the same thing with only 3 tables: <code>Pages, Groups, Users</code>.</p>
<p><code>set</code> seems a natural choice for implementing ACL, as group and permission related operations can be expres... | 1 | 2009-04-26T10:37:33Z | 790,673 | <p>If you're going to pickle sets, you should find a good object database (like <a href="http://wiki.zope.org/ZODB/FrontPage" rel="nofollow">ZODB</a>). In a pure-relational world, your sets are stored as BLOBS, which works out well. Trying to pickle sets in an ORM situation may lead to confusing problems with the ORM... | 3 | 2009-04-26T11:24:59Z | [
"python",
"set",
"acl",
"pickle"
] |
Using Python set type to implement ACL | 790,613 | <p>Currently I have tables like: <code>Pages, Groups, GroupPage, Users, UserGroup</code>. With pickled sets I can implement the same thing with only 3 tables: <code>Pages, Groups, Users</code>.</p>
<p><code>set</code> seems a natural choice for implementing ACL, as group and permission related operations can be expres... | 1 | 2009-04-26T10:37:33Z | 790,675 | <p>If it simplifies things and you won't be editing the file a whole lot (or it will be edited infrequently), I say go for it. Of course, a third option to consider is using a <a href="http://docs.python.org/library/sqlite3.html" rel="nofollow">sqlite</a> database to store this stuff. There are tools to make these ea... | 1 | 2009-04-26T11:26:36Z | [
"python",
"set",
"acl",
"pickle"
] |
Using Python set type to implement ACL | 790,613 | <p>Currently I have tables like: <code>Pages, Groups, GroupPage, Users, UserGroup</code>. With pickled sets I can implement the same thing with only 3 tables: <code>Pages, Groups, Users</code>.</p>
<p><code>set</code> seems a natural choice for implementing ACL, as group and permission related operations can be expres... | 1 | 2009-04-26T10:37:33Z | 791,425 | <p>Me, I'd stick with keeping persistent info in the relational DB in a form that's independent from a specific programming language used to access it -- much as I love Python (and that's a <strong>lot</strong>), some day I may want to access that info from some other language, and if I went for Python-specific formats... | 2 | 2009-04-26T19:18:26Z | [
"python",
"set",
"acl",
"pickle"
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.