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 |
|---|---|---|---|---|---|---|---|---|---|
Subtract dict A from dict B (deep del)? | 2,100,697 | <p>If I have a deeply nested dict is there a built-in way to subtract/remove list of "paths" (eg: keyA.keyB.key1, keyA.keyC.key2, etc) or a the keys of a second dict from the original dict? Or maybe there is a common module which has functionality like this?</p>
| 4 | 2010-01-20T10:42:32Z | 2,101,407 | <p>Another solution:</p>
<pre><code>d = {
'A' : {
'C' : {
'D' : {
'E' : 4,
},
'F' : 5,
},
},
'B' : 2,
}
def DeepDictDel(path, dict):
for key in path.split('.'):
owner = dict
dict = dict[key]
del owner[key]
print... | 1 | 2010-01-20T12:51:39Z | [
"python",
"dictionary"
] |
Subtract dict A from dict B (deep del)? | 2,100,697 | <p>If I have a deeply nested dict is there a built-in way to subtract/remove list of "paths" (eg: keyA.keyB.key1, keyA.keyC.key2, etc) or a the keys of a second dict from the original dict? Or maybe there is a common module which has functionality like this?</p>
| 4 | 2010-01-20T10:42:32Z | 2,102,174 | <p>Just in case the other answers aren't what you're looking for, here's one that subtracts one dictionary from another.</p>
<pre><code>def subtract(a, b):
""" Remove the keys in b from a. """
for k in b:
if k in a:
if isinstance(b[k], dict):
subtract(a[k], b[k])
... | 2 | 2010-01-20T14:49:50Z | [
"python",
"dictionary"
] |
Can not get the Auth Token for GData After Authentication on App Engine | 2,100,699 | <p>I would like to pull the Auth Token for the Gdata auth so that I can write to a google calendar. I am having issues getting the token after authentication so that I can send the token to the calendar service.</p>
<p>I am using the default login screen provided by appengine (/_ah/login) and I am able to login and au... | 0 | 2010-01-20T10:43:00Z | 2,101,920 | <p>The login screen only authenticates the user to your application, it does not give you authorization to the user's gdata. </p>
<p>You will need to have the user authorize your use of the calendar api - I suggest through oauth here: <a href="http://code.google.com/apis/gdata/docs/auth/overview.html#OAuth" rel="nofo... | 3 | 2010-01-20T14:17:05Z | [
"python",
"google-app-engine",
"gdata-api",
"gdata",
"google-data-api"
] |
Can not get the Auth Token for GData After Authentication on App Engine | 2,100,699 | <p>I would like to pull the Auth Token for the Gdata auth so that I can write to a google calendar. I am having issues getting the token after authentication so that I can send the token to the calendar service.</p>
<p>I am using the default login screen provided by appengine (/_ah/login) and I am able to login and au... | 0 | 2010-01-20T10:43:00Z | 3,782,884 | <p>There are limitations about number of tokens outstanding - e.g. numbers of users possible. What about number of ClientLogin tokens outstanding?</p>
| 0 | 2010-09-23T22:10:17Z | [
"python",
"google-app-engine",
"gdata-api",
"gdata",
"google-data-api"
] |
Is there a javascript equivalent to unpack sequences like in python? | 2,100,731 | <p>Is there a javascript equivalent to unpack sequences like in python?</p>
<pre><code>a, b = (1, 2)
</code></pre>
| 11 | 2010-01-20T10:48:23Z | 2,100,754 | <p>There isn't. JavaScript doesn't have such syntax sugar.</p>
| 10 | 2010-01-20T10:53:06Z | [
"javascript",
"python",
"iterable-unpacking"
] |
Is there a javascript equivalent to unpack sequences like in python? | 2,100,731 | <p>Is there a javascript equivalent to unpack sequences like in python?</p>
<pre><code>a, b = (1, 2)
</code></pre>
| 11 | 2010-01-20T10:48:23Z | 2,100,781 | <pre><code>[a, b] = [1, 2]
</code></pre>
<p><strong>Update:</strong></p>
<p>Browser compatibility matrix:</p>
<ul>
<li>Firefox: all versions</li>
<li>Opera: 9.x only</li>
<li>Chrome: no</li>
<li>MSIE: no</li>
</ul>
| 4 | 2010-01-20T10:56:51Z | [
"javascript",
"python",
"iterable-unpacking"
] |
Is there a javascript equivalent to unpack sequences like in python? | 2,100,731 | <p>Is there a javascript equivalent to unpack sequences like in python?</p>
<pre><code>a, b = (1, 2)
</code></pre>
| 11 | 2010-01-20T10:48:23Z | 2,100,833 | <p>An object cannot contain a reference to an integer, only its value. So I can't see any way to do what you ask in javascript.</p>
| 0 | 2010-01-20T11:07:41Z | [
"javascript",
"python",
"iterable-unpacking"
] |
How to call a function and change a variable | 2,100,847 | <p>I am calling a function several times as I am testing several responses. I am asking on how I call a function earlier in the program, changing a variable in this function and then calling it. Below is a snippet of the code.</p>
<pre><code>class AbsoluteMove(unittest.TestCase):
def Ssh(self):
p=pexpec... | 0 | 2010-01-20T11:09:42Z | 2,100,890 | <p>You'll need to have a wrapper for the runTest function. Notice that I commented the <code>self.command='./ptzpanposition -c 0 -u degx10'</code> in <code>runTest</code></p>
<pre><code>class VerifyTilt(AbsoluteMove):
def testWrapper(self):
self.command = './ptzpanposition -c 0 -u degx10'
runTest()
sel... | 0 | 2010-01-20T11:16:28Z | [
"python",
"inheritance",
"variables"
] |
How to call a function and change a variable | 2,100,847 | <p>I am calling a function several times as I am testing several responses. I am asking on how I call a function earlier in the program, changing a variable in this function and then calling it. Below is a snippet of the code.</p>
<pre><code>class AbsoluteMove(unittest.TestCase):
def Ssh(self):
p=pexpec... | 0 | 2010-01-20T11:09:42Z | 2,100,891 | <p>is it doable to add another parameter to Absolute Move?</p>
| 1 | 2010-01-20T11:16:43Z | [
"python",
"inheritance",
"variables"
] |
How to call a function and change a variable | 2,100,847 | <p>I am calling a function several times as I am testing several responses. I am asking on how I call a function earlier in the program, changing a variable in this function and then calling it. Below is a snippet of the code.</p>
<pre><code>class AbsoluteMove(unittest.TestCase):
def Ssh(self):
p=pexpec... | 0 | 2010-01-20T11:09:42Z | 2,100,904 | <p>What it looks like is that self.command is just a string, and since AbsoluteMove.Ssh() takes no arguments it must use that string somehow..., so you could just change the value of self.command. A better design would have two commands, and an argument to AbsoluteMove.Ssh() to choose between them.</p>
| 0 | 2010-01-20T11:18:23Z | [
"python",
"inheritance",
"variables"
] |
How to call a function and change a variable | 2,100,847 | <p>I am calling a function several times as I am testing several responses. I am asking on how I call a function earlier in the program, changing a variable in this function and then calling it. Below is a snippet of the code.</p>
<pre><code>class AbsoluteMove(unittest.TestCase):
def Ssh(self):
p=pexpec... | 0 | 2010-01-20T11:09:42Z | 2,101,265 | <p>Sorry for wasting time,</p>
<p>I had declared the variable in the Ssh() function. I removed this and the variables were changed later down the code. The code will work this way thanks.</p>
| 0 | 2010-01-20T12:25:02Z | [
"python",
"inheritance",
"variables"
] |
Making a web interface to a script that takes 30 minutes to execute | 2,101,052 | <p>I wrote a python script to process some data from CSV files. The script takes between 3 to 30 minutes to complete, depending on the size of the CSV.</p>
<p>Now I want to put in a web interface to this, so I can upload the CSV data files from anywhere. I wrote a basic HTTP POST upload page and used Python's CGI modu... | 7 | 2010-01-20T11:47:10Z | 2,101,073 | <p>I've had this situation before and I used cronjobs. The HTTP script would just write in a queue a job to be performed (a DB or a file in a directory) and the cronjob would read it and execute that job.</p>
| 5 | 2010-01-20T11:52:15Z | [
"python",
"http-headers",
"timeout",
"http-status-code-504"
] |
Making a web interface to a script that takes 30 minutes to execute | 2,101,052 | <p>I wrote a python script to process some data from CSV files. The script takes between 3 to 30 minutes to complete, depending on the size of the CSV.</p>
<p>Now I want to put in a web interface to this, so I can upload the CSV data files from anywhere. I wrote a basic HTTP POST upload page and used Python's CGI modu... | 7 | 2010-01-20T11:47:10Z | 2,101,085 | <p>imho the best way would be to run an independent script which posts updates somewhere (flat file, database, etc...). I don't know how to fork an independent process from python so i can't give any code examples.</p>
<p>To show progress on a WebSite implement an ajax request to a page that reads those status updates... | 1 | 2010-01-20T11:54:01Z | [
"python",
"http-headers",
"timeout",
"http-status-code-504"
] |
Making a web interface to a script that takes 30 minutes to execute | 2,101,052 | <p>I wrote a python script to process some data from CSV files. The script takes between 3 to 30 minutes to complete, depending on the size of the CSV.</p>
<p>Now I want to put in a web interface to this, so I can upload the CSV data files from anywhere. I wrote a basic HTTP POST upload page and used Python's CGI modu... | 7 | 2010-01-20T11:47:10Z | 2,101,110 | <p>You'll probably need to do a <code>stdout.flush()</code>, as the script isn't really writing anything yet to the webserver until you've written a page buffer's worth of data - which doesn't happen before the timeout.</p>
<p>But the proper way to solve this is, as others suggested, to do the processing in a separate... | 4 | 2010-01-20T11:59:40Z | [
"python",
"http-headers",
"timeout",
"http-status-code-504"
] |
Making a web interface to a script that takes 30 minutes to execute | 2,101,052 | <p>I wrote a python script to process some data from CSV files. The script takes between 3 to 30 minutes to complete, depending on the size of the CSV.</p>
<p>Now I want to put in a web interface to this, so I can upload the CSV data files from anywhere. I wrote a basic HTTP POST upload page and used Python's CGI modu... | 7 | 2010-01-20T11:47:10Z | 2,101,113 | <p>I would separate the work like this:</p>
<ol>
<li><p>A web app URL that accept the POSTed CSV file. The web app puts the CSV content into an off line queue, for instance a database table. The web app's response should be an unique ID for the queued item (use an auto-incremented ID column, for instance). The client ... | 12 | 2010-01-20T12:00:21Z | [
"python",
"http-headers",
"timeout",
"http-status-code-504"
] |
Making a web interface to a script that takes 30 minutes to execute | 2,101,052 | <p>I wrote a python script to process some data from CSV files. The script takes between 3 to 30 minutes to complete, depending on the size of the CSV.</p>
<p>Now I want to put in a web interface to this, so I can upload the CSV data files from anywhere. I wrote a basic HTTP POST upload page and used Python's CGI modu... | 7 | 2010-01-20T11:47:10Z | 2,101,134 | <p>See Randal Schwartz's <a href="http://www.stonehenge.com/merlyn/LinuxMag/col39.html" rel="nofollow">Watching long processes through CGI</a>. The article uses Perl, but the technique does not depend on the language.</p>
| 2 | 2010-01-20T12:03:14Z | [
"python",
"http-headers",
"timeout",
"http-status-code-504"
] |
Making a web interface to a script that takes 30 minutes to execute | 2,101,052 | <p>I wrote a python script to process some data from CSV files. The script takes between 3 to 30 minutes to complete, depending on the size of the CSV.</p>
<p>Now I want to put in a web interface to this, so I can upload the CSV data files from anywhere. I wrote a basic HTTP POST upload page and used Python's CGI modu... | 7 | 2010-01-20T11:47:10Z | 2,101,155 | <p>Very similar question <a href="http://stackoverflow.com/questions/510455/how-can-i-keep-an-ie-page-request-alive-more-than-1-minute">here</a>. I suggest spawning off the lengthy process and returning an ajax based progress bar to the user. This way they user has the luxury of the web-interface and you have the luxur... | 2 | 2010-01-20T12:06:52Z | [
"python",
"http-headers",
"timeout",
"http-status-code-504"
] |
problem in installing django | 2,101,132 | <p>problem with installing django
i am geting folllowing error</p>
<pre><code>E:\Softwares\Django-1.1.1.tar\Django-1.1.1\Django-1.1.1>setup.py install
Traceback (most recent call last):
File "E:\Softwares\Django-1.1.1.tar\Django-1.1.1\Django-1.1.1\setup.py", line
48, in ?
root_dir = os.path.dirname(__file__)
... | 0 | 2010-01-20T12:03:13Z | 2,101,229 | <p>You should use<code>python setup.py install</code></p>
| 0 | 2010-01-20T12:19:16Z | [
"python",
"django"
] |
problem in installing django | 2,101,132 | <p>problem with installing django
i am geting folllowing error</p>
<pre><code>E:\Softwares\Django-1.1.1.tar\Django-1.1.1\Django-1.1.1>setup.py install
Traceback (most recent call last):
File "E:\Softwares\Django-1.1.1.tar\Django-1.1.1\Django-1.1.1\setup.py", line
48, in ?
root_dir = os.path.dirname(__file__)
... | 0 | 2010-01-20T12:03:13Z | 2,102,536 | <p>The Python version you are using, 2.2, is more than seven years old. Django is only compatible with versions 2.4 upwards.</p>
| 4 | 2010-01-20T15:32:44Z | [
"python",
"django"
] |
Parsing a stdout in Python | 2,101,426 | <p>In Python I need to get the version of an external binary I need to call in my script.</p>
<p>Let's say that I want to use <a href="http://en.wikipedia.org/wiki/Wget">Wget</a> in Python and I want to know its version.</p>
<p>I will call </p>
<pre><code>os.system( "wget --version | grep Wget" )
</code></pre>
<p>... | 7 | 2010-01-20T12:54:41Z | 2,101,436 | <p>use <a href="http://docs.python.org/library/subprocess.html" rel="nofollow"><code>subprocess</code></a>.</p>
| 2 | 2010-01-20T12:56:55Z | [
"python"
] |
Parsing a stdout in Python | 2,101,426 | <p>In Python I need to get the version of an external binary I need to call in my script.</p>
<p>Let's say that I want to use <a href="http://en.wikipedia.org/wiki/Wget">Wget</a> in Python and I want to know its version.</p>
<p>I will call </p>
<pre><code>os.system( "wget --version | grep Wget" )
</code></pre>
<p>... | 7 | 2010-01-20T12:54:41Z | 2,101,437 | <p>Use <code>subprocess</code> instead.</p>
| 0 | 2010-01-20T12:57:11Z | [
"python"
] |
Parsing a stdout in Python | 2,101,426 | <p>In Python I need to get the version of an external binary I need to call in my script.</p>
<p>Let's say that I want to use <a href="http://en.wikipedia.org/wiki/Wget">Wget</a> in Python and I want to know its version.</p>
<p>I will call </p>
<pre><code>os.system( "wget --version | grep Wget" )
</code></pre>
<p>... | 7 | 2010-01-20T12:54:41Z | 2,101,448 | <p>One "old" way is:</p>
<pre><code>fin,fout=os.popen4("wget --version | grep Wget")
print fout.read()
</code></pre>
<p>The other modern way is to use a <code>subprocess</code> module:</p>
<pre><code>import subprocess
cmd = subprocess.Popen('wget --version', shell=True, stdout=subprocess.PIPE)
for line in cmd.stdout... | 27 | 2010-01-20T12:58:23Z | [
"python"
] |
Parsing a stdout in Python | 2,101,426 | <p>In Python I need to get the version of an external binary I need to call in my script.</p>
<p>Let's say that I want to use <a href="http://en.wikipedia.org/wiki/Wget">Wget</a> in Python and I want to know its version.</p>
<p>I will call </p>
<pre><code>os.system( "wget --version | grep Wget" )
</code></pre>
<p>... | 7 | 2010-01-20T12:54:41Z | 2,101,458 | <p>Use the <code>subprocess</code> module:</p>
<pre><code>from subprocess import Popen, PIPE
p1 = Popen(["wget", "--version"], stdout=PIPE)
p2 = Popen(["grep", "Wget"], stdin=p1.stdout, stdout=PIPE)
output = p2.communicate()[0]
</code></pre>
| 8 | 2010-01-20T13:00:34Z | [
"python"
] |
Parsing a stdout in Python | 2,101,426 | <p>In Python I need to get the version of an external binary I need to call in my script.</p>
<p>Let's say that I want to use <a href="http://en.wikipedia.org/wiki/Wget">Wget</a> in Python and I want to know its version.</p>
<p>I will call </p>
<pre><code>os.system( "wget --version | grep Wget" )
</code></pre>
<p>... | 7 | 2010-01-20T12:54:41Z | 2,101,482 | <p>If you are on *nix, I would recommend you to use commands module.</p>
<pre><code>import commands
status, res = commands.getstatusoutput("wget --version | grep Wget")
print status # Should be zero in case of of success, otherwise would have an error code
print res # Contains stdout
</code></pre>
| 0 | 2010-01-20T13:05:22Z | [
"python"
] |
Google App Engine and OpenID | 2,101,817 | <p>I am trying to implement OpenID in a GoogleAppEngine project. In this case, which OpenIDStore I have to use. Thanks</p>
| 1 | 2010-01-20T14:01:50Z | 2,102,518 | <p>Have you tried using the <a href="http://blog.notdot.net/2009/12/OpenID-on-App-Engine-made-easy-with-AEoid" rel="nofollow">AEoid</a> library? I haven't tried this myself, but it looks promising.</p>
<p>In case you are using java... <a href="http://code.google.com/p/dyuproject/" rel="nofollow">http://code.google.com... | 3 | 2010-01-20T15:30:47Z | [
"python",
"google-app-engine",
"openid"
] |
Google App Engine and OpenID | 2,101,817 | <p>I am trying to implement OpenID in a GoogleAppEngine project. In this case, which OpenIDStore I have to use. Thanks</p>
| 1 | 2010-01-20T14:01:50Z | 2,109,783 | <p>I try with AEoid which seems alright. Here's <a href="http://www.koolbusiness.com" rel="nofollow">live example</a> and <a href="http://montao.googlecode.com" rel="nofollow">my code</a></p>
| 0 | 2010-01-21T14:11:55Z | [
"python",
"google-app-engine",
"openid"
] |
Django primary key | 2,101,838 | <p>When querying in django say <code>People.objects.all(pk=code)</code>, what does <code>pk=code</code> mean?</p>
| 1 | 2010-01-20T14:06:04Z | 2,101,869 | <p>It's a query to get the People object that has a primary key of whatever the value of "code" is.</p>
<p>By default, all Django model instances have a primary key that uniquely identifies the object. Generally it's an auto-incrementing integer, but you could define it to be whatever you want, so long as it's certain... | 5 | 2010-01-20T14:11:15Z | [
"python",
"django"
] |
Django primary key | 2,101,838 | <p>When querying in django say <code>People.objects.all(pk=code)</code>, what does <code>pk=code</code> mean?</p>
| 1 | 2010-01-20T14:06:04Z | 2,102,333 | <p>Calling <code>People.objects.all(pk=code)</code> (calling <strong>all</strong>) will result in the pk=code being ignored and a QuerySet for all People returned.</p>
<p>Calling <code>People.objects.get(pk=code)</code> (calling <strong>get</strong>) will result in the People object with pk=code returned, or an error ... | 6 | 2010-01-20T15:08:22Z | [
"python",
"django"
] |
serializing python objects to XML | 2,101,902 | <p>I need to serialize my python objects to XML. I tried to use Django one but it's only for QuerySet objects and not for any simple Python object.</p>
<p>Is there any package to do that?</p>
| 6 | 2010-01-20T14:14:30Z | 2,101,938 | <p><a href="http://freshmeat.net/projects/gnosisxml/" rel="nofollow">http://freshmeat.net/projects/gnosisxml/</a></p>
| 4 | 2010-01-20T14:19:32Z | [
"python"
] |
serializing python objects to XML | 2,101,902 | <p>I need to serialize my python objects to XML. I tried to use Django one but it's only for QuerySet objects and not for any simple Python object.</p>
<p>Is there any package to do that?</p>
| 6 | 2010-01-20T14:14:30Z | 2,101,939 | <p>You could also have a look at the <a href="http://lxml.de/objectify.html" rel="nofollow">objectify</a> module from lxml.</p>
| 4 | 2010-01-20T14:19:33Z | [
"python"
] |
Python state-machine design | 2,101,961 | <p>Related to this <strong><a href="http://stackoverflow.com/questions/1647631/c-state-machine-design">SO question (C state-machine design)</a></strong>, could you SO folks share with me (and the community!) your Python state-machine design techniques?</p>
<p><strong>Update3</strong>: At the moment, I am going for an ... | 34 | 2010-01-20T14:22:22Z | 2,102,001 | <p>I don't really get the question. The <strong>State</strong> Design pattern is pretty clear. See the <a href="http://rads.stackoverflow.com/amzn/click/0201633612">Design Patterns book</a>.</p>
<pre><code>class SuperState( object ):
def someStatefulMethod( self ):
raise NotImplementedError()
def tra... | 30 | 2010-01-20T14:27:44Z | [
"python",
"state-machines",
"fsm"
] |
Python state-machine design | 2,101,961 | <p>Related to this <strong><a href="http://stackoverflow.com/questions/1647631/c-state-machine-design">SO question (C state-machine design)</a></strong>, could you SO folks share with me (and the community!) your Python state-machine design techniques?</p>
<p><strong>Update3</strong>: At the moment, I am going for an ... | 34 | 2010-01-20T14:22:22Z | 2,102,129 | <p>It probably depends on how complex your state machine is. For simple state machines, a dict of dicts (of event-keys to state-keys for DFAs, or event-keys to lists/sets/tuples of state-keys for NFAs) will probably be the simplest thing to write and understand.</p>
<p>For more complex state machines, I've heard good ... | 2 | 2010-01-20T14:45:07Z | [
"python",
"state-machines",
"fsm"
] |
Python state-machine design | 2,101,961 | <p>Related to this <strong><a href="http://stackoverflow.com/questions/1647631/c-state-machine-design">SO question (C state-machine design)</a></strong>, could you SO folks share with me (and the community!) your Python state-machine design techniques?</p>
<p><strong>Update3</strong>: At the moment, I am going for an ... | 34 | 2010-01-20T14:22:22Z | 2,102,191 | <p>There is <a href="http://wiki.python.org/moin/State%20Machine%20via%20Decorators" rel="nofollow">this design pattern</a> for using decorators to implement state machines. From the description on the page: </p>
<blockquote>
<p>Decorators are used to specify which methods are the event handlers for the class.</p>
... | 8 | 2010-01-20T14:51:51Z | [
"python",
"state-machines",
"fsm"
] |
Python state-machine design | 2,101,961 | <p>Related to this <strong><a href="http://stackoverflow.com/questions/1647631/c-state-machine-design">SO question (C state-machine design)</a></strong>, could you SO folks share with me (and the community!) your Python state-machine design techniques?</p>
<p><strong>Update3</strong>: At the moment, I am going for an ... | 34 | 2010-01-20T14:22:22Z | 2,102,203 | <p>I think S. Lott's answer is a much better way to implement a state machine, but if you still want to continue with your approach, using <code>(state,event)</code> as the key for your <code>dict</code> is better. Modifying your code:</p>
<pre><code>class HandlerFsm(object):
_fsm = {
("state_a","event"): "next... | 3 | 2010-01-20T14:53:30Z | [
"python",
"state-machines",
"fsm"
] |
Python state-machine design | 2,101,961 | <p>Related to this <strong><a href="http://stackoverflow.com/questions/1647631/c-state-machine-design">SO question (C state-machine design)</a></strong>, could you SO folks share with me (and the community!) your Python state-machine design techniques?</p>
<p><strong>Update3</strong>: At the moment, I am going for an ... | 34 | 2010-01-20T14:22:22Z | 2,102,458 | <p>I wouldn't think to reach for a finite state machine for handling XML. The usual way to do this, I think, is to use a stack:</p>
<pre><code>class TrackInfoHandler(object):
def __init__(self):
self._stack=[]
## ================================== Event callbacks
def startElement(self, name, attr... | 1 | 2010-01-20T15:24:44Z | [
"python",
"state-machines",
"fsm"
] |
Python state-machine design | 2,101,961 | <p>Related to this <strong><a href="http://stackoverflow.com/questions/1647631/c-state-machine-design">SO question (C state-machine design)</a></strong>, could you SO folks share with me (and the community!) your Python state-machine design techniques?</p>
<p><strong>Update3</strong>: At the moment, I am going for an ... | 34 | 2010-01-20T14:22:22Z | 2,102,810 | <p>Check <a href="http://www.ibm.com/developerworks/linux/library/l-python-state.html" rel="nofollow">this</a> and <a href="http://www.ibm.com/developerworks/library/l-pygen.html" rel="nofollow">this</a>.</p>
| 0 | 2010-01-20T16:07:29Z | [
"python",
"state-machines",
"fsm"
] |
Python state-machine design | 2,101,961 | <p>Related to this <strong><a href="http://stackoverflow.com/questions/1647631/c-state-machine-design">SO question (C state-machine design)</a></strong>, could you SO folks share with me (and the community!) your Python state-machine design techniques?</p>
<p><strong>Update3</strong>: At the moment, I am going for an ... | 34 | 2010-01-20T14:22:22Z | 2,103,398 | <p>In the April, 2009 issue of Python Magazine, I wrote an article on embedding a State DSL within Python, using pyparsing and imputil. This code would allow you to write the module trafficLight.pystate:</p>
<pre><code># trafficLight.pystate
# define state machine
statemachine TrafficLight:
Red -> Green
G... | 11 | 2010-01-20T17:19:18Z | [
"python",
"state-machines",
"fsm"
] |
Python state-machine design | 2,101,961 | <p>Related to this <strong><a href="http://stackoverflow.com/questions/1647631/c-state-machine-design">SO question (C state-machine design)</a></strong>, could you SO folks share with me (and the community!) your Python state-machine design techniques?</p>
<p><strong>Update3</strong>: At the moment, I am going for an ... | 34 | 2010-01-20T14:22:22Z | 6,159,076 | <p>The following code is a really simple solution. The only interesting part is:</p>
<pre><code> def next_state(self,cls):
self.__class__ = cls
</code></pre>
<p>All the logic for each state is contained in a separate class. The 'state' is changed by replacing the '<a href="http://docs.python.org/library/stdty... | 1 | 2011-05-28T01:18:25Z | [
"python",
"state-machines",
"fsm"
] |
Python state-machine design | 2,101,961 | <p>Related to this <strong><a href="http://stackoverflow.com/questions/1647631/c-state-machine-design">SO question (C state-machine design)</a></strong>, could you SO folks share with me (and the community!) your Python state-machine design techniques?</p>
<p><strong>Update3</strong>: At the moment, I am going for an ... | 34 | 2010-01-20T14:22:22Z | 7,470,672 | <p>I think that the tool <a href="http://code.google.com/p/pyscxml/" rel="nofollow">PySCXML</a> needs a closer look too.
This project uses the W3C definition: <a href="http://www.w3.org/TR/scxml/" rel="nofollow">State Chart XML (SCXML)</a>: State Machine Notation for Control Abstraction</p>
<blockquote>
<p>SCXML pro... | 2 | 2011-09-19T12:07:36Z | [
"python",
"state-machines",
"fsm"
] |
Python state-machine design | 2,101,961 | <p>Related to this <strong><a href="http://stackoverflow.com/questions/1647631/c-state-machine-design">SO question (C state-machine design)</a></strong>, could you SO folks share with me (and the community!) your Python state-machine design techniques?</p>
<p><strong>Update3</strong>: At the moment, I am going for an ... | 34 | 2010-01-20T14:22:22Z | 16,936,023 | <p>Another related projects: </p>
<p><a href="http://fsme.sourceforge.net/" rel="nofollow">http://fsme.sourceforge.net/</a></p>
<p><a href="https://code.google.com/p/visio2python/" rel="nofollow">https://code.google.com/p/visio2python/</a></p>
<p>You can paint state-machine and than use it in your code. </p>
| 0 | 2013-06-05T09:16:52Z | [
"python",
"state-machines",
"fsm"
] |
Python state-machine design | 2,101,961 | <p>Related to this <strong><a href="http://stackoverflow.com/questions/1647631/c-state-machine-design">SO question (C state-machine design)</a></strong>, could you SO folks share with me (and the community!) your Python state-machine design techniques?</p>
<p><strong>Update3</strong>: At the moment, I am going for an ... | 34 | 2010-01-20T14:22:22Z | 22,388,152 | <p>I also was not happy with the current options for state_machines so I wrote the <a href="https://github.com/jtushman/state_machine" rel="nofollow">state_machine</a> library</p>
<p>you can install it by <code>pip install state_machine</code> and use it like so:</p>
<pre><code>@acts_as_state_machine
class Person():
... | 4 | 2014-03-13T18:48:51Z | [
"python",
"state-machines",
"fsm"
] |
Python state-machine design | 2,101,961 | <p>Related to this <strong><a href="http://stackoverflow.com/questions/1647631/c-state-machine-design">SO question (C state-machine design)</a></strong>, could you SO folks share with me (and the community!) your Python state-machine design techniques?</p>
<p><strong>Update3</strong>: At the moment, I am going for an ... | 34 | 2010-01-20T14:22:22Z | 33,074,080 | <p>A related project is <a href="https://github.com/ourway/marmoolak" rel="nofollow">marmoolak</a>. Here is a <a href="http://stackoverflow.com/a/33074050/895659">description</a> about it.</p>
| 0 | 2015-10-12T05:50:42Z | [
"python",
"state-machines",
"fsm"
] |
Python state-machine design | 2,101,961 | <p>Related to this <strong><a href="http://stackoverflow.com/questions/1647631/c-state-machine-design">SO question (C state-machine design)</a></strong>, could you SO folks share with me (and the community!) your Python state-machine design techniques?</p>
<p><strong>Update3</strong>: At the moment, I am going for an ... | 34 | 2010-01-20T14:22:22Z | 39,149,854 | <p>I would definitely not recommend implementing such a well known pattern yourself. Just go for an open source implementation like <a href="https://github.com/tyarkoni/transitions" rel="nofollow" title="transitions">transitions</a> and wrap another class around it if you need custom features. In <a href="http://stacko... | 0 | 2016-08-25T15:58:01Z | [
"python",
"state-machines",
"fsm"
] |
Is it possible to make user input invisible as a 'sudo' password input? | 2,101,975 | <p>I'm using <strong>raw_input()</strong> to receive password from user in interactive mode, but I want to make input symbols invisible for security reasons, as it is when you're typing your password using <em>sudo</em> or connecting to a database. How I should do it?</p>
| 8 | 2010-01-20T14:24:24Z | 2,101,992 | <p>You need the <a href="http://docs.python.org/library/getpass.html"><code>getpass</code></a> module.</p>
<pre><code>from getpass import getpass
password = getpass()
</code></pre>
| 13 | 2010-01-20T14:26:51Z | [
"python",
"input",
"console",
"user",
"interaction"
] |
How can multiple calculations be launched in parallel, while stopping them all when the first one returns? [Python] | 2,102,216 | <p>How can multiple calculations be launched in parallel, while stopping them all when the first one returns?</p>
<p>The application I have in mind is the following: there are multiple ways of calculating a certain value; each method takes a different amount of time depending on the function parameters; by launching c... | 0 | 2010-01-20T14:55:11Z | 2,102,248 | <p>Because of the global interpreter lock you would be hard pressed to get any speedup this way. In reality even multithreaded programs in Python only run on one core. Thus, you would just be doing N processes at 1/N times the speed. Even if one finished in half the time of the others you would still lose time in th... | 0 | 2010-01-20T14:59:24Z | [
"python",
"parallel-processing",
"multiple-processes"
] |
How can multiple calculations be launched in parallel, while stopping them all when the first one returns? [Python] | 2,102,216 | <p>How can multiple calculations be launched in parallel, while stopping them all when the first one returns?</p>
<p>The application I have in mind is the following: there are multiple ways of calculating a certain value; each method takes a different amount of time depending on the function parameters; by launching c... | 0 | 2010-01-20T14:55:11Z | 2,102,262 | <p>I would look at the <a href="http://docs.python.org/library/multiprocessing.html" rel="nofollow"><code>multiprocessing</code></a> module if you haven't already. It offers a way of offloading tasks to separate processes whilst providing you with a simple, <a href="http://docs.python.org/library/threading.html" rel="... | 1 | 2010-01-20T15:00:34Z | [
"python",
"parallel-processing",
"multiple-processes"
] |
How can multiple calculations be launched in parallel, while stopping them all when the first one returns? [Python] | 2,102,216 | <p>How can multiple calculations be launched in parallel, while stopping them all when the first one returns?</p>
<p>The application I have in mind is the following: there are multiple ways of calculating a certain value; each method takes a different amount of time depending on the function parameters; by launching c... | 0 | 2010-01-20T14:55:11Z | 2,102,475 | <p>Processes can be started and killed trivially. </p>
<p>You can do this.</p>
<pre><code>import subprocess
watch = []
for s in ( "process1.py", "process2.py", "process3.py" ):
sp = subprocess.Popen( s )
watch.append( sp )
</code></pre>
<p>Now you're simply waiting for one of those to finish. When one finis... | 0 | 2010-01-20T15:26:29Z | [
"python",
"parallel-processing",
"multiple-processes"
] |
trapping a MySql warning | 2,102,251 | <p>In my python script I would like to trap a "Data truncated for column 'xxx'" warning durnig my query using MySql.</p>
<p>I saw some posts suggesting the code below, but it doesn' work.</p>
<p>Do you know if some specific module must be imported or if some option/flag should be called before using this code?</p>
<... | 24 | 2010-01-20T14:59:39Z | 2,102,315 | <p>Warnings are just that: warnings. They get reported to (usually) stderr, but nothing else is done. You can't catch them like exceptions because they aren't being raised.</p>
<p>You can, however, configure what to <em>do</em> with warnings, and turn them off or turn them into exceptions, using the <code>warnings</co... | 34 | 2010-01-20T15:06:59Z | [
"python",
"mysql"
] |
trapping a MySql warning | 2,102,251 | <p>In my python script I would like to trap a "Data truncated for column 'xxx'" warning durnig my query using MySql.</p>
<p>I saw some posts suggesting the code below, but it doesn' work.</p>
<p>Do you know if some specific module must be imported or if some option/flag should be called before using this code?</p>
<... | 24 | 2010-01-20T14:59:39Z | 2,102,358 | <p>Have you tried using MySQL's <a href="http://dev.mysql.com/doc/refman/5.0/en/show-warnings.html" rel="nofollow">SHOW WARNINGS</a> command?</p>
| 2 | 2010-01-20T15:11:39Z | [
"python",
"mysql"
] |
trapping a MySql warning | 2,102,251 | <p>In my python script I would like to trap a "Data truncated for column 'xxx'" warning durnig my query using MySql.</p>
<p>I saw some posts suggesting the code below, but it doesn' work.</p>
<p>Do you know if some specific module must be imported or if some option/flag should be called before using this code?</p>
<... | 24 | 2010-01-20T14:59:39Z | 2,102,366 | <p>I would try first to set the <code>sql_mode</code>. You can do this at the session level. If you execute a:</p>
<pre><code>SET @@sql_mode:=TRADITIONAL;
</code></pre>
<p>(you could also set it at the server level, but you need access to the server to do that. and, that setting an still be overridden at the session ... | 3 | 2010-01-20T15:12:38Z | [
"python",
"mysql"
] |
trapping a MySql warning | 2,102,251 | <p>In my python script I would like to trap a "Data truncated for column 'xxx'" warning durnig my query using MySql.</p>
<p>I saw some posts suggesting the code below, but it doesn' work.</p>
<p>Do you know if some specific module must be imported or if some option/flag should be called before using this code?</p>
<... | 24 | 2010-01-20T14:59:39Z | 2,102,811 | <p>Stop using MySQLdb. It has such stupid behavior as truncating data and issuing only a warning. Use <a href="https://launchpad.net/oursql" rel="nofollow">oursql</a> instead. </p>
| 1 | 2010-01-20T16:07:32Z | [
"python",
"mysql"
] |
trapping a MySql warning | 2,102,251 | <p>In my python script I would like to trap a "Data truncated for column 'xxx'" warning durnig my query using MySql.</p>
<p>I saw some posts suggesting the code below, but it doesn' work.</p>
<p>Do you know if some specific module must be imported or if some option/flag should be called before using this code?</p>
<... | 24 | 2010-01-20T14:59:39Z | 6,611,148 | <p>Just to add to Thomas Wouters reply, there is no need to import the warnings module to turn them into errors. Just run your script with "-W error" (or ignore) as flag for Python.</p>
| 2 | 2011-07-07T13:13:04Z | [
"python",
"mysql"
] |
trapping a MySql warning | 2,102,251 | <p>In my python script I would like to trap a "Data truncated for column 'xxx'" warning durnig my query using MySql.</p>
<p>I saw some posts suggesting the code below, but it doesn' work.</p>
<p>Do you know if some specific module must be imported or if some option/flag should be called before using this code?</p>
<... | 24 | 2010-01-20T14:59:39Z | 23,984,425 | <p>If you want to trap it to ignore it see "Temporarily suppressing warnings" in Python's documentation:</p>
<p><a href="https://docs.python.org/2/library/warnings.html#temporarily-suppressing-warnings" rel="nofollow">https://docs.python.org/2/library/warnings.html#temporarily-suppressing-warnings</a></p>
<pre><code>... | 3 | 2014-06-01T21:01:00Z | [
"python",
"mysql"
] |
trapping a MySql warning | 2,102,251 | <p>In my python script I would like to trap a "Data truncated for column 'xxx'" warning durnig my query using MySql.</p>
<p>I saw some posts suggesting the code below, but it doesn' work.</p>
<p>Do you know if some specific module must be imported or if some option/flag should be called before using this code?</p>
<... | 24 | 2010-01-20T14:59:39Z | 36,271,435 | <p>Raise MySQL Warnings as errors:</p>
<pre><code>import warnings, MySQLdb
warnings.filterwarnings('error', category=MySQLdb.Warning)
</code></pre>
<p>To ignore instead of raising an error, replace <code>"error"</code> with <code>"ignore"</code>.</p>
<p>Handle them in a try-except block like:</p>
<pre><code>try:
... | 0 | 2016-03-28T21:24:04Z | [
"python",
"mysql"
] |
Json communication between flash and javascript | 2,102,294 | <p>note: using django/python/javascript/flash</p>
<p>So its been two days since I'm stuck at the error. I did the things you told me to and found a couple of ways around it but nothing worked. These are the results.</p>
<p>Javascript does not receive the normal string it has to be a json object so. in views.py </p>
... | 1 | 2010-01-20T15:04:13Z | 2,102,319 | <p>why do you communicate between flash and js via json? actionscript has a very powerfull build in <a href="http://livedocs.adobe.com/flash/9.0_de/ActionScriptLangRefV3/flash/external/ExternalInterface.html" rel="nofollow">ExternalInterface</a> to communicate with javascript.</p>
| 1 | 2010-01-20T15:07:25Z | [
"python",
"flash",
"json"
] |
Why do I need the DJANGO_SETTINGS_MODULE set? | 2,102,330 | <p>Every time I log on to my server through SSH I need to type the following:</p>
<pre><code>export DJANGO_SETTINGS_MODULE=settings
</code></pre>
<p>if I do not any usage of the manage.py module fails</p>
<p>My manage.py has the following added code:</p>
<pre><code>if "notification" in settings.INSTALLED_APPS:
... | 13 | 2010-01-20T15:08:08Z | 2,102,365 | <p>Your<code>manage.py</code> is referencing an application (<code>notifications</code>). This forces Django to complain about DJANGO_SETTINGS_MODULE being set because the Django environment hasn't been set up yet.</p>
<p>Incidentally, you can force the enviroment setup manually, but honestly I wouldn't do this in man... | 11 | 2010-01-20T15:12:22Z | [
"python",
"django"
] |
Why do I need the DJANGO_SETTINGS_MODULE set? | 2,102,330 | <p>Every time I log on to my server through SSH I need to type the following:</p>
<pre><code>export DJANGO_SETTINGS_MODULE=settings
</code></pre>
<p>if I do not any usage of the manage.py module fails</p>
<p>My manage.py has the following added code:</p>
<pre><code>if "notification" in settings.INSTALLED_APPS:
... | 13 | 2010-01-20T15:08:08Z | 2,102,371 | <p>You need to set the DJANGO_SETTINGS_MODULE environment variable because it's how Django knows what your settings module is called (so you can have different ones per project or for testing and development.) You can set it in the scripts themselves <em>before</em> you import django (directly or indirectly) but that w... | 6 | 2010-01-20T15:12:57Z | [
"python",
"django"
] |
Why do I need the DJANGO_SETTINGS_MODULE set? | 2,102,330 | <p>Every time I log on to my server through SSH I need to type the following:</p>
<pre><code>export DJANGO_SETTINGS_MODULE=settings
</code></pre>
<p>if I do not any usage of the manage.py module fails</p>
<p>My manage.py has the following added code:</p>
<pre><code>if "notification" in settings.INSTALLED_APPS:
... | 13 | 2010-01-20T15:08:08Z | 2,348,775 | <p>By default, manage.py looks for a settings module in the same directory as itself. If it doesn't find one, it bombs out with a message to use django-admin.py instead. It doesn't actually set up the environemnt until it runs <code>execute_manager</code>. If you need to run your hooks before calling your management... | 0 | 2010-02-27T20:07:58Z | [
"python",
"django"
] |
why this dos command does not work inside python? | 2,102,452 | <p>I try to move some dos command from my batch file into python but get this error, The filename, directory name, or volume label syntax is incorrect, for the following statement.</p>
<pre><code>subprocess.Popen('rd /s /q .\ProcessControlSimulator\bin', shell=True,
stdout=subprocess.PIPE, stderr=su... | 3 | 2010-01-20T15:24:14Z | 2,102,476 | <p><code>\</code> (backslash) is an escape character within string constants, so your string ends up changed. Use double <code>\</code>s (like so <code>\\</code>) within string constants:
</p>
<pre><code>subprocess.Popen('rd /s /q .\\ProcessControlSimulator\\bin', shell=True, stdout=subprocess.PIPE, stderr=subprocess.... | 12 | 2010-01-20T15:26:32Z | [
"python",
"subprocess"
] |
why this dos command does not work inside python? | 2,102,452 | <p>I try to move some dos command from my batch file into python but get this error, The filename, directory name, or volume label syntax is incorrect, for the following statement.</p>
<pre><code>subprocess.Popen('rd /s /q .\ProcessControlSimulator\bin', shell=True,
stdout=subprocess.PIPE, stderr=su... | 3 | 2010-01-20T15:24:14Z | 2,102,489 | <p>You can't just copy it one-to-one. For example, your escape characters () become incorrect. You may need a double \ in this case.</p>
<p>Also, there are specific API calls for creating and killing directories, look at os.path</p>
| 2 | 2010-01-20T15:27:32Z | [
"python",
"subprocess"
] |
why this dos command does not work inside python? | 2,102,452 | <p>I try to move some dos command from my batch file into python but get this error, The filename, directory name, or volume label syntax is incorrect, for the following statement.</p>
<pre><code>subprocess.Popen('rd /s /q .\ProcessControlSimulator\bin', shell=True,
stdout=subprocess.PIPE, stderr=su... | 3 | 2010-01-20T15:24:14Z | 2,102,506 | <p>You've got unescaped backslashes. You can use a python raw string to avoid having to escape your slashes, or double them up:</p>
<pre><code>subprocess.Popen(r'rd /s /q .\ProcessControlSimulator\bin', shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
</code></pre>
<p>or</p>
<pre><code>subprocess.Popen... | 7 | 2010-01-20T15:29:25Z | [
"python",
"subprocess"
] |
why this dos command does not work inside python? | 2,102,452 | <p>I try to move some dos command from my batch file into python but get this error, The filename, directory name, or volume label syntax is incorrect, for the following statement.</p>
<pre><code>subprocess.Popen('rd /s /q .\ProcessControlSimulator\bin', shell=True,
stdout=subprocess.PIPE, stderr=su... | 3 | 2010-01-20T15:24:14Z | 2,102,519 | <p>My advice is try not to use system commands unnecessarily. You are using Python, so use the available modules that come with it. From what i see, you are trying to remove directories right? Then you can use modules like shutil. Example:</p>
<pre><code>import shutil
import os
path = os.path.join("c:\\","ProcessContr... | 8 | 2010-01-20T15:30:50Z | [
"python",
"subprocess"
] |
determine the type of a value which is represented as string in python | 2,103,071 | <p>When I read a comma seperated file or string with the csv parser in python all items are represented as a string. see example below.</p>
<p><pre><code>import csv
a = "1,2,3,4,5"
r = csv.reader([a])
for row in r:
d = row</p>
<p>d
['1', '2', '3', '4', '5']
type(d[0])
<type 'str'>
</pre></code></p>
<p>I want ... | 5 | 2010-01-20T16:35:58Z | 2,103,111 | <p>From the <a href="http://docs.python.org/library/csv.html" rel="nofollow">manual</a>:</p>
<blockquote>
<p>Return a reader object which will
iterate over lines in the given
csvfile. csvfile can be any object
which supports the iterator protocol
and returns a string each time its
next() method is called â... | 0 | 2010-01-20T16:40:55Z | [
"python",
"csv",
"types",
"casting"
] |
determine the type of a value which is represented as string in python | 2,103,071 | <p>When I read a comma seperated file or string with the csv parser in python all items are represented as a string. see example below.</p>
<p><pre><code>import csv
a = "1,2,3,4,5"
r = csv.reader([a])
for row in r:
d = row</p>
<p>d
['1', '2', '3', '4', '5']
type(d[0])
<type 'str'>
</pre></code></p>
<p>I want ... | 5 | 2010-01-20T16:35:58Z | 2,103,116 | <p>The date is a bit harder. It depends on the format and how regular it is. Here is a clue to get you started on the rest.</p>
<pre><code>>>> int('a')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ValueError: invalid literal for int() with base 10: 'a'
>>> in... | 0 | 2010-01-20T16:41:34Z | [
"python",
"csv",
"types",
"casting"
] |
determine the type of a value which is represented as string in python | 2,103,071 | <p>When I read a comma seperated file or string with the csv parser in python all items are represented as a string. see example below.</p>
<p><pre><code>import csv
a = "1,2,3,4,5"
r = csv.reader([a])
for row in r:
d = row</p>
<p>d
['1', '2', '3', '4', '5']
type(d[0])
<type 'str'>
</pre></code></p>
<p>I want ... | 5 | 2010-01-20T16:35:58Z | 2,103,117 | <p>What you want to acheive is difficult because the types are ambiguous: "1" could either be a string, or an int for example. At any rate, you could try something like this:</p>
<ul>
<li><p>Dates: presumably they are in a known format: if so, you can try instantiating a datetime from the timestamp string (<a href="h... | 1 | 2010-01-20T16:41:46Z | [
"python",
"csv",
"types",
"casting"
] |
determine the type of a value which is represented as string in python | 2,103,071 | <p>When I read a comma seperated file or string with the csv parser in python all items are represented as a string. see example below.</p>
<p><pre><code>import csv
a = "1,2,3,4,5"
r = csv.reader([a])
for row in r:
d = row</p>
<p>d
['1', '2', '3', '4', '5']
type(d[0])
<type 'str'>
</pre></code></p>
<p>I want ... | 5 | 2010-01-20T16:35:58Z | 2,103,132 | <p>Well..you can't.</p>
<p>How would you decide if "5" is meant as a string or an integer?
How would you decide if "20100120" is meant as an integer or a date?</p>
<p>You can of course make educated guesses, and implement some kind of parse order. First try it as a date, then as a float, then as an int, and lastly as... | 1 | 2010-01-20T16:43:02Z | [
"python",
"csv",
"types",
"casting"
] |
determine the type of a value which is represented as string in python | 2,103,071 | <p>When I read a comma seperated file or string with the csv parser in python all items are represented as a string. see example below.</p>
<p><pre><code>import csv
a = "1,2,3,4,5"
r = csv.reader([a])
for row in r:
d = row</p>
<p>d
['1', '2', '3', '4', '5']
type(d[0])
<type 'str'>
</pre></code></p>
<p>I want ... | 5 | 2010-01-20T16:35:58Z | 2,103,143 | <p>There's no <em>real</em> answer to this as far as I can tell since these are just strings. They're not integers or floats or whatever. Those are roles you decide. eg. Is <code>1</code> an integer or a float? </p>
<p>A couple of things come to mind though. One is to do some kind of pattern matching (eg. If it contai... | 2 | 2010-01-20T16:44:31Z | [
"python",
"csv",
"types",
"casting"
] |
determine the type of a value which is represented as string in python | 2,103,071 | <p>When I read a comma seperated file or string with the csv parser in python all items are represented as a string. see example below.</p>
<p><pre><code>import csv
a = "1,2,3,4,5"
r = csv.reader([a])
for row in r:
d = row</p>
<p>d
['1', '2', '3', '4', '5']
type(d[0])
<type 'str'>
</pre></code></p>
<p>I want ... | 5 | 2010-01-20T16:35:58Z | 2,103,183 | <p>You could do something like this:</p>
<pre><code>from datetime import datetime
tests = [
# (Type, Test)
(int, int),
(float, float),
(datetime, lambda value: datetime.strptime(value, "%Y/%m/%d"))
]
def getType(value):
for typ, test in tests:
try:
test(value)
... | 9 | 2010-01-20T16:48:52Z | [
"python",
"csv",
"types",
"casting"
] |
determine the type of a value which is represented as string in python | 2,103,071 | <p>When I read a comma seperated file or string with the csv parser in python all items are represented as a string. see example below.</p>
<p><pre><code>import csv
a = "1,2,3,4,5"
r = csv.reader([a])
for row in r:
d = row</p>
<p>d
['1', '2', '3', '4', '5']
type(d[0])
<type 'str'>
</pre></code></p>
<p>I want ... | 5 | 2010-01-20T16:35:58Z | 2,103,432 | <p>This cannot be done in a reliable manner and that is not due to limitations in Python or any other programming language for that matter. <strong>A human being could not do this in a predictable manner without guessing and following a few rules</strong> (usually called <a href="http://en.wikipedia.org/wiki/Heuristic"... | 3 | 2010-01-20T17:24:00Z | [
"python",
"csv",
"types",
"casting"
] |
SqlAlchemy add new Field to class and create corresponding column in table | 2,103,274 | <p>I want to add a field to an existing mapped class, how would I update the sql table automatically. Does sqlalchemy provide a method to update the database with a new column, if a field is added to the class. </p>
| 9 | 2010-01-20T17:01:53Z | 2,107,904 | <p>SQLAlchemy itself doesn't support automatic updates of schema, but there is a third party <a href="http://packages.python.org/sqlalchemy-migrate/" rel="nofollow">SQLAlchemy Migrate</a> tool to automate migrations. Look though <a href="http://packages.python.org/sqlalchemy-migrate/versioning.html" rel="nofollow">"Dat... | 4 | 2010-01-21T08:48:26Z | [
"python",
"sqlalchemy"
] |
SqlAlchemy add new Field to class and create corresponding column in table | 2,103,274 | <p>I want to add a field to an existing mapped class, how would I update the sql table automatically. Does sqlalchemy provide a method to update the database with a new column, if a field is added to the class. </p>
| 9 | 2010-01-20T17:01:53Z | 7,610,243 |
<p>Sometimes Migrate is too much work - you just want to column automatically added when you run your changed code. So here is a function that does that.</p>
<p>Caveats: it pokes around in the SQLAlchemy internals and tends to require small changes every time SQLAlchemy undergoes a major revision. (There's probably ... | 7 | 2011-09-30T12:18:35Z | [
"python",
"sqlalchemy"
] |
SqlAlchemy add new Field to class and create corresponding column in table | 2,103,274 | <p>I want to add a field to an existing mapped class, how would I update the sql table automatically. Does sqlalchemy provide a method to update the database with a new column, if a field is added to the class. </p>
| 9 | 2010-01-20T17:01:53Z | 8,462,508 | <pre class="lang-python prettyprint-override"><code># database.py has definition for engine.
# from sqlalchemy import create_engine
# engine = create_engine('mysql://......', convert_unicode=True)
from database import engine
from sqlalchemy import DDL
add_column = DDL('ALTER TABLE USERS ADD COLUMN city VARCHAR(60) AF... | 0 | 2011-12-11T07:12:22Z | [
"python",
"sqlalchemy"
] |
SqlAlchemy add new Field to class and create corresponding column in table | 2,103,274 | <p>I want to add a field to an existing mapped class, how would I update the sql table automatically. Does sqlalchemy provide a method to update the database with a new column, if a field is added to the class. </p>
| 9 | 2010-01-20T17:01:53Z | 30,834,350 | <p><a href="http://alembic.readthedocs.org" rel="nofollow">Alembic</a> is the latest package that offers migration of database. </p>
<p>See <a href="http://docs.sqlalchemy.org/en/latest/core/metadata.html#altering-schemas-through-migrations" rel="nofollow">sqlalchemy docs regarding migration here</a>.</p>
| 0 | 2015-06-14T20:44:27Z | [
"python",
"sqlalchemy"
] |
Prepare a string for Google Ajax Search? | 2,103,317 | <p>I have strings such as</p>
<pre><code>["Tabula Rasa", "façade", "DJ Tiësto"]
</code></pre>
<p>I'm accessing Google Ajax API in <strong>Python</strong> using the base url:</p>
<pre><code>base = 'http://ajax.googleapis.com/ajax/services/search/web'
'?v=1.0&q=%s'
</code></pre>
<p>I'm having issues using th... | 1 | 2010-01-20T17:09:01Z | 2,103,337 | <p>What you're looking for is urllib.quote():</p>
<pre><code>>>> urllib.quote("Tabula Rasa")
'Tabula%20Rasa'
</code></pre>
<p>The non-ASCII strings may need to be recoded into the encoding expected by the Google AJAX API, if you don't have them in the same encoding already.</p>
| 2 | 2010-01-20T17:12:16Z | [
"python",
"url",
"google-api",
"google-ajax-api"
] |
Python newbie class design question | 2,103,532 | <p>I'm trying to figure out the best way to design a couple of classes. I'm pretty new to Python (and OOP in general) and just want to make sure that I'm doing this right. I have two classes: "Users" and "User".</p>
<pre><code>class User(object):
def __init__(self):
pass
class Users(object):
def __init... | 6 | 2010-01-20T17:38:38Z | 2,103,567 | <p>Put this in your <code>Users</code>:</p>
<pre><code>def __iter__(self):
return iter(self.users)
</code></pre>
<p>Now you can:</p>
<pre><code>for u in users:
print u.email
</code></pre>
<p><a href="http://docs.python.org/library/stdtypes.html#iterator-types" rel="nofollow">Docs</a></p>
| 11 | 2010-01-20T17:43:31Z | [
"python",
"oop",
"iterator"
] |
Python newbie class design question | 2,103,532 | <p>I'm trying to figure out the best way to design a couple of classes. I'm pretty new to Python (and OOP in general) and just want to make sure that I'm doing this right. I have two classes: "Users" and "User".</p>
<pre><code>class User(object):
def __init__(self):
pass
class Users(object):
def __init... | 6 | 2010-01-20T17:38:38Z | 2,103,574 | <p>You probably just want a list of User objects rather than a class which contains multiple users.</p>
<pre><code>class User(object):
def __init__(self, user_id, email):
self.user_id = user_id
self.email = email
users = []
users.append(User(user_id = 1, email = 'bob@example.com'))
</code></pre>
<p>... | 6 | 2010-01-20T17:44:17Z | [
"python",
"oop",
"iterator"
] |
Python newbie class design question | 2,103,532 | <p>I'm trying to figure out the best way to design a couple of classes. I'm pretty new to Python (and OOP in general) and just want to make sure that I'm doing this right. I have two classes: "Users" and "User".</p>
<pre><code>class User(object):
def __init__(self):
pass
class Users(object):
def __init... | 6 | 2010-01-20T17:38:38Z | 2,103,576 | <p>I don't see anything wrong with users.users, but if you prefer a nicer way to do it you could override <a href="http://docs.python.org/reference/datamodel.html#object.__iter__" rel="nofollow"><code>__iter__</code></a> in Users.</p>
<pre><code>class Users(object):
def __init__(self):
self.users = []
de... | 4 | 2010-01-20T17:44:23Z | [
"python",
"oop",
"iterator"
] |
Python newbie class design question | 2,103,532 | <p>I'm trying to figure out the best way to design a couple of classes. I'm pretty new to Python (and OOP in general) and just want to make sure that I'm doing this right. I have two classes: "Users" and "User".</p>
<pre><code>class User(object):
def __init__(self):
pass
class Users(object):
def __init... | 6 | 2010-01-20T17:38:38Z | 2,103,580 | <p>I would say not really. Your <code>Users</code> class appears to just be a list of users, so I would just make it a list rather than a whole class. Here's what I would do:</p>
<pre><code>class User(object):
def __init__(self, user_id=None, email=None):
self.user_id, self.email = user_id, email
users = ... | 17 | 2010-01-20T17:45:08Z | [
"python",
"oop",
"iterator"
] |
Python newbie class design question | 2,103,532 | <p>I'm trying to figure out the best way to design a couple of classes. I'm pretty new to Python (and OOP in general) and just want to make sure that I'm doing this right. I have two classes: "Users" and "User".</p>
<pre><code>class User(object):
def __init__(self):
pass
class Users(object):
def __init... | 6 | 2010-01-20T17:38:38Z | 2,103,678 | <p>There's no "black" and "white" here, just shades of grey. You don't need a special <code>Users</code> class if it's just going to be a list.</p>
<p>Another way:</p>
<pre><code>class User:
all_users = []
def __init__(self, id, email):
self.id = id # No need to call it user_id - it's a User object, ... | 1 | 2010-01-20T17:58:04Z | [
"python",
"oop",
"iterator"
] |
Selecting An Embedded Language | 2,103,728 | <p>I'm making an application that analyses one or more series of data using several different algorithms (agents). I came to the idea that each of these agents could be implemented as separate Python scripts which I run using either the Python C API or Boost.Python in my app.</p>
<p>I'm a little worried about runtime ... | 7 | 2010-01-20T18:04:49Z | 2,103,784 | <p>you could probably create an embedded language using C++ templates and operator overloading, see for example ublas or ftensor matrix languages. i do not think python or other interpreted languages of is suitable for having numbercrunching/data processing.</p>
| 0 | 2010-01-20T18:12:02Z | [
"c++",
"python",
"perl",
"performance",
"lua"
] |
Selecting An Embedded Language | 2,103,728 | <p>I'm making an application that analyses one or more series of data using several different algorithms (agents). I came to the idea that each of these agents could be implemented as separate Python scripts which I run using either the Python C API or Boost.Python in my app.</p>
<p>I'm a little worried about runtime ... | 7 | 2010-01-20T18:04:49Z | 2,103,831 | <p>For millions of calls (from I'm assuming c++, because you mentioned boost) into python, yes: you will notice a performance hit. This may or may not be significant - perhaps the speed gain of trying out new 'agents' would be greater than the hit. Python does have fast numerical libraries (such as numpy) that might h... | 1 | 2010-01-20T18:19:49Z | [
"c++",
"python",
"perl",
"performance",
"lua"
] |
Selecting An Embedded Language | 2,103,728 | <p>I'm making an application that analyses one or more series of data using several different algorithms (agents). I came to the idea that each of these agents could be implemented as separate Python scripts which I run using either the Python C API or Boost.Python in my app.</p>
<p>I'm a little worried about runtime ... | 7 | 2010-01-20T18:04:49Z | 2,103,850 | <p>Yes, tons. Lua and Python seems to be the most popular:</p>
<p><strong>Embedding Lua</strong></p>
<ul>
<li><a href="http://www.lua.org/pil/24.html" rel="nofollow">http://www.lua.org/pil/24.html</a></li>
<li><a href="http://stackoverflow.com/questions/38338/why-is-lua-considered-a-game-language">Why is Lua consider... | 10 | 2010-01-20T18:23:06Z | [
"c++",
"python",
"perl",
"performance",
"lua"
] |
Selecting An Embedded Language | 2,103,728 | <p>I'm making an application that analyses one or more series of data using several different algorithms (agents). I came to the idea that each of these agents could be implemented as separate Python scripts which I run using either the Python C API or Boost.Python in my app.</p>
<p>I'm a little worried about runtime ... | 7 | 2010-01-20T18:04:49Z | 2,103,936 | <blockquote>
<p>I will typically be making hundreds of thousands, if not millions, of iterations in which I invoke the external "agents"</p>
</blockquote>
<p>The performance drop will be noticeable, perhaps painful. If you can put the data into arrays and process it in batches using <a href="http://numpy.scipy.org/"... | 3 | 2010-01-20T18:35:06Z | [
"c++",
"python",
"perl",
"performance",
"lua"
] |
Selecting An Embedded Language | 2,103,728 | <p>I'm making an application that analyses one or more series of data using several different algorithms (agents). I came to the idea that each of these agents could be implemented as separate Python scripts which I run using either the Python C API or Boost.Python in my app.</p>
<p>I'm a little worried about runtime ... | 7 | 2010-01-20T18:04:49Z | 2,104,152 | <p>Tcl was designed from the ground up to be an embedded language. </p>
| 5 | 2010-01-20T19:08:53Z | [
"c++",
"python",
"perl",
"performance",
"lua"
] |
Selecting An Embedded Language | 2,103,728 | <p>I'm making an application that analyses one or more series of data using several different algorithms (agents). I came to the idea that each of these agents could be implemented as separate Python scripts which I run using either the Python C API or Boost.Python in my app.</p>
<p>I'm a little worried about runtime ... | 7 | 2010-01-20T18:04:49Z | 2,104,186 | <p>I believe <a href="http://www.tcl.tk/" rel="nofollow">tcl</a> and <a href="http://www.rexx.org/" rel="nofollow">Rexx</a> were both intended for this purpose.</p>
| 2 | 2010-01-20T19:14:19Z | [
"c++",
"python",
"perl",
"performance",
"lua"
] |
Selecting An Embedded Language | 2,103,728 | <p>I'm making an application that analyses one or more series of data using several different algorithms (agents). I came to the idea that each of these agents could be implemented as separate Python scripts which I run using either the Python C API or Boost.Python in my app.</p>
<p>I'm a little worried about runtime ... | 7 | 2010-01-20T18:04:49Z | 4,950,642 | <p>Lua is quite fast as it is. If you need more speed, try <a href="http://luajit.org/">LuaJIT</a>, which is excellent.</p>
| 9 | 2011-02-09T21:24:57Z | [
"c++",
"python",
"perl",
"performance",
"lua"
] |
Two forms in django templates without conflict | 2,103,805 | <p>I'm creating a template with two different forms but I have the following problem: when I submit the first one the second is also validated and get validation errors. What can I do to avoid this conflict?</p>
<p>Thanks and sorry for my english.</p>
| 1 | 2010-01-20T18:15:58Z | 2,103,834 | <p>use the <a href="http://docs.djangoproject.com/en/dev/ref/forms/api/#prefixes-for-forms">prefix argument</a> on your forms</p>
| 5 | 2010-01-20T18:20:02Z | [
"python",
"django",
"django-templates",
"django-forms"
] |
Help creating model for Django app | 2,104,033 | <p>I'm trying to make a childcare administration app with Django but I've some problems with the payments code.</p>
<p>Each kid has to pay monthly 10 times a year. These payments have some particularities:</p>
<ul>
<li><p>Some kids could pay a different amount of money depending on the economical situation of the par... | 1 | 2010-01-20T18:49:44Z | 2,106,023 | <p>No matter how your final models will look like, assuming that you will keep Payment model, you could add to it two fields:</p>
<pre><code> payment_date = model.DateField()
already_paid = models.BooleanField()
</code></pre>
<p>Then, to get overdue payments, you will be able to make a query:</p>
<pre><code> ... | 0 | 2010-01-21T00:10:00Z | [
"python",
"django",
"models"
] |
Help creating model for Django app | 2,104,033 | <p>I'm trying to make a childcare administration app with Django but I've some problems with the payments code.</p>
<p>Each kid has to pay monthly 10 times a year. These payments have some particularities:</p>
<ul>
<li><p>Some kids could pay a different amount of money depending on the economical situation of the par... | 1 | 2010-01-20T18:49:44Z | 2,106,158 | <p>I would make the payment calculated off of the attributes of the child so by updating the child the payment would change. The payment would not be a entry in the database until it had been paid, the payment would be calculated each time the user requests it.</p>
<pre><code>class Child(object):
def __init__(self,... | 0 | 2010-01-21T00:42:53Z | [
"python",
"django",
"models"
] |
How to check file size in python? | 2,104,080 | <p>I am writing a Python script in Windows. I want to do something based on the file size. For example, if the size is greater than 0, I will send an email to somebody, otherwise continue to other things. </p>
<p>How do I check the file size?</p>
| 357 | 2010-01-20T18:58:29Z | 2,104,083 | <p>Like this (credit <a href="http://www.daniweb.com/forums/thread78629.html">http://www.daniweb.com/forums/thread78629.html</a>):</p>
<pre><code>>>> import os
>>> b = os.path.getsize("/path/isa_005.mp3")
>>> b
2071611L
</code></pre>
| 586 | 2010-01-20T18:59:16Z | [
"python"
] |
How to check file size in python? | 2,104,080 | <p>I am writing a Python script in Windows. I want to do something based on the file size. For example, if the size is greater than 0, I will send an email to somebody, otherwise continue to other things. </p>
<p>How do I check the file size?</p>
| 357 | 2010-01-20T18:58:29Z | 2,104,107 | <p>Use <a href="https://docs.python.org/2/library/os.html#os.stat"><code>os.stat</code></a>, and use the <code>st_size</code> member of the resulting object:</p>
<pre><code>>>> import os
>>> statinfo = os.stat('somefile.txt')
>>> statinfo
(33188, 422511L, 769L, 1, 1032, 100, 926L, 1105022698... | 327 | 2010-01-20T19:01:53Z | [
"python"
] |
How to check file size in python? | 2,104,080 | <p>I am writing a Python script in Windows. I want to do something based on the file size. For example, if the size is greater than 0, I will send an email to somebody, otherwise continue to other things. </p>
<p>How do I check the file size?</p>
| 357 | 2010-01-20T18:58:29Z | 19,079,887 | <p>The other answers work for real files, but if you need something that works for "file-like objects", try this:</p>
<pre><code># f is a file-like object.
f.seek(0, os.SEEK_END)
size = f.tell()
</code></pre>
<p>It works for real files and StringIO's, in my limited testing. (Python 2.7.3.) The "file-like object" API... | 65 | 2013-09-29T15:41:10Z | [
"python"
] |
How to check file size in python? | 2,104,080 | <p>I am writing a Python script in Windows. I want to do something based on the file size. For example, if the size is greater than 0, I will send an email to somebody, otherwise continue to other things. </p>
<p>How do I check the file size?</p>
| 357 | 2010-01-20T18:58:29Z | 39,988,702 | <pre><code>import os
def convert_bytes(num):
"""
this function will convert bytes to MB.... GB... etc
"""
for x in ['bytes', 'KB', 'MB', 'GB', 'TB']:
if num < 1024.0:
return "%3.1f %s" % (num, x)
num /= 1024.0
def file_size(file_path):
"""
this function will re... | 0 | 2016-10-12T00:22:27Z | [
"python"
] |
Efficiently search two-tuple | 2,104,095 | <p>What's the best one-liner replacement for the code below? I'm sure there's a smarter way.</p>
<pre><code>choices = ((1, 'ONE'), (2, 'TWO'), (3, 'THREE'))
some_int = 2
for choice in choices:
if choice[0] == some_int:
label = choice[1]
break;
# label == 'TWO'
</code></pre>
| 2 | 2010-01-20T19:00:37Z | 2,104,108 | <p>You could use a dict.</p>
<pre><code>>>> choices = { 1: 'ONE', 2: 'TWO', 3: 'THREE' }
>>> label = choices[2]
>>> label
'TWO'
</code></pre>
| 6 | 2010-01-20T19:02:08Z | [
"python",
"tuples"
] |
Efficiently search two-tuple | 2,104,095 | <p>What's the best one-liner replacement for the code below? I'm sure there's a smarter way.</p>
<pre><code>choices = ((1, 'ONE'), (2, 'TWO'), (3, 'THREE'))
some_int = 2
for choice in choices:
if choice[0] == some_int:
label = choice[1]
break;
# label == 'TWO'
</code></pre>
| 2 | 2010-01-20T19:00:37Z | 2,104,111 | <pre><code>labels = dict(choices)
label = labels[some_int]
</code></pre>
<p>you could, of course, join this into an one-liner, if you don't need <code>labels</code> anywhere else.</p>
| 14 | 2010-01-20T19:02:52Z | [
"python",
"tuples"
] |
Efficiently search two-tuple | 2,104,095 | <p>What's the best one-liner replacement for the code below? I'm sure there's a smarter way.</p>
<pre><code>choices = ((1, 'ONE'), (2, 'TWO'), (3, 'THREE'))
some_int = 2
for choice in choices:
if choice[0] == some_int:
label = choice[1]
break;
# label == 'TWO'
</code></pre>
| 2 | 2010-01-20T19:00:37Z | 2,104,123 | <p>If you're really looking for a one liner...</p>
<pre><code>label = dict(choices)[some_int]
</code></pre>
<p>that is,</p>
<pre><code>>>> choices = ((1, 'ONE'), (2, 'TWO'), (3, 'THREE'))
>>> dict(choices)[1]
'ONE'
</code></pre>
| 3 | 2010-01-20T19:04:53Z | [
"python",
"tuples"
] |
Efficiently search two-tuple | 2,104,095 | <p>What's the best one-liner replacement for the code below? I'm sure there's a smarter way.</p>
<pre><code>choices = ((1, 'ONE'), (2, 'TWO'), (3, 'THREE'))
some_int = 2
for choice in choices:
if choice[0] == some_int:
label = choice[1]
break;
# label == 'TWO'
</code></pre>
| 2 | 2010-01-20T19:00:37Z | 2,104,163 | <p>For a one-off search, if you're committed to starting with that data structure and can't amortize the time it takes to build it into a dictionary, and don't know whether the starting structure is sorted (so that bisection-search is not an option), there are no substantially faster algorithms than simple linear searc... | 5 | 2010-01-20T19:09:56Z | [
"python",
"tuples"
] |
Python tool to balance parentheses, quotes, and brackets | 2,104,227 | <p>Does anyone know of an already-written Python script, tool, or editor that will check for unbalanced multi-line tokens? (parentheses, quotes, {}, [], etc.)</p>
<p>I've been writing Python code in IDLE, and every so often I'll get "EOF token in multi-line statement" and start swearing, because it means that somewher... | 1 | 2010-01-20T19:20:10Z | 2,104,239 | <p>I use <a href="http://www.eclipse.org/" rel="nofollow">Eclipse</a> with <a href="http://pydev.org/" rel="nofollow">PyDev</a>. It's very good for this sort of thing, and lots more.</p>
| 1 | 2010-01-20T19:22:24Z | [
"python"
] |
Python tool to balance parentheses, quotes, and brackets | 2,104,227 | <p>Does anyone know of an already-written Python script, tool, or editor that will check for unbalanced multi-line tokens? (parentheses, quotes, {}, [], etc.)</p>
<p>I've been writing Python code in IDLE, and every so often I'll get "EOF token in multi-line statement" and start swearing, because it means that somewher... | 1 | 2010-01-20T19:20:10Z | 2,104,240 | <p><a href="http://www.gnu.org/software/emacs/" rel="nofollow">emacs</a> will automatically highlight matching pairs of parentheses/brackets/quotes/etc. as you type them, and it will inform you immediately if you mismatch them (e.g. if you type a <code>[</code> followed by a <code>)</code>). I'm sure vim also does thi... | 1 | 2010-01-20T19:22:33Z | [
"python"
] |
Python tool to balance parentheses, quotes, and brackets | 2,104,227 | <p>Does anyone know of an already-written Python script, tool, or editor that will check for unbalanced multi-line tokens? (parentheses, quotes, {}, [], etc.)</p>
<p>I've been writing Python code in IDLE, and every so often I'll get "EOF token in multi-line statement" and start swearing, because it means that somewher... | 1 | 2010-01-20T19:20:10Z | 2,104,247 | <p><a href="http://www.pydev.org" rel="nofollow">PyDev</a> is the best IDE to develop in Python. Has this feature and a lot of more.</p>
| 0 | 2010-01-20T19:23:17Z | [
"python"
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.