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 |
|---|---|---|---|---|---|---|---|---|---|
Python tool that builds a dependency diagram for methods of a class | 798,389 | <p>I'm digging into a huge legacy Python class that has a lot of methods. I eventually break complex ones into smaller pieces so the amount of methods increases even more. I wonder if there is a tool that can scan the Python code and build some kind of dependency diagram for its methods.</p>
<p>I define method <code>x... | 16 | 2009-04-28T14:54:26Z | 800,083 | <p>Have you looked at <a href="http://furius.ca/snakefood/" rel="nofollow">Snakefood</a> yet? It looks like it's exactly what you're looking for.</p>
| 3 | 2009-04-28T22:24:17Z | [
"python",
"refactoring"
] |
Python tool that builds a dependency diagram for methods of a class | 798,389 | <p>I'm digging into a huge legacy Python class that has a lot of methods. I eventually break complex ones into smaller pieces so the amount of methods increases even more. I wonder if there is a tool that can scan the Python code and build some kind of dependency diagram for its methods.</p>
<p>I define method <code>x... | 16 | 2009-04-28T14:54:26Z | 2,398,941 | <p>i was confuse in this question too,i have found a search helper help me to find the call hierarchy in another way. not very good but better than donot have. sorry about my english.</p>
<p>ps.IDE eclipse+pydev</p>
| 0 | 2010-03-08T02:20:36Z | [
"python",
"refactoring"
] |
Python tool that builds a dependency diagram for methods of a class | 798,389 | <p>I'm digging into a huge legacy Python class that has a lot of methods. I eventually break complex ones into smaller pieces so the amount of methods increases even more. I wonder if there is a tool that can scan the Python code and build some kind of dependency diagram for its methods.</p>
<p>I define method <code>x... | 16 | 2009-04-28T14:54:26Z | 17,953,557 | <p><a href="http://pycallgraph.slowchop.com/" rel="nofollow">Pycallgraph</a> should do what you are looking for.</p>
| 0 | 2013-07-30T17:30:15Z | [
"python",
"refactoring"
] |
How to call a Perl script from Python, piping input to it? | 798,413 | <p>I'm hacking some support for DomainKeys and DKIM into an open source email marketing program, which uses a python script to send the actual emails via SMTP. I decided to go the quick and dirty route, and just write a perl script that accepts an email message from STDIN, signs it, then returns it signed.</p>
<p>What... | 6 | 2009-04-28T14:58:34Z | 798,425 | <p><a href="http://docs.python.org/library/os.html#os.popen" rel="nofollow">os.popen()</a> will return a tuple with the stdin and stdout of the subprocess.</p>
| 9 | 2009-04-28T15:00:49Z | [
"python",
"perl",
"domainkeys",
"dkim"
] |
How to call a Perl script from Python, piping input to it? | 798,413 | <p>I'm hacking some support for DomainKeys and DKIM into an open source email marketing program, which uses a python script to send the actual emails via SMTP. I decided to go the quick and dirty route, and just write a perl script that accepts an email message from STDIN, signs it, then returns it signed.</p>
<p>What... | 6 | 2009-04-28T14:58:34Z | 798,432 | <p>"I'm pretty sure I can use something like os.system for this, but piping a variable to the perl script is something that seems to elude me."</p>
<p>Correct. The <a href="http://docs.python.org/library/subprocess.html" rel="nofollow">subprocess</a> module is like os.system, but provides the piping features you're l... | 2 | 2009-04-28T15:01:48Z | [
"python",
"perl",
"domainkeys",
"dkim"
] |
How to call a Perl script from Python, piping input to it? | 798,413 | <p>I'm hacking some support for DomainKeys and DKIM into an open source email marketing program, which uses a python script to send the actual emails via SMTP. I decided to go the quick and dirty route, and just write a perl script that accepts an email message from STDIN, signs it, then returns it signed.</p>
<p>What... | 6 | 2009-04-28T14:58:34Z | 798,485 | <pre><code>from subprocess import Popen, PIPE
p = Popen(['./foo.pl'], stdin=PIPE, stdout=PIPE)
p.stdin.write(the_input)
p.stdin.close()
the_output = p.stdout.read()
</code></pre>
| 6 | 2009-04-28T15:12:26Z | [
"python",
"perl",
"domainkeys",
"dkim"
] |
How to call a Perl script from Python, piping input to it? | 798,413 | <p>I'm hacking some support for DomainKeys and DKIM into an open source email marketing program, which uses a python script to send the actual emails via SMTP. I decided to go the quick and dirty route, and just write a perl script that accepts an email message from STDIN, signs it, then returns it signed.</p>
<p>What... | 6 | 2009-04-28T14:58:34Z | 798,508 | <p>I'm sure there's a reason you're going down the route you've chosen, but why not just do the signing in Python?</p>
<p>How are you signing it? Maybe we could provide some assitance in writing a python implementation?</p>
| 2 | 2009-04-28T15:18:12Z | [
"python",
"perl",
"domainkeys",
"dkim"
] |
How to call a Perl script from Python, piping input to it? | 798,413 | <p>I'm hacking some support for DomainKeys and DKIM into an open source email marketing program, which uses a python script to send the actual emails via SMTP. I decided to go the quick and dirty route, and just write a perl script that accepts an email message from STDIN, signs it, then returns it signed.</p>
<p>What... | 6 | 2009-04-28T14:58:34Z | 798,534 | <p>Use <a href="http://docs.python.org/library/subprocess.html">subprocess</a>. Here is the Python script:</p>
<pre><code>#!/usr/bin/python
import subprocess
var = "world"
pipe = subprocess.Popen(["./x.pl", var], stdout=subprocess.PIPE)
result = pipe.stdout.read()
print result
</code></pre>
<p>And here is the P... | 10 | 2009-04-28T15:25:57Z | [
"python",
"perl",
"domainkeys",
"dkim"
] |
How to call a Perl script from Python, piping input to it? | 798,413 | <p>I'm hacking some support for DomainKeys and DKIM into an open source email marketing program, which uses a python script to send the actual emails via SMTP. I decided to go the quick and dirty route, and just write a perl script that accepts an email message from STDIN, signs it, then returns it signed.</p>
<p>What... | 6 | 2009-04-28T14:58:34Z | 14,704,170 | <p>I tried also to do that only configure how to make it work as</p>
<pre><code>pipe = subprocess.Popen(
['someperlfile.perl', 'param(s)'],
stdin=subprocess.PIPE
)
response = pipe.communicate()[0]
</code></pre>
<p>I wish this will assist u to make it work.</p>
| 1 | 2013-02-05T09:34:12Z | [
"python",
"perl",
"domainkeys",
"dkim"
] |
What is the correct (or best) way to subclass the Python set class, adding a new instance variable? | 798,442 | <p>I'm implementing an object that is almost identical to a set, but requires an extra instance variable, so I am subclassing the built-in set object. What is the best way to make sure that the value of this variable is copied when one of my objects is copied?</p>
<p>Using the old sets module, the following code worke... | 5 | 2009-04-28T15:05:21Z | 798,548 | <p><code>set1 | set2</code> is an operation that won't modify either existing <code>set</code>, but return a new <code>set</code> instead. The new <code>set</code> is created and returned. There is no way to make it automatically copy arbritary attributes from one or both of the <code>set</code>s to the newly created <... | 2 | 2009-04-28T15:29:24Z | [
"python",
"subclass",
"set",
"instance-variables"
] |
What is the correct (or best) way to subclass the Python set class, adding a new instance variable? | 798,442 | <p>I'm implementing an object that is almost identical to a set, but requires an extra instance variable, so I am subclassing the built-in set object. What is the best way to make sure that the value of this variable is copied when one of my objects is copied?</p>
<p>Using the old sets module, the following code worke... | 5 | 2009-04-28T15:05:21Z | 798,595 | <p>For me this works perfectly using Python 2.5.2 on Win32. Using you class definition and the following test:</p>
<pre><code>f = Fooset([1,2,4])
s = sets.Set((5,6,7))
print f, f.foo
f.foo = 'bar'
print f, f.foo
g = f | s
print g, g.foo
assert( (f | f).foo == 'bar')
</code></pre>
<p>I get this output, which is what I... | -2 | 2009-04-28T15:39:34Z | [
"python",
"subclass",
"set",
"instance-variables"
] |
What is the correct (or best) way to subclass the Python set class, adding a new instance variable? | 798,442 | <p>I'm implementing an object that is almost identical to a set, but requires an extra instance variable, so I am subclassing the built-in set object. What is the best way to make sure that the value of this variable is copied when one of my objects is copied?</p>
<p>Using the old sets module, the following code worke... | 5 | 2009-04-28T15:05:21Z | 798,676 | <p>It looks like set bypasses <code>__init__</code> in the <a href="http://svn.python.org/view/python/trunk/Objects/setobject.c?view=markup" rel="nofollow">c code</a>. However you will end an instance of <code>Fooset</code>, it just won't have had a chance to copy the field.</p>
<p>Apart from overriding the methods t... | 2 | 2009-04-28T15:59:59Z | [
"python",
"subclass",
"set",
"instance-variables"
] |
What is the correct (or best) way to subclass the Python set class, adding a new instance variable? | 798,442 | <p>I'm implementing an object that is almost identical to a set, but requires an extra instance variable, so I am subclassing the built-in set object. What is the best way to make sure that the value of this variable is copied when one of my objects is copied?</p>
<p>Using the old sets module, the following code worke... | 5 | 2009-04-28T15:05:21Z | 798,794 | <p>Assuming the other answers are correct, and overriding all the methods is the only way to do this, here's my attempt at a moderately elegant way of doing this. If more instance variables are added, only one piece of code needs to change. Unfortunately if a new binary operator is added to the set object, this code wi... | 0 | 2009-04-28T16:31:30Z | [
"python",
"subclass",
"set",
"instance-variables"
] |
What is the correct (or best) way to subclass the Python set class, adding a new instance variable? | 798,442 | <p>I'm implementing an object that is almost identical to a set, but requires an extra instance variable, so I am subclassing the built-in set object. What is the best way to make sure that the value of this variable is copied when one of my objects is copied?</p>
<p>Using the old sets module, the following code worke... | 5 | 2009-04-28T15:05:21Z | 804,973 | <p>My favorite way to wrap methods of a built-in collection:</p>
<pre><code>class Fooset(set):
def __init__(self, s=(), foo=None):
super(Fooset,self).__init__(s)
if foo is None and hasattr(s, 'foo'):
foo = s.foo
self.foo = foo
@classmethod
def _wrap_methods(cls, names... | 11 | 2009-04-30T01:01:00Z | [
"python",
"subclass",
"set",
"instance-variables"
] |
What is the correct (or best) way to subclass the Python set class, adding a new instance variable? | 798,442 | <p>I'm implementing an object that is almost identical to a set, but requires an extra instance variable, so I am subclassing the built-in set object. What is the best way to make sure that the value of this variable is copied when one of my objects is copied?</p>
<p>Using the old sets module, the following code worke... | 5 | 2009-04-28T15:05:21Z | 6,698,723 | <p>I think that the recommended way to do this is not to subclass directly from the built-in <code>set</code>, but rather to make use of the <a href="http://docs.python.org/library/collections.html#collections.Set" rel="nofollow">Abstract Base Class <code>Set</code></a> available in <a href="http://docs.python.org/libr... | 3 | 2011-07-14T19:15:53Z | [
"python",
"subclass",
"set",
"instance-variables"
] |
What is the correct (or best) way to subclass the Python set class, adding a new instance variable? | 798,442 | <p>I'm implementing an object that is almost identical to a set, but requires an extra instance variable, so I am subclassing the built-in set object. What is the best way to make sure that the value of this variable is copied when one of my objects is copied?</p>
<p>Using the old sets module, the following code worke... | 5 | 2009-04-28T15:05:21Z | 12,319,510 | <p>Sadly, set does not follow the rules and <code>__new__</code> is not called to make new <code>set</code> objects, even though they keep the type. This is clearly a bug in Python (issue #1721812, which will not be fixed in the 2.x sequence). You should never be able to get an object of type X without calling the <c... | 2 | 2012-09-07T13:53:11Z | [
"python",
"subclass",
"set",
"instance-variables"
] |
All combinations of a list of lists | 798,854 | <p>I'm basically looking for a python version of <a href="http://stackoverflow.com/questions/545703/combination-of-listlistint">Combination of <code>List<List<int>></code></a></p>
<p>Given a list of lists, I need a new list that gives all the possible combinations of items between the lists.</p>
<pre><cod... | 95 | 2009-04-28T16:44:47Z | 798,893 | <p>you need <a href="https://docs.python.org/2/library/itertools.html#itertools.product"><code>itertools.product</code></a>:</p>
<pre><code>>>> import itertools
>>> a = [[1,2,3],[4,5,6],[7,8,9,10]]
>>> list(itertools.product(*a))
[(1, 4, 7), (1, 4, 8), (1, 4, 9), (1, 4, 10), (1, 5, 7), (1, 5... | 168 | 2009-04-28T16:54:56Z | [
"python",
"combinations"
] |
All combinations of a list of lists | 798,854 | <p>I'm basically looking for a python version of <a href="http://stackoverflow.com/questions/545703/combination-of-listlistint">Combination of <code>List<List<int>></code></a></p>
<p>Given a list of lists, I need a new list that gives all the possible combinations of items between the lists.</p>
<pre><cod... | 95 | 2009-04-28T16:44:47Z | 798,894 | <p>The most elegant solution is to use <a href="https://docs.python.org/2/library/itertools.html#itertools.product" rel="nofollow">itertools.product</a> in python 2.6.</p>
<p>If you aren't using Python 2.6, the docs for itertools.product actually show an equivalent function to do the product the "manual" way:</p>
<pr... | 17 | 2009-04-28T16:55:04Z | [
"python",
"combinations"
] |
All combinations of a list of lists | 798,854 | <p>I'm basically looking for a python version of <a href="http://stackoverflow.com/questions/545703/combination-of-listlistint">Combination of <code>List<List<int>></code></a></p>
<p>Given a list of lists, I need a new list that gives all the possible combinations of items between the lists.</p>
<pre><cod... | 95 | 2009-04-28T16:44:47Z | 798,908 | <pre><code>listOLists = [[1,2,3],[4,5,6],[7,8,9,10]]
for list in itertools.product(*listOLists):
print list;
</code></pre>
<p>I hope you find that as elegant as I did when I first encountered it.</p>
| 10 | 2009-04-28T16:58:13Z | [
"python",
"combinations"
] |
Python exceptions: call same function for any Exception | 799,293 | <p>Notice in the code below that <code>foobar()</code> is called if any Exception is thrown. Is there a way to do this without using the same line in every Exception?</p>
<pre><code>try:
foo()
except(ErrorTypeA):
bar()
foobar()
except(ErrorTypeB):
baz()
foobar()
except(SwineFlu):
print 'You have caught Swi... | 4 | 2009-04-28T18:35:33Z | 799,315 | <pre><code>success = False
try:
foo()
success = True
except(A):
bar()
except(B):
baz()
except(C):
bay()
finally:
if not success:
foobar()
</code></pre>
| 15 | 2009-04-28T18:42:01Z | [
"python",
"exception"
] |
Python exceptions: call same function for any Exception | 799,293 | <p>Notice in the code below that <code>foobar()</code> is called if any Exception is thrown. Is there a way to do this without using the same line in every Exception?</p>
<pre><code>try:
foo()
except(ErrorTypeA):
bar()
foobar()
except(ErrorTypeB):
baz()
foobar()
except(SwineFlu):
print 'You have caught Swi... | 4 | 2009-04-28T18:35:33Z | 799,323 | <p>You can use a dictionary to map exceptions against functions to call:</p>
<pre><code>exception_map = { ErrorTypeA : bar, ErrorTypeB : baz }
try:
try:
somthing()
except tuple(exception_map), e: # this catches only the exceptions in the map
exception_map[type(e)]() # calls the related function... | 11 | 2009-04-28T18:43:22Z | [
"python",
"exception"
] |
Configure Apache to use Python just like CGI PHP | 799,354 | <p>I think one commonly known way of adding PHP to an Apache webserver is to configure it like this:</p>
<pre><code>ScriptAlias /php5.3 /usr/local/php5.3/bin
Action application/php5.3 /php5.3/php-cgi
AddType application/php5.3 .php
</code></pre>
<p>Now I tried to write a similar configuration for Python:</p>
<pre><c... | 0 | 2009-04-28T18:51:59Z | 799,432 | <p>" So maybe it is not possible, but then I'm curious why this is the case?"</p>
<p>Correct. It's not possible. It was never intended, either.</p>
<p>Reason 1 - Python is not PHP. PHP -- as a whole -- expects to be a CGI. Python does not.</p>
<p>Reason 2 - Python is not inherently a CGI. It's an interpreter th... | 5 | 2009-04-28T19:11:46Z | [
"python",
"apache",
"cgi"
] |
Configure Apache to use Python just like CGI PHP | 799,354 | <p>I think one commonly known way of adding PHP to an Apache webserver is to configure it like this:</p>
<pre><code>ScriptAlias /php5.3 /usr/local/php5.3/bin
Action application/php5.3 /php5.3/php-cgi
AddType application/php5.3 .php
</code></pre>
<p>Now I tried to write a similar configuration for Python:</p>
<pre><c... | 0 | 2009-04-28T18:51:59Z | 799,630 | <p>You can use <em>any</em> type of executable as cgi. Your problem is in your apache config, which looks like you just made it up. Check the apache docs for more details, but you don't need the Action and AddType.</p>
<pre><code>ScriptAlias /cgi-bin/ "/var/www/cgi-bin/"
</code></pre>
<p>Then drop the following into ... | 12 | 2009-04-28T20:13:58Z | [
"python",
"apache",
"cgi"
] |
Configure Apache to use Python just like CGI PHP | 799,354 | <p>I think one commonly known way of adding PHP to an Apache webserver is to configure it like this:</p>
<pre><code>ScriptAlias /php5.3 /usr/local/php5.3/bin
Action application/php5.3 /php5.3/php-cgi
AddType application/php5.3 .php
</code></pre>
<p>Now I tried to write a similar configuration for Python:</p>
<pre><c... | 0 | 2009-04-28T18:51:59Z | 11,747,828 | <p>The error "Premature end of script headers:" can occur if the .py file was edited in a Windows program that uses CRLF characters for line breaks instead of the Unix LF.</p>
<p>Some programs like Dreamweaver have line-break-type in preferences. Notepad also uses CRLF.</p>
<p>If your host has a file editor, you coul... | 1 | 2012-07-31T19:45:54Z | [
"python",
"apache",
"cgi"
] |
Configure Apache to use Python just like CGI PHP | 799,354 | <p>I think one commonly known way of adding PHP to an Apache webserver is to configure it like this:</p>
<pre><code>ScriptAlias /php5.3 /usr/local/php5.3/bin
Action application/php5.3 /php5.3/php-cgi
AddType application/php5.3 .php
</code></pre>
<p>Now I tried to write a similar configuration for Python:</p>
<pre><c... | 0 | 2009-04-28T18:51:59Z | 24,783,017 | <p>When you open for example <code>http://localhost/test.py</code> you expect that Apache will somehow start process <code>/usr/bin/python /var/www/test.py</code> (i.e the interpreter with single command line argument). But this is not what happens because Apache calls the cgi script with <em>no</em> arguments. Instead... | 0 | 2014-07-16T14:09:37Z | [
"python",
"apache",
"cgi"
] |
Print long integers in python | 799,434 | <p>If I run this where vote.created_on is a python datetime:</p>
<pre><code>import calendar
created_on_timestamp = calendar.timegm(vote.created_on.timetuple())*1000
created_on_timestamp = str(created_on_timestamp)
</code></pre>
<p>created_on_timestamp will be printed with encapsulating tick marks ('). If I do int() ... | 3 | 2009-04-28T19:12:27Z | 799,447 | <pre><code>>>> i = 1240832864000L
>>> i
1240832864000L
>>> print i
1240832864000
>>>
>>> '<script type="text/javascript"> var num = %s; </script>' % i
'<script type="text/javascript"> var num = 1240832864000; </script>'
</code></pre>
<p>The L only s... | 5 | 2009-04-28T19:16:07Z | [
"python",
"django",
"datetime"
] |
Print long integers in python | 799,434 | <p>If I run this where vote.created_on is a python datetime:</p>
<pre><code>import calendar
created_on_timestamp = calendar.timegm(vote.created_on.timetuple())*1000
created_on_timestamp = str(created_on_timestamp)
</code></pre>
<p>created_on_timestamp will be printed with encapsulating tick marks ('). If I do int() ... | 3 | 2009-04-28T19:12:27Z | 799,492 | <p>With the line:</p>
<pre><code>created_on_timestamp = str(created_on_timestamp)
</code></pre>
<p>You are converting something into a string. The python console represents strings with single-quotes (is this what you mean by tick marks?) The string data, of course, does not include the quotes. </p>
<p>When you us... | 3 | 2009-04-28T19:30:36Z | [
"python",
"django",
"datetime"
] |
Python html output (first attempt), several questions (code included) | 799,479 | <p>While I have been playing with python for a few months now (just a hobbyist), I know very little about web programming (a little html, zero javascript, etc). That said, I have a current project that is making me look at web programming for the first time. This led me to ask:</p>
<p><a href="http://stackoverflow.c... | 2 | 2009-04-28T19:27:29Z | 799,513 | <p>The issue that you will run into is that you will need to change the python whenever you want to change the html. For this case, that might be fine, but it can lead to trouble. I think using something with a template system makes a lot of sense. I would suggest looking at Django. The <a href="http://docs.djangoproje... | 1 | 2009-04-28T19:35:34Z | [
"javascript",
"python"
] |
Python html output (first attempt), several questions (code included) | 799,479 | <p>While I have been playing with python for a few months now (just a hobbyist), I know very little about web programming (a little html, zero javascript, etc). That said, I have a current project that is making me look at web programming for the first time. This led me to ask:</p>
<p><a href="http://stackoverflow.c... | 2 | 2009-04-28T19:27:29Z | 799,528 | <p>I'd suggest using a template to generate the output, you can start with the buildin <a href="http://docs.python.org/library/string.html#template-strings" rel="nofollow">string.Template</a> or try something fancier, for example <a href="http://www.makotemplates.org/" rel="nofollow">Mako</a> (or Cheetah, Genshi, Jinja... | 4 | 2009-04-28T19:40:57Z | [
"javascript",
"python"
] |
Python html output (first attempt), several questions (code included) | 799,479 | <p>While I have been playing with python for a few months now (just a hobbyist), I know very little about web programming (a little html, zero javascript, etc). That said, I have a current project that is making me look at web programming for the first time. This led me to ask:</p>
<p><a href="http://stackoverflow.c... | 2 | 2009-04-28T19:27:29Z | 799,586 | <p>It would not be overkill to use a framework for something like this; python frameworks tend to be very light and easy to work with, and would make it much easier for you to add features to your tiny site. But neither is it required; I'll assume you're doing this for learning purposes and talk about how I would chang... | 8 | 2009-04-28T20:00:40Z | [
"javascript",
"python"
] |
Python html output (first attempt), several questions (code included) | 799,479 | <p>While I have been playing with python for a few months now (just a hobbyist), I know very little about web programming (a little html, zero javascript, etc). That said, I have a current project that is making me look at web programming for the first time. This led me to ask:</p>
<p><a href="http://stackoverflow.c... | 2 | 2009-04-28T19:27:29Z | 799,739 | <p><a href="http://www.python.org/doc/2.5.2/lib/typesseq-strings.html" rel="nofollow">String formatting</a> can make things a lot neater, and less error-prone.</p>
<p>Simple example, <code>%s</code> is replaced by <code>a title</code>:</p>
<pre><code>my_html = "<html><body><h1>%s</h1></body... | 5 | 2009-04-28T20:44:15Z | [
"javascript",
"python"
] |
Getting name of windows computer running python script? | 799,767 | <p>Basically, I have a couple Windows computers on my network that will be running a python script. A different set of configuration options should be used in the script depending on which computer is running this script. </p>
<p>How would I get that computer name in the python script?</p>
<p>Let's say the script w... | 45 | 2009-04-28T20:49:11Z | 799,775 | <p>I bet <a href="http://pydoc.org/1.6/socket.html#-gethostname" rel="nofollow">gethostname</a> will work beautifully.</p>
| 2 | 2009-04-28T20:51:15Z | [
"python",
"windows",
"networking"
] |
Getting name of windows computer running python script? | 799,767 | <p>Basically, I have a couple Windows computers on my network that will be running a python script. A different set of configuration options should be used in the script depending on which computer is running this script. </p>
<p>How would I get that computer name in the python script?</p>
<p>Let's say the script w... | 45 | 2009-04-28T20:49:11Z | 799,779 | <p>Since the python scrips are for sure running on a windows system, you should use the Win32 API <a href="http://msdn.microsoft.com/en-us/library/ms724295%28VS.85%29.aspx" rel="nofollow">GetComputerName</a> or <a href="http://msdn.microsoft.com/en-us/library/ms724301%28VS.85%29.aspx" rel="nofollow">GetComputerNameEx</... | 4 | 2009-04-28T20:52:31Z | [
"python",
"windows",
"networking"
] |
Getting name of windows computer running python script? | 799,767 | <p>Basically, I have a couple Windows computers on my network that will be running a python script. A different set of configuration options should be used in the script depending on which computer is running this script. </p>
<p>How would I get that computer name in the python script?</p>
<p>Let's say the script w... | 45 | 2009-04-28T20:49:11Z | 799,782 | <p>From <a href="https://mail.python.org/pipermail/python-list/2006-April/397494.html" rel="nofollow">https://mail.python.org/pipermail/python-list/2006-April/397494.html</a></p>
<pre><code>import os
os.getenv('COMPUTERNAME')
</code></pre>
| 9 | 2009-04-28T20:53:12Z | [
"python",
"windows",
"networking"
] |
Getting name of windows computer running python script? | 799,767 | <p>Basically, I have a couple Windows computers on my network that will be running a python script. A different set of configuration options should be used in the script depending on which computer is running this script. </p>
<p>How would I get that computer name in the python script?</p>
<p>Let's say the script w... | 45 | 2009-04-28T20:49:11Z | 799,783 | <pre><code>import socket
socket.gethostname()
</code></pre>
| 15 | 2009-04-28T20:53:25Z | [
"python",
"windows",
"networking"
] |
Getting name of windows computer running python script? | 799,767 | <p>Basically, I have a couple Windows computers on my network that will be running a python script. A different set of configuration options should be used in the script depending on which computer is running this script. </p>
<p>How would I get that computer name in the python script?</p>
<p>Let's say the script w... | 45 | 2009-04-28T20:49:11Z | 799,799 | <p>It turns out there are three options (including the two already answered earlier):</p>
<pre><code>>>> import platform
>>> import socket
>>> import os
>>> platform.node()
'DARK-TOWER'
>>> socket.gethostname()
'DARK-TOWER'
>>> os.environ['COMPUTERNAME']
'DARK-TOWE... | 83 | 2009-04-28T20:57:22Z | [
"python",
"windows",
"networking"
] |
Getting name of windows computer running python script? | 799,767 | <p>Basically, I have a couple Windows computers on my network that will be running a python script. A different set of configuration options should be used in the script depending on which computer is running this script. </p>
<p>How would I get that computer name in the python script?</p>
<p>Let's say the script w... | 45 | 2009-04-28T20:49:11Z | 34,773,209 | <p>As Eric Carr said you could use these three variants.</p>
<p>I prefer using them together:</p>
<pre><code>def getpcname():
n1 = platform.node()
n2 = socket.gethostname()
n3 = os.environ["COMPUTERNAME"]
if n1 == n2 == n3:
return n1
elif n1 == n2:
return n1
elif n1 == n3:
... | 2 | 2016-01-13T17:29:57Z | [
"python",
"windows",
"networking"
] |
How to get last inserted item's key in google app engine | 799,803 | <p>I am working with google app engine and python.<br />
I have a model with Items.<br />
Immediately after I insert an item with item.put()<br />
I want to get it's key and redirect to a page using this key</p>
<p>something like,</p>
<pre><code>redirectUrl = "/view/key/%s/" % item.key
self.redirect(redirectUrl)
</co... | 1 | 2009-04-28T20:58:22Z | 799,926 | <p>After you did you <code>put()</code> you can run</p>
<pre><code>item.key().id()
</code></pre>
<p>Getting the <code>id()</code> is slightly safer than just using <code>key()</code> directly, since you'd be indirectly calling <code>__str__()</code>, which may not happen in a non strincg context.</p>
<p>The other op... | 1 | 2009-04-28T21:36:37Z | [
"python",
"google-app-engine"
] |
How to get last inserted item's key in google app engine | 799,803 | <p>I am working with google app engine and python.<br />
I have a model with Items.<br />
Immediately after I insert an item with item.put()<br />
I want to get it's key and redirect to a page using this key</p>
<p>something like,</p>
<pre><code>redirectUrl = "/view/key/%s/" % item.key
self.redirect(redirectUrl)
</co... | 1 | 2009-04-28T20:58:22Z | 799,967 | <p>Thanks for the initiative Scott Kirkwood.
I was actually missing the ()</p>
<pre><code>redirectUrl = "/view/key/%s/" % item.key()
self.redirect(redirectUrl)
</code></pre>
<p>Good to know that in google datastore you don't need to use anything like Scope_identity, but you can just get the item.key() just after ite... | 1 | 2009-04-28T21:47:53Z | [
"python",
"google-app-engine"
] |
How to get last inserted item's key in google app engine | 799,803 | <p>I am working with google app engine and python.<br />
I have a model with Items.<br />
Immediately after I insert an item with item.put()<br />
I want to get it's key and redirect to a page using this key</p>
<p>something like,</p>
<pre><code>redirectUrl = "/view/key/%s/" % item.key
self.redirect(redirectUrl)
</co... | 1 | 2009-04-28T20:58:22Z | 804,324 | <p>Also, item.put() returns the key as the result, so it's hardly ever necessary to fetch that key immediately again -- just change your sequence, e.g</p>
<pre><code> item.put()
redirectUrl = "/view/key/%s/" % item.key()
</code></pre>
<p>into</p>
<pre><code> k = item.put()
redirectUrl = "/view/key/%s/" % k
</c... | 4 | 2009-04-29T21:18:38Z | [
"python",
"google-app-engine"
] |
keeping same formatting for floating point values | 800,015 | <p>I have a python program that reads floating point values using the following regular expression</p>
<pre><code> (-?\d+\.\d+)
</code></pre>
<p>once I extract the value using float(match.group(1)), I get the actual floating point number. However, I am not able to distinguish if the number was 1.2345678 or 1.234 or 1... | 1 | 2009-04-28T22:01:29Z | 800,035 | <p>If you want to keep a fixed precision, avoid using <code>float</code>s and use <code>Decimal</code> instead:</p>
<pre><code>>>> from decimal import Decimal
>>> d = Decimal('-1.2345')
>>> str(d)
'-1.2345'
>>> float(d)
-1.2344999999999999
</code></pre>
| 8 | 2009-04-28T22:07:44Z | [
"python",
"formatting",
"floating-point"
] |
keeping same formatting for floating point values | 800,015 | <p>I have a python program that reads floating point values using the following regular expression</p>
<pre><code> (-?\d+\.\d+)
</code></pre>
<p>once I extract the value using float(match.group(1)), I get the actual floating point number. However, I am not able to distinguish if the number was 1.2345678 or 1.234 or 1... | 1 | 2009-04-28T22:01:29Z | 800,041 | <pre><code>>>> from decimal import Decimal as d
>>> d('1.13200000')
Decimal('1.13200000')
>>> print d('1.13200000')
1.13200000
</code></pre>
| 1 | 2009-04-28T22:09:09Z | [
"python",
"formatting",
"floating-point"
] |
keeping same formatting for floating point values | 800,015 | <p>I have a python program that reads floating point values using the following regular expression</p>
<pre><code> (-?\d+\.\d+)
</code></pre>
<p>once I extract the value using float(match.group(1)), I get the actual floating point number. However, I am not able to distinguish if the number was 1.2345678 or 1.234 or 1... | 1 | 2009-04-28T22:01:29Z | 800,329 | <p>You method is basically correct.
String formatting has a less often used <code>*</code> operator you can put for the formatting sizes, here's some code:</p>
<pre><code>import re
def parse_float(str):
re_float = re.compile(r'(-?)(\d+)\.(\d+)')
grps = re_float.search(str)
sign, decimal, fraction = grps.groups... | 3 | 2009-04-28T23:54:10Z | [
"python",
"formatting",
"floating-point"
] |
How to get all of the immediate subdirectories in Python | 800,197 | <p>I'm trying to write a simple Python script that will copy a index.tpl to index.html in all of the subdirectories (with a few exceptions). </p>
<p>I'm getting bogged down by trying to get the list of subdirectories.</p>
| 63 | 2009-04-28T22:59:11Z | 800,201 | <pre><code>import os
def get_immediate_subdirectories(a_dir):
return [name for name in os.listdir(a_dir)
if os.path.isdir(os.path.join(a_dir, name))]
</code></pre>
| 115 | 2009-04-28T23:02:06Z | [
"python",
"file"
] |
How to get all of the immediate subdirectories in Python | 800,197 | <p>I'm trying to write a simple Python script that will copy a index.tpl to index.html in all of the subdirectories (with a few exceptions). </p>
<p>I'm getting bogged down by trying to get the list of subdirectories.</p>
| 63 | 2009-04-28T22:59:11Z | 800,203 | <p><a href="http://www.python.org/doc/2.5.4/lib/os-file-dir.html" rel="nofollow"><code>os.walk</code></a> is your friend in this situation.</p>
<p>Straight from the documentation:</p>
<blockquote>
<p>walk() generates the file names in a directory tree, by walking the tree either top down or bottom up. For each dire... | 7 | 2009-04-28T23:02:46Z | [
"python",
"file"
] |
How to get all of the immediate subdirectories in Python | 800,197 | <p>I'm trying to write a simple Python script that will copy a index.tpl to index.html in all of the subdirectories (with a few exceptions). </p>
<p>I'm getting bogged down by trying to get the list of subdirectories.</p>
| 63 | 2009-04-28T22:59:11Z | 800,206 | <p>Using Twisted's FilePath module:</p>
<pre><code>from twisted.python.filepath import FilePath
def subdirs(pathObj):
for subpath in pathObj.walk():
if subpath.isdir():
yield subpath
if __name__ == '__main__':
for subdir in subdirs(FilePath(".")):
print "Subdirectory:", subdir
</c... | 5 | 2009-04-28T23:03:54Z | [
"python",
"file"
] |
How to get all of the immediate subdirectories in Python | 800,197 | <p>I'm trying to write a simple Python script that will copy a index.tpl to index.html in all of the subdirectories (with a few exceptions). </p>
<p>I'm getting bogged down by trying to get the list of subdirectories.</p>
| 63 | 2009-04-28T22:59:11Z | 800,299 | <p>Here's one way:</p>
<pre><code>import os
import shutil
def copy_over(path, from_name, to_name):
for path, dirname, fnames in os.walk(path):
for fname in fnames:
if fname == from_name:
shutil.copy(os.path.join(path, from_name), os.path.join(path, to_name))
copy_over('.', 'index.tpl', 'index.ht... | 0 | 2009-04-28T23:42:09Z | [
"python",
"file"
] |
How to get all of the immediate subdirectories in Python | 800,197 | <p>I'm trying to write a simple Python script that will copy a index.tpl to index.html in all of the subdirectories (with a few exceptions). </p>
<p>I'm getting bogged down by trying to get the list of subdirectories.</p>
| 63 | 2009-04-28T22:59:11Z | 800,539 | <p>I just wrote some code to move vmware virtual machines around, and ended up using <code>os.path</code> and <code>shutil</code> to accomplish file copying between sub-directories.</p>
<pre><code>def copy_client_files (file_src, file_dst):
for file in os.listdir(file_src):
print "Copying file: %s" % f... | 1 | 2009-04-29T01:38:14Z | [
"python",
"file"
] |
How to get all of the immediate subdirectories in Python | 800,197 | <p>I'm trying to write a simple Python script that will copy a index.tpl to index.html in all of the subdirectories (with a few exceptions). </p>
<p>I'm getting bogged down by trying to get the list of subdirectories.</p>
| 63 | 2009-04-28T22:59:11Z | 17,460,317 | <pre><code>import os, os.path
</code></pre>
<p><strong>To get (full-path) immediate sub-directories in a directory:</strong></p>
<pre><code>def SubDirPath (d):
return filter(os.path.isdir, [os.path.join(d,f) for f in os.listdir(d)])
</code></pre>
<p><strong>To get the latest (newest) sub-directory:</strong></p>
... | 11 | 2013-07-04T00:47:48Z | [
"python",
"file"
] |
How to get all of the immediate subdirectories in Python | 800,197 | <p>I'm trying to write a simple Python script that will copy a index.tpl to index.html in all of the subdirectories (with a few exceptions). </p>
<p>I'm getting bogged down by trying to get the list of subdirectories.</p>
| 63 | 2009-04-28T22:59:11Z | 18,278,257 | <p>Why has no one mentioned <a href="https://docs.python.org/2/library/glob.html"><code>glob</code></a>? <code>glob</code> lets you use Unix-style pathname expansion, and is my go to function for almost everything that needs to find more than one path name. It makes it very easy:</p>
<pre><code>from glob import glob
p... | 23 | 2013-08-16T16:41:50Z | [
"python",
"file"
] |
How to get all of the immediate subdirectories in Python | 800,197 | <p>I'm trying to write a simple Python script that will copy a index.tpl to index.html in all of the subdirectories (with a few exceptions). </p>
<p>I'm getting bogged down by trying to get the list of subdirectories.</p>
| 63 | 2009-04-28T22:59:11Z | 25,705,093 | <p>Check "<a href="http://stackoverflow.com/questions/973473/getting-a-list-of-all-subdirectories-in-the-current-directory/973488#973488">Getting a list of all subdirectories in the current directory</a>".</p>
<p>Here's a Python 3 version:</p>
<pre><code>import os
dir_list = next(os.walk('.'))[1]
print(dir_list)
</... | 5 | 2014-09-06T21:50:37Z | [
"python",
"file"
] |
How to initialize variables to None/Undefined and compare to other variables in Python? | 800,248 | <p>Basically I have some variables that I don't want to preinitialize:</p>
<pre><code>originalTime = None
recentTime = None
postTime = None
def DoSomething ( ) :
if originalTime == None or (postTime - recentTime).seconds > 5 :
...
</code></pre>
<p>I get compile error on the if:</p>
<pre><code>Unbound... | 1 | 2009-04-28T23:22:37Z | 800,267 | <p>I just tried your code in the shell and I didn't get an error. It should work. Maybe post the entire code?
You can also use try/catch.</p>
<p>Or maybe locals().has_key('originalTime') ?</p>
| -2 | 2009-04-28T23:30:25Z | [
"python"
] |
How to initialize variables to None/Undefined and compare to other variables in Python? | 800,248 | <p>Basically I have some variables that I don't want to preinitialize:</p>
<pre><code>originalTime = None
recentTime = None
postTime = None
def DoSomething ( ) :
if originalTime == None or (postTime - recentTime).seconds > 5 :
...
</code></pre>
<p>I get compile error on the if:</p>
<pre><code>Unbound... | 1 | 2009-04-28T23:22:37Z | 800,280 | <p>Your code should have worked, I'm guessing that it's inside a function but originalTime is defined somewhere else.
Also it's a bit better to say <code>originalTime is None</code> if that's what you really want or even better, <code>not originalTime</code>.</p>
| 5 | 2009-04-28T23:34:18Z | [
"python"
] |
How to initialize variables to None/Undefined and compare to other variables in Python? | 800,248 | <p>Basically I have some variables that I don't want to preinitialize:</p>
<pre><code>originalTime = None
recentTime = None
postTime = None
def DoSomething ( ) :
if originalTime == None or (postTime - recentTime).seconds > 5 :
...
</code></pre>
<p>I get compile error on the if:</p>
<pre><code>Unbound... | 1 | 2009-04-28T23:22:37Z | 800,330 | <p>If the <code>if</code> statement is inside a function, but the <code>= None</code> declarations are at the module-level, then the variables are out of scope inside the function. The simplest fix is to explicitly indicate that the variable identifiers are to be found in the global scope:</p>
<pre><code>def doSomethi... | 0 | 2009-04-28T23:54:33Z | [
"python"
] |
How to initialize variables to None/Undefined and compare to other variables in Python? | 800,248 | <p>Basically I have some variables that I don't want to preinitialize:</p>
<pre><code>originalTime = None
recentTime = None
postTime = None
def DoSomething ( ) :
if originalTime == None or (postTime - recentTime).seconds > 5 :
...
</code></pre>
<p>I get compile error on the if:</p>
<pre><code>Unbound... | 1 | 2009-04-28T23:22:37Z | 800,389 | <p>There's not really any "pretty" way around this. Just based on the variable names that you've given, my first instinct is to create an object:</p>
<pre><code>class SomeTimeClass(object):
def __init__(self, recentTime=None, originalTime=None, postTime=None):
self.recentTime = recentTime
self.ori... | -2 | 2009-04-29T00:24:53Z | [
"python"
] |
How to initialize variables to None/Undefined and compare to other variables in Python? | 800,248 | <p>Basically I have some variables that I don't want to preinitialize:</p>
<pre><code>originalTime = None
recentTime = None
postTime = None
def DoSomething ( ) :
if originalTime == None or (postTime - recentTime).seconds > 5 :
...
</code></pre>
<p>I get compile error on the if:</p>
<pre><code>Unbound... | 1 | 2009-04-28T23:22:37Z | 802,450 | <p>I need to correct Jarret Hardie, and since I don't have enough rep to comment.</p>
<p>The global scope is not an issue. Python will automatically look up variable names in enclosing scopes. The only issue is when you want to change the value. If you simply redefine the variable, Python will create a new local va... | 8 | 2009-04-29T13:50:16Z | [
"python"
] |
About GUI editor that would be compatible with Python 3.0 | 800,769 | <p>I would like to start learning Python (zero past experience). I am a bit inclined to start with Python 3.0. However, I am not sure if at this time there exists a GUI editor that would be compatible with Python 3.0. I've tried installing Glade, but the one I've got works only with Python 2.5. What could I possibly us... | 3 | 2009-04-29T03:37:44Z | 800,794 | <p>Just use whichever editor you are most comfortable with.</p>
<p>The "leading space as logic" and duck typing mean that there is a limited amount of syntax checking and re-factoring an editor can reasonably do (or is required!) with python source.</p>
<p>If you dont have a favorite editor then just use the "idle" e... | 0 | 2009-04-29T03:49:55Z | [
"python",
"user-interface",
"python-3.x"
] |
About GUI editor that would be compatible with Python 3.0 | 800,769 | <p>I would like to start learning Python (zero past experience). I am a bit inclined to start with Python 3.0. However, I am not sure if at this time there exists a GUI editor that would be compatible with Python 3.0. I've tried installing Glade, but the one I've got works only with Python 2.5. What could I possibly us... | 3 | 2009-04-29T03:37:44Z | 800,824 | <p>There are many useful libraries (not to mention educational material, cookbook snippets, etc.) that have yet to be ported to Python 3.0, so I recommend using Python 2.x for now (where, currently, 5 <= x <= 6). Doubly so if you're a beginner to Python. Triply so if you're actually planning on releasing some sof... | 1 | 2009-04-29T04:03:50Z | [
"python",
"user-interface",
"python-3.x"
] |
About GUI editor that would be compatible with Python 3.0 | 800,769 | <p>I would like to start learning Python (zero past experience). I am a bit inclined to start with Python 3.0. However, I am not sure if at this time there exists a GUI editor that would be compatible with Python 3.0. I've tried installing Glade, but the one I've got works only with Python 2.5. What could I possibly us... | 3 | 2009-04-29T03:37:44Z | 800,918 | <p>The only GUI toolkit currently available in Python3.0 is Tkinter, and I don't think there are any Python3.0 GUI-builders available yet.</p>
| 0 | 2009-04-29T04:47:19Z | [
"python",
"user-interface",
"python-3.x"
] |
About GUI editor that would be compatible with Python 3.0 | 800,769 | <p>I would like to start learning Python (zero past experience). I am a bit inclined to start with Python 3.0. However, I am not sure if at this time there exists a GUI editor that would be compatible with Python 3.0. I've tried installing Glade, but the one I've got works only with Python 2.5. What could I possibly us... | 3 | 2009-04-29T03:37:44Z | 800,941 | <p>WING 3.2 beta work in python 3.</p>
<p>ricnar</p>
| 0 | 2009-04-29T05:00:23Z | [
"python",
"user-interface",
"python-3.x"
] |
About GUI editor that would be compatible with Python 3.0 | 800,769 | <p>I would like to start learning Python (zero past experience). I am a bit inclined to start with Python 3.0. However, I am not sure if at this time there exists a GUI editor that would be compatible with Python 3.0. I've tried installing Glade, but the one I've got works only with Python 2.5. What could I possibly us... | 3 | 2009-04-29T03:37:44Z | 801,121 | <p>If your looking for a GUI editor, have a look at these:</p>
<ul>
<li><a href="http://wxformbuilder.org" rel="nofollow">wxFormBuilder</a> can generate .XRC files for wxpython.</li>
<li>XRCed ships with wxpython and could do this as well.</li>
</ul>
<p>.XRC files are xml file which describes your GUI and are not lan... | 1 | 2009-04-29T06:31:22Z | [
"python",
"user-interface",
"python-3.x"
] |
About GUI editor that would be compatible with Python 3.0 | 800,769 | <p>I would like to start learning Python (zero past experience). I am a bit inclined to start with Python 3.0. However, I am not sure if at this time there exists a GUI editor that would be compatible with Python 3.0. I've tried installing Glade, but the one I've got works only with Python 2.5. What could I possibly us... | 3 | 2009-04-29T03:37:44Z | 972,835 | <p><a href="http://www.riverbankcomputing.co.uk/software/pyqt/download" rel="nofollow">PyQt 4.5</a> (released a couple of days ago) added support for Python 3</p>
<p>That doesn't of course devaluate gotgenes answer: most of the 3rd party libraries are just not ready yet for Python 3.</p>
| 0 | 2009-06-09T22:34:28Z | [
"python",
"user-interface",
"python-3.x"
] |
C# Nmath to Python SciPy | 801,128 | <p>I need to port some functions from C# to Python, but i can't implement next code right:</p>
<pre><code>[SqlFunction(IsDeterministic = true, DataAccess = DataAccessKind.None)]
public static SqlDouble LogNormDist(double probability, double mean, double stddev)
{
LognormalDistribution lnd = new LognormalDistributi... | 1 | 2009-04-29T06:33:05Z | 801,435 | <p>Maybe you can use Python.NET (this is <em>NOT</em> IronPython), it allows to access .NET components and services:</p>
<p><a href="http://pythonnet.sourceforge.net/" rel="nofollow">http://pythonnet.sourceforge.net/</a></p>
| 0 | 2009-04-29T08:29:43Z | [
"c#",
"python",
"scipy",
"nmath"
] |
C# Nmath to Python SciPy | 801,128 | <p>I need to port some functions from C# to Python, but i can't implement next code right:</p>
<pre><code>[SqlFunction(IsDeterministic = true, DataAccess = DataAccessKind.None)]
public static SqlDouble LogNormDist(double probability, double mean, double stddev)
{
LognormalDistribution lnd = new LognormalDistributi... | 1 | 2009-04-29T06:33:05Z | 801,457 | <p>Scipy has a bunch of distributions defined in the scipy.stats package</p>
<pre><code>import scipy.stats
def LogNormDist(prob, mean=0, stddev=1):
return scipy.stats.lognorm.cdf(prob,stddev,mean)
</code></pre>
<h3>Update</h3>
<p>Okay, it looks like Scipy's stat definitions are a little nonstandard. Here's the ... | 3 | 2009-04-29T08:39:10Z | [
"c#",
"python",
"scipy",
"nmath"
] |
C# Nmath to Python SciPy | 801,128 | <p>I need to port some functions from C# to Python, but i can't implement next code right:</p>
<pre><code>[SqlFunction(IsDeterministic = true, DataAccess = DataAccessKind.None)]
public static SqlDouble LogNormDist(double probability, double mean, double stddev)
{
LognormalDistribution lnd = new LognormalDistributi... | 1 | 2009-04-29T06:33:05Z | 801,643 | <p>The Python docs describe a method random.lognormvariate(mu, sigma):</p>
<p><a href="http://docs.python.org/library/random.html" rel="nofollow">http://docs.python.org/library/random.html</a></p>
<p>Maybe that's what you want.</p>
| 2 | 2009-04-29T09:46:48Z | [
"c#",
"python",
"scipy",
"nmath"
] |
C# Nmath to Python SciPy | 801,128 | <p>I need to port some functions from C# to Python, but i can't implement next code right:</p>
<pre><code>[SqlFunction(IsDeterministic = true, DataAccess = DataAccessKind.None)]
public static SqlDouble LogNormDist(double probability, double mean, double stddev)
{
LognormalDistribution lnd = new LognormalDistributi... | 1 | 2009-04-29T06:33:05Z | 19,847,809 | <p>Ivan,</p>
<p>We've got no interest in keeping people locked into NMath. Here's what we're doing in NMath.</p>
<pre><code> double t = ( Math.Log( x ) - mu_ ) / sigmaRoot2_;
return ( 0.5 + 0.5 * Erf( t ) );
</code></pre>
<p>where</p>
<pre><code>private static double Erf( double x )
{
return ( x < 0.0 ? -St... | 0 | 2013-11-07T22:16:32Z | [
"c#",
"python",
"scipy",
"nmath"
] |
Django equivalent of PHP's form value array/associative array | 801,354 | <p>In PHP, I would do this to get <code>name</code> as an array.</p>
<pre><code><input type"text" name="name[]" />
<input type"text" name="name[]" />
</code></pre>
<p>Or if I wanted to get <code>name</code> as an associative array:</p>
<pre><code><input type"text" name="name[first]" />
<input ty... | 42 | 2009-04-29T08:04:10Z | 802,053 | <p><a href="http://docs.djangoproject.com/en/dev/ref/request-response/#querydict-objects">Check out the QueryDict documentation</a>, particularly the usage of <a href="http://docs.djangoproject.com/en/dev/ref/request-response/#django.http.QueryDict.getlist"><code>QueryDict.getlist(key)</code></a>.</p>
<p>Since request... | 57 | 2009-04-29T12:03:36Z | [
"python",
"django",
"forms",
"html-form"
] |
Django equivalent of PHP's form value array/associative array | 801,354 | <p>In PHP, I would do this to get <code>name</code> as an array.</p>
<pre><code><input type"text" name="name[]" />
<input type"text" name="name[]" />
</code></pre>
<p>Or if I wanted to get <code>name</code> as an associative array:</p>
<pre><code><input type"text" name="name[first]" />
<input ty... | 42 | 2009-04-29T08:04:10Z | 804,798 | <p>Django does not provide a way to get associative arrays (dictionaries in Python) from the request object. As the first answer pointed out, you can use <code>.getlist()</code> as needed, or write a function that can take a <code>QueryDict</code> and reorganize it to your liking (pulling out key/value pairs if the key... | 4 | 2009-04-29T23:40:42Z | [
"python",
"django",
"forms",
"html-form"
] |
Django equivalent of PHP's form value array/associative array | 801,354 | <p>In PHP, I would do this to get <code>name</code> as an array.</p>
<pre><code><input type"text" name="name[]" />
<input type"text" name="name[]" />
</code></pre>
<p>Or if I wanted to get <code>name</code> as an associative array:</p>
<pre><code><input type"text" name="name[first]" />
<input ty... | 42 | 2009-04-29T08:04:10Z | 4,746,016 | <p>Sorry for digging this up, but Django has an utils.datastructures.DotExpandedDict. Here's a piece of it's docs:</p>
<pre><code>>>> d = DotExpandedDict({'person.1.firstname': ['Simon'], \
'person.1.lastname': ['Willison'], \
'person.2.firstname': ['Adrian'], \
'person.2.lastname': ['... | 17 | 2011-01-20T10:34:39Z | [
"python",
"django",
"forms",
"html-form"
] |
Updating data in google app engine | 801,477 | <p>I'm attempting my first google app engine project â a simple player stats database for a sports team I'm involved with. Given this model:</p>
<pre><code>class Player(db.Model):
""" Represents a player in the club. """
first_name = db.StringProperty()
surname = db.StringProperty()
gender = db.Str... | 0 | 2009-04-29T08:47:56Z | 801,491 | <p>On each request you are working on a new instance of the same class. That's why you can't create a varable in <code>get()</code> and use its value in <code>post()</code>. What you could do is either retrieve the values again in your <code>post()</code>-method or store the data in the <code>memcache</code>.</p>
<p>R... | 2 | 2009-04-29T08:54:58Z | [
"python",
"google-app-engine"
] |
Updating data in google app engine | 801,477 | <p>I'm attempting my first google app engine project â a simple player stats database for a sports team I'm involved with. Given this model:</p>
<pre><code>class Player(db.Model):
""" Represents a player in the club. """
first_name = db.StringProperty()
surname = db.StringProperty()
gender = db.Str... | 0 | 2009-04-29T08:47:56Z | 801,526 | <p>I've never tried building a google app engine app, but I understand it's somewhat similar to Django in it's handling of databases etc.</p>
<p>I don't think you should be storing things in global variables and instead should be treating each transaction seperately. The get request works because you're doing what you... | 1 | 2009-04-29T09:05:18Z | [
"python",
"google-app-engine"
] |
Updating data in google app engine | 801,477 | <p>I'm attempting my first google app engine project â a simple player stats database for a sports team I'm involved with. Given this model:</p>
<pre><code>class Player(db.Model):
""" Represents a player in the club. """
first_name = db.StringProperty()
surname = db.StringProperty()
gender = db.Str... | 0 | 2009-04-29T08:47:56Z | 801,535 | <p>In your post method, just before the "for" clause, retrieve the players list from where it is stored:</p>
<pre><code>def post(self):
# some code skipped
self.shown_players = Player.all().fetch()
for i, player in enumerate(self.shown_players):
...
</code></pre>
| 2 | 2009-04-29T09:06:28Z | [
"python",
"google-app-engine"
] |
Why Python informixdb package is throwing an error! | 801,515 | <p>I have downloaded & installed the latest Python InformixDB package, but when I try to import it from the shell, I am getting the following error in the form of a Windows dialog box!</p>
<p><strong>"A procedure entry point sqli_describe_input_stmt could not be located in the dynamic link isqlit09a.dll"</strong><... | 1 | 2009-04-29T09:01:20Z | 803,958 | <p>Which version of IBM Informix Connect (I-Connect) or IBM Informix ClientSDK (CSDK) are you using? The 'describe input' function is a more recent addition, but it is likely that you have it.</p>
<p>Have you been able to connect to any Informix DBMS from the command shell? If not, then the suspicion must be that yo... | 1 | 2009-04-29T19:43:50Z | [
"python",
"informix"
] |
Why Python informixdb package is throwing an error! | 801,515 | <p>I have downloaded & installed the latest Python InformixDB package, but when I try to import it from the shell, I am getting the following error in the form of a Windows dialog box!</p>
<p><strong>"A procedure entry point sqli_describe_input_stmt could not be located in the dynamic link isqlit09a.dll"</strong><... | 1 | 2009-04-29T09:01:20Z | 823,474 | <p>Does other way to connect to database work?
Can you use (configure in control panel) ODBC? If ODBC works then you can use Python win32 extensions (ActiveState distribution comes with it) and there is ODBC support. You can also use Jython which can work with ODBC via JDBC-ODBC bridge or with Informix JDBC driver.</p>... | 0 | 2009-05-05T05:29:22Z | [
"python",
"informix"
] |
How to put timedelta in django model? | 801,912 | <p>With inspectdb I was able to get a "interval" field from postgres into django. In Django, it was a TextField. The object that I retrieved was indeed a timedelta object!</p>
<p>Now I want to put this timedelta object in a new model. What's the best way to do this? Because putting a timedelta in a TextField results i... | 20 | 2009-04-29T11:26:47Z | 801,933 | <p>This link may be helpfull: <a href="http://www.djangosnippets.org/snippets/1060/" rel="nofollow">Timedelta Snippets</a></p>
| 2 | 2009-04-29T11:31:33Z | [
"python",
"django",
"model"
] |
How to put timedelta in django model? | 801,912 | <p>With inspectdb I was able to get a "interval" field from postgres into django. In Django, it was a TextField. The object that I retrieved was indeed a timedelta object!</p>
<p>Now I want to put this timedelta object in a new model. What's the best way to do this? Because putting a timedelta in a TextField results i... | 20 | 2009-04-29T11:26:47Z | 801,963 | <p>You can trivially normalize a timedelta to a single floating-point number in days or seconds. </p>
<p>Here's the "Normalize to Days" version.</p>
<pre><code>float(timedelta.days) + float(timedelta.seconds) / float(86400)
</code></pre>
<p>You can trivially turn a floating-point number into a timedelta. </p>
<pre>... | 27 | 2009-04-29T11:40:52Z | [
"python",
"django",
"model"
] |
How to put timedelta in django model? | 801,912 | <p>With inspectdb I was able to get a "interval" field from postgres into django. In Django, it was a TextField. The object that I retrieved was indeed a timedelta object!</p>
<p>Now I want to put this timedelta object in a new model. What's the best way to do this? Because putting a timedelta in a TextField results i... | 20 | 2009-04-29T11:26:47Z | 3,329,149 | <p>For PostgreSQL, use django-pgsql-interval-field here: <a href="http://code.google.com/p/django-pgsql-interval-field/" rel="nofollow">http://code.google.com/p/django-pgsql-interval-field/</a></p>
| 3 | 2010-07-25T12:16:14Z | [
"python",
"django",
"model"
] |
How to put timedelta in django model? | 801,912 | <p>With inspectdb I was able to get a "interval" field from postgres into django. In Django, it was a TextField. The object that I retrieved was indeed a timedelta object!</p>
<p>Now I want to put this timedelta object in a new model. What's the best way to do this? Because putting a timedelta in a TextField results i... | 20 | 2009-04-29T11:26:47Z | 5,686,428 | <p><a href="https://bitbucket.org/schinckel/django-timedelta-field/src">https://bitbucket.org/schinckel/django-timedelta-field/src</a></p>
| 5 | 2011-04-16T12:23:10Z | [
"python",
"django",
"model"
] |
How to put timedelta in django model? | 801,912 | <p>With inspectdb I was able to get a "interval" field from postgres into django. In Django, it was a TextField. The object that I retrieved was indeed a timedelta object!</p>
<p>Now I want to put this timedelta object in a new model. What's the best way to do this? Because putting a timedelta in a TextField results i... | 20 | 2009-04-29T11:26:47Z | 10,576,547 | <p>First, define your model:</p>
<pre><code>class TimeModel(models.Model):
time = models.FloatField()
</code></pre>
<p>To store a timedelta object:</p>
<pre><code># td is a timedelta object
TimeModel.objects.create(time=td.total_seconds())
</code></pre>
<p>To get the timedelta object out of the database:</p>
<... | 7 | 2012-05-14T01:16:07Z | [
"python",
"django",
"model"
] |
How to put timedelta in django model? | 801,912 | <p>With inspectdb I was able to get a "interval" field from postgres into django. In Django, it was a TextField. The object that I retrieved was indeed a timedelta object!</p>
<p>Now I want to put this timedelta object in a new model. What's the best way to do this? Because putting a timedelta in a TextField results i... | 20 | 2009-04-29T11:26:47Z | 16,954,516 | <p>There is a ticket which dates back to July 2006 relating to this:
<a href="https://code.djangoproject.com/ticket/2443" rel="nofollow">https://code.djangoproject.com/ticket/2443</a></p>
<p>Several patches were written but the one that was turned in to a project:
<a href="https://github.com/johnpaulett/django-duratio... | 2 | 2013-06-06T05:47:58Z | [
"python",
"django",
"model"
] |
How to put timedelta in django model? | 801,912 | <p>With inspectdb I was able to get a "interval" field from postgres into django. In Django, it was a TextField. The object that I retrieved was indeed a timedelta object!</p>
<p>Now I want to put this timedelta object in a new model. What's the best way to do this? Because putting a timedelta in a TextField results i... | 20 | 2009-04-29T11:26:47Z | 28,830,179 | <p>Putting this out there cause it might be another way to solve this problem.
first install this library: <a href="https://pypi.python.org/pypi/django-timedeltafield" rel="nofollow">https://pypi.python.org/pypi/django-timedeltafield</a> </p>
<p>Then:</p>
<pre><code>import timedelta
class ModelWithTimeDelta(models.M... | 2 | 2015-03-03T11:03:20Z | [
"python",
"django",
"model"
] |
How to put timedelta in django model? | 801,912 | <p>With inspectdb I was able to get a "interval" field from postgres into django. In Django, it was a TextField. The object that I retrieved was indeed a timedelta object!</p>
<p>Now I want to put this timedelta object in a new model. What's the best way to do this? Because putting a timedelta in a TextField results i... | 20 | 2009-04-29T11:26:47Z | 29,516,197 | <p>Since Django 1.8 you can use <a href="https://docs.djangoproject.com/en/1.8/ref/models/fields/#django.db.models.DurationField">DurationField</a>.</p>
| 38 | 2015-04-08T13:35:20Z | [
"python",
"django",
"model"
] |
Notifying container object: best practices | 801,931 | <p>I have two classes: Account and Operator. Account contains a list of Operators. Now, whenever an operator (in the list) receives a message I want to notify Account object to perform some business logic as well.</p>
<p>I think of three alternatives on how to achieve this:</p>
<p>1) Hold a reference within Operator ... | 4 | 2009-04-29T11:31:06Z | 802,031 | <p>There is no "one-size-fits-all" solution for the Observer pattern. But usually, it's better to define an EventManager object where interested parties can register themselves for certain events and post these events whenever they happen. It simply creates less dependencies.</p>
<p>Note that you need to use a global ... | 3 | 2009-04-29T12:00:25Z | [
"python",
"architecture",
"containers",
"notifications"
] |
Notifying container object: best practices | 801,931 | <p>I have two classes: Account and Operator. Account contains a list of Operators. Now, whenever an operator (in the list) receives a message I want to notify Account object to perform some business logic as well.</p>
<p>I think of three alternatives on how to achieve this:</p>
<p>1) Hold a reference within Operator ... | 4 | 2009-04-29T11:31:06Z | 802,083 | <p>I would use event handling for this. You don't have to implement it yourself -- I use <a href="http://pydispatcher.sourceforge.net/" rel="nofollow">pydispatcher</a> for exactly this kind of event handling, and it's always worked very well (it uses weak references internally, to avoid the circular reference problem).... | 3 | 2009-04-29T12:14:12Z | [
"python",
"architecture",
"containers",
"notifications"
] |
Notifying container object: best practices | 801,931 | <p>I have two classes: Account and Operator. Account contains a list of Operators. Now, whenever an operator (in the list) receives a message I want to notify Account object to perform some business logic as well.</p>
<p>I think of three alternatives on how to achieve this:</p>
<p>1) Hold a reference within Operator ... | 4 | 2009-04-29T11:31:06Z | 802,084 | <p>You're over-thinking this. Seriously. Python isn't C++; your concerns are non-issues in Python. Just write what makes sense in your problem domain.</p>
<p>" Not absolutely good because of circular references."</p>
<p>Why not? Circularity is of no relevance here at all. Bidirectional relationships are great th... | 5 | 2009-04-29T12:15:23Z | [
"python",
"architecture",
"containers",
"notifications"
] |
Notifying container object: best practices | 801,931 | <p>I have two classes: Account and Operator. Account contains a list of Operators. Now, whenever an operator (in the list) receives a message I want to notify Account object to perform some business logic as well.</p>
<p>I think of three alternatives on how to achieve this:</p>
<p>1) Hold a reference within Operator ... | 4 | 2009-04-29T11:31:06Z | 802,088 | <pre><code>>>> class Account(object):
... def notify(self):
... print "Account notified"
...
>>> class Operator(object):
... def __init__(self, notifier):
... self.notifier = notifier
...
>>> A = Account()
>>> O = Operator(A.notify)
>>> O.notifier()
A... | 3 | 2009-04-29T12:15:39Z | [
"python",
"architecture",
"containers",
"notifications"
] |
Notifying container object: best practices | 801,931 | <p>I have two classes: Account and Operator. Account contains a list of Operators. Now, whenever an operator (in the list) receives a message I want to notify Account object to perform some business logic as well.</p>
<p>I think of three alternatives on how to achieve this:</p>
<p>1) Hold a reference within Operator ... | 4 | 2009-04-29T11:31:06Z | 802,261 | <p>There are Observer pattern snippets all over the Web. A good source of reliable code is active state, E.G :</p>
<p><a href="http://code.activestate.com/recipes/131499/" rel="nofollow">http://code.activestate.com/recipes/131499/</a></p>
| 0 | 2009-04-29T13:00:07Z | [
"python",
"architecture",
"containers",
"notifications"
] |
Changing user agent on urllib2.urlopen | 802,134 | <p>How can I download a webpage with a user agent other than the default one on urllib2.urlopen?</p>
| 75 | 2009-04-29T12:32:36Z | 802,146 | <p><a href="http://www.diveintopython.net/http_web_services/user_agent.html">Setting the User-Agent</a> from everyone's favorite <a href="http://diveintopython.net/">Dive Into Python</a>.</p>
<p>The short story: You can use <a href="http://docs.python.org/library/urllib2.html#urllib2.Request.add_header">Request.add_he... | 50 | 2009-04-29T12:34:30Z | [
"python",
"urllib2",
"user-agent"
] |
Changing user agent on urllib2.urlopen | 802,134 | <p>How can I download a webpage with a user agent other than the default one on urllib2.urlopen?</p>
| 75 | 2009-04-29T12:32:36Z | 802,246 | <p>I <a href="http://stackoverflow.com/a/762007/3790126">answered</a> a <a href="http://stackoverflow.com/questions/761978/send-headers-along-in-python">similar question</a> a couple weeks ago.</p>
<p>There is example code in that question, but basically you can do something like this: (Note the capitalization of <cod... | 89 | 2009-04-29T12:56:46Z | [
"python",
"urllib2",
"user-agent"
] |
Changing user agent on urllib2.urlopen | 802,134 | <p>How can I download a webpage with a user agent other than the default one on urllib2.urlopen?</p>
| 75 | 2009-04-29T12:32:36Z | 5,196,160 | <pre><code>headers = { 'User-Agent' : 'Mozilla/5.0' }
req = urllib2.Request('www.example.com', None, headers)
html = urllib2.urlopen(req).read()
</code></pre>
<p>Or, a bit shorter:</p>
<pre><code>req = urllib2.Request('www.example.com', headers={ 'User-Agent': 'Mozilla/5.0' })
html = urllib2.urlopen(req).read()
</cod... | 72 | 2011-03-04T15:58:58Z | [
"python",
"urllib2",
"user-agent"
] |
Changing user agent on urllib2.urlopen | 802,134 | <p>How can I download a webpage with a user agent other than the default one on urllib2.urlopen?</p>
| 75 | 2009-04-29T12:32:36Z | 8,994,498 | <p>All these should work in theory, but (with Python 2.7.2 on Windows at least) any time you send a custom User-agent header, urllib2 doesn't send that header. If you don't try to send a User-agent header, it sends the default Python / urllib2 </p>
<p>None of these methods seem to work for adding User-agent but they ... | 8 | 2012-01-24T21:32:26Z | [
"python",
"urllib2",
"user-agent"
] |
Changing user agent on urllib2.urlopen | 802,134 | <p>How can I download a webpage with a user agent other than the default one on urllib2.urlopen?</p>
| 75 | 2009-04-29T12:32:36Z | 10,468,884 | <p>For python 3, urllib is split into 3 modules...</p>
<pre><code>import urllib.request
req = urllib.request.Request(url="http://localhost/",data=b'None',headers={'User-Agent':' Mozilla/5.0 (Windows NT 6.1; WOW64; rv:12.0) Gecko/20100101 Firefox/12.0'})
handler = urllib.request.urlopen(req)
</code></pre>
| 8 | 2012-05-06T07:19:05Z | [
"python",
"urllib2",
"user-agent"
] |
Changing user agent on urllib2.urlopen | 802,134 | <p>How can I download a webpage with a user agent other than the default one on urllib2.urlopen?</p>
| 75 | 2009-04-29T12:32:36Z | 14,324,710 | <p>Another solution in <code>urllib2</code> and Python 2.7:</p>
<pre><code>req = urllib2.Request('http://www.example.com/')
req.add_unredirected_header('User-Agent', 'Custom User-Agent')
urllib2.urlopen(req)
</code></pre>
| 5 | 2013-01-14T18:54:25Z | [
"python",
"urllib2",
"user-agent"
] |
Changing user agent on urllib2.urlopen | 802,134 | <p>How can I download a webpage with a user agent other than the default one on urllib2.urlopen?</p>
| 75 | 2009-04-29T12:32:36Z | 29,161,951 | <p>For urllib you can use:</p>
<pre><code>from urllib import FancyURLopener
class MyOpener(FancyURLopener, object):
version = 'Mozilla/5.0 (Windows; U; Windows NT 5.1; it; rv:1.8.1.11) Gecko/20071127 Firefox/2.0.0.11'
myopener = MyOpener()
myopener.retrieve('https://www.google.com/search?q=test', 'useragent.html... | 2 | 2015-03-20T08:01:49Z | [
"python",
"urllib2",
"user-agent"
] |
Changing user agent on urllib2.urlopen | 802,134 | <p>How can I download a webpage with a user agent other than the default one on urllib2.urlopen?</p>
| 75 | 2009-04-29T12:32:36Z | 31,693,953 | <p>Try this :</p>
<pre><code>html_source_code = requests.get("http://www.example.com/", headers={'User-Agent':'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/44.0.2403.107 Safari/537.36','Upgrade-Insecure-Requests': '1','x-runtime': '148ms'}, allow_redirects=True).content
</code></pr... | 1 | 2015-07-29T07:30:42Z | [
"python",
"urllib2",
"user-agent"
] |
Face-tracking libraries for Java or Python | 802,243 | <p>I'm looking for a way to identify faces (not specific people, just where the faces are) and track them as they move across a room. </p>
<p>We're trying to measure walking speed for people, and I assumed this would be the easiest way of identifying a person as a person. We'll have a reasonably fast camera for the pr... | 8 | 2009-04-29T12:55:12Z | 802,278 | <p>"faint" (The Face Annotation Interface) might be what you're looking for.</p>
<p><a href="http://faint.sourceforge.net/" rel="nofollow">http://faint.sourceforge.net/</a></p>
<p><a href="http://technoroy.blogspot.com/2008/06/faint-search-for-faces.html" rel="nofollow">http://technoroy.blogspot.com/2008/06/faint-sea... | 2 | 2009-04-29T13:04:58Z | [
"java",
"python",
"face-detection"
] |
Face-tracking libraries for Java or Python | 802,243 | <p>I'm looking for a way to identify faces (not specific people, just where the faces are) and track them as they move across a room. </p>
<p>We're trying to measure walking speed for people, and I assumed this would be the easiest way of identifying a person as a person. We'll have a reasonably fast camera for the pr... | 8 | 2009-04-29T12:55:12Z | 802,289 | <p>There was an <a href="http://www.linux-magazin.de/heft%5Fabo/ausgaben/2008/02/ins%5Fgesicht%5Fgeblickt" rel="nofollow">article about this</a> in the German "Linux Magazin".</p>
<p>They used the <a href="http://sourceforge.net/projects/opencvlibrary/" rel="nofollow">Open Computer Vision Library</a> which offers a wh... | 2 | 2009-04-29T13:07:05Z | [
"java",
"python",
"face-detection"
] |
Face-tracking libraries for Java or Python | 802,243 | <p>I'm looking for a way to identify faces (not specific people, just where the faces are) and track them as they move across a room. </p>
<p>We're trying to measure walking speed for people, and I assumed this would be the easiest way of identifying a person as a person. We'll have a reasonably fast camera for the pr... | 8 | 2009-04-29T12:55:12Z | 802,381 | <p>Checkout <a href="http://opencv.willowgarage.com/wiki/PythonInterface" rel="nofollow">OpenCV Python Interface</a></p>
| 7 | 2009-04-29T13:32:51Z | [
"java",
"python",
"face-detection"
] |
Face-tracking libraries for Java or Python | 802,243 | <p>I'm looking for a way to identify faces (not specific people, just where the faces are) and track them as they move across a room. </p>
<p>We're trying to measure walking speed for people, and I assumed this would be the easiest way of identifying a person as a person. We'll have a reasonably fast camera for the pr... | 8 | 2009-04-29T12:55:12Z | 2,272,905 | <p><a href="http://www.codeproject.com/info/search.aspx?artkw=face+recognition" rel="nofollow">CodeProject has a whole raft of articles in various languages.</a></p>
| 0 | 2010-02-16T12:44:44Z | [
"java",
"python",
"face-detection"
] |
How can I enumerate/list all installed applications in Windows XP? | 802,499 | <p>When I say "installed application", I basically mean any application visible in [Control Panel]->[Add/Remove Programs]. </p>
<p>I would prefer to do it in Python, but C or C++ is also fine.</p>
| 6 | 2009-04-29T14:02:12Z | 802,510 | <p>Check out the <a href="http://msdn.microsoft.com/en-us/library/aa394378%28VS.85%29.aspx">Win32_Product</a> WMI (Windows Management Instrumentation) class. <a href="http://timgolden.me.uk/python/wmi.html">Here's a tutorial</a> on using WMI in Python.</p>
| 10 | 2009-04-29T14:05:59Z | [
"c++",
"python",
"winapi",
"enumeration"
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.