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
Django forms, inheritance and order of form fields
913,589
<p>I'm using Django forms in my website and would like to control the order of the fields.</p> <p>Here's how I define my forms:</p> <pre><code>class edit_form(forms.Form): summary = forms.CharField() description = forms.CharField(widget=forms.TextArea) class create_form(edit_form): name = forms.CharFiel...
53
2009-05-27T01:46:50Z
2,619,586
<p>I used the solution posted by Selene but found that it removed all fields which weren't assigned to keyOrder. The form that I'm subclassing has a lot of fields so this didn't work very well for me. I coded up this function to solve the problem using akaihola's answer, but if you want it to work like Selene's all you...
11
2010-04-12T02:38:58Z
[ "python", "django", "django-forms" ]
Django forms, inheritance and order of form fields
913,589
<p>I'm using Django forms in my website and would like to control the order of the fields.</p> <p>Here's how I define my forms:</p> <pre><code>class edit_form(forms.Form): summary = forms.CharField() description = forms.CharField(widget=forms.TextArea) class create_form(edit_form): name = forms.CharFiel...
53
2009-05-27T01:46:50Z
8,476,642
<p>You could also create a decorator to order fields (inspired by Joshua's solution):</p> <pre><code>def order_fields(*field_list): def decorator(form): original_init = form.__init__ def init(self, *args, **kwargs): original_init(self, *args, **kwargs) for field in f...
7
2011-12-12T15:26:51Z
[ "python", "django", "django-forms" ]
Django forms, inheritance and order of form fields
913,589
<p>I'm using Django forms in my website and would like to control the order of the fields.</p> <p>Here's how I define my forms:</p> <pre><code>class edit_form(forms.Form): summary = forms.CharField() description = forms.CharField(widget=forms.TextArea) class create_form(edit_form): name = forms.CharFiel...
53
2009-05-27T01:46:50Z
12,463,656
<p>Based on an answer by @akaihola and updated to work with latest Django 1.5 as <code>self.fields.insert</code> is being <a href="https://github.com/django/django/blob/master/django/utils/datastructures.py#L227" rel="nofollow">depreciated</a>. </p> <pre><code>from easycontactus.forms import * from django import forms...
1
2012-09-17T16:40:49Z
[ "python", "django", "django-forms" ]
Django forms, inheritance and order of form fields
913,589
<p>I'm using Django forms in my website and would like to control the order of the fields.</p> <p>Here's how I define my forms:</p> <pre><code>class edit_form(forms.Form): summary = forms.CharField() description = forms.CharField(widget=forms.TextArea) class create_form(edit_form): name = forms.CharFiel...
53
2009-05-27T01:46:50Z
23,615,361
<p>It appears that at some point the underlying structure of field order was changed from a django specific <code>SordedDict</code> to a python standard <code>OrderedDict</code></p> <p>Thus, in 1.7 I had to do the following:</p> <pre><code>from collections import OrderedDict class MyForm(forms.Form): def __init...
9
2014-05-12T17:35:17Z
[ "python", "django", "django-forms" ]
Django forms, inheritance and order of form fields
913,589
<p>I'm using Django forms in my website and would like to control the order of the fields.</p> <p>Here's how I define my forms:</p> <pre><code>class edit_form(forms.Form): summary = forms.CharField() description = forms.CharField(widget=forms.TextArea) class create_form(edit_form): name = forms.CharFiel...
53
2009-05-27T01:46:50Z
27,493,844
<p>The accepted answer's approach makes use of an internal Django forms API that was changed in Django 1.7. <a href="https://code.djangoproject.com/timeline?from=2014-09-07T19%3A47%3A59%2B01%3A00&amp;precision=second" rel="nofollow">The project team's opinion is that it should never have been used in the first place.</...
4
2014-12-15T21:53:46Z
[ "python", "django", "django-forms" ]
Django forms, inheritance and order of form fields
913,589
<p>I'm using Django forms in my website and would like to control the order of the fields.</p> <p>Here's how I define my forms:</p> <pre><code>class edit_form(forms.Form): summary = forms.CharField() description = forms.CharField(widget=forms.TextArea) class create_form(edit_form): name = forms.CharFiel...
53
2009-05-27T01:46:50Z
30,794,861
<p>Django 1.9 will support this by default on the form with <code>field_order</code>:</p> <pre><code>class MyForm(forms.Form): ... field_order = ['field_1', 'field_2'] ... </code></pre> <p><a href="https://github.com/django/django/commit/28986da4ca167ae257abcaf7caea230eca2bcd80">https://github.com/django/...
6
2015-06-12T03:27:41Z
[ "python", "django", "django-forms" ]
Django forms, inheritance and order of form fields
913,589
<p>I'm using Django forms in my website and would like to control the order of the fields.</p> <p>Here's how I define my forms:</p> <pre><code>class edit_form(forms.Form): summary = forms.CharField() description = forms.CharField(widget=forms.TextArea) class create_form(edit_form): name = forms.CharFiel...
53
2009-05-27T01:46:50Z
33,034,723
<p>I built a form 'ExRegistrationForm' inherited from the 'RegistrationForm' from Django-Registration-Redux. I faced two issues, one of which was reordering the fields on the html output page once the new form had been created.</p> <p>I solved them as follows:</p> <p><strong>1. ISSUE 1: Remove Username from the Regis...
0
2015-10-09T09:31:11Z
[ "python", "django", "django-forms" ]
django error 'too many values to unpack'
913,590
<p>I'm learning Django by building a simple recipes app. I have a 1 table model using the 'choices' field option for recipe categories rather than using a 2nd 'categories' table and a foreign key relationship. So i created db table via syncdb and then loaded table with test data. When i go to admin and click on the 'Re...
13
2009-05-27T01:46:50Z
913,605
<p>If I had to guess, it's because whatever is in the administrative template expects a list of tuples, but you've instead supplied a tuple of tuples (hence the "too many values"). Try replacing with a list instead:</p> <pre><code>CATEGORY_CHOICES = [ # Note square brackets. (1, u'Appetizer'), (2, u'Bread')...
1
2009-05-27T01:53:35Z
[ "python", "django", "sqlite" ]
django error 'too many values to unpack'
913,590
<p>I'm learning Django by building a simple recipes app. I have a 1 table model using the 'choices' field option for recipe categories rather than using a 2nd 'categories' table and a foreign key relationship. So i created db table via syncdb and then loaded table with test data. When i go to admin and click on the 'Re...
13
2009-05-27T01:46:50Z
913,660
<p>Per <a href="http://code.djangoproject.com/ticket/972" rel="nofollow">http://code.djangoproject.com/ticket/972</a> , you need to move the assignment <code>CATEGORY_CHOICES = ...</code> <em>outside</em> the <code>class</code> statement.</p>
1
2009-05-27T02:22:04Z
[ "python", "django", "sqlite" ]
django error 'too many values to unpack'
913,590
<p>I'm learning Django by building a simple recipes app. I have a 1 table model using the 'choices' field option for recipe categories rather than using a 2nd 'categories' table and a foreign key relationship. So i created db table via syncdb and then loaded table with test data. When i go to admin and click on the 'Re...
13
2009-05-27T01:46:50Z
913,705
<p>I got it working. Most of the 'too many values to unpack' errors that i came across while googling were Value Error types. My error was a Template Syntax type. To load my recipe table i had imported a csv file. I was thinking maybe there was a problem somewhere in the data that sqlite allowed on import. So i deleted...
0
2009-05-27T02:37:17Z
[ "python", "django", "sqlite" ]
django error 'too many values to unpack'
913,590
<p>I'm learning Django by building a simple recipes app. I have a 1 table model using the 'choices' field option for recipe categories rather than using a 2nd 'categories' table and a foreign key relationship. So i created db table via syncdb and then loaded table with test data. When i go to admin and click on the 'Re...
13
2009-05-27T01:46:50Z
2,777,895
<p>I just had the same problem... my cvs file came from ms excel and the date fields gotten the wrong format at saving time. I change the format to something like '2010-05-04 13:05:46.790454' (excel gave me 5/5/2010 10:05:47) and voilaaaa no more 'too many values to unpack’</p>
0
2010-05-06T01:37:56Z
[ "python", "django", "sqlite" ]
django error 'too many values to unpack'
913,590
<p>I'm learning Django by building a simple recipes app. I have a 1 table model using the 'choices' field option for recipe categories rather than using a 2nd 'categories' table and a foreign key relationship. So i created db table via syncdb and then loaded table with test data. When i go to admin and click on the 'Re...
13
2009-05-27T01:46:50Z
5,990,777
<p>You should use a <code>ChoiceField</code> instead of <code>SmallIntegerField</code></p>
2
2011-05-13T10:45:47Z
[ "python", "django", "sqlite" ]
django error 'too many values to unpack'
913,590
<p>I'm learning Django by building a simple recipes app. I have a 1 table model using the 'choices' field option for recipe categories rather than using a 2nd 'categories' table and a foreign key relationship. So i created db table via syncdb and then loaded table with test data. When i go to admin and click on the 'Re...
13
2009-05-27T01:46:50Z
8,206,621
<p><strong>Edit: Updated in light of kibibu's correction.</strong></p> <p>I have encountered what I believe is this same error, producing the message:</p> <pre><code>Caught ValueError while rendering: too many values to unpack </code></pre> <p>My form class was as follows:</p> <pre><code>class CalcForm(forms.Form):...
12
2011-11-21T02:24:40Z
[ "python", "django", "sqlite" ]
django error 'too many values to unpack'
913,590
<p>I'm learning Django by building a simple recipes app. I have a 1 table model using the 'choices' field option for recipe categories rather than using a 2nd 'categories' table and a foreign key relationship. So i created db table via syncdb and then loaded table with test data. When i go to admin and click on the 'Re...
13
2009-05-27T01:46:50Z
19,302,943
<p>kibibu's comment to Kreychek's answer is correct. This isn't a Django issue but rather an interesting aspect of Python. To summarize:</p> <p>In Python, round parentheses are used for both order of operations and tuples. So:</p> <pre><code>foo = (2+2) </code></pre> <p>will result in foo being 4, not a tuple who's ...
0
2013-10-10T18:01:42Z
[ "python", "django", "sqlite" ]
How does one debug a fastcgi application?
913,817
<p>How does one debug a FastCGI application? I've got an app that's dying but I can't figure out why, even though it's likely throwing a stack trace on stderr. Running it from the commandline results in an error saying: </p> <pre><code>RuntimeError: No FastCGI Environment: 88 - Socket operation on non-socket </code>...
3
2009-05-27T03:32:40Z
1,005,007
<p>It does matter that the application is Python; your question is really "how do I debug Python when I'm not starting the script myself".</p> <p>You want to use a remote debugger. The excellent WinPDB has <a href="http://winpdb.org/docs/embedded-debugging/" rel="nofollow">some documentation on embedded debugging</a>...
2
2009-06-17T03:43:01Z
[ "python", "debugging", "web-applications", "fastcgi" ]
Using poll on file-like object returned by urllib2.urlopen()?
913,913
<p>I've run into the bug described at <a href="http://bugs.python.org/issue1327971" rel="nofollow">http://bugs.python.org/issue1327971</a> while trying to poll a file-like object returned by urllib2.urlopen(). </p> <p>Unfortunately, being relatively new to Python, I can't actually determine from the responses how to g...
0
2009-05-27T04:22:12Z
913,925
<p>It looks like you want to modify urllib with <a href="http://bugs.python.org/file13033/urllib%5Ffileno%5F2.diff" rel="nofollow">this patch</a>. Keep in mind, there's a reason this code hasn't been released. It hasn't been completely reviewed.</p> <p>EDIT: Actually, I think you want to modify httplib with <a href=...
0
2009-05-27T04:29:08Z
[ "python", "python-2.6" ]
Using poll on file-like object returned by urllib2.urlopen()?
913,913
<p>I've run into the bug described at <a href="http://bugs.python.org/issue1327971" rel="nofollow">http://bugs.python.org/issue1327971</a> while trying to poll a file-like object returned by urllib2.urlopen(). </p> <p>Unfortunately, being relatively new to Python, I can't actually determine from the responses how to g...
0
2009-05-27T04:22:12Z
914,011
<p>If you don't want to modify you system libraries you also can patch <code>httplib</code> on the fly to match the patch in the bug report:</p> <pre><code>import httplib @property def http_fileno(self): return self.fp.fileno @http_fileno.setter def http_fileno(self, value): self.fp.fileno = value httplib.HTT...
1
2009-05-27T04:56:09Z
[ "python", "python-2.6" ]
Decoding html encoded strings in python
913,933
<p>I have the following string...</p> <pre><code>"Scam, hoax, or the real deal, he&amp;#8217;s gonna work his way to the bottom of the sordid tale, and hopefully end up with an arcade game in the process." </code></pre> <p>I need to turn it into this string...</p> <blockquote> <p>Scam, hoax, or the real deal, he...
1
2009-05-27T04:32:50Z
913,989
<p>What's you're trying to do is called "HTML entity decoding" and it's covered in a number of past Stack Overflow questions, for example:</p> <ul> <li><a href="http://stackoverflow.com/questions/816272/how-to-unescape-apostrophes-and-such-in-python">How to unescape apostrophes and such in Python?</a></li> <li><a href...
4
2009-05-27T04:49:52Z
[ "python", "html", "xml" ]
Python script embedded in Windows Registry
914,106
<p>We all know that windows has the feature that you can right click on a file and numerous options are shown. Well you can add a value to this menu. I followed this guide : jfitz.com/tips/rclick_custom.html</p> <p>Basically I have a script that runs when I right click on a certain file type. Alright, so everything i...
0
2009-05-27T05:30:49Z
914,117
<p>yes, call pythonw.exe and pass the script path as a parameter</p> <pre><code>"C:\Python26\pythonw.exe" "C:\Users\daved\Documents\Python\backup.py" "%1" </code></pre> <p>It's also recommended (but not required) to use the extension .pyw when your script doesn't run in a console.</p>
2
2009-05-27T05:32:57Z
[ "python", "winapi" ]
What is the underlying data structure for Python lists?
914,233
<p>What is the typical underlying data structure used to implement Python's built-in list data type?</p>
44
2009-05-27T06:22:56Z
914,248
<p>CPython:</p> <pre><code>typedef struct { PyObject_VAR_HEAD /* Vector of pointers to list elements. list[0] is ob_item[0], etc. */ PyObject **ob_item; /* ob_item contains space for 'allocated' elements. The number * currently in use is ob_size. * Invariants: * 0 &lt;= ob_size &l...
21
2009-05-27T06:29:28Z
[ "python", "list", "data-structures" ]
What is the underlying data structure for Python lists?
914,233
<p>What is the typical underlying data structure used to implement Python's built-in list data type?</p>
44
2009-05-27T06:22:56Z
914,271
<p>In the <a href="http://fisheye3.atlassian.com/browse/jython/trunk/jython/src/org/python/core/PyList.java?r1=6244&amp;r2=6257&amp;u=-1&amp;ignore=&amp;k=">Jython implementation</a>, it's an <code>ArrayList&lt;PyObject&gt;</code>.</p>
9
2009-05-27T06:35:03Z
[ "python", "list", "data-structures" ]
What is the underlying data structure for Python lists?
914,233
<p>What is the typical underlying data structure used to implement Python's built-in list data type?</p>
44
2009-05-27T06:22:56Z
915,593
<blockquote> <p>List objects are implemented as arrays. They are optimized for fast fixed-length operations and incur O(n) memory movement costs for pop(0) and insert(0, v) operations which change both the size and position of the underlying data representation.</p> </blockquote> <p>See also: <a href="ht...
34
2009-05-27T13:04:07Z
[ "python", "list", "data-structures" ]
capture stderr from python subprocess.Popen(command, stderr=subprocess.PIPE, stdout=subprocess.PIPE)
914,320
<p>I have seen this posted so many times here; yet failed to capture intentional errors from command. Best partial work I have found so far..</p> <pre><code>from Tkinter import * import os import Image, ImageTk import subprocess as sub p = sub.Popen('datdsade',stdout=sub.PIPE,stderr=sub.PIPE) output, errors = p.commun...
4
2009-05-27T06:51:33Z
914,328
<p>Are you 100% sure 'datdsade' actually writes to stderr? If so then possibly it's buffering its stderr, or blocking on it.</p> <p>EDIT: I'd suggest running 'datdsade' (your program) in bash (assuming you have linux, you can dl sh.exe for windows) and seeing if you can capture your stderr to a file datdsade 2> errors...
2
2009-05-27T06:56:31Z
[ "python", "subprocess" ]
capture stderr from python subprocess.Popen(command, stderr=subprocess.PIPE, stdout=subprocess.PIPE)
914,320
<p>I have seen this posted so many times here; yet failed to capture intentional errors from command. Best partial work I have found so far..</p> <pre><code>from Tkinter import * import os import Image, ImageTk import subprocess as sub p = sub.Popen('datdsade',stdout=sub.PIPE,stderr=sub.PIPE) output, errors = p.commun...
4
2009-05-27T06:51:33Z
24,171,613
<p>This works perfectly for me: </p> <pre><code>import subprocess try: #prints results result = subprocess.check_output("echo %USERNAME%", stderr=subprocess.STDOUT, shell=True) print result #causes error result = subprocess.check_output("copy testfds", stderr=subprocess.STDOUT, shell=True) except s...
4
2014-06-11T20:03:47Z
[ "python", "subprocess" ]
How can I count unique terms in a plaintext file case-insensitively?
914,382
<p>This can be in any high-level language that is likely to be available on a typical unix-like system (Python, Perl, awk, standard unix utils {sort, uniq}, etc). Hopefully it's fast enough to report the total number of unique terms for a 2MB text file.</p> <p>I only need this for quick sanity-checking, so it doesn't ...
2
2009-05-27T07:18:15Z
914,390
<p>In Python 2.4 (possibly it works on earlier systems as well):</p> <pre><code>#! /usr/bin/python2.4 import sys h = set() for line in sys.stdin.xreadlines(): for term in line.split(): h.add(term) print len(h) </code></pre> <p>In Perl:</p> <pre><code>$ perl -ne 'for (split(" ", $_)) { $H{$_} = 1 } END { print ...
4
2009-05-27T07:19:54Z
[ "python", "perl", "unix", "count", "awk" ]
How can I count unique terms in a plaintext file case-insensitively?
914,382
<p>This can be in any high-level language that is likely to be available on a typical unix-like system (Python, Perl, awk, standard unix utils {sort, uniq}, etc). Hopefully it's fast enough to report the total number of unique terms for a 2MB text file.</p> <p>I only need this for quick sanity-checking, so it doesn't ...
2
2009-05-27T07:18:15Z
914,415
<p>Using bash/UNIX commands:</p> <pre><code>sed -e 's/[[:space:]]\+/\n/g' $FILE | sort -fu | wc -l </code></pre>
5
2009-05-27T07:34:19Z
[ "python", "perl", "unix", "count", "awk" ]
How can I count unique terms in a plaintext file case-insensitively?
914,382
<p>This can be in any high-level language that is likely to be available on a typical unix-like system (Python, Perl, awk, standard unix utils {sort, uniq}, etc). Hopefully it's fast enough to report the total number of unique terms for a 2MB text file.</p> <p>I only need this for quick sanity-checking, so it doesn't ...
2
2009-05-27T07:18:15Z
914,419
<p>Using just standard Unix utilities:</p> <pre><code>&lt; somefile tr 'A-Z[:blank:][:punct:]' 'a-z\n' | sort | uniq -c </code></pre> <p>If you're on a system without Gnu <code>tr</code>, you'll need to replace "<code>[:blank:][:punct:]</code>" with a list of all the whitespace and punctuation characters you'd like t...
4
2009-05-27T07:34:47Z
[ "python", "perl", "unix", "count", "awk" ]
How can I count unique terms in a plaintext file case-insensitively?
914,382
<p>This can be in any high-level language that is likely to be available on a typical unix-like system (Python, Perl, awk, standard unix utils {sort, uniq}, etc). Hopefully it's fast enough to report the total number of unique terms for a 2MB text file.</p> <p>I only need this for quick sanity-checking, so it doesn't ...
2
2009-05-27T07:18:15Z
914,430
<p>In Perl:</p> <pre><code>my %words; while (&lt;&gt;) { map { $words{lc $_} = 1 } split /\s/); } print scalar keys %words, "\n"; </code></pre>
6
2009-05-27T07:38:23Z
[ "python", "perl", "unix", "count", "awk" ]
How can I count unique terms in a plaintext file case-insensitively?
914,382
<p>This can be in any high-level language that is likely to be available on a typical unix-like system (Python, Perl, awk, standard unix utils {sort, uniq}, etc). Hopefully it's fast enough to report the total number of unique terms for a 2MB text file.</p> <p>I only need this for quick sanity-checking, so it doesn't ...
2
2009-05-27T07:18:15Z
914,787
<p>Simply (52 strokes):</p> <pre><code>perl -nE'@w{map lc,split/\W+/}=();END{say 0+keys%w}' </code></pre> <p>For older perl versions (55 strokes):</p> <pre><code>perl -lne'@w{map lc,split/\W+/}=();END{print 0+keys%w}' </code></pre>
3
2009-05-27T09:19:37Z
[ "python", "perl", "unix", "count", "awk" ]
How can I count unique terms in a plaintext file case-insensitively?
914,382
<p>This can be in any high-level language that is likely to be available on a typical unix-like system (Python, Perl, awk, standard unix utils {sort, uniq}, etc). Hopefully it's fast enough to report the total number of unique terms for a 2MB text file.</p> <p>I only need this for quick sanity-checking, so it doesn't ...
2
2009-05-27T07:18:15Z
914,907
<p>Here is a Perl one-liner:</p> <pre><code>perl -lne '$h{lc $_}++ for split /[\s.,]+/; END{print scalar keys %h}' file.txt </code></pre> <p>Or to list the count for each item:</p> <pre><code>perl -lne '$h{lc $_}++ for split /[\s.,]+/; END{printf "%-12s %d\n", $_, $h{$_} for sort keys %h}' file.txt </code></pre> <p...
4
2009-05-27T09:55:37Z
[ "python", "perl", "unix", "count", "awk" ]
How can I count unique terms in a plaintext file case-insensitively?
914,382
<p>This can be in any high-level language that is likely to be available on a typical unix-like system (Python, Perl, awk, standard unix utils {sort, uniq}, etc). Hopefully it's fast enough to report the total number of unique terms for a 2MB text file.</p> <p>I only need this for quick sanity-checking, so it doesn't ...
2
2009-05-27T07:18:15Z
915,110
<p>Here is an awk oneliner.</p> <pre><code>$ gawk -v RS='[[:space:]]' 'NF&amp;&amp;!a[toupper($0)]++{i++}END{print i}' somefile </code></pre> <ul> <li>'NF' means 'if there is a charactor'.</li> <li>'!a[topuuer[$0]++]' means 'show only uniq words'.</li> </ul>
0
2009-05-27T10:53:51Z
[ "python", "perl", "unix", "count", "awk" ]
How can I count unique terms in a plaintext file case-insensitively?
914,382
<p>This can be in any high-level language that is likely to be available on a typical unix-like system (Python, Perl, awk, standard unix utils {sort, uniq}, etc). Hopefully it's fast enough to report the total number of unique terms for a 2MB text file.</p> <p>I only need this for quick sanity-checking, so it doesn't ...
2
2009-05-27T07:18:15Z
930,185
<p>A shorter version in Python:</p> <pre><code>print len(set(w.lower() for w in open('filename.dat').read().split())) </code></pre> <p>Reads the entire file into memory, splits it into words using whitespace, converts each word to lower case, creates a (unique) set from the lowercase words, counts them and prints the...
3
2009-05-30T17:40:52Z
[ "python", "perl", "unix", "count", "awk" ]
How to save indention format of file in Python
914,626
<p>I am saving all the words from a file like so:</p> <pre><code> sentence = " " fileName = sys.argv[1] fileIn = open(sys.argv[1],"r") for line in open(sys.argv[1]): for word in line.split(" "): sentence += word </code></pre> <p>Everything works okay when outputting it except the formattin...
1
2009-05-27T08:37:48Z
914,651
<p>Since you state, that you want to <em>move source code files</em>, why not just copy/move them?</p> <pre><code>import shutil shutil.move(src, dest) </code></pre> <p>If you read source file, </p> <pre><code>fh = open("yourfilename", "r") content = fh.read() </code></pre> <p>should load your file as it is (with in...
3
2009-05-27T08:43:44Z
[ "python" ]
How to save indention format of file in Python
914,626
<p>I am saving all the words from a file like so:</p> <pre><code> sentence = " " fileName = sys.argv[1] fileIn = open(sys.argv[1],"r") for line in open(sys.argv[1]): for word in line.split(" "): sentence += word </code></pre> <p>Everything works okay when outputting it except the formattin...
1
2009-05-27T08:37:48Z
914,702
<p>Split removes all spaces:</p> <pre><code>&gt;&gt;&gt; a=" a b c" &gt;&gt;&gt; a.split(" ") ['', '', '', 'a', 'b', '', '', 'c'] </code></pre> <p>As you can see, the resulting array doesn't contain any spaces anymore. But you can see these strange empty strings (''). They denote that there has been a space. To r...
1
2009-05-27T08:57:57Z
[ "python" ]
How to save indention format of file in Python
914,626
<p>I am saving all the words from a file like so:</p> <pre><code> sentence = " " fileName = sys.argv[1] fileIn = open(sys.argv[1],"r") for line in open(sys.argv[1]): for word in line.split(" "): sentence += word </code></pre> <p>Everything works okay when outputting it except the formattin...
1
2009-05-27T08:37:48Z
914,709
<p>When you invoke <code>line.split()</code>, you remove all leading spaces.</p> <p>What's wrong with just reading the file into a single string?</p> <pre><code>textWithIndentation = open(sys.argv[1], "r").read() </code></pre>
2
2009-05-27T08:59:02Z
[ "python" ]
best practice for user preferences in $HOME in Python
914,675
<p>For some small programs in Python, I would like to set, store and retrieve user preferences in a file in a portable (multi-platform) way.</p> <p>I am thinking about a very simple ConfigParser file like "~/.program" or "~/.program/program.cfg".</p> <p>Is <code>os.path.expanduser()</code> the best way for achieving ...
3
2009-05-27T08:49:25Z
914,812
<pre><code>os.path.expanduser("~") </code></pre> <p>is more portable than </p> <pre><code>os.environ['HOME'] </code></pre> <p>so it should be ok to use the first.</p>
8
2009-05-27T09:26:06Z
[ "python", "preferences" ]
best practice for user preferences in $HOME in Python
914,675
<p>For some small programs in Python, I would like to set, store and retrieve user preferences in a file in a portable (multi-platform) way.</p> <p>I am thinking about a very simple ConfigParser file like "~/.program" or "~/.program/program.cfg".</p> <p>Is <code>os.path.expanduser()</code> the best way for achieving ...
3
2009-05-27T08:49:25Z
914,818
<p>You can use os.environ:</p> <pre><code>import os print os.environ["HOME"] </code></pre>
0
2009-05-27T09:27:44Z
[ "python", "preferences" ]
Python: Looping through all but the last item of a list
914,715
<p>I would like to loop through a list checking each item against the one following it.</p> <p>Is there a way I can loop through all but the last item using for x in y? I would prefer to do it without using indexes if I can.</p> <p><strong>Note</strong></p> <p>freespace answered my actual question, which is why I ac...
61
2009-05-27T08:59:35Z
914,733
<pre><code>for x in y[:-1] </code></pre> <p>If <code>y</code> is a generator, then the above will not work.</p>
136
2009-05-27T09:04:36Z
[ "python" ]
Python: Looping through all but the last item of a list
914,715
<p>I would like to loop through a list checking each item against the one following it.</p> <p>Is there a way I can loop through all but the last item using for x in y? I would prefer to do it without using indexes if I can.</p> <p><strong>Note</strong></p> <p>freespace answered my actual question, which is why I ac...
61
2009-05-27T08:59:35Z
914,786
<p>If you want to get all the elements in the sequence pair wise, use this approach (the pairwise function is from the examples in the itertools module).</p> <pre><code>from itertools import tee, izip, chain def pairwise(seq): a,b = tee(seq) b.next() return izip(a,b) for current_item, next_item in pairwi...
15
2009-05-27T09:18:47Z
[ "python" ]
Python: Looping through all but the last item of a list
914,715
<p>I would like to loop through a list checking each item against the one following it.</p> <p>Is there a way I can loop through all but the last item using for x in y? I would prefer to do it without using indexes if I can.</p> <p><strong>Note</strong></p> <p>freespace answered my actual question, which is why I ac...
61
2009-05-27T08:59:35Z
914,813
<p>if you meant comparing nth item with n+1 th item in the list you could also do with</p> <pre><code>&gt;&gt;&gt; for i in range(len(list[:-1])): ... print list[i]&gt;list[i+1] </code></pre> <p>note there is no hard coding going on there. This should be ok unless you feel otherwise.</p>
3
2009-05-27T09:26:25Z
[ "python" ]
Python: Looping through all but the last item of a list
914,715
<p>I would like to loop through a list checking each item against the one following it.</p> <p>Is there a way I can loop through all but the last item using for x in y? I would prefer to do it without using indexes if I can.</p> <p><strong>Note</strong></p> <p>freespace answered my actual question, which is why I ac...
61
2009-05-27T08:59:35Z
914,815
<p>the easiest way to compare the sequence item with the following:</p> <pre><code>for i, j in zip(a, a[1:]): # compare i (the current) to j (the following) </code></pre>
32
2009-05-27T09:26:29Z
[ "python" ]
Python: Looping through all but the last item of a list
914,715
<p>I would like to loop through a list checking each item against the one following it.</p> <p>Is there a way I can loop through all but the last item using for x in y? I would prefer to do it without using indexes if I can.</p> <p><strong>Note</strong></p> <p>freespace answered my actual question, which is why I ac...
61
2009-05-27T08:59:35Z
914,944
<p>To compare each item with the next one in an iterator without instantiating a list:</p> <pre><code>import itertools it = (x for x in range(10)) data1, data2 = itertools.tee(it) data2.next() for a, b in itertools.izip(data1, data2): print a, b </code></pre>
0
2009-05-27T10:07:46Z
[ "python" ]
producer/consumer problem with python multiprocessing
914,821
<p>I am writing a server program with one producer and multiple consumers, what confuses me is only the first task producer put into the queue gets consumed, after which tasks enqueued no longer get consumed, they remain in the queue forever.</p> <pre><code>from multiprocessing import Process, Queue, cpu_count from ht...
10
2009-05-27T09:28:56Z
915,616
<p>I think there must be something wrong with the web server part, as this works perfectly:</p> <pre><code>from multiprocessing import Process, Queue, cpu_count import random import time def serve(queue): works = ["task_1", "task_2"] while True: time.sleep(0.01) queue.put(random.choice(works)...
3
2009-05-27T13:08:41Z
[ "python", "multiprocessing" ]
producer/consumer problem with python multiprocessing
914,821
<p>I am writing a server program with one producer and multiple consumers, what confuses me is only the first task producer put into the queue gets consumed, after which tasks enqueued no longer get consumed, they remain in the queue forever.</p> <pre><code>from multiprocessing import Process, Queue, cpu_count from ht...
10
2009-05-27T09:28:56Z
915,958
<p><strong>"Second question, what's the best way to stop the HTTP server gracefully?"</strong></p> <p>This is hard.</p> <p>You have two choices for Interprocess Communication:</p> <ul> <li><p>Out-of-band controls. The server has another mechanism for communication. Another socket, a Unix Signal, or something else....
3
2009-05-27T14:16:14Z
[ "python", "multiprocessing" ]
producer/consumer problem with python multiprocessing
914,821
<p>I am writing a server program with one producer and multiple consumers, what confuses me is only the first task producer put into the queue gets consumed, after which tasks enqueued no longer get consumed, they remain in the queue forever.</p> <pre><code>from multiprocessing import Process, Queue, cpu_count from ht...
10
2009-05-27T09:28:56Z
5,132,614
<p>This can help: <a href="http://www.rsdcbabu.com/2011/02/multiprocessing-with-python.html" rel="nofollow">http://www.rsdcbabu.com/2011/02/multiprocessing-with-python.html</a></p>
1
2011-02-27T10:18:38Z
[ "python", "multiprocessing" ]
Regular Expression for Stripping Strings from Source Code
914,913
<p>I'm looking for a regular expression that will replace strings in an input source code with some constant string value such as "string", and that will also take into account escaping the string-start character that is denoted by a double string-start character (e.g. "he said ""hello"""). </p> <p>To clarify, I will ...
0
2009-05-27T09:57:29Z
914,965
<p>Maybe:</p> <pre><code>re.sub(r"[^\"]\"[^\"].*[^\"]\"[^\"]",'"string"',input) </code></pre> <p>EDIT:</p> <p>No that won't work for the final example.</p> <p>I don't think your requirements are regular: they can't be matched by a regular expression. This is because at the heart of the matter, you need to match any...
0
2009-05-27T10:13:18Z
[ "python", "regex", "string" ]
Regular Expression for Stripping Strings from Source Code
914,913
<p>I'm looking for a regular expression that will replace strings in an input source code with some constant string value such as "string", and that will also take into account escaping the string-start character that is denoted by a double string-start character (e.g. "he said ""hello"""). </p> <p>To clarify, I will ...
0
2009-05-27T09:57:29Z
916,022
<p>There's a very good <a href="http://code.activestate.com/recipes/475109/" rel="nofollow">string-matching regular expression</a> over at ActiveState. If it doesn't work straight out for your last example it should be a fairly trivial repeat to group adjacent quoted strings together.</p>
0
2009-05-27T14:28:38Z
[ "python", "regex", "string" ]
Regular Expression for Stripping Strings from Source Code
914,913
<p>I'm looking for a regular expression that will replace strings in an input source code with some constant string value such as "string", and that will also take into account escaping the string-start character that is denoted by a double string-start character (e.g. "he said ""hello"""). </p> <p>To clarify, I will ...
0
2009-05-27T09:57:29Z
916,277
<p>If you're parsing Python code, save yourself the hassle and let the standard library's <a href="http://docs.python.org/library/parser.html" rel="nofollow">parser module</a> do the heavy lifting.</p> <p>If you're writing your own parser for some custom language, it's awfully tempting to start out by just hacking tog...
3
2009-05-27T15:04:10Z
[ "python", "regex", "string" ]
Migrating from python 2.4 to python 2.6
915,135
<p>I'm migrating a legacy codebase at work from python 2.4 to python 2.6. This is being done as part of a push to remove the 'legacy' tag and make a maintainable, extensible foundation for active development, so I'm getting a chance to "do things right", including refactoring to use new 2.6 features if that leads to cl...
4
2009-05-27T11:03:02Z
915,182
<p>I guess you have already found them, but reference and for others, here are the lists of new features in those two versions:</p> <ul> <li><a href="http://docs.python.org/whatsnew/2.5.html" rel="nofollow">http://docs.python.org/whatsnew/2.5.html</a></li> <li><a href="http://docs.python.org/whatsnew/2.6.html" rel="no...
2
2009-05-27T11:18:06Z
[ "python", "design" ]
Migrating from python 2.4 to python 2.6
915,135
<p>I'm migrating a legacy codebase at work from python 2.4 to python 2.6. This is being done as part of a push to remove the 'legacy' tag and make a maintainable, extensible foundation for active development, so I'm getting a chance to "do things right", including refactoring to use new 2.6 features if that leads to cl...
4
2009-05-27T11:03:02Z
915,195
<p>Read the Python 3.0 changes. The point of 2.6 is to aim for 3.0.</p> <p>From 2.4 to 2.6 you gained a lot of things. These are the the most important. I'm making this answer community wiki so other folks can edit it.</p> <ol> <li><p>Generator functions and the yield statement.</p></li> <li><p>More consistent use ...
5
2009-05-27T11:22:46Z
[ "python", "design" ]
How to convert specific character sequences in a string to upper case using Python?
915,391
<p>I am looking to accomplish the following and am wondering if anyone has a suggestion as to how best go about it.</p> <p>I have a string, say 'this-is,-toronto.-and-this-is,-boston', and I would like to convert all occurrences of ',-[a-z]' to ',-[A-Z]'. In this case the result of the conversion would be 'this-is,-T...
2
2009-05-27T12:16:37Z
915,460
<p>re.sub can take a function which returns the replacement string:</p> <pre><code>import re s = 'this-is,-toronto.-and-this-is,-boston' t = re.sub(',-[a-z]', lambda x: x.group(0).upper(), s) print t </code></pre> <p>prints</p> <pre><code>this-is,-Toronto.-and-this-is,-Boston </code></pre>
11
2009-05-27T12:29:50Z
[ "python" ]
Please point me to (good) documentation about QT layouts for plasma development
915,633
<p>I am trying to develop a plasmoid in python. I got some good tutorials here (techbase.kde.org/Development/Tutorials/Plasma) and they are really helpful, but they don't have documentation or examples about QT layouts and their usage.</p> <p>I haven't programmed with QT, but I know C++ well. So, the resources should...
1
2009-05-27T13:14:10Z
915,666
<p>Perhaps a good place to start would be the <a href="http://doc.qtsoftware.com/4.5/qlayout.html#details" rel="nofollow">Qt documentation</a>?</p>
1
2009-05-27T13:23:55Z
[ "python", "qt", "kde4", "plasma", "plasmoid" ]
Please point me to (good) documentation about QT layouts for plasma development
915,633
<p>I am trying to develop a plasmoid in python. I got some good tutorials here (techbase.kde.org/Development/Tutorials/Plasma) and they are really helpful, but they don't have documentation or examples about QT layouts and their usage.</p> <p>I haven't programmed with QT, but I know C++ well. So, the resources should...
1
2009-05-27T13:14:10Z
916,001
<p>Plasma works as a big QGraphicsView, and applets are QGraphicsWidget items, meaning it's the documentation for <a href="http://doc.qtsoftware.com/4.5/qgraphicslayout.html" rel="nofollow">QGraphicsLayout</a> that you should be looking at, not QLayout as suggested.</p> <p>For a grid layout you want to use <a href="ht...
3
2009-05-27T14:25:24Z
[ "python", "qt", "kde4", "plasma", "plasmoid" ]
Reporting charts and data for MS-Office users
915,726
<p>We have lots of data and some charts repesenting one logical item. Charts and data is stored in various files. As a result, most users can easily access and re-use the information in their applications.</p> <p>However, this not exactly a good way of storing data. Amongst other reasons, charts belong to some data, t...
2
2009-05-27T13:34:06Z
920,669
<p>Instead of using one big file, You should use a database. Yes, You can store various types of files like gifs in the database if You like to.</p> <p>The file would not be human readable or accessible by non-technical users, but this is good.</p> <p>The database would have a website that Your non-technical users wo...
1
2009-05-28T12:49:33Z
[ "python", "web-services", "scripting", "reporting", "ms-office" ]
Reporting charts and data for MS-Office users
915,726
<p>We have lots of data and some charts repesenting one logical item. Charts and data is stored in various files. As a result, most users can easily access and re-use the information in their applications.</p> <p>However, this not exactly a good way of storing data. Amongst other reasons, charts belong to some data, t...
2
2009-05-27T13:34:06Z
921,061
<p>I can only agree with Reef on the general concepts he presented:</p> <ul> <li><p>You will almost certainly prefer the data in a database than in a single large file</p></li> <li><p>You should not worry that the data is not directly manipulated by users because as Reef mentioned, it can only go wrong. And you would ...
2
2009-05-28T14:15:05Z
[ "python", "web-services", "scripting", "reporting", "ms-office" ]
django auth User truncating email field
915,910
<p>I have an issue with the django.contrib.auth User model where the email max_length is 75.</p> <p>I am receiving email addresses that are longer than 75 characters from the facebook api, and I need to (would really like to) store them in the user for continuity among users that are from facebook connect and others.<...
9
2009-05-27T14:06:33Z
916,176
<p>EmailField 75 chars length is hardcoded in django. You can fix this like that:</p> <pre><code>from django.db.models.fields import EmailField def email_field_init(self, *args, **kwargs): kwargs['max_length'] = kwargs.get('max_length', 200) CharField.__init__(self, *args, **kwargs) EmailField.__init__ = email_fie...
12
2009-05-27T14:49:41Z
[ "python", "mysql", "django", "authentication" ]
django auth User truncating email field
915,910
<p>I have an issue with the django.contrib.auth User model where the email max_length is 75.</p> <p>I am receiving email addresses that are longer than 75 characters from the facebook api, and I need to (would really like to) store them in the user for continuity among users that are from facebook connect and others.<...
9
2009-05-27T14:06:33Z
1,196,117
<p>There is now a ticket to increase the length of the email field in Django: <a href="http://code.djangoproject.com/ticket/11579" rel="nofollow">http://code.djangoproject.com/ticket/11579</a></p>
2
2009-07-28T19:04:45Z
[ "python", "mysql", "django", "authentication" ]
How can I handle a mouseMiddleDrag event in PythonCard?
916,435
<p>I would like to use the middle mouse button to drag an image in an application written in Python and using PythonCard/wxPython for the GUI.</p> <p>The latest version of PythonCard only implements a "left mouse button drag" event and I am trying to modify PythonCard to handle a "middle mouse button drag" as well.</p...
1
2009-05-27T15:33:55Z
917,752
<p>It turns out the the <em>mouseDrag</em> event is active regardless of which button on the mouse is pressed. To filter the middle mouse button, you need to call the <em>MiddleIsDown()</em> method from the <em>MouseEvent</em>.</p> <pre><code>def on_mouseDrag( self, event ): do_stuff() if event.MiddleI...
1
2009-05-27T20:01:59Z
[ "python", "user-interface", "wxpython", "mouse", "pythoncard" ]
Would it be possible to write a 3D game as large as World of Warcraft in pure Python?
916,663
<p>Would it be possible to write a 3D game as large as World of Warcraft in pure Python? Assuming the use of DirectX / D3D bindings or OpenGL bindings.</p> <p>If not, what would be the largest hold-up to doing such a project in Python? I know games tend to fall into the realm of C and C++ but sometimes people do thing...
10
2009-05-27T16:16:05Z
916,686
<p>Yes. How it will perform is another question.</p> <p>A good development pattern would be to develop it in pure python, and then profile it, and rewrite performance-critical bottlenecks, either in C/C++/Cython or even python itself but with more efficient code.</p>
14
2009-05-27T16:19:57Z
[ "python", "3d", "direct3d" ]
Would it be possible to write a 3D game as large as World of Warcraft in pure Python?
916,663
<p>Would it be possible to write a 3D game as large as World of Warcraft in pure Python? Assuming the use of DirectX / D3D bindings or OpenGL bindings.</p> <p>If not, what would be the largest hold-up to doing such a project in Python? I know games tend to fall into the realm of C and C++ but sometimes people do thing...
10
2009-05-27T16:16:05Z
916,693
<p>Because Python is interpreted there would be a performance hit, as opposed to C/C++, but, you would want to use something like PyOpenGL instead of DirectX though, to run on more operating systems.</p> <p>But, I don't see why you couldn't write such a game in Python.</p>
0
2009-05-27T16:20:34Z
[ "python", "3d", "direct3d" ]
Would it be possible to write a 3D game as large as World of Warcraft in pure Python?
916,663
<p>Would it be possible to write a 3D game as large as World of Warcraft in pure Python? Assuming the use of DirectX / D3D bindings or OpenGL bindings.</p> <p>If not, what would be the largest hold-up to doing such a project in Python? I know games tend to fall into the realm of C and C++ but sometimes people do thing...
10
2009-05-27T16:16:05Z
916,701
<p>Technically, anything is possible in any Turing Complete programming language.</p> <p>Practically though, you will run into trouble making the networking stack out of a high level language, because the server will have to be VERY fast to handle so many players. </p> <p>The gaming side of things on the client, the...
7
2009-05-27T16:21:14Z
[ "python", "3d", "direct3d" ]
Would it be possible to write a 3D game as large as World of Warcraft in pure Python?
916,663
<p>Would it be possible to write a 3D game as large as World of Warcraft in pure Python? Assuming the use of DirectX / D3D bindings or OpenGL bindings.</p> <p>If not, what would be the largest hold-up to doing such a project in Python? I know games tend to fall into the realm of C and C++ but sometimes people do thing...
10
2009-05-27T16:16:05Z
916,704
<p>Yes, you could write it in assembly, or Java, or Python, or brainfuck. It's just how much time you are willing to put into it. Language performance's aren't a major issue anymore, it's more about which algorithms you use, not what language you use.</p>
5
2009-05-27T16:22:05Z
[ "python", "3d", "direct3d" ]
Would it be possible to write a 3D game as large as World of Warcraft in pure Python?
916,663
<p>Would it be possible to write a 3D game as large as World of Warcraft in pure Python? Assuming the use of DirectX / D3D bindings or OpenGL bindings.</p> <p>If not, what would be the largest hold-up to doing such a project in Python? I know games tend to fall into the realm of C and C++ but sometimes people do thing...
10
2009-05-27T16:16:05Z
916,740
<p>While I don't know all the technical details of World of Warcraft, I would say that an MMO of its size could be built in <a href="http://en.wikipedia.org/wiki/Stackless%5FPython">Stackless Python</a>.</p> <p>EVE Online uses it and they have one server for 200,000 users.</p>
14
2009-05-27T16:30:00Z
[ "python", "3d", "direct3d" ]
Would it be possible to write a 3D game as large as World of Warcraft in pure Python?
916,663
<p>Would it be possible to write a 3D game as large as World of Warcraft in pure Python? Assuming the use of DirectX / D3D bindings or OpenGL bindings.</p> <p>If not, what would be the largest hold-up to doing such a project in Python? I know games tend to fall into the realm of C and C++ but sometimes people do thing...
10
2009-05-27T16:16:05Z
916,753
<p>The game <a href="http://minionsofmirth.com/">Minions of Mirth</a> is a full MMO more or less on the scale of WoW, and was done <a href="http://www.garagegames.com/community/forums/viewthread/37703">mostly in Python</a>. The client side used the Torque Game Engine, which is written in C++, but the server code and be...
7
2009-05-27T16:32:33Z
[ "python", "3d", "direct3d" ]
Would it be possible to write a 3D game as large as World of Warcraft in pure Python?
916,663
<p>Would it be possible to write a 3D game as large as World of Warcraft in pure Python? Assuming the use of DirectX / D3D bindings or OpenGL bindings.</p> <p>If not, what would be the largest hold-up to doing such a project in Python? I know games tend to fall into the realm of C and C++ but sometimes people do thing...
10
2009-05-27T16:16:05Z
916,775
<p>Since your main question has already been answered well, I'll answer your latter questions:</p> <blockquote> <p>Would the GIL post a major issue on 3d client performance?</p> </blockquote> <p>In Python 2.6, the <a href="http://docs.python.org/library/multiprocessing.html">multiprocessing</a> library was introduc...
5
2009-05-27T16:38:35Z
[ "python", "3d", "direct3d" ]
Would it be possible to write a 3D game as large as World of Warcraft in pure Python?
916,663
<p>Would it be possible to write a 3D game as large as World of Warcraft in pure Python? Assuming the use of DirectX / D3D bindings or OpenGL bindings.</p> <p>If not, what would be the largest hold-up to doing such a project in Python? I know games tend to fall into the realm of C and C++ but sometimes people do thing...
10
2009-05-27T16:16:05Z
930,968
<p>Just because it might give an interesting read, Civilization is partly written using Python. A google on it returns interesting reading material.</p>
2
2009-05-31T00:46:38Z
[ "python", "3d", "direct3d" ]
Would it be possible to write a 3D game as large as World of Warcraft in pure Python?
916,663
<p>Would it be possible to write a 3D game as large as World of Warcraft in pure Python? Assuming the use of DirectX / D3D bindings or OpenGL bindings.</p> <p>If not, what would be the largest hold-up to doing such a project in Python? I know games tend to fall into the realm of C and C++ but sometimes people do thing...
10
2009-05-27T16:16:05Z
1,004,597
<p>There are some additional real industry examples in addition to Eve Online. The server backend on the Ultima Online 2 project at Origin in the late 90's was mostly Python over a C++ server infrastructure, and the late Tablua Rasa game from NCSoft (with most of the same dev team) had the same architecture.</p> <p>Th...
5
2009-06-17T00:51:39Z
[ "python", "3d", "direct3d" ]
Would it be possible to write a 3D game as large as World of Warcraft in pure Python?
916,663
<p>Would it be possible to write a 3D game as large as World of Warcraft in pure Python? Assuming the use of DirectX / D3D bindings or OpenGL bindings.</p> <p>If not, what would be the largest hold-up to doing such a project in Python? I know games tend to fall into the realm of C and C++ but sometimes people do thing...
10
2009-05-27T16:16:05Z
1,316,198
<p>Python is not interpreted - it is tokenized/'just in time' bytecode 'interpreted' and it doesn't have a VM like Java does. This means, in english, it can be daaaaaamnfast. Not all the time though, it depends on the problem and the libraries, but python is <em>not</em> slow, this is a common misconception even amon...
0
2009-08-22T15:29:28Z
[ "python", "3d", "direct3d" ]
Would it be possible to write a 3D game as large as World of Warcraft in pure Python?
916,663
<p>Would it be possible to write a 3D game as large as World of Warcraft in pure Python? Assuming the use of DirectX / D3D bindings or OpenGL bindings.</p> <p>If not, what would be the largest hold-up to doing such a project in Python? I know games tend to fall into the realm of C and C++ but sometimes people do thing...
10
2009-05-27T16:16:05Z
1,360,670
<p>The answer to what I think your specific question is, "... in pure Python ..." the answer is NO.</p> <p>Python is not fast enough to call OpenGL or DirectX efficently enough to re-create World Of Warcraft at an exceptable frame rate.</p> <p>Like many others have answered, given some high level frame work, it would...
5
2009-09-01T05:27:02Z
[ "python", "3d", "direct3d" ]
Would it be possible to write a 3D game as large as World of Warcraft in pure Python?
916,663
<p>Would it be possible to write a 3D game as large as World of Warcraft in pure Python? Assuming the use of DirectX / D3D bindings or OpenGL bindings.</p> <p>If not, what would be the largest hold-up to doing such a project in Python? I know games tend to fall into the realm of C and C++ but sometimes people do thing...
10
2009-05-27T16:16:05Z
1,656,654
<p>I have been trying my hand at writing 3D games in Python, and given a good rendering framework (my favourite is OGRE) and decent bindings, it is amazing what you can get away with. However, especially with games, you are always trying to squeeze as much as you can out of the hardware. The performance disadvantage of...
4
2009-11-01T08:22:16Z
[ "python", "3d", "direct3d" ]
Would it be possible to write a 3D game as large as World of Warcraft in pure Python?
916,663
<p>Would it be possible to write a 3D game as large as World of Warcraft in pure Python? Assuming the use of DirectX / D3D bindings or OpenGL bindings.</p> <p>If not, what would be the largest hold-up to doing such a project in Python? I know games tend to fall into the realm of C and C++ but sometimes people do thing...
10
2009-05-27T16:16:05Z
1,656,715
<p>As a technologist I know:</p> <p>If it can be written in C\C++ it can be written in assembly (though it will take longer). If it can be written in C\C++ and is not a low-level code - it can be written in any managed environment. WoW is a high-level program that is written in C\C++ python is a managed environment</p...
2
2009-11-01T09:16:19Z
[ "python", "3d", "direct3d" ]
How to debug PYGTK program
916,674
<p>When python raise an exception in the middle of a pygtk signal handling callback, the exception is catched by the gtk main loop, its value printed and the main loop just continue, ignoring it.</p> <p>If you want to debug, with something like pdb (python -m pdb myscript.py), you want that when the exception occure P...
5
2009-05-27T16:17:48Z
916,702
<p>You can't make pdb jump to the exception, since the exception is caught and silenced by gtk's main loop.</p> <p>One of the alternatives is using <code>pdb.set_trace()</code>:</p> <pre><code>import pdb pdb.set_trace() </code></pre> <p>See <a href="http://docs.python.org/library/pdb.html" rel="nofollow">pdb documen...
4
2009-05-27T16:21:23Z
[ "python", "debugging", "gtk", "pygtk" ]
Set up svnperms pre-commit hook
916,758
<p>I'm trying to implement svnperms into a repository, but am having difficulty with a few things:</p> <p>pre-commit has the execute permissions:</p> <pre><code>-rwxrwxr-x 1 svnadm svn 3018 May 27 10:11 pre-commit </code></pre> <p>This is my call to svnperms within pre-commit:</p> <pre><code># Check...
0
2009-05-27T16:34:15Z
917,021
<p>My guess is that the location of the <code>python</code> binary is not in <code>$PATH</code> for the svn server. The shabang line of <code>svnperms.py</code> reads:</p> <pre><code>#!/usr/bin/env python </code></pre> <p>But that assumes that the executable lies in the <code>$PATH</code> of the caller. If you don't...
6
2009-05-27T17:28:47Z
[ "python", "svn", "unix", "pre-commit" ]
Is something like ConfigParser appropriate for saving state (key, value) between runs?
916,779
<p>I want to save a set of key, value pairs (string, int) between runs of a Python program, reload them on subsequent runs and write the changes to be available on the next run.</p> <p>I don't think of this data as a configuration file, but it would fit the ConfigParser capabilities quite well. I would only need two [...
1
2009-05-27T16:39:41Z
916,833
<p>Well, you have better options. You can for example use <a href="http://docs.python.org/library/pickle.html" rel="nofollow">pickle</a> or <a href="http://docs.python.org/library/json.html" rel="nofollow">json</a> format. Pickle serializing module is very easy to use.</p> <pre><code>import cPickle cPickle.dump(obj, o...
15
2009-05-27T16:49:26Z
[ "python", "xml", "perl", "configparser" ]
Is something like ConfigParser appropriate for saving state (key, value) between runs?
916,779
<p>I want to save a set of key, value pairs (string, int) between runs of a Python program, reload them on subsequent runs and write the changes to be available on the next run.</p> <p>I don't think of this data as a configuration file, but it would fit the ConfigParser capabilities quite well. I would only need two [...
1
2009-05-27T16:39:41Z
916,869
<p>For me, <a href="http://pyyaml.org/wiki/PyYAML" rel="nofollow">PyYAML</a> works well for these kind of things. I used to use pickle or ConfigParser before.</p>
8
2009-05-27T16:55:39Z
[ "python", "xml", "perl", "configparser" ]
Is something like ConfigParser appropriate for saving state (key, value) between runs?
916,779
<p>I want to save a set of key, value pairs (string, int) between runs of a Python program, reload them on subsequent runs and write the changes to be available on the next run.</p> <p>I don't think of this data as a configuration file, but it would fit the ConfigParser capabilities quite well. I would only need two [...
1
2009-05-27T16:39:41Z
916,912
<p>Re doing it in bash: If your strings are valid identifiers, you could use environment variables and <code>env</code>.</p>
0
2009-05-27T17:02:14Z
[ "python", "xml", "perl", "configparser" ]
Is something like ConfigParser appropriate for saving state (key, value) between runs?
916,779
<p>I want to save a set of key, value pairs (string, int) between runs of a Python program, reload them on subsequent runs and write the changes to be available on the next run.</p> <p>I don't think of this data as a configuration file, but it would fit the ConfigParser capabilities quite well. I would only need two [...
1
2009-05-27T16:39:41Z
916,939
<p>ConfigParser is a fine way of doing it. There are other ways (the json and cPickle modules already mentioned may be useful) that are also good, depending on whether you want to have text files or binary files and if you want code to work simply in older versions of Python or not.</p> <p>You may want to have a thin ...
2
2009-05-27T17:06:22Z
[ "python", "xml", "perl", "configparser" ]
Is something like ConfigParser appropriate for saving state (key, value) between runs?
916,779
<p>I want to save a set of key, value pairs (string, int) between runs of a Python program, reload them on subsequent runs and write the changes to be available on the next run.</p> <p>I don't think of this data as a configuration file, but it would fit the ConfigParser capabilities quite well. I would only need two [...
1
2009-05-27T16:39:41Z
917,375
<p>Sounds like a job for a <a href="http://en.wikipedia.org/wiki/Dbm" rel="nofollow">dbm</a>. Basically it is a hash that lives external to your program. There are many implementations. In Perl it is trivial to <a href="http://perldoc.perl.org/AnyDBM%5FFile.html" rel="nofollow">tie a dbm to a hash</a> (i.e. make it ...
2
2009-05-27T18:46:12Z
[ "python", "xml", "perl", "configparser" ]
Is something like ConfigParser appropriate for saving state (key, value) between runs?
916,779
<p>I want to save a set of key, value pairs (string, int) between runs of a Python program, reload them on subsequent runs and write the changes to be available on the next run.</p> <p>I don't think of this data as a configuration file, but it would fit the ConfigParser capabilities quite well. I would only need two [...
1
2009-05-27T16:39:41Z
919,084
<p>If you can update the state key by key then any of the DBM databases will work. If you need really high performance and compact storage then Tokyo Cabinet - <a href="http://tokyocabinet.sourceforge.net/" rel="nofollow">http://tokyocabinet.sourceforge.net/</a> is the cool toy.</p> <p>If you want to save and load th...
0
2009-05-28T03:45:52Z
[ "python", "xml", "perl", "configparser" ]
Is there a list of Python packages that are not 64 bit compatible somewhere?
916,952
<p>I am going to move to a 64 bit machine and a 64 bit OS (Windows) and am trying to figure out if any of the extensions/packages I am using are going to be lost when I make the move. I can't seem to find whether someone has built a list of known issues as flagged on the Python 2.5 <a href="http://www.python.org/down...
3
2009-05-27T17:07:22Z
916,964
<p>Perhaps you should figure out what "make a meaningful move up the memory ladder" means. Do you currently need to address more than 4GB of RAM? If not then you don't need a 64-bit system.</p>
3
2009-05-27T17:09:48Z
[ "python", "64bit", "packages" ]
Is there a list of Python packages that are not 64 bit compatible somewhere?
916,952
<p>I am going to move to a 64 bit machine and a 64 bit OS (Windows) and am trying to figure out if any of the extensions/packages I am using are going to be lost when I make the move. I can't seem to find whether someone has built a list of known issues as flagged on the Python 2.5 <a href="http://www.python.org/down...
3
2009-05-27T17:07:22Z
916,983
<p>We're running 2.5 on a 64-bit Red Hat Enterprise Linux server.</p> <p>Everything appears to be working.</p> <p>I would suggest you do what we did. </p> <ol> <li><p>Get a VM.</p></li> <li><p>Load up the app.</p></li> <li><p>Test it.</p></li> </ol> <p>It was easier than trying to do research.</p>
4
2009-05-27T17:15:06Z
[ "python", "64bit", "packages" ]
Is there a list of Python packages that are not 64 bit compatible somewhere?
916,952
<p>I am going to move to a 64 bit machine and a 64 bit OS (Windows) and am trying to figure out if any of the extensions/packages I am using are going to be lost when I make the move. I can't seem to find whether someone has built a list of known issues as flagged on the Python 2.5 <a href="http://www.python.org/down...
3
2009-05-27T17:07:22Z
917,007
<p>It really depends on the specific modules you are using. I am running several 64-bit Linux systems and I have yet to come across problems with any of the C modules that I use.</p> <p>Most C modules can be built from source, so you should read about the Python distribution utility <a href="http://docs.python.org/ins...
1
2009-05-27T17:23:28Z
[ "python", "64bit", "packages" ]
Is there a list of Python packages that are not 64 bit compatible somewhere?
916,952
<p>I am going to move to a 64 bit machine and a 64 bit OS (Windows) and am trying to figure out if any of the extensions/packages I am using are going to be lost when I make the move. I can't seem to find whether someone has built a list of known issues as flagged on the Python 2.5 <a href="http://www.python.org/down...
3
2009-05-27T17:07:22Z
917,067
<p>It seems like you already know this, but it's worth pointing out for the sake of completeness. With that said, remember that you shouldn't have any problems with pure Python packages. </p> <p>Secondly, you also don't necessarily <em>have to</em> install the 64-bit version of Python unless you're planning on runni...
1
2009-05-27T17:39:22Z
[ "python", "64bit", "packages" ]
How does Python OOP compare to PHP OOP?
916,962
<p>I'm basically wondering if Python has any OOP shortcomings like PHP does. PHP has been developing their OOP practices for the last few versions. It's getting better in PHP but it's still not perfect. I'm new to Python and I'm just wondering if Python's OOP support is better or just comparable. </p> <p>If there are...
15
2009-05-27T17:09:28Z
916,974
<p>I would say that Python's OOP support is much better given the fact that it was introduced into the language in its infancy as opposed to PHP which bolted OOP onto an existing procedural model.</p>
21
2009-05-27T17:12:51Z
[ "php", "python", "oop", "comparison" ]
How does Python OOP compare to PHP OOP?
916,962
<p>I'm basically wondering if Python has any OOP shortcomings like PHP does. PHP has been developing their OOP practices for the last few versions. It's getting better in PHP but it's still not perfect. I'm new to Python and I'm just wondering if Python's OOP support is better or just comparable. </p> <p>If there are...
15
2009-05-27T17:09:28Z
916,988
<p>I think they're comparable at this point. As a simple test, I doubt there's any pattern in <a href="http://rads.stackoverflow.com/amzn/click/0201633612" rel="nofollow">Design Patterns</a> or <a href="http://rads.stackoverflow.com/amzn/click/0321127420" rel="nofollow">Patterns of Enterprise Application Architecture<...
3
2009-05-27T17:16:37Z
[ "php", "python", "oop", "comparison" ]
How does Python OOP compare to PHP OOP?
916,962
<p>I'm basically wondering if Python has any OOP shortcomings like PHP does. PHP has been developing their OOP practices for the last few versions. It's getting better in PHP but it's still not perfect. I'm new to Python and I'm just wondering if Python's OOP support is better or just comparable. </p> <p>If there are...
15
2009-05-27T17:09:28Z
917,005
<p>Python's OOP support is very strong; it does allow multiple inheritance, and everything is manipulable as a first-class object (including classes, methods, etc). </p> <p>Polymorphism is expressed through duck typing. For example, you can iterate over a list, a tuple, a dictionary, a file, a web resource, and more a...
8
2009-05-27T17:21:57Z
[ "php", "python", "oop", "comparison" ]
How does Python OOP compare to PHP OOP?
916,962
<p>I'm basically wondering if Python has any OOP shortcomings like PHP does. PHP has been developing their OOP practices for the last few versions. It's getting better in PHP but it's still not perfect. I'm new to Python and I'm just wondering if Python's OOP support is better or just comparable. </p> <p>If there are...
15
2009-05-27T17:09:28Z
917,052
<p>Also: Python has native operator overloading, unlike PHP (although it does exist an extension). Love it or hate it, it's there.</p>
3
2009-05-27T17:35:30Z
[ "php", "python", "oop", "comparison" ]
How does Python OOP compare to PHP OOP?
916,962
<p>I'm basically wondering if Python has any OOP shortcomings like PHP does. PHP has been developing their OOP practices for the last few versions. It's getting better in PHP but it's still not perfect. I'm new to Python and I'm just wondering if Python's OOP support is better or just comparable. </p> <p>If there are...
15
2009-05-27T17:09:28Z
917,054
<p>If you are looking for "more pure" OOP, you should be looking at SmallTalk and/or Ruby.</p> <p>PHP has grown considerably with it's support for OOP, but because of the way it works (reloads everything every time), things can get really slow if OOP best practices are followed. Which is one of the reasons you don't h...
1
2009-05-27T17:35:45Z
[ "php", "python", "oop", "comparison" ]
How does Python OOP compare to PHP OOP?
916,962
<p>I'm basically wondering if Python has any OOP shortcomings like PHP does. PHP has been developing their OOP practices for the last few versions. It's getting better in PHP but it's still not perfect. I'm new to Python and I'm just wondering if Python's OOP support is better or just comparable. </p> <p>If there are...
15
2009-05-27T17:09:28Z
917,143
<p>One aspect of Python's OOP model that is unusual is its encapsulation mechanism. Basically, Python assumes that programmers don't do bad things, and so it doesn't go out of its way to any extent to protect private member variables or methods. </p> <p>It works by mangling names of members that begin with a two und...
7
2009-05-27T17:56:20Z
[ "php", "python", "oop", "comparison" ]
Python equivalent of maplist?
916,978
<p>What's the best Python equivalent of Common Lisp's <code>maplist</code> function? From the <a href="http://www.ai.mit.edu/projects/iiip/doc/CommonLISP/HyperSpec/Body/fun%5Fmapccm%5Fma%5Fistcm%5Fmapcon.html" rel="nofollow">maplist documentation</a>:</p> <blockquote> <p>maplist is like mapcar except that functio...
11
2009-05-27T17:13:40Z
917,028
<p>You can write a little function for that</p> <pre><code>def maplist(func, values): return [map(func, values[i:]) for i in xrange(len(values))] &gt;&gt;&gt; maplist(lambda a: a* 2, [1,2,3]) [[2, 4, 6], [4, 6], [6]] </code></pre> <p><strong>[Edit]</strong></p> <p>if you want to apply the function on the sublis...
11
2009-05-27T17:29:30Z
[ "python", "functional-programming", "lisp" ]
Python equivalent of maplist?
916,978
<p>What's the best Python equivalent of Common Lisp's <code>maplist</code> function? From the <a href="http://www.ai.mit.edu/projects/iiip/doc/CommonLISP/HyperSpec/Body/fun%5Fmapccm%5Fma%5Fistcm%5Fmapcon.html" rel="nofollow">maplist documentation</a>:</p> <blockquote> <p>maplist is like mapcar except that functio...
11
2009-05-27T17:13:40Z
917,029
<p>I think there isn't, but the following function can work:</p> <pre><code>def maplist(func, l): for i in range(len(l)): func(l[i:]) </code></pre>
-1
2009-05-27T17:30:23Z
[ "python", "functional-programming", "lisp" ]
Python equivalent of maplist?
916,978
<p>What's the best Python equivalent of Common Lisp's <code>maplist</code> function? From the <a href="http://www.ai.mit.edu/projects/iiip/doc/CommonLISP/HyperSpec/Body/fun%5Fmapccm%5Fma%5Fistcm%5Fmapcon.html" rel="nofollow">maplist documentation</a>:</p> <blockquote> <p>maplist is like mapcar except that functio...
11
2009-05-27T17:13:40Z
917,044
<p>this works like your example (I've modified reyjavikvi's code)</p> <pre><code>def maplist(func, l): result=[] for i in range(len(l)): result.append(func(l[i:])) return result </code></pre>
1
2009-05-27T17:34:11Z
[ "python", "functional-programming", "lisp" ]
Python equivalent of maplist?
916,978
<p>What's the best Python equivalent of Common Lisp's <code>maplist</code> function? From the <a href="http://www.ai.mit.edu/projects/iiip/doc/CommonLISP/HyperSpec/Body/fun%5Fmapccm%5Fma%5Fistcm%5Fmapcon.html" rel="nofollow">maplist documentation</a>:</p> <blockquote> <p>maplist is like mapcar except that functio...
11
2009-05-27T17:13:40Z
917,051
<p>You can use nested list comprehensions:</p> <pre><code>&gt;&gt;&gt; def p(x): return x &gt;&gt;&gt; l = range(4)[1:] &gt;&gt;&gt; [p([i:]) for i in range(len(l))] [[1, 2, 3], [2, 3], [3]] </code></pre> <p>Which you can use to define maplist yourself:</p> <pre><code>&gt;&gt;&gt; def maplist(p, l): return [p([i:]) ...
1
2009-05-27T17:35:27Z
[ "python", "functional-programming", "lisp" ]
Python equivalent of maplist?
916,978
<p>What's the best Python equivalent of Common Lisp's <code>maplist</code> function? From the <a href="http://www.ai.mit.edu/projects/iiip/doc/CommonLISP/HyperSpec/Body/fun%5Fmapccm%5Fma%5Fistcm%5Fmapcon.html" rel="nofollow">maplist documentation</a>:</p> <blockquote> <p>maplist is like mapcar except that functio...
11
2009-05-27T17:13:40Z
917,278
<p>Modifying Aaron's answer:</p> <pre><code>In [8]: def maplist(p, l): return [p([x for x in l[i:]]) for i in range(len(l))] ...: In [9]: maplist(lambda x: x + x, [1,2,3]) Out[9]: [[1, 2, 3, 1, 2, 3], [2, 3, 2, 3], [3, 3]] </code></pre>
0
2009-05-27T18:23:34Z
[ "python", "functional-programming", "lisp" ]
Python equivalent of maplist?
916,978
<p>What's the best Python equivalent of Common Lisp's <code>maplist</code> function? From the <a href="http://www.ai.mit.edu/projects/iiip/doc/CommonLISP/HyperSpec/Body/fun%5Fmapccm%5Fma%5Fistcm%5Fmapcon.html" rel="nofollow">maplist documentation</a>:</p> <blockquote> <p>maplist is like mapcar except that functio...
11
2009-05-27T17:13:40Z
917,520
<p>Eewww... Slicing a list is a linear-time operation. All of the solutions posted thus far have O(n^2) time complexity. Lisp's maplist, I believe, has O(n).</p> <p>The problem is, Python's list type isn't a linked list. It's a dynamically resizable array (i.e., like C++ STL's "vector" type). </p> <p>If maintaining l...
3
2009-05-27T19:13:39Z
[ "python", "functional-programming", "lisp" ]
Python equivalent of maplist?
916,978
<p>What's the best Python equivalent of Common Lisp's <code>maplist</code> function? From the <a href="http://www.ai.mit.edu/projects/iiip/doc/CommonLISP/HyperSpec/Body/fun%5Fmapccm%5Fma%5Fistcm%5Fmapcon.html" rel="nofollow">maplist documentation</a>:</p> <blockquote> <p>maplist is like mapcar except that functio...
11
2009-05-27T17:13:40Z
917,911
<p>As @Cybis and others mentioned, you can't keep the O(N) complexity with Python lists; you'll have to create a linked list. At the risk of proving <a href="http://en.wikipedia.org/wiki/Greenspun%27s%5FTenth%5FRule" rel="nofollow">Greenspun's 10th rule</a>, here is such a solution:</p> <pre><code>class cons(tuple): ...
6
2009-05-27T20:39:28Z
[ "python", "functional-programming", "lisp" ]
Python equivalent of maplist?
916,978
<p>What's the best Python equivalent of Common Lisp's <code>maplist</code> function? From the <a href="http://www.ai.mit.edu/projects/iiip/doc/CommonLISP/HyperSpec/Body/fun%5Fmapccm%5Fma%5Fistcm%5Fmapcon.html" rel="nofollow">maplist documentation</a>:</p> <blockquote> <p>maplist is like mapcar except that functio...
11
2009-05-27T17:13:40Z
925,611
<h3>O(N) implementation of <code>maplist()</code> for linked lists</h3> <pre><code>maplist = lambda f, lst: cons(f(lst), maplist(f, cdr(lst))) if lst else lst </code></pre> <p>See <a href="http://stackoverflow.com/questions/280243/python-linked-list">Python Linked List</a> question.</p>
1
2009-05-29T11:40:27Z
[ "python", "functional-programming", "lisp" ]
Python equivalent of maplist?
916,978
<p>What's the best Python equivalent of Common Lisp's <code>maplist</code> function? From the <a href="http://www.ai.mit.edu/projects/iiip/doc/CommonLISP/HyperSpec/Body/fun%5Fmapccm%5Fma%5Fistcm%5Fmapcon.html" rel="nofollow">maplist documentation</a>:</p> <blockquote> <p>maplist is like mapcar except that functio...
11
2009-05-27T17:13:40Z
9,757,474
<p>Python has a linked list type, called <code>deque</code>:</p> <pre><code>from collections import deque def maplist(f, lst): linked = deque(lst) results = [] while linked: results.append(f(linked)) linked.popleft() # assumes left is head, as in lisp return results In [134]: maplist...
1
2012-03-18T10:09:18Z
[ "python", "functional-programming", "lisp" ]
WxPython differences between Windows and Linux
916,987
<p>The tutorials I've found on WxPython all use examples from Linux, but there seem to be differences in some details.</p> <p>For example, in Windows a Panel behind the widgets is mandatory to show the background properly. Additionally, some examples that look fine in the tutorials don't work in my computer.</p> <p>S...
1
2009-05-27T17:16:34Z
917,040
<blockquote> <p><strong>EDIT:</strong> I just remembered this: Does anybody know why when subclassing wx.App an OnInit() method is required, rather than the more logical <code>__init__()</code>?</p> </blockquote> <p>I use <code>OnInit()</code> for symmetry: there's also an <code>OnExit()</code> method.</p> <p>Edit...
0
2009-05-27T17:33:12Z
[ "python", "windows", "linux", "user-interface", "wxpython" ]
WxPython differences between Windows and Linux
916,987
<p>The tutorials I've found on WxPython all use examples from Linux, but there seem to be differences in some details.</p> <p>For example, in Windows a Panel behind the widgets is mandatory to show the background properly. Additionally, some examples that look fine in the tutorials don't work in my computer.</p> <p>S...
1
2009-05-27T17:16:34Z
917,063
<p>I've noticed odd peculiarities in a small GUI I wrote a while back, but it's been a long time since I tried to the specifics are a rather distant memory. Do you have some specific examples which fail? Maybe we can improve them and fix the bugs?</p> <p>Have you tried <a href="http://www.wxpython.org/tut-part1.php" r...
2
2009-05-27T17:38:02Z
[ "python", "windows", "linux", "user-interface", "wxpython" ]