title
stringlengths
10
172
question_id
int64
469
40.1M
question_body
stringlengths
22
48.2k
question_score
int64
-44
5.52k
question_date
stringlengths
20
20
answer_id
int64
497
40.1M
answer_body
stringlengths
18
33.9k
answer_score
int64
-38
8.38k
answer_date
stringlengths
20
20
tags
listlengths
1
5
print vs stderr
939,866
<p>Are there any specific advantages or disadvantages to either <code>print</code> or <code>stderr</code>?</p>
23
2009-06-02T14:25:54Z
16,592,589
<p>It is useful to separate stderr and stdout when running your script by redirecting them to different files. I usually use stderr for log messages and to keep track of the flow of the program, but use stdout for more useful messages that I am going to use them later.</p> <p>One another way to write to stderr is as t...
2
2013-05-16T16:16:23Z
[ "python", "printing", "stderr" ]
How do I update an object's members using a dict?
940,089
<p>I'm writing a Django app that performs various functions, including inserting, or updating new records into the database via the URL.</p> <p>So some internal application sends off a request to <code>/import/?a=1&amp;b=2&amp;c=3</code>, for example. In the view, I want to create a new object, <code>foo = Foo()</code...
9
2009-06-02T15:07:29Z
940,101
<p>You can use the setattr function to dynamically set attributes:</p> <pre><code>for key,value in request.GET.items(): setattr(foo, key, value) </code></pre>
17
2009-06-02T15:09:14Z
[ "python", "django" ]
How do I update an object's members using a dict?
940,089
<p>I'm writing a Django app that performs various functions, including inserting, or updating new records into the database via the URL.</p> <p>So some internal application sends off a request to <code>/import/?a=1&amp;b=2&amp;c=3</code>, for example. In the view, I want to create a new object, <code>foo = Foo()</code...
9
2009-06-02T15:07:29Z
940,131
<p>You've almost got it.</p> <pre><code>foo = Foo(**request.GET) </code></pre> <p>should do the trick.</p>
1
2009-06-02T15:13:08Z
[ "python", "django" ]
How do I update an object's members using a dict?
940,089
<p>I'm writing a Django app that performs various functions, including inserting, or updating new records into the database via the URL.</p> <p>So some internal application sends off a request to <code>/import/?a=1&amp;b=2&amp;c=3</code>, for example. In the view, I want to create a new object, <code>foo = Foo()</code...
9
2009-06-02T15:07:29Z
940,203
<p>If you are using this to create a model object that then gets persisted, I'd strongly recommend using a <a href="http://docs.djangoproject.com/en/1.0/topics/forms/modelforms/" rel="nofollow">ModelForm</a>. This would do what you described, in the canonical way for Django, with the addition of validation.</p> <p>To ...
1
2009-06-02T15:24:36Z
[ "python", "django" ]
How do I update an object's members using a dict?
940,089
<p>I'm writing a Django app that performs various functions, including inserting, or updating new records into the database via the URL.</p> <p>So some internal application sends off a request to <code>/import/?a=1&amp;b=2&amp;c=3</code>, for example. In the view, I want to create a new object, <code>foo = Foo()</code...
9
2009-06-02T15:07:29Z
953,807
<p>If <code>request.GET</code> is a dictionary and <code>class Foo</code> does not use <code>__slots__</code>, then this should also work:</p> <pre><code># foo is a Foo instance foo.__dict__.update(request.GET) </code></pre>
3
2009-06-05T00:51:04Z
[ "python", "django" ]
How to pass pointer to an array in Python for a wrapped C++ function
940,132
<p>I am new to C++/Python mixed language programming and do not have much idea about Python/C API. I just started using Boost.Python to wrap a C++ library for Python. I am stuck at wrapping a function that takes pointer to an array as an argument. Following (2nd ctor) is its prototype in C++.</p> <pre><code>class AAF{...
4
2009-06-02T15:13:49Z
940,782
<p>The wrapping is right (in principle) but in</p> <pre><code>AAF(10, [4, 5.5, 10], [1, 1, 2], 3); </code></pre> <p>(as the interpreter points out) you're passing to your function python's list objects, not pointers.</p> <p>In short, if your function needs only to work on python's lists you need to change your code ...
4
2009-06-02T17:22:33Z
[ "python", "arrays", "pointers", "wrapping", "boost-python" ]
Distributing Ruby/Python desktop apps
940,149
<p>Is there any way besides Shoes to develop and distribute cross-platform GUI desktop applications written in Ruby?</p> <p>I come to believe that general bugginess of _why's applications is exceptionally crippling in case of Shoes, and anything more complex than a two-button form is a pain to maintain.</p> <p>RubyGT...
10
2009-06-02T15:15:46Z
940,214
<p>The state of affairs is pretty bad. The most reliable method at present is probably to use JRuby. I know that's probably not the answer you want to hear, but, as you say, ruby2exe is unreliable, and Shoes is a long way off (and isn't even intended to be a full-scale application). Personally, I dislike forcing use...
2
2009-06-02T15:26:15Z
[ "python", "ruby", "user-interface", "desktop", "software-distribution" ]
Distributing Ruby/Python desktop apps
940,149
<p>Is there any way besides Shoes to develop and distribute cross-platform GUI desktop applications written in Ruby?</p> <p>I come to believe that general bugginess of _why's applications is exceptionally crippling in case of Shoes, and anything more complex than a two-button form is a pain to maintain.</p> <p>RubyGT...
10
2009-06-02T15:15:46Z
940,241
<p>I don't know about ruby2exe, but py2exe works perfeclty fine. Even with librairies like wxWidgets. <strong>Edit</strong>: you don't even have to ask the user to install wxWidgets, it's bundled with the app (same goes for py2app)</p> <p>I use it for my very small project <a href="http://github.com/loicwolff/notagapp...
11
2009-06-02T15:31:46Z
[ "python", "ruby", "user-interface", "desktop", "software-distribution" ]
Distributing Ruby/Python desktop apps
940,149
<p>Is there any way besides Shoes to develop and distribute cross-platform GUI desktop applications written in Ruby?</p> <p>I come to believe that general bugginess of _why's applications is exceptionally crippling in case of Shoes, and anything more complex than a two-button form is a pain to maintain.</p> <p>RubyGT...
10
2009-06-02T15:15:46Z
940,261
<p>I don't know about Ruby, but the standard for Python is <a href="http://www.py2exe.org/" rel="nofollow">py2exe</a> to create Windows binaries. For me, the cross-plattform <a href="http://www.pyinstaller.org/" rel="nofollow">pyinstaller</a> has worked well, once. For your GUI, <a href="http://wiki.python.org/moin/TkI...
6
2009-06-02T15:37:18Z
[ "python", "ruby", "user-interface", "desktop", "software-distribution" ]
Distributing Ruby/Python desktop apps
940,149
<p>Is there any way besides Shoes to develop and distribute cross-platform GUI desktop applications written in Ruby?</p> <p>I come to believe that general bugginess of _why's applications is exceptionally crippling in case of Shoes, and anything more complex than a two-button form is a pain to maintain.</p> <p>RubyGT...
10
2009-06-02T15:15:46Z
940,509
<p>Depending on how far you development is, <a href="http://shoesrb.com/" rel="nofollow">Shoes</a> is pretty good. Its basically it's own Ruby Distribution. It may be a bit hidden (in the files menu), but it allows you to package your application for all 3 platforms without having that Shoes startup screen.</p> <p>The...
1
2009-06-02T16:30:05Z
[ "python", "ruby", "user-interface", "desktop", "software-distribution" ]
Distributing Ruby/Python desktop apps
940,149
<p>Is there any way besides Shoes to develop and distribute cross-platform GUI desktop applications written in Ruby?</p> <p>I come to believe that general bugginess of _why's applications is exceptionally crippling in case of Shoes, and anything more complex than a two-button form is a pain to maintain.</p> <p>RubyGT...
10
2009-06-02T15:15:46Z
941,539
<p>For Ruby, the <a href="http://rubyforge.org/projects/ocra/">One-Click Ruby Application Builder</a> (OCRA) is emerging as the successor to <a href="http://www.erikveen.dds.nl/rubyscript2exe/">RubyScript2Exe</a>. </p> <p>Ocra works with both Ruby 1.8.6 and 1.9.1, and with wxRuby. Supports LZMA compression for relativ...
8
2009-06-02T19:48:28Z
[ "python", "ruby", "user-interface", "desktop", "software-distribution" ]
Distributing Ruby/Python desktop apps
940,149
<p>Is there any way besides Shoes to develop and distribute cross-platform GUI desktop applications written in Ruby?</p> <p>I come to believe that general bugginess of _why's applications is exceptionally crippling in case of Shoes, and anything more complex than a two-button form is a pain to maintain.</p> <p>RubyGT...
10
2009-06-02T15:15:46Z
942,712
<p>I've read about (but not used) Seattlerb's Wilson, which describes itself as a pure x86 assembler, but it doesn't sound like it'd be cross-platform or GUI.</p>
-2
2009-06-03T01:32:42Z
[ "python", "ruby", "user-interface", "desktop", "software-distribution" ]
Distributing Ruby/Python desktop apps
940,149
<p>Is there any way besides Shoes to develop and distribute cross-platform GUI desktop applications written in Ruby?</p> <p>I come to believe that general bugginess of _why's applications is exceptionally crippling in case of Shoes, and anything more complex than a two-button form is a pain to maintain.</p> <p>RubyGT...
10
2009-06-02T15:15:46Z
976,069
<p>I don't think anyone really answered his question.</p> <p>As for me, I use VB to do Shell() calls to Ocra compiled Ruby scripts. It works pretty well and allows me to create apps that run in all modern OS.</p> <p>Linux testing is done by using Wine to run and ensuring that I use a pre .NET version of VB for the .e...
0
2009-06-10T14:50:17Z
[ "python", "ruby", "user-interface", "desktop", "software-distribution" ]
Getting a list of specific index items from a list of dictionaries in python (list comprehension)
940,442
<p>I have a list of dictionaries like so:</p> <pre><code>listDict = [{'id':1,'other':2},{'id':3,'other':4},{'id':5,'other':6}] </code></pre> <p>I want a list of all the ids from the dictionaries. So, from the given list I would get the list:</p> <pre><code>[1,3,5] </code></pre> <p>It should be one line. I know I'...
1
2009-06-02T16:18:43Z
940,450
<pre><code>[i['id'] for i in listDict] </code></pre>
2
2009-06-02T16:20:59Z
[ "python" ]
Getting a list of specific index items from a list of dictionaries in python (list comprehension)
940,442
<p>I have a list of dictionaries like so:</p> <pre><code>listDict = [{'id':1,'other':2},{'id':3,'other':4},{'id':5,'other':6}] </code></pre> <p>I want a list of all the ids from the dictionaries. So, from the given list I would get the list:</p> <pre><code>[1,3,5] </code></pre> <p>It should be one line. I know I'...
1
2009-06-02T16:18:43Z
940,455
<p>[elem['id'] for elem in listDict]</p>
0
2009-06-02T16:21:57Z
[ "python" ]
Getting a list of specific index items from a list of dictionaries in python (list comprehension)
940,442
<p>I have a list of dictionaries like so:</p> <pre><code>listDict = [{'id':1,'other':2},{'id':3,'other':4},{'id':5,'other':6}] </code></pre> <p>I want a list of all the ids from the dictionaries. So, from the given list I would get the list:</p> <pre><code>[1,3,5] </code></pre> <p>It should be one line. I know I'...
1
2009-06-02T16:18:43Z
940,457
<pre><code>&gt;&gt;&gt; listDict = [{'id':1,'other':2},{'id':3,'other':4},{'id':5,'other':6}] &gt;&gt;&gt; [item["id"] for item in listDict] [1, 3, 5] </code></pre>
10
2009-06-02T16:22:07Z
[ "python" ]
Getting a list of specific index items from a list of dictionaries in python (list comprehension)
940,442
<p>I have a list of dictionaries like so:</p> <pre><code>listDict = [{'id':1,'other':2},{'id':3,'other':4},{'id':5,'other':6}] </code></pre> <p>I want a list of all the ids from the dictionaries. So, from the given list I would get the list:</p> <pre><code>[1,3,5] </code></pre> <p>It should be one line. I know I'...
1
2009-06-02T16:18:43Z
940,969
<p>For the python geeks:</p> <pre><code>import operator map(operator.itemgetter('id'), listDict) </code></pre>
1
2009-06-02T17:51:56Z
[ "python" ]
Getting a list of specific index items from a list of dictionaries in python (list comprehension)
940,442
<p>I have a list of dictionaries like so:</p> <pre><code>listDict = [{'id':1,'other':2},{'id':3,'other':4},{'id':5,'other':6}] </code></pre> <p>I want a list of all the ids from the dictionaries. So, from the given list I would get the list:</p> <pre><code>[1,3,5] </code></pre> <p>It should be one line. I know I'...
1
2009-06-02T16:18:43Z
39,280,827
<p>More conceptually pleasing and potentially faster method depending on how big your data is.</p> <p>Using pandas package to simply refer to keys as column headers and group values using the same key:</p> <pre><code>import pandas as pd listDict = [{'id':1,'other':2},{'id':3,'other':4},{'id':5,'other':6}] df = pd.Dat...
2
2016-09-01T21:03:00Z
[ "python" ]
Python 2.6 subprocess.call() appears to be invoking setgid behavior triggering Perl's taint checks. How can I resolve?
940,552
<p>I've got some strange behavioral differences between Python's subprocess.call() and os.system() that appears to be related to setgid. The difference is causing Perl's taint checks to be invoked when subprocess.call() is used, which creates problems because I do not have the ability to modify all the Perl scripts tha...
2
2009-06-02T16:36:22Z
940,740
<p>Doesn't happen for me:</p> <pre><code>$ python proc.py Python calling os.system perl subprocess perl subprocess done Python done calling os.system Python calling subprocess.call perl subprocess perl subprocess done Python done calling subprocess.call $ python --version Python 2.5.2 $ perl --version This is perl, ...
0
2009-06-02T17:13:47Z
[ "python", "perl", "subprocess" ]
Python 2.6 subprocess.call() appears to be invoking setgid behavior triggering Perl's taint checks. How can I resolve?
940,552
<p>I've got some strange behavioral differences between Python's subprocess.call() and os.system() that appears to be related to setgid. The difference is causing Perl's taint checks to be invoked when subprocess.call() is used, which creates problems because I do not have the ability to modify all the Perl scripts tha...
2
2009-06-02T16:36:22Z
941,219
<p>I think your error is with perl, or the way it's interacting with your environment. Your backtick process is calling setgid for some reason. The only way I can replicate this, is to setgid on /usr/bin/perl (-rwxr-sr-x). [EDIT] Having python setgid does this too!</p> <p>[EDIT] I forgot that os.system <em>is</em> wor...
2
2009-06-02T18:45:03Z
[ "python", "perl", "subprocess" ]
PyQt sending parameter to slot when connecting to a signal
940,555
<p>I have a taskbar menu that when clicked is connected to a slot that gets the trigger event. Now the problem is that I want to know which menu item was clicked, but I don't know how to send that information to the function connected to. Here is the used to connect the action to the function:</p> <pre><code>QtCore.QO...
21
2009-06-02T16:38:00Z
940,655
<p>Use a <code>lambda</code></p> <p>Here's an example from the <a href="http://www.qtrac.eu/pyqtbook.html">PyQt book</a>:</p> <pre><code>self.connect(button3, SIGNAL("clicked()"), lambda who="Three": self.anyButton(who)) </code></pre> <p>By the way, you can also use <code>functools.partial</code>, but I find the...
33
2009-06-02T16:52:11Z
[ "python", "qt4", "pyqt" ]
PyQt sending parameter to slot when connecting to a signal
940,555
<p>I have a taskbar menu that when clicked is connected to a slot that gets the trigger event. Now the problem is that I want to know which menu item was clicked, but I don't know how to send that information to the function connected to. Here is the used to connect the action to the function:</p> <pre><code>QtCore.QO...
21
2009-06-02T16:38:00Z
940,658
<p>In general, you should have each menu item connected to a different slot, and have each slot handle the functionality only for it's own menu item. For example, if you have menu items like "save", "close", "open", you ought to make a separate slot for each, not try to have a single slot with a case statement in it.<...
0
2009-06-02T16:52:40Z
[ "python", "qt4", "pyqt" ]
PyQt sending parameter to slot when connecting to a signal
940,555
<p>I have a taskbar menu that when clicked is connected to a slot that gets the trigger event. Now the problem is that I want to know which menu item was clicked, but I don't know how to send that information to the function connected to. Here is the used to connect the action to the function:</p> <pre><code>QtCore.QO...
21
2009-06-02T16:38:00Z
19,752,158
<p>As already mentioned <a href="http://stackoverflow.com/questions/8824311">here</a> you can use the lambda function to pass extra arguments to the method you want to execute.</p> <p>In this example you can pass a string obj to the function AddControl() invoked when the button is pressed.</p> <pre><code># Create the...
6
2013-11-03T10:56:42Z
[ "python", "qt4", "pyqt" ]
PyQt sending parameter to slot when connecting to a signal
940,555
<p>I have a taskbar menu that when clicked is connected to a slot that gets the trigger event. Now the problem is that I want to know which menu item was clicked, but I don't know how to send that information to the function connected to. Here is the used to connect the action to the function:</p> <pre><code>QtCore.QO...
21
2009-06-02T16:38:00Z
34,001,792
<p>use functools.partial</p> <p>otherwise you will find you cannot pass arguments dynamically when script is running, if you use lambda.</p>
3
2015-11-30T15:13:04Z
[ "python", "qt4", "pyqt" ]
Python Extension Returned Object Etiquette
940,563
<p>I am writing a python extension to provide access to Solaris kstat data ( in the same spirit as the shipping perl library Sun::Solaris::Kstat ) and I have a question about conditionally returning a list or a single object. The python use case would look something like:</p> <pre> cpu_stats = cKstats.lookup(modu...
1
2009-06-02T16:39:04Z
940,741
<p>"My question is it poor form to return a single object when there is only one match, and a list when there are many?"</p> <p>It's poor form to return inconsistent types.</p> <p>Return a consistent type: List of kstat.</p> <p>Most Pythonistas don't like using <code>type(result)</code> to determine if it's a kstat...
7
2009-06-02T17:13:49Z
[ "python", "python-c-api" ]
How does Spring for Python compare with Spring for Java
940,564
<p>I am an avid fan of the Spring framework for Java (by Rod Johnson). I am learning Python and was excited to find about Spring for Python. I would be interested in hearing the community's views on the comparison of these two flavours of Spring. How well does it fit Python's paradigms etc.</p>
6
2009-06-02T16:39:13Z
940,804
<p>Dependency injection frameworks are not nearly as useful in a dynamically typed language. See for example the presentation <a href="http://onestepback.org/articles/depinj/index.html">Dependency Injection: Vitally important or totally irrelevant?</a> In Java the flexibility provided by a dependency injection framewor...
20
2009-06-02T17:26:25Z
[ "java", "python", "spring" ]
How does Spring for Python compare with Spring for Java
940,564
<p>I am an avid fan of the Spring framework for Java (by Rod Johnson). I am learning Python and was excited to find about Spring for Python. I would be interested in hearing the community's views on the comparison of these two flavours of Spring. How well does it fit Python's paradigms etc.</p>
6
2009-06-02T16:39:13Z
945,831
<p>DISCLOSURE: I am the project lead for Spring Python, so you can consider my opinion biased.</p> <p>I find that several of the options provided by Spring Python are useful including: <a href="http://blog.springpython.webfactional.com/2009/03/23/the-case-for-aop-in-python/">aspect oriented programming</a>, <a href="h...
11
2009-06-03T16:54:44Z
[ "java", "python", "spring" ]
How does Spring for Python compare with Spring for Java
940,564
<p>I am an avid fan of the Spring framework for Java (by Rod Johnson). I am learning Python and was excited to find about Spring for Python. I would be interested in hearing the community's views on the comparison of these two flavours of Spring. How well does it fit Python's paradigms etc.</p>
6
2009-06-02T16:39:13Z
10,500,205
<p>Good stuff. I have used Spring Java, Spring Dot Net and now starting with Spring Python. Python has always been pretty easy to use for programmers; I think, especially since it's easy to write. I found Spring Dot Net to be a bit confusing, but both Spring Java and Python seem to be similar. I'm sure they have th...
0
2012-05-08T14:04:41Z
[ "java", "python", "spring" ]
Using list comprehensions and exceptions?
940,783
<p>Okay lets say I have a list, and I want to check if that list exists within another list. I can do that doing this:</p> <pre><code>all(value in some_map for value in required_values) </code></pre> <p>Which works fine, but lets say I want to the raise an exception when a required value is missing, with the value th...
3
2009-06-02T17:22:34Z
940,793
<p>If you don't want to consider duplicates and the values are hashable, use sets. They're easier, faster, and can extract "all" elements missing in a single operation:</p> <pre><code>required_values = set('abc') # store this as a set from the beginning values = set('ab') missing = required_values - values if missing:...
2
2009-06-02T17:24:05Z
[ "python", "list", "list-comprehension" ]
Using list comprehensions and exceptions?
940,783
<p>Okay lets say I have a list, and I want to check if that list exists within another list. I can do that doing this:</p> <pre><code>all(value in some_map for value in required_values) </code></pre> <p>Which works fine, but lets say I want to the raise an exception when a required value is missing, with the value th...
3
2009-06-02T17:22:34Z
940,809
<p>You can't use raise in a list comprehension. You can check for yourself by looking at <a href="http://docs.python.org/3.0/reference/expressions.html#comprehensions" rel="nofollow">the grammar in the Python Language Reference</a>.</p> <p>You can however, invoke a function which raises an exception for you.</p>
2
2009-06-02T17:27:55Z
[ "python", "list", "list-comprehension" ]
Using list comprehensions and exceptions?
940,783
<p>Okay lets say I have a list, and I want to check if that list exists within another list. I can do that doing this:</p> <pre><code>all(value in some_map for value in required_values) </code></pre> <p>Which works fine, but lets say I want to the raise an exception when a required value is missing, with the value th...
3
2009-06-02T17:22:34Z
940,834
<blockquote> <p>lets say i want to the raise an exception when a required value is missing, with the value that it is missing. How can i do that using list comprehension?</p> </blockquote> <p>List comprehensions are a syntactically concise way to create a list based on some existing list—they're <em>not</em> a gen...
13
2009-06-02T17:33:13Z
[ "python", "list", "list-comprehension" ]
Using list comprehensions and exceptions?
940,783
<p>Okay lets say I have a list, and I want to check if that list exists within another list. I can do that doing this:</p> <pre><code>all(value in some_map for value in required_values) </code></pre> <p>Which works fine, but lets say I want to the raise an exception when a required value is missing, with the value th...
3
2009-06-02T17:22:34Z
940,979
<p>While I think using sets (like nosklo's example) is better, you could do something simple like this:</p> <pre><code>def has_required(some_map, value): if not value in some_map: raise RequiredException('Missing required value: %s' % value) all(has_required(some_map, value) for value in required_values) </code...
-2
2009-06-02T17:54:05Z
[ "python", "list", "list-comprehension" ]
Using list comprehensions and exceptions?
940,783
<p>Okay lets say I have a list, and I want to check if that list exists within another list. I can do that doing this:</p> <pre><code>all(value in some_map for value in required_values) </code></pre> <p>Which works fine, but lets say I want to the raise an exception when a required value is missing, with the value th...
3
2009-06-02T17:22:34Z
941,057
<p>Another (ugly) possibility would be the <code>error_on_false</code> function:</p> <pre><code>def error_on_false(value) if value: return value else: raise Exception('Wrong value: %r' % value) if all(error_on_false(value in some_map) for value in required_values): continue_code() do_s...
0
2009-06-02T18:11:28Z
[ "python", "list", "list-comprehension" ]
Passing data to mod_wsgi
940,816
<p>In mod_wsgi I send the headers by running the function start_response(), but all the page content is passed by yield/return. Is there a way to pass the page content in a similar fashion as start_response()? Using the return.yield statement is very restrictive when it comes to working with chunked data.</p> <p>E.g.<...
0
2009-06-02T17:29:07Z
940,827
<p>No; But I don't think it is restrictive. Maybe you want to paste an example code where you describe your restriction and we can help.</p> <p>To work with chunk data you just <code>yield</code> the chunks:</p> <pre><code>def application(environ, start_response): start_response('200 OK', [('Content-type', 'text/...
2
2009-06-02T17:31:52Z
[ "python", "mod-wsgi", "wsgi" ]
Passing data to mod_wsgi
940,816
<p>In mod_wsgi I send the headers by running the function start_response(), but all the page content is passed by yield/return. Is there a way to pass the page content in a similar fashion as start_response()? Using the return.yield statement is very restrictive when it comes to working with chunked data.</p> <p>E.g.<...
0
2009-06-02T17:29:07Z
941,090
<p>It is <em>possible</em> for your application to "push" data to the WSGI server:</p> <blockquote> <p>Some existing application framework APIs support unbuffered output in a different manner than WSGI. Specifically, they provide a "write" function or method of some kind to write an unbuffered block of data, or else...
1
2009-06-02T18:19:46Z
[ "python", "mod-wsgi", "wsgi" ]
Passing data to mod_wsgi
940,816
<p>In mod_wsgi I send the headers by running the function start_response(), but all the page content is passed by yield/return. Is there a way to pass the page content in a similar fashion as start_response()? Using the return.yield statement is very restrictive when it comes to working with chunked data.</p> <p>E.g.<...
0
2009-06-02T17:29:07Z
1,041,588
<p>If you don't want to change your WSGI application itself to partially buffer response data before sending it, then implement a WSGI middleware that wraps your WSGI application and which performs that task.</p>
1
2009-06-25T00:13:09Z
[ "python", "mod-wsgi", "wsgi" ]
Regular expression syntax for "match nothing"?
940,822
<p>I have a python template engine that heavily uses regexp. It uses concatenation like:</p> <pre><code>re.compile( regexp1 + "|" + regexp2 + "*|" + regexp3 + "+" ) </code></pre> <p>I can modify individual substrings (regexp1, regexp2 etc).</p> <p>Is there any small and light expression that matches nothing, which I...
42
2009-06-02T17:30:50Z
940,840
<p>This shouldn't match anything:</p> <pre><code>re.compile('$^') </code></pre> <p>So if you replace regexp1, regexp2 and regexp3 with '$^' it will be impossible to find a match. Unless you are using the multi line mode.</p> <p><hr /></p> <p>After some tests I found a better solution</p> <pre><code>re.compile('a^'...
59
2009-06-02T17:34:15Z
[ "python", "regex" ]
Regular expression syntax for "match nothing"?
940,822
<p>I have a python template engine that heavily uses regexp. It uses concatenation like:</p> <pre><code>re.compile( regexp1 + "|" + regexp2 + "*|" + regexp3 + "+" ) </code></pre> <p>I can modify individual substrings (regexp1, regexp2 etc).</p> <p>Is there any small and light expression that matches nothing, which I...
42
2009-06-02T17:30:50Z
940,846
<p>Maybe <code>'.{0}'</code>?</p>
2
2009-06-02T17:34:58Z
[ "python", "regex" ]
Regular expression syntax for "match nothing"?
940,822
<p>I have a python template engine that heavily uses regexp. It uses concatenation like:</p> <pre><code>re.compile( regexp1 + "|" + regexp2 + "*|" + regexp3 + "+" ) </code></pre> <p>I can modify individual substrings (regexp1, regexp2 etc).</p> <p>Is there any small and light expression that matches nothing, which I...
42
2009-06-02T17:30:50Z
940,856
<pre><code>"()" </code></pre> <p>matches nothing and nothing only.</p>
2
2009-06-02T17:36:07Z
[ "python", "regex" ]
Regular expression syntax for "match nothing"?
940,822
<p>I have a python template engine that heavily uses regexp. It uses concatenation like:</p> <pre><code>re.compile( regexp1 + "|" + regexp2 + "*|" + regexp3 + "+" ) </code></pre> <p>I can modify individual substrings (regexp1, regexp2 etc).</p> <p>Is there any small and light expression that matches nothing, which I...
42
2009-06-02T17:30:50Z
940,934
<p>To match an empty string - even in multiline mode - you can use <code>\A\Z</code>, so:</p> <pre><code>re.compile('\A\Z|\A\Z*|\A\Z+') </code></pre> <p>The difference is that <code>\A</code> and <code>\Z</code> are start and end of <em>string</em>, whilst <code>^</code> and <code>$</code> these can match start/end o...
14
2009-06-02T17:45:58Z
[ "python", "regex" ]
Regular expression syntax for "match nothing"?
940,822
<p>I have a python template engine that heavily uses regexp. It uses concatenation like:</p> <pre><code>re.compile( regexp1 + "|" + regexp2 + "*|" + regexp3 + "+" ) </code></pre> <p>I can modify individual substrings (regexp1, regexp2 etc).</p> <p>Is there any small and light expression that matches nothing, which I...
42
2009-06-02T17:30:50Z
941,007
<p>You could use<br /> <code>\z..</code><br /> This is the absolute end of string, followed by two of anything</p> <p>If <code>+</code> or <code>*</code> is tacked on the end this still works refusing to match anything </p>
1
2009-06-02T17:58:27Z
[ "python", "regex" ]
Regular expression syntax for "match nothing"?
940,822
<p>I have a python template engine that heavily uses regexp. It uses concatenation like:</p> <pre><code>re.compile( regexp1 + "|" + regexp2 + "*|" + regexp3 + "+" ) </code></pre> <p>I can modify individual substrings (regexp1, regexp2 etc).</p> <p>Is there any small and light expression that matches nothing, which I...
42
2009-06-02T17:30:50Z
942,104
<p>Or, use some list comprehension to remove the useless regexp entries and join to put them all together. Something like:</p> <pre><code>re.compile('|'.join([x for x in [regexp1, regexp2, ...] if x != None])) </code></pre> <p>Be sure to add some comments next to that line of code though :-)</p>
0
2009-06-02T21:56:16Z
[ "python", "regex" ]
Regular expression syntax for "match nothing"?
940,822
<p>I have a python template engine that heavily uses regexp. It uses concatenation like:</p> <pre><code>re.compile( regexp1 + "|" + regexp2 + "*|" + regexp3 + "+" ) </code></pre> <p>I can modify individual substrings (regexp1, regexp2 etc).</p> <p>Is there any small and light expression that matches nothing, which I...
42
2009-06-02T17:30:50Z
942,122
<p><code>(?!)</code> should always fail to match. It is the zero-width negative look-ahead. If what is in the parentheses matches then the whole match fails. Given that it has nothing in it, it will fail the match for anything (including nothing).</p>
18
2009-06-02T22:02:15Z
[ "python", "regex" ]
Is it reasonable to integrate python with c for performance?
940,982
<p>I like to use python for almost everything and always had clear in my mind that if for some reason I was to find a bottleneck in my python code(due to python's limitations), I could always use a C script integrated to my code.</p> <p>But, as I started to read a <a href="http://www.suttoncourtenay.org.uk/duncan/accu...
2
2009-06-02T17:54:54Z
940,997
<blockquote> <p>* Optimising inner loops in code</p> </blockquote> <p>Isn't that about performance ?</p>
8
2009-06-02T17:57:11Z
[ "python", "c", "performance" ]
Is it reasonable to integrate python with c for performance?
940,982
<p>I like to use python for almost everything and always had clear in my mind that if for some reason I was to find a bottleneck in my python code(due to python's limitations), I could always use a C script integrated to my code.</p> <p>But, as I started to read a <a href="http://www.suttoncourtenay.org.uk/duncan/accu...
2
2009-06-02T17:54:54Z
941,020
<p>Performance is a broad topic so you should be more specific. If the bottleneck in your program involves a lot of networking then rewriting it in C/C++ probably won't make a difference since it's the network calls taking up time, not your code. You would be better off rewriting the slow section of your program to use...
6
2009-06-02T18:02:36Z
[ "python", "c", "performance" ]
Is it reasonable to integrate python with c for performance?
940,982
<p>I like to use python for almost everything and always had clear in my mind that if for some reason I was to find a bottleneck in my python code(due to python's limitations), I could always use a C script integrated to my code.</p> <p>But, as I started to read a <a href="http://www.suttoncourtenay.org.uk/duncan/accu...
2
2009-06-02T17:54:54Z
941,036
<p>In my experience it is rarely necessary to optimize using C. I prefer to identify bottlenecks and improve algorithms in those areas completely in Python. Using hash tables, caching, and generally re-organizing your data structures to suit future needs has amazing potential for speeding up your program. As your progr...
9
2009-06-02T18:06:23Z
[ "python", "c", "performance" ]
Is it reasonable to integrate python with c for performance?
940,982
<p>I like to use python for almost everything and always had clear in my mind that if for some reason I was to find a bottleneck in my python code(due to python's limitations), I could always use a C script integrated to my code.</p> <p>But, as I started to read a <a href="http://www.suttoncourtenay.org.uk/duncan/accu...
2
2009-06-02T17:54:54Z
941,041
<p>You will gain a large performance boost using C from Python (assuming your code is well written, etc) because Python is interpreted at run time, whereas C is compiled beforehand. This will speed up things quite a bit because with C, your code is simply running, whereas with Python, the Python interpreter must figure...
0
2009-06-02T18:07:35Z
[ "python", "c", "performance" ]
Is it reasonable to integrate python with c for performance?
940,982
<p>I like to use python for almost everything and always had clear in my mind that if for some reason I was to find a bottleneck in my python code(due to python's limitations), I could always use a C script integrated to my code.</p> <p>But, as I started to read a <a href="http://www.suttoncourtenay.org.uk/duncan/accu...
2
2009-06-02T17:54:54Z
941,079
<p>C can definitely speed up processor bound tasks. Integrating is even easier now, with the ctypes library, or you could go for any of the other methods you mention.</p> <p>I feel mercurial has done a good job with the integration if you want to look at their code as an example. The compute intensive tasks are in C, ...
2
2009-06-02T18:17:51Z
[ "python", "c", "performance" ]
Is it reasonable to integrate python with c for performance?
940,982
<p>I like to use python for almost everything and always had clear in my mind that if for some reason I was to find a bottleneck in my python code(due to python's limitations), I could always use a C script integrated to my code.</p> <p>But, as I started to read a <a href="http://www.suttoncourtenay.org.uk/duncan/accu...
2
2009-06-02T17:54:54Z
941,373
<p>I've been told for the calculating portion use C for the scripting use python. So yes you can integrate both. C is capable of faster calculations than that of python</p>
0
2009-06-02T19:12:54Z
[ "python", "c", "performance" ]
Is it reasonable to integrate python with c for performance?
940,982
<p>I like to use python for almost everything and always had clear in my mind that if for some reason I was to find a bottleneck in my python code(due to python's limitations), I could always use a C script integrated to my code.</p> <p>But, as I started to read a <a href="http://www.suttoncourtenay.org.uk/duncan/accu...
2
2009-06-02T17:54:54Z
941,727
<p>The C extensions API is notoriously hard to work with, but there are a number of other ways to integrate C code. </p> <p>For some more usable alternatives see <a href="http://www.scipy.org/PerformancePython" rel="nofollow">http://www.scipy.org/PerformancePython</a>, in particular the section about using Weave for e...
3
2009-06-02T20:28:29Z
[ "python", "c", "performance" ]
Save an html page + change all links to point to the right place
941,235
<p>You probably know that IE has this thing where you can save a web page, and it will automatically download the html file and all he image/css/js files that the html file uses. </p> <p>Now there is one problem with this- the links in the html file are not changed. So if I download the html page of example.com, whic...
0
2009-06-02T18:47:55Z
941,424
<p>Since you're mentioning IE specifically, I'm not sure if this is gonna be of any use to you, but on linux the easiest way to completely mirror a website is with the wget command.</p> <pre><code>wget --mirror --convert-links -w 1 http://www.example.com </code></pre> <p>Run man wget if you need more options.</p>
8
2009-06-02T19:22:33Z
[ "javascript", "python", "html", "css", "screen-scraping" ]
Save an html page + change all links to point to the right place
941,235
<p>You probably know that IE has this thing where you can save a web page, and it will automatically download the html file and all he image/css/js files that the html file uses. </p> <p>Now there is one problem with this- the links in the html file are not changed. So if I download the html page of example.com, whic...
0
2009-06-02T18:47:55Z
34,292,231
<p>I've written a tool to save web pages into a single standalone html file, and the links are pointed to the same place as it should be.</p> <p><a href="https://github.com/zTrix/webpage2html" rel="nofollow">https://github.com/zTrix/webpage2html</a></p>
0
2015-12-15T14:50:43Z
[ "javascript", "python", "html", "css", "screen-scraping" ]
Validating a slug in Django
941,270
<p>I'm guessing this is going to involve regexp or something, but I'll give it a shot. At the minute, a user can break a website by typing something similar to <code>£$(*£$(£@$&amp;£($</code> in the title field, which is converted into a slug using Django <code>slugify</code>.</p> <p>Because none of these charact...
6
2009-06-02T18:54:25Z
941,297
<p>This question is half a decade old so in updating my question I should explain that I'm at least nodding to the past where some features might not have existed.</p> <p>The easiest way to handle slugs in forms these days is to just use <code>django.models.SlugField</code>. It will validate itself for you and imply t...
10
2009-06-02T18:59:15Z
[ "python", "django", "validation", "slug" ]
Validating a slug in Django
941,270
<p>I'm guessing this is going to involve regexp or something, but I'll give it a shot. At the minute, a user can break a website by typing something similar to <code>£$(*£$(£@$&amp;£($</code> in the title field, which is converted into a slug using Django <code>slugify</code>.</p> <p>Because none of these charact...
6
2009-06-02T18:54:25Z
6,466,286
<p>SLUG_REGEX = re.compile('^[-\w]+$')</p>
12
2011-06-24T10:03:14Z
[ "python", "django", "validation", "slug" ]
using "range" in a google app engine template for - loop
941,282
<p>i've got an appengine project and in my template i want to do something like </p> <pre><code>{% for i in range(0, len(somelist)) %} {{ somelist[i] }} {{ otherlist[i] }} {% endfor %} </code></pre> <p>i've tried using 'forloop.counter' to access list items too, but that didn't work out either. any suggestions?</p...
0
2009-06-02T18:57:17Z
941,367
<p>What you might want to do instead is change the data that you're passing in to the template so that somelist and otherlist are zipped together into a single list:</p> <pre><code>combined_list = zip(somelist, otherlist) ... {% for item in combined_list %} {{ item.0 }} {{ item.1 }} {% endfor %} </code></pre>
6
2009-06-02T19:12:02Z
[ "python", "django-templates" ]
Any python OpenID server available?
941,296
<p>I'd like to host my own OpenID provider. Is there anything available in Python?</p>
12
2009-06-02T18:59:07Z
941,311
<p><a href="http://openidenabled.com/python-openid/">You are weak with the Google.</a></p> <p>(Edit: That's a link to <a href="http://openidenabled.com/">OpenID-Enabled.com</a>. There are also PHP and Ruby versions available there.)</p>
14
2009-06-02T19:01:47Z
[ "python", "openid" ]
Any python OpenID server available?
941,296
<p>I'd like to host my own OpenID provider. Is there anything available in Python?</p>
12
2009-06-02T18:59:07Z
1,513,138
<p><a href="http://yangman.ca/poit/">poit</a> is a standalone, single-user OpenID server implemented in Python, using python-openid. (It's a project I started)</p>
7
2009-10-03T07:57:29Z
[ "python", "openid" ]
wxPython won't close Frame with a parent who is a window handle
941,470
<p>I have a program in Python that gets a window handle via COM from another program (think of the Python program as an addin) I set this window to be the main Python frame's parent so that if the other program minimizes, the python frame will too. The problem is when I go to exit, and try to close or destroy the main...
1
2009-06-02T19:33:30Z
941,655
<p>I wonder if your <code>Close</code> call may be hanging in the close-handler. Have you tried calling <code>Destroy</code> instead? If that doesn't help, then the only solution would seem to be "reparenting" or "detaching" your frame -- I don't see a way to do that in <code>wx</code>, but maybe you could drop down t...
1
2009-06-02T20:15:58Z
[ "python", "windows", "wxpython", "handle" ]
wxPython won't close Frame with a parent who is a window handle
941,470
<p>I have a program in Python that gets a window handle via COM from another program (think of the Python program as an addin) I set this window to be the main Python frame's parent so that if the other program minimizes, the python frame will too. The problem is when I go to exit, and try to close or destroy the main...
1
2009-06-02T19:33:30Z
952,990
<p>If reparenting is all you need, you can try <code>frame.Reparent(None)</code> before <code>frame.Close()</code></p>
0
2009-06-04T20:46:21Z
[ "python", "windows", "wxpython", "handle" ]
wxPython won't close Frame with a parent who is a window handle
941,470
<p>I have a program in Python that gets a window handle via COM from another program (think of the Python program as an addin) I set this window to be the main Python frame's parent so that if the other program minimizes, the python frame will too. The problem is when I go to exit, and try to close or destroy the main...
1
2009-06-02T19:33:30Z
1,711,471
<p>My resolution to this is a little bit hacked, and admittedly not the most elegant solution that I've ever come up with - but it works rather effectively...</p> <p>Basically my steps are to start a thread that polls to see whether the window handle is existent or not. While it's still existent, do nothing. If it n...
0
2009-11-10T21:48:13Z
[ "python", "windows", "wxpython", "handle" ]
How to construct a web file browser?
941,638
<p>Goal: simple browser app, for navigating files on a web server, in a tree view.</p> <p>Background: Building a web site as a learning experience, w/ Apache, mod_python, Python code. (No mod_wsgi yet.)</p> <p>What tools should I learn to write the browser tree? I see JavaScript, Ajax, neither of which I know. L...
2
2009-06-02T20:11:52Z
941,652
<p>First, switch to mod_wsgi.</p> <p>Second, write a hello world in Python using mod_wsgi.</p> <p>Third, change your hello world to show the results of <code>os.listdir()</code>.</p> <p>I think you're approximately done.</p> <p>As you mess with this, you'll realize that transforming the content you have (informatio...
10
2009-06-02T20:14:50Z
[ "javascript", "python", "html", "web-applications" ]
How to construct a web file browser?
941,638
<p>Goal: simple browser app, for navigating files on a web server, in a tree view.</p> <p>Background: Building a web site as a learning experience, w/ Apache, mod_python, Python code. (No mod_wsgi yet.)</p> <p>What tools should I learn to write the browser tree? I see JavaScript, Ajax, neither of which I know. L...
2
2009-06-02T20:11:52Z
941,664
<p>If you want to make interactive browser, you have to learn JS and ajax. </p> <p>If you want to build only browser based on links, python would be enough.</p>
1
2009-06-02T20:17:50Z
[ "javascript", "python", "html", "web-applications" ]
How to construct a web file browser?
941,638
<p>Goal: simple browser app, for navigating files on a web server, in a tree view.</p> <p>Background: Building a web site as a learning experience, w/ Apache, mod_python, Python code. (No mod_wsgi yet.)</p> <p>What tools should I learn to write the browser tree? I see JavaScript, Ajax, neither of which I know. L...
2
2009-06-02T20:11:52Z
942,293
<p>The "totally cheesy" way:</p> <pre><code>python -m SimpleHTTPServer </code></pre> <p>This will serve up the files in the current directory at <a href="http://localhost:8000/" rel="nofollow">http://localhost:8000/</a></p>
1
2009-06-02T22:43:50Z
[ "javascript", "python", "html", "web-applications" ]
How to construct a web file browser?
941,638
<p>Goal: simple browser app, for navigating files on a web server, in a tree view.</p> <p>Background: Building a web site as a learning experience, w/ Apache, mod_python, Python code. (No mod_wsgi yet.)</p> <p>What tools should I learn to write the browser tree? I see JavaScript, Ajax, neither of which I know. L...
2
2009-06-02T20:11:52Z
943,612
<p>set "Indexes" option to the directory in the apache config.</p> <p>To learn how to build webapps in python, learn django.</p>
0
2009-06-03T08:18:36Z
[ "javascript", "python", "html", "web-applications" ]
Django 1.0, using default password reset
942,148
<p>I'm trying to use the password reset setup that comes with Django, but the documentation is not very good for it. I'm using Django 1.0 and I keep getting this error:</p> <pre><code>Caught an exception while rendering: Reverse for 'mysite.django.contrib.auth.views.password_reset_confirm' with arguments '()' and key...
6
2009-06-02T22:09:28Z
942,169
<p>This is a problem I figured out myself not 10 minutes ago. The solution is to add the post_change_redirect value to the dictionary of arguments you are passing to the password_reset view.</p> <p>So this is what mine now look like:</p> <pre><code>(r'^/password/$', password_change, {'template_name': 'testing/passwor...
0
2009-06-02T22:15:04Z
[ "python", "django" ]
Django 1.0, using default password reset
942,148
<p>I'm trying to use the password reset setup that comes with Django, but the documentation is not very good for it. I'm using Django 1.0 and I keep getting this error:</p> <pre><code>Caught an exception while rendering: Reverse for 'mysite.django.contrib.auth.views.password_reset_confirm' with arguments '()' and key...
6
2009-06-02T22:09:28Z
944,440
<p><strong>Edit</strong>: I used your example, and had to change to not use keyword parameters.</p> <pre><code>{% url django.contrib.auth.views.password_reset_confirm uid, token %} </code></pre> <p>Named parameters do work, as long as both uid and token are defined. If either are not defined or blank I get the same ...
3
2009-06-03T12:26:55Z
[ "python", "django" ]
Django 1.0, using default password reset
942,148
<p>I'm trying to use the password reset setup that comes with Django, but the documentation is not very good for it. I'm using Django 1.0 and I keep getting this error:</p> <pre><code>Caught an exception while rendering: Reverse for 'mysite.django.contrib.auth.views.password_reset_confirm' with arguments '()' and key...
6
2009-06-02T22:09:28Z
945,160
<p>Just wanted to post the solution I came up with. The problem was in this line:</p> <pre><code>{% url django.contrib.auth.views.password_reset_confirm uidb36=uid, token=token %} </code></pre> <p>I'm not really a 100% why either, so I just hard coded the url like this:</p> <pre><code>http://mysite.com/accounts/res...
2
2009-06-03T14:38:23Z
[ "python", "django" ]
Django 1.0, using default password reset
942,148
<p>I'm trying to use the password reset setup that comes with Django, but the documentation is not very good for it. I'm using Django 1.0 and I keep getting this error:</p> <pre><code>Caught an exception while rendering: Reverse for 'mysite.django.contrib.auth.views.password_reset_confirm' with arguments '()' and key...
6
2009-06-02T22:09:28Z
6,640,223
<p>I've struggled with this for over an hour trying everything on this page and every other page on the internet. Finally to solve the problem in my case i had to delete </p> <pre><code>{% load url from future %} </code></pre> <p>from the top of my password_reset_email.html template.</p> <p>Also note, "uidb36=uid" i...
2
2011-07-10T09:13:00Z
[ "python", "django" ]
Efficient python code for printing the product of divisors of a number
942,198
<p>I am trying to solve a problem involving printing the product of all divisors of a given number. The number of test cases is a number 1 &lt;= t &lt;= 300000 , and the number itself can range from 1 &lt;= n &lt;= 500000</p> <p>I wrote the following code, but it always exceeds the time limit of 2 seconds. Are there a...
3
2009-06-02T22:20:03Z
942,306
<p>You could eliminate the if statement in the loop by only looping to less than the square root, and check for square root integer-ness outside the loop. <p> It is a rather strange question you pose. I have a hard time imagine a use for it, other than it possibly being an assignment in a course. My first thought was...
1
2009-06-02T22:48:32Z
[ "python", "math" ]
Efficient python code for printing the product of divisors of a number
942,198
<p>I am trying to solve a problem involving printing the product of all divisors of a given number. The number of test cases is a number 1 &lt;= t &lt;= 300000 , and the number itself can range from 1 &lt;= n &lt;= 500000</p> <p>I wrote the following code, but it always exceeds the time limit of 2 seconds. Are there a...
3
2009-06-02T22:20:03Z
942,784
<p>You need to clarify by what you mean by "product of divisors." The code posted in the question doesn't work for any definition yet. This sounds like a homework question. If it is, then perhaps your instructor was expecting you to think outside the code to meet the time goals.</p> <p>If you mean the product of uniqu...
6
2009-06-03T02:19:42Z
[ "python", "math" ]
Efficient python code for printing the product of divisors of a number
942,198
<p>I am trying to solve a problem involving printing the product of all divisors of a given number. The number of test cases is a number 1 &lt;= t &lt;= 300000 , and the number itself can range from 1 &lt;= n &lt;= 500000</p> <p>I wrote the following code, but it always exceeds the time limit of 2 seconds. Are there a...
3
2009-06-02T22:20:03Z
951,395
<p>Okay, I think this is close to the optimal algorithm. It produces the product_of_divisors for each number in range(500000).</p> <pre><code>import math def number_of_divisors(maxval=500001): """ Example: the number of divisors of 12 is 6: 1, 2, 3, 4, 6, 12. Given a prime factoring of n, the number of ...
1
2009-06-04T15:47:39Z
[ "python", "math" ]
Help me to port this NetHack function to Python please!
942,328
<p>I am trying to write a Python function which returns the same moon phase value as in the game NetHack. This is found in <a href="http://nethack.wikia.com/wiki/Source:Hacklib.c#phase%5Fof%5Fthe%5Fmoon" rel="nofollow">hacklib.c</a>.</p> <p>I have tried to simply copy the corresponding function from the NetHack code b...
9
2009-06-02T22:53:55Z
942,456
<p><strong>Edit:</strong> Turns out both of the "problems" I spotted here were based on a misunderstanding of the <code>tm</code> struct. I'll leave the answer intact for the sake of the discussion in the comments, but save your votes for someone who might actually be correct. ;-)</p> <p><hr /></p> <p>Caveat: I'm no...
3
2009-06-02T23:44:57Z
[ "python", "c", "time", "porting", "nethack" ]
Help me to port this NetHack function to Python please!
942,328
<p>I am trying to write a Python function which returns the same moon phase value as in the game NetHack. This is found in <a href="http://nethack.wikia.com/wiki/Source:Hacklib.c#phase%5Fof%5Fthe%5Fmoon" rel="nofollow">hacklib.c</a>.</p> <p>I have tried to simply copy the corresponding function from the NetHack code b...
9
2009-06-02T22:53:55Z
942,559
<p>Curiously, when I compile and run the nethack example I get "2" as the answer ("First Quarter" which is the same as your port)</p> <pre><code>#include &lt;time.h&gt; static struct tm * getlt() { time_t date; (void) time(&amp;date); return(localtime(&amp;date)); } /* * moon period = 29.5305...
1
2009-06-03T00:27:40Z
[ "python", "c", "time", "porting", "nethack" ]
Help me to port this NetHack function to Python please!
942,328
<p>I am trying to write a Python function which returns the same moon phase value as in the game NetHack. This is found in <a href="http://nethack.wikia.com/wiki/Source:Hacklib.c#phase%5Fof%5Fthe%5Fmoon" rel="nofollow">hacklib.c</a>.</p> <p>I have tried to simply copy the corresponding function from the NetHack code b...
9
2009-06-02T22:53:55Z
942,628
<p>The code as written is largely untestable - and you need to make it testable. So, you need the C code to be:</p> <pre><code>int phase_of_the_moon() /* 0-7, with 0: new, 4: full */ { register struct tm *lt = getlt(); return testable_potm(lt); } static int testable_potm(const struct tm *lt) { regist...
4
2009-06-03T00:54:48Z
[ "python", "c", "time", "porting", "nethack" ]
Help me to port this NetHack function to Python please!
942,328
<p>I am trying to write a Python function which returns the same moon phase value as in the game NetHack. This is found in <a href="http://nethack.wikia.com/wiki/Source:Hacklib.c#phase%5Fof%5Fthe%5Fmoon" rel="nofollow">hacklib.c</a>.</p> <p>I have tried to simply copy the corresponding function from the NetHack code b...
9
2009-06-02T22:53:55Z
1,945,192
<p>I like to think I know a thing or two about calendars, so let's see if I can clear a few things up.</p> <p>The Catholic Church defines the date of Easter in terms of lunar phases (this is why the date jumps around from year to year). Because of this, it needs to be able to calculate the approximate moon phase, and ...
0
2009-12-22T09:30:24Z
[ "python", "c", "time", "porting", "nethack" ]
Help me to port this NetHack function to Python please!
942,328
<p>I am trying to write a Python function which returns the same moon phase value as in the game NetHack. This is found in <a href="http://nethack.wikia.com/wiki/Source:Hacklib.c#phase%5Fof%5Fthe%5Fmoon" rel="nofollow">hacklib.c</a>.</p> <p>I have tried to simply copy the corresponding function from the NetHack code b...
9
2009-06-02T22:53:55Z
1,945,256
<p>Following code is <a href="http://www.daniweb.com/code/post968407.html" rel="nofollow">borrowed from this site</a>, pasting it here for easy reference (and in case the other site goes down). Seems to do what you want.</p> <pre><code># Determine the moon phase of a date given # Python code by HAB def moon_phase(mon...
1
2009-12-22T09:42:18Z
[ "python", "c", "time", "porting", "nethack" ]
Help me to port this NetHack function to Python please!
942,328
<p>I am trying to write a Python function which returns the same moon phase value as in the game NetHack. This is found in <a href="http://nethack.wikia.com/wiki/Source:Hacklib.c#phase%5Fof%5Fthe%5Fmoon" rel="nofollow">hacklib.c</a>.</p> <p>I have tried to simply copy the corresponding function from the NetHack code b...
9
2009-06-02T22:53:55Z
4,066,395
<p>Here is my conversion of it, and I've tested this against the C code by passing in values from xrange(0, 1288578760, 3601), and they both return the same values. Note that I've changed it so that you can pass the seconds since epoch, so that I could test it against the C version for a third of a million different v...
0
2010-11-01T02:56:56Z
[ "python", "c", "time", "porting", "nethack" ]
Help me to port this NetHack function to Python please!
942,328
<p>I am trying to write a Python function which returns the same moon phase value as in the game NetHack. This is found in <a href="http://nethack.wikia.com/wiki/Source:Hacklib.c#phase%5Fof%5Fthe%5Fmoon" rel="nofollow">hacklib.c</a>.</p> <p>I have tried to simply copy the corresponding function from the NetHack code b...
9
2009-06-02T22:53:55Z
5,161,447
<p>I'm long late on this thread but fwiw, the alt.org server's display of pom via the web only updates on cron a couple times per day so if you're off by just a bit from it, that could be the reason. The game itself runs from whatever is in the nethack code itself so doesn't suffer the same caching issue. -drew (alt.or...
2
2011-03-01T22:58:43Z
[ "python", "c", "time", "porting", "nethack" ]
Operation on every pair of element in a list
942,543
<p>Using Python, I'd like to compare every possible pair in a list.</p> <p>Suppose I have</p> <pre><code>my_list = [1,2,3,4] </code></pre> <p>I'd like to do an operation (let's call it foo) on every combination of 2 elements from the list.</p> <p>The final result should be the same as</p> <pre><code>foo(1,1) foo(1...
25
2009-06-03T00:21:23Z
942,551
<p>Check out <a href="http://docs.python.org/library/itertools.html#itertools.product"><code>product()</code></a> in the <code>itertools</code> module. It does exactly what you describe.</p> <pre><code>import itertools my_list = [1,2,3,4] for pair in itertools.product(my_list, repeat=2): foo(*pair) </code></pre>...
89
2009-06-03T00:24:43Z
[ "python" ]
Operation on every pair of element in a list
942,543
<p>Using Python, I'd like to compare every possible pair in a list.</p> <p>Suppose I have</p> <pre><code>my_list = [1,2,3,4] </code></pre> <p>I'd like to do an operation (let's call it foo) on every combination of 2 elements from the list.</p> <p>The final result should be the same as</p> <pre><code>foo(1,1) foo(1...
25
2009-06-03T00:21:23Z
942,565
<p>If you're just calling a function, you can't really do much better than:</p> <pre><code>for i in my_list: for j in my_list: foo(i, j) </code></pre> <p>If you want to collect a list of the results of calling the function, you can do:</p> <pre><code>[foo(i, j) for i my_list for j in my_list] </code></pr...
1
2009-06-03T00:29:43Z
[ "python" ]
Operation on every pair of element in a list
942,543
<p>Using Python, I'd like to compare every possible pair in a list.</p> <p>Suppose I have</p> <pre><code>my_list = [1,2,3,4] </code></pre> <p>I'd like to do an operation (let's call it foo) on every combination of 2 elements from the list.</p> <p>The final result should be the same as</p> <pre><code>foo(1,1) foo(1...
25
2009-06-03T00:21:23Z
37,907,649
<p>I had a similar problem and found the solution <a href="http://www.wellho.net/resources/ex.php4?item=y104/tessapy" rel="nofollow">here</a>. It works without having to import any module.</p> <p>Supposing a list like:</p> <pre><code>people = ["Lisa","Pam","Phil","John"] </code></pre> <p>A simplified one-line soluti...
1
2016-06-19T13:15:38Z
[ "python" ]
Missing 'Median' Aggregate Function in Django?
942,620
<p>The Development version of Django has aggregate functions like Avg, Count, Max, Min, StdDev, Sum, and Variance (<a href="http://docs.djangoproject.com/en/dev/ref/models/querysets/#id8">link text</a>). Is there a reason Median is missing from the list? </p> <p>Implementing one seems like it would be easy. Am I missi...
8
2009-06-03T00:51:25Z
942,633
<p>Well, the <em>reason</em> is probably that you need to track all the numbers to calculate median. Avg, Count, Max, Min, StDev, Sum, and Variance can all be calculated with constant storage needs. That is, once you "record" a number you'll never need it again.</p> <p>FWIW, the variables you need to track are: min,...
7
2009-06-03T00:57:17Z
[ "python", "django", "aggregate-functions" ]
Missing 'Median' Aggregate Function in Django?
942,620
<p>The Development version of Django has aggregate functions like Avg, Count, Max, Min, StdDev, Sum, and Variance (<a href="http://docs.djangoproject.com/en/dev/ref/models/querysets/#id8">link text</a>). Is there a reason Median is missing from the list? </p> <p>Implementing one seems like it would be easy. Am I missi...
8
2009-06-03T00:51:25Z
942,638
<p>A strong possibility is that median is not part of standard SQL. </p> <p>Also, it requires a sort, making it quite expensive to compute.</p>
2
2009-06-03T00:59:05Z
[ "python", "django", "aggregate-functions" ]
Missing 'Median' Aggregate Function in Django?
942,620
<p>The Development version of Django has aggregate functions like Avg, Count, Max, Min, StdDev, Sum, and Variance (<a href="http://docs.djangoproject.com/en/dev/ref/models/querysets/#id8">link text</a>). Is there a reason Median is missing from the list? </p> <p>Implementing one seems like it would be easy. Am I missi...
8
2009-06-03T00:51:25Z
942,940
<p>Because median isn't a SQL aggregate. See, for example, the <a href="http://www.postgresql.org/docs/8.3/static/functions-aggregate.html">list of PostgreSQL aggregate functions</a> and <a href="http://dev.mysql.com/doc/refman/5.0/en/group-by-functions.html">the list of MySQL aggregate functions</a>.</p>
12
2009-06-03T03:27:26Z
[ "python", "django", "aggregate-functions" ]
Missing 'Median' Aggregate Function in Django?
942,620
<p>The Development version of Django has aggregate functions like Avg, Count, Max, Min, StdDev, Sum, and Variance (<a href="http://docs.djangoproject.com/en/dev/ref/models/querysets/#id8">link text</a>). Is there a reason Median is missing from the list? </p> <p>Implementing one seems like it would be easy. Am I missi...
8
2009-06-03T00:51:25Z
942,985
<p>I have no idea what db backend you are using, but if your db supports another aggregate, or you can find a clever way of doing it, You can probably access it easily by <a href="http://code.djangoproject.com/browser/django/trunk/django/db/models/aggregates.py" rel="nofollow">Aggregate</a>.</p>
2
2009-06-03T03:56:12Z
[ "python", "django", "aggregate-functions" ]
Missing 'Median' Aggregate Function in Django?
942,620
<p>The Development version of Django has aggregate functions like Avg, Count, Max, Min, StdDev, Sum, and Variance (<a href="http://docs.djangoproject.com/en/dev/ref/models/querysets/#id8">link text</a>). Is there a reason Median is missing from the list? </p> <p>Implementing one seems like it would be easy. Am I missi...
8
2009-06-03T00:51:25Z
6,595,428
<p>FWIW, you can extend PostgreSQL 8.4 and above to have a median aggregate function with <a href="http://wiki.postgresql.org/wiki/Aggregate_Median" rel="nofollow">these code snippets</a>.</p> <p>Other code snippets (which work for older versions of PostgreSQL) are <a href="http://www.postgresonline.com/journal/archiv...
1
2011-07-06T11:09:41Z
[ "python", "django", "aggregate-functions" ]
Missing 'Median' Aggregate Function in Django?
942,620
<p>The Development version of Django has aggregate functions like Avg, Count, Max, Min, StdDev, Sum, and Variance (<a href="http://docs.djangoproject.com/en/dev/ref/models/querysets/#id8">link text</a>). Is there a reason Median is missing from the list? </p> <p>Implementing one seems like it would be easy. Am I missi...
8
2009-06-03T00:51:25Z
9,503,282
<p>Here's your missing function. Pass it a queryset and the name of the column that you want to find the median for:</p> <pre><code>def median_value(queryset, term): count = queryset.count() return queryset.values_list(term, flat=True).order_by(term)[int(round(count/2))] </code></pre> <p>That wasn't as hard ...
12
2012-02-29T16:56:05Z
[ "python", "django", "aggregate-functions" ]
How to Change Mouse Cursor in PythonCard
942,730
<p>How do I change the mouse cursor to indicate a waiting state using Python and PythonCard? </p> <p>I didn't see anything in the documentation.</p>
0
2009-06-03T01:46:13Z
942,839
<p>PythonCard builds on top of wx, so if you import wx you should be able to build a suitable cursor (e.g. with <code>wx.CursorFromImage</code>), set it (e.g. with <code>wx.BeginBusyCursor</code>) when your wait begins, and end it (with <code>wx.EndBusyCursor</code>) when your wait ends.</p>
1
2009-06-03T02:42:28Z
[ "python", "user-interface", "mouse", "cursor", "pythoncard" ]
Is a list or dictionary faster in Python?
942,902
<p>How much of a difference are these two as far as performance?</p> <pre><code>tmp = [] tmp.append(True) print tmp[0] </code></pre> <p>And</p> <pre><code>tmp = {} tmp[0] = True print tmp[0] </code></pre>
1
2009-06-03T03:14:39Z
942,924
<p>The <code>timeit</code> module in the standard library is designed just to answer such questions! Forget the <code>print</code> (which would have the nasty side effect of spewing stuff to your terminal;-) and compare:</p> <pre><code>$ python -mtimeit 'tmp=[]; tmp.append(True); x=tmp[0]' 1000000 loops, best of 3: 0....
18
2009-06-03T03:21:04Z
[ "python", "data-structures" ]
Is a list or dictionary faster in Python?
942,902
<p>How much of a difference are these two as far as performance?</p> <pre><code>tmp = [] tmp.append(True) print tmp[0] </code></pre> <p>And</p> <pre><code>tmp = {} tmp[0] = True print tmp[0] </code></pre>
1
2009-06-03T03:14:39Z
942,931
<p>they are equitable in my testing</p>
0
2009-06-03T03:25:26Z
[ "python", "data-structures" ]
Is a list or dictionary faster in Python?
942,902
<p>How much of a difference are these two as far as performance?</p> <pre><code>tmp = [] tmp.append(True) print tmp[0] </code></pre> <p>And</p> <pre><code>tmp = {} tmp[0] = True print tmp[0] </code></pre>
1
2009-06-03T03:14:39Z
942,933
<p>Of course there will be a slight difference, but honestly you shouldn't be worrying about this. What you're doing is <a href="https://web.archive.org/web/20120131020641/http://ajbrown.org/blog/2008/11/05/micro-optimize-your-time-not-your-code.html" rel="nofollow">micro-optimizing</a> your code, which is something yo...
1
2009-06-03T03:25:35Z
[ "python", "data-structures" ]
Is a list or dictionary faster in Python?
942,902
<p>How much of a difference are these two as far as performance?</p> <pre><code>tmp = [] tmp.append(True) print tmp[0] </code></pre> <p>And</p> <pre><code>tmp = {} tmp[0] = True print tmp[0] </code></pre>
1
2009-06-03T03:14:39Z
943,046
<p>Not only is micro-optimization usually pointless in general, I find it is especially difficult and arcane for Python in particular. It is very easy to actually make your code simultaneously slower and more complicated. See <a href="http://stackoverflow.com/questions/900420/elegant-way-to-compare-sequences">this St...
6
2009-06-03T04:22:49Z
[ "python", "data-structures" ]
Flash-based file upload (swfupload) fails with Apache/mod-wsgi
943,000
<p><strong>This question has been retitled/retagged so that others may more easily find the solution to this problem.</strong></p> <p><hr /></p> <p>I am in the process of trying to migrate a project from the Django development server to a Apache/mod-wsgi environment. If you had asked me yesterday I would have said t...
0
2009-06-03T04:05:37Z
943,117
<p>Normally apache runs as a user "www-data"; and you could have problems if it doesn't have read/write access. However, your setup doesn't seem to use apache to access the '/home/sk/src/sitename/uploads'; my understanding from this config file is unless it hit /static or /media, apache will hand it off WGSI, so it mig...
3
2009-06-03T04:54:55Z
[ "python", "flash", "apache", "file-upload", "mod-wsgi" ]
Flash-based file upload (swfupload) fails with Apache/mod-wsgi
943,000
<p><strong>This question has been retitled/retagged so that others may more easily find the solution to this problem.</strong></p> <p><hr /></p> <p>I am in the process of trying to migrate a project from the Django development server to a Apache/mod-wsgi environment. If you had asked me yesterday I would have said t...
0
2009-06-03T04:05:37Z
943,476
<p>Another possibility is a bug in "old" releases of mod_wsgi (I got crazy to find, and fix, it). More info in this <a href="http://code.google.com/p/modwsgi/issues/detail?id=121" rel="nofollow">bug report</a>. I fixed it (for curl uploads) thanks to the <a href="http://the-stickman.com/web-development/php-and-curl-dis...
2
2009-06-03T07:18:33Z
[ "python", "flash", "apache", "file-upload", "mod-wsgi" ]
Benefit of installing Django from .deb versus .tar.gz?
943,242
<p>I'm starting Django development, and I can either install it from the .deb using</p> <pre><code>$ apt-get install python-django </code></pre> <p>on my Ubuntu machine, or I can download the .tar.gz from <a href="http://djangoproject.com" rel="nofollow">djangoproject.com</a>, and start with that.</p> <p>What are th...
4
2009-06-03T05:50:43Z
943,264
<p>Using apt-get you'll get better uninstall support via the package manager and it can also install dependencies for you. If you install with apt-get you might get automatic updates, which is very nice for security patches.</p> <p>With the tar you might get a newer version and you might get the opportunity to tailor...
4
2009-06-03T05:58:57Z
[ "python", "django", "ubuntu", "apt-get" ]
Benefit of installing Django from .deb versus .tar.gz?
943,242
<p>I'm starting Django development, and I can either install it from the .deb using</p> <pre><code>$ apt-get install python-django </code></pre> <p>on my Ubuntu machine, or I can download the .tar.gz from <a href="http://djangoproject.com" rel="nofollow">djangoproject.com</a>, and start with that.</p> <p>What are th...
4
2009-06-03T05:50:43Z
943,265
<p>Using <code>apt-get</code> lets your system keep track of the install (e.g. if you want to disinstall, upgrade, or the like, late). Installing from source (<code>.tar.gz</code> or otherwise) puts you in charge of what's what and where -- you can have multiple versions installed at various locations, etc, but there's...
8
2009-06-03T05:59:05Z
[ "python", "django", "ubuntu", "apt-get" ]
Benefit of installing Django from .deb versus .tar.gz?
943,242
<p>I'm starting Django development, and I can either install it from the .deb using</p> <pre><code>$ apt-get install python-django </code></pre> <p>on my Ubuntu machine, or I can download the .tar.gz from <a href="http://djangoproject.com" rel="nofollow">djangoproject.com</a>, and start with that.</p> <p>What are th...
4
2009-06-03T05:50:43Z
943,313
<p>I've always installed using the dev version. <a href="http://docs.djangoproject.com/en/dev/topics/install/#installing-development-version" rel="nofollow">(Instructions)</a></p> <p>This makes updating really easy and gives you all the fancy features in the /dev/ docs. I would suggest you try going this route if poss...
0
2009-06-03T06:18:44Z
[ "python", "django", "ubuntu", "apt-get" ]
Benefit of installing Django from .deb versus .tar.gz?
943,242
<p>I'm starting Django development, and I can either install it from the .deb using</p> <pre><code>$ apt-get install python-django </code></pre> <p>on my Ubuntu machine, or I can download the .tar.gz from <a href="http://djangoproject.com" rel="nofollow">djangoproject.com</a>, and start with that.</p> <p>What are th...
4
2009-06-03T05:50:43Z
943,415
<p>The best way to install is to check out the code, which ever the changeset (branch/tag) you want, and define a symbolic link to it</p> <p>Checkout the version you want:</p> <pre><code># For trunk svn co http://code.djangoproject.com/svn/django/trunk/ django-trunk # For a tag, 1.02 release svn co http://code.dja...
6
2009-06-03T06:51:48Z
[ "python", "django", "ubuntu", "apt-get" ]
Benefit of installing Django from .deb versus .tar.gz?
943,242
<p>I'm starting Django development, and I can either install it from the .deb using</p> <pre><code>$ apt-get install python-django </code></pre> <p>on my Ubuntu machine, or I can download the .tar.gz from <a href="http://djangoproject.com" rel="nofollow">djangoproject.com</a>, and start with that.</p> <p>What are th...
4
2009-06-03T05:50:43Z
943,660
<p>I know with debian and probably some other distros, the version of django in the package manager is the 0.9 branch, not the 1.X branch. Definately something you want to avoid.</p>
0
2009-06-03T08:35:01Z
[ "python", "django", "ubuntu", "apt-get" ]
Benefit of installing Django from .deb versus .tar.gz?
943,242
<p>I'm starting Django development, and I can either install it from the .deb using</p> <pre><code>$ apt-get install python-django </code></pre> <p>on my Ubuntu machine, or I can download the .tar.gz from <a href="http://djangoproject.com" rel="nofollow">djangoproject.com</a>, and start with that.</p> <p>What are th...
4
2009-06-03T05:50:43Z
944,831
<p>Getting Django from your Ubuntu repository gives you the older "stable" version. This may be fine with you, but I believe most developers prefer sticking with latest code available in the trunk to get more features.</p> <p>IMHO the cleanest solution is not to install .tar.gz/SVN version with straightforward <code>s...
1
2009-06-03T13:43:54Z
[ "python", "django", "ubuntu", "apt-get" ]