title
stringlengths
10
172
question_id
int64
469
40.1M
question_body
stringlengths
22
48.2k
question_score
int64
-44
5.52k
question_date
stringlengths
20
20
answer_id
int64
497
40.1M
answer_body
stringlengths
18
33.9k
answer_score
int64
-38
8.38k
answer_date
stringlengths
20
20
tags
list
Python hexadecimal comparison
1,888,114
<p>Hey guys, I got a problem I was hoping someone could help me figure out! </p> <p>I have a string with a hexadecimal number = <code>'0x00000000'</code> which means: </p> <pre><code>0x01000000 = apple 0x00010000 = orange 0x00000100 = banana </code></pre> <p>All combinations with those are possible. i.e., <code...
3
2009-12-11T13:35:41Z
1,888,154
<pre><code>def WhichFruit(n): if n &amp; int('0x01000000',16): print 'apple' if n &amp; int('0x00010000',16): print 'orange' if n &amp; int('0x00000100',16): print 'banana' WhichFruit(int('0x01010000',16)) </code></pre>
0
2009-12-11T13:43:16Z
[ "python", "hex" ]
give an active to class to active link
1,888,519
<p>I am writing a python website built on the back of the django framework, I am looking for a way to highlight the current link the user is on depening on what the URL, I thought doing some thing like this would work.</p> <p>What I have done is create a new application called <code>nav</code> and built some templatet...
0
2009-12-11T14:45:05Z
1,888,571
<p>Some things to check:</p> <p>Is the <code>request</code> object actually in your context? Are you passing it in specifically, or are you using a <code>RequestContext</code>?</p> <p>Why are you defining regexes in your templatetags, rather than using the built-in <code>reverse</code> function to look them up in the...
0
2009-12-11T14:52:50Z
[ "python", "django", "django-templates", "templatetags" ]
numpy : How to convert an array type quickly
1,888,870
<p>I find the astype() method of numpy arrays not very efficient. I have an array containing 3 million of Uint8 point. Multiplying it by a 3x3 matrix takes 2 second, but converting the result from uint16 to uint8 takes another second.</p> <p>More precisely :</p> <pre><code> print time.clock() imgarray = np.dot...
13
2009-12-11T15:35:31Z
1,889,627
<p>When you use <code>imgarray = imgarray.astype('B')</code>, you get a copy of the array, cast to the specified type. This requires extra memory allocation, even though you immediately flip imgarray to point to the newly allocated array.</p> <p>If you use <code>imgarray.view('uint8')</code>, then you get a view of th...
23
2009-12-11T17:34:10Z
[ "python", "numpy" ]
How to Sort Arrays in Dictionary?
1,888,910
<p>I'm currently writing a program in Python to track statistics on video games. An example of the dictionary I'm using to track the scores :</p> <pre><code>ten = 1 sec = 9 fir = 10 thi5 = 6 sec5 = 8 games = { 'adom': [ten+fir+sec+sec5, "Ancient Domain of Mysteries"], 'nethack': [fir+fir+fir+sec+thi5,...
0
2009-12-11T15:43:29Z
1,888,968
<p>How about something like this:</p> <pre><code>scores = games.items() scores.sort(key = lambda key, value: value[0]) return scores[:10] </code></pre> <p>This will return the first 10 items, sorted by the first item in the array. I'm not sure if this is what you want though, please update the question (and fix the e...
3
2009-12-11T15:51:35Z
[ "python", "arrays", "dictionary", "sorting", "logic" ]
How to Sort Arrays in Dictionary?
1,888,910
<p>I'm currently writing a program in Python to track statistics on video games. An example of the dictionary I'm using to track the scores :</p> <pre><code>ten = 1 sec = 9 fir = 10 thi5 = 6 sec5 = 8 games = { 'adom': [ten+fir+sec+sec5, "Ancient Domain of Mysteries"], 'nethack': [fir+fir+fir+sec+thi5,...
0
2009-12-11T15:43:29Z
1,889,064
<pre><code>import heapq return heapq.nlargest(10, games.iteritems(), key=lambda k, v: v[0]) </code></pre> <p>is the most direct way to get the top ten key / value pairs, sorted by the first item of each "value" list. If you can define more precisely what output you want (just the names, the name / value pairs, or wh...
2
2009-12-11T16:07:39Z
[ "python", "arrays", "dictionary", "sorting", "logic" ]
How to Sort Arrays in Dictionary?
1,888,910
<p>I'm currently writing a program in Python to track statistics on video games. An example of the dictionary I'm using to track the scores :</p> <pre><code>ten = 1 sec = 9 fir = 10 thi5 = 6 sec5 = 8 games = { 'adom': [ten+fir+sec+sec5, "Ancient Domain of Mysteries"], 'nethack': [fir+fir+fir+sec+thi5,...
0
2009-12-11T15:43:29Z
1,889,092
<p>Wim's solution is good, but I'd say that you should probably go the extra mile and push this work off onto a database, rather than relying on Python. Python interfaces well with most types of databases, where much of what you're exploring is already a solved problem.</p> <p>For example, instead of worrying about sh...
0
2009-12-11T16:11:32Z
[ "python", "arrays", "dictionary", "sorting", "logic" ]
Problem creating N*N*N list in Python
1,889,080
<p>I'm trying to create a 3-dimensional N*N*N list in Python, like such:</p> <pre><code>n=3 l = [[[0,]*n]*n]*n </code></pre> <p>Unfortunately, this does not seem to properly "clone" the list, as I thought it would:</p> <pre><code>&gt;&gt;&gt; l [[[0, 0, 0], [0, 0, 0], [0, 0, 0]], [[0, 0, 0], [0, 0, 0], [0, 0, 0]], [...
2
2009-12-11T16:10:04Z
1,889,106
<p>It's not cloning the list. It's inserting a reference to the same list over and over. Try creating the list using a set of nested for loops.</p>
2
2009-12-11T16:13:46Z
[ "python", "list", "mutable" ]
Problem creating N*N*N list in Python
1,889,080
<p>I'm trying to create a 3-dimensional N*N*N list in Python, like such:</p> <pre><code>n=3 l = [[[0,]*n]*n]*n </code></pre> <p>Unfortunately, this does not seem to properly "clone" the list, as I thought it would:</p> <pre><code>&gt;&gt;&gt; l [[[0, 0, 0], [0, 0, 0], [0, 0, 0]], [[0, 0, 0], [0, 0, 0], [0, 0, 0]], [...
2
2009-12-11T16:10:04Z
1,889,112
<p>The problem is that <code>* n</code> does a shallow copy of the list. A solution is to use nested loops, or try the numpy library.</p>
5
2009-12-11T16:14:45Z
[ "python", "list", "mutable" ]
Problem creating N*N*N list in Python
1,889,080
<p>I'm trying to create a 3-dimensional N*N*N list in Python, like such:</p> <pre><code>n=3 l = [[[0,]*n]*n]*n </code></pre> <p>Unfortunately, this does not seem to properly "clone" the list, as I thought it would:</p> <pre><code>&gt;&gt;&gt; l [[[0, 0, 0], [0, 0, 0], [0, 0, 0]], [[0, 0, 0], [0, 0, 0], [0, 0, 0]], [...
2
2009-12-11T16:10:04Z
1,889,134
<p>As others have mentioned, it's building the 2nd and 3rd levels with references, not clones. Try:</p> <pre><code>&gt;&gt;&gt; n = 3 &gt;&gt;&gt; l = [[[0]*n for _ in xrange(n)] for _ in xrange(n)] &gt;&gt;&gt; l[0][0][0] = 1 &gt;&gt;&gt; l [[[1, 0, 0], [0, 0, 0], [0, 0, 0]], [[0, 0, 0], [0, 0, 0], [0, 0, 0]], [[...
3
2009-12-11T16:18:58Z
[ "python", "list", "mutable" ]
Problem creating N*N*N list in Python
1,889,080
<p>I'm trying to create a 3-dimensional N*N*N list in Python, like such:</p> <pre><code>n=3 l = [[[0,]*n]*n]*n </code></pre> <p>Unfortunately, this does not seem to properly "clone" the list, as I thought it would:</p> <pre><code>&gt;&gt;&gt; l [[[0, 0, 0], [0, 0, 0], [0, 0, 0]], [[0, 0, 0], [0, 0, 0], [0, 0, 0]], [...
2
2009-12-11T16:10:04Z
1,891,074
<p>If you want to do numerical processing with 3-d matrix you are better of using numpy. It is quite easy:</p> <pre><code>&gt;&gt;&gt; import numpy &gt;&gt;&gt; numpy.zeros((3,3,3), dtype=numpy.int) array([[[0, 0, 0], [0, 0, 0], [0, 0, 0]], [[0, 0, 0], [0, 0, 0], [0, 0, 0]], ...
4
2009-12-11T21:45:43Z
[ "python", "list", "mutable" ]
Problem creating N*N*N list in Python
1,889,080
<p>I'm trying to create a 3-dimensional N*N*N list in Python, like such:</p> <pre><code>n=3 l = [[[0,]*n]*n]*n </code></pre> <p>Unfortunately, this does not seem to properly "clone" the list, as I thought it would:</p> <pre><code>&gt;&gt;&gt; l [[[0, 0, 0], [0, 0, 0], [0, 0, 0]], [[0, 0, 0], [0, 0, 0], [0, 0, 0]], [...
2
2009-12-11T16:10:04Z
1,891,126
<p>I have to second what leonardo-santagada suggested, with the addition that creating N dimensional arrays/lists is very unpythonic and you should reconsider how you're keeping your data and seeing if it doesn't belong better in a class or a list of dictionaries (or dictionaries of lists). </p>
2
2009-12-11T21:56:44Z
[ "python", "list", "mutable" ]
Writing to stdout from within a Microsoft VBA macro
1,889,175
<p>I'm using Python (and the Win32 extensions) to execute macros in an Excel spreadsheet via the COM interface, as shown below:</p> <pre><code>import win32com.client o = win32com.client.Dispatch("Excel.Application") o.Visible = 1 o.Workbooks.Open (r"C:\test.xls") o.Application.Run("macro1") </code></pre> <p>What I'd ...
2
2009-12-11T16:25:12Z
1,889,208
<p>What happens if you write to stdout? Either:</p> <pre><code>print "Hello, world!" </code></pre> <p>or:</p> <pre><code>import sys sys.stdout.write("Hello, world!\n") </code></pre> <p>or even:</p> <pre><code>import sys sys.__stdout__.write("Hello, world!\n") </code></pre> <p><code>sys.stdout</code> is the curre...
0
2009-12-11T16:31:02Z
[ "python", "vba", "com", "excel-vba", "stdout" ]
Writing to stdout from within a Microsoft VBA macro
1,889,175
<p>I'm using Python (and the Win32 extensions) to execute macros in an Excel spreadsheet via the COM interface, as shown below:</p> <pre><code>import win32com.client o = win32com.client.Dispatch("Excel.Application") o.Visible = 1 o.Workbooks.Open (r"C:\test.xls") o.Application.Run("macro1") </code></pre> <p>What I'd ...
2
2009-12-11T16:25:12Z
1,896,466
<p>You almost certainly have to use Win32 API to get anywhere here. The question <a href="http://stackoverflow.com/questions/1692987/redirect-stdout-to-an-edit-control-win32">http://stackoverflow.com/questions/1692987/redirect-stdout-to-an-edit-control-win32</a> refers to using stdin/stdout in a GUI application. Unfo...
0
2009-12-13T13:09:21Z
[ "python", "vba", "com", "excel-vba", "stdout" ]
Writing to stdout from within a Microsoft VBA macro
1,889,175
<p>I'm using Python (and the Win32 extensions) to execute macros in an Excel spreadsheet via the COM interface, as shown below:</p> <pre><code>import win32com.client o = win32com.client.Dispatch("Excel.Application") o.Visible = 1 o.Workbooks.Open (r"C:\test.xls") o.Application.Run("macro1") </code></pre> <p>What I'd ...
2
2009-12-11T16:25:12Z
1,896,650
<p>You can write to and read stdout with VB6 with a bit of drama.. but creating a console app with Excel and VBA? I'm not sure that is possible.</p> <p>I've found a simple <a href="http://snippets.dzone.com/posts/show/2036" rel="nofollow">Python COM example</a> which you may have already investigated. Could you make y...
1
2009-12-13T14:26:10Z
[ "python", "vba", "com", "excel-vba", "stdout" ]
Writing to stdout from within a Microsoft VBA macro
1,889,175
<p>I'm using Python (and the Win32 extensions) to execute macros in an Excel spreadsheet via the COM interface, as shown below:</p> <pre><code>import win32com.client o = win32com.client.Dispatch("Excel.Application") o.Visible = 1 o.Workbooks.Open (r"C:\test.xls") o.Application.Run("macro1") </code></pre> <p>What I'd ...
2
2009-12-11T16:25:12Z
1,896,823
<p>One solution is to write a COM server in Python. The VBA macro could instantiate the COM server, and then send it messages.</p> <p>Once you've sent the data from VBA to your Python COM server, writing to stdout via a console application would be tricky, but you could write to a file, a web browser (via COM automati...
1
2009-12-13T15:29:30Z
[ "python", "vba", "com", "excel-vba", "stdout" ]
SQLAlchemy Many-to-Many Relationship on a Single Table
1,889,251
<p>I have a SQLAlchemy model set up in my application that should mimic the functionality of "followers" on Twitter, ie. users have have a many-to-many relationship with eachother (both followers and following). The tables are structured as follows (sa is the sqlalchemy module):</p> <pre><code>t_users = sa.Table("use...
10
2009-12-11T16:39:51Z
1,889,593
<p>You have to write <code>primaryjoin</code> and <code>secondaryjoin</code> conditions explicitly in this case:</p> <pre><code>mapper( User, t_users, properties={ 'followers': relation( User, secondary=t_follows, primaryjoin=(t_follows.c.followee_id==t_users.c.id), ...
6
2009-12-11T17:28:09Z
[ "python", "orm", "sqlalchemy" ]
SQLAlchemy Many-to-Many Relationship on a Single Table
1,889,251
<p>I have a SQLAlchemy model set up in my application that should mimic the functionality of "followers" on Twitter, ie. users have have a many-to-many relationship with eachother (both followers and following). The tables are structured as follows (sa is the sqlalchemy module):</p> <pre><code>t_users = sa.Table("use...
10
2009-12-11T16:39:51Z
5,652,169
<p>You can also do this declaratively.</p> <p>Here is a similar example based on teh above code, I do use the backref.</p> <pre><code>VolumeRelationship = Table( 'VolumeRelationship', Base.metadata, Column('ParentID', Integer, ForeignKey('Volumes.ID')), Column('VolumeID', Integer, ForeignKey('Volumes.ID')...
13
2011-04-13T16:01:51Z
[ "python", "orm", "sqlalchemy" ]
setting XML value using xmlrpc & python
1,889,313
<p>I need to set the value of a field in an XML file which exists on a remote Linux box. How do I find out which port I should connect to ? But even a proper ping is not happening:</p> <pre><code>import xmlrpclib server = xmlrpclib.ServerProxy('http://10.77.21.240:9000') print server.ping() print "I'm in hurray" </c...
0
2009-12-11T16:47:10Z
1,894,206
<p>A couple of things to try / think about:</p> <ol> <li><p>Go to a command prompt on the remote host and type "<code>netstat -nap | grep 9000</code>". If you don't get back something interesting it means that nothing is running at port 9000.</p></li> <li><p>You show the remote host at 10.77.21.240. This is an unrouta...
2
2009-12-12T17:57:48Z
[ "python", "xml", "xml-rpc" ]
List of dictionaries, in a dictionary - in Python
1,889,385
<p>I have a case where I need to construct following structure <strong>programmatically</strong> (yes I am aware of .setdefault and defaultdict but I can not get what I want)</p> <p>I basically need a dictionary, with a dictionary of dictionaries created within the loop. At the beginning the structure is completely bl...
2
2009-12-11T16:58:44Z
1,889,441
<p>Example, that you've posted is not a valid python code, I could only imagine that you're trying to do something like this:</p> <pre><code>self.rules[a] = [{b:{'f_expr': c, 'c_expr': d}}] </code></pre> <p>this way <code>self.rules</code> is a dictionary of a list of a dictionary of a dictionary. I bet there is mor...
5
2009-12-11T17:07:34Z
[ "python", "list", "dictionary", "nested" ]
List of dictionaries, in a dictionary - in Python
1,889,385
<p>I have a case where I need to construct following structure <strong>programmatically</strong> (yes I am aware of .setdefault and defaultdict but I can not get what I want)</p> <p>I basically need a dictionary, with a dictionary of dictionaries created within the loop. At the beginning the structure is completely bl...
2
2009-12-11T16:58:44Z
1,889,449
<p>Your example code doesn't seem to be valid Python. It's not clear if the second level element is supposed to be a list or a dictionary.</p> <p>However, if you're doing what I think you're doing, and it's a dictionary, you could use a tuple as a key in the top-level dictionary instead of nesting dictionaries:</p> ...
0
2009-12-11T17:08:37Z
[ "python", "list", "dictionary", "nested" ]
List of dictionaries, in a dictionary - in Python
1,889,385
<p>I have a case where I need to construct following structure <strong>programmatically</strong> (yes I am aware of .setdefault and defaultdict but I can not get what I want)</p> <p>I basically need a dictionary, with a dictionary of dictionaries created within the loop. At the beginning the structure is completely bl...
2
2009-12-11T16:58:44Z
1,889,468
<p>My favorite way to deal with nested dictionaries &amp; lists of dictionaries is to use <a href="http://pyyaml.org/" rel="nofollow">PyYAML</a>. <a href="http://stackoverflow.com/questions/635483/what-is-the-best-way-to-implement-nested-dictionaries-in-python/636138#636138">See this response for details</a>.</p>
0
2009-12-11T17:11:45Z
[ "python", "list", "dictionary", "nested" ]
List of dictionaries, in a dictionary - in Python
1,889,385
<p>I have a case where I need to construct following structure <strong>programmatically</strong> (yes I am aware of .setdefault and defaultdict but I can not get what I want)</p> <p>I basically need a dictionary, with a dictionary of dictionaries created within the loop. At the beginning the structure is completely bl...
2
2009-12-11T16:58:44Z
1,889,554
<pre><code>rules = {} failure = 'hard_failure' rules[failure] = [] for row in rows: #this is what people are referring to below. You left out the addition of the dictionary structure to the list. rules[failure][row[0]] = {} rules[failure][row[0]]['type 1'] = row[1] rules[failure][row[0]]['type 2'] = row[2]...
1
2009-12-11T17:22:41Z
[ "python", "list", "dictionary", "nested" ]
List of dictionaries, in a dictionary - in Python
1,889,385
<p>I have a case where I need to construct following structure <strong>programmatically</strong> (yes I am aware of .setdefault and defaultdict but I can not get what I want)</p> <p>I basically need a dictionary, with a dictionary of dictionaries created within the loop. At the beginning the structure is completely bl...
2
2009-12-11T16:58:44Z
1,890,201
<p>Well, I apologize for the confusion, I never claimed that code actually compiled, hence (pseudo). Arthur Thomas put me on the right track, here is slightly modified version. (Yes, now its a simply nested dictionary, 3 levels down)</p> <pre><code> RULE_k = 'hard_failure' self.rules = {} for row in rows: ...
0
2009-12-11T19:05:02Z
[ "python", "list", "dictionary", "nested" ]
Deleting directory in Python
1,889,597
<p><code>shutil.rmtree</code> will not delete read-only files on Windows. Is there a python equivalent of "rm -rf" ? Why oh why is this such a pain?</p>
25
2009-12-11T17:29:20Z
1,889,631
<p>There's a comment at the <a href="http://code.activestate.com/recipes/193736/" rel="nofollow">ActiveState</a> site that says:</p> <blockquote> <p>shutil.rmtree has its shortcomings. Although it is true you can use shutil.rmtree() in many cases, there are some cases where it does not work. For example, files that ...
2
2009-12-11T17:34:30Z
[ "python", "directory", "delete-file" ]
Deleting directory in Python
1,889,597
<p><code>shutil.rmtree</code> will not delete read-only files on Windows. Is there a python equivalent of "rm -rf" ? Why oh why is this such a pain?</p>
25
2009-12-11T17:29:20Z
1,889,632
<p>If you import win32api from PyWin32, you can use:</p> <pre><code>win32api.SetFileAttributes(path, win32con.FILE_ATTRIBUTE_NORMAL) </code></pre> <p>To make files cease to be read-only.</p>
3
2009-12-11T17:34:38Z
[ "python", "directory", "delete-file" ]
Deleting directory in Python
1,889,597
<p><code>shutil.rmtree</code> will not delete read-only files on Windows. Is there a python equivalent of "rm -rf" ? Why oh why is this such a pain?</p>
25
2009-12-11T17:29:20Z
1,889,686
<p><code>shutil.rmtree</code> can take an error-handling function that will be called when it has problem removing a file. You can use that to force the removal of the problematic file(s).</p> <p>Inspired by <a href="http://mail.python.org/pipermail/tutor/2006-June/047551.html">http://mail.python.org/pipermail/tutor/...
32
2009-12-11T17:41:23Z
[ "python", "directory", "delete-file" ]
Deleting directory in Python
1,889,597
<p><code>shutil.rmtree</code> will not delete read-only files on Windows. Is there a python equivalent of "rm -rf" ? Why oh why is this such a pain?</p>
25
2009-12-11T17:29:20Z
1,891,271
<p>Here is a variant of what Steve posted, it uses the same basic mechanism, and this one <em>is</em> tested :-)</p> <p><a href="http://stackoverflow.com/questions/1213706/what-user-do-python-scripts-run-as-in-windows/1214935#1214935">http://stackoverflow.com/questions/1213706/what-user-do-python-scripts-run-as-in-win...
2
2009-12-11T22:26:01Z
[ "python", "directory", "delete-file" ]
Deleting directory in Python
1,889,597
<p><code>shutil.rmtree</code> will not delete read-only files on Windows. Is there a python equivalent of "rm -rf" ? Why oh why is this such a pain?</p>
25
2009-12-11T17:29:20Z
25,812,140
<p>Another way is to define rmtree on Windows as </p> <pre><code>rmtree = lambda path: subprocess.check_call(['cmd', '/c', 'rd', '/s', '/q', path]) </code></pre>
3
2014-09-12T15:49:52Z
[ "python", "directory", "delete-file" ]
Deleting directory in Python
1,889,597
<p><code>shutil.rmtree</code> will not delete read-only files on Windows. Is there a python equivalent of "rm -rf" ? Why oh why is this such a pain?</p>
25
2009-12-11T17:29:20Z
28,072,346
<p>This will presumably be fixed with the release of <strong>Python 3.5</strong> (currently - June 2015 - still in development) in the sense of giving a hint about this in the documentation.</p> <p>You can find the bugreport <a href="http://bugs.python.org/issue19643" rel="nofollow">here</a>. And <a href="https://hg.p...
1
2015-01-21T16:39:48Z
[ "python", "directory", "delete-file" ]
How to replace models.py in Django app in the production server
1,889,622
<p>I have a simple django app that is using only the admin. This is the model as is now in the server:</p> <pre><code>from django.db import models class School(models.Model): school = models.CharField(max_length=200) def __unicode__(self): return self.school class Lawyer(models.Model): first ...
-1
2009-12-11T17:33:14Z
1,889,648
<p>No, you cannot just replace models.py. You need some kind of schema migration. If you don't use a tool like django south, you'll have to do it manually.</p> <p>Look at <a href="http://www.sqlite.org/lang%5Faltertable.html" rel="nofollow">http://www.sqlite.org/lang%5Faltertable.html</a> You can use manage.py sqlall ...
0
2009-12-11T17:37:06Z
[ "python", "django", "sqlite3" ]
How to replace models.py in Django app in the production server
1,889,622
<p>I have a simple django app that is using only the admin. This is the model as is now in the server:</p> <pre><code>from django.db import models class School(models.Model): school = models.CharField(max_length=200) def __unicode__(self): return self.school class Lawyer(models.Model): first ...
-1
2009-12-11T17:33:14Z
1,889,650
<p>Since you're using a sqlite database, and you want to clear the data anyway, this is dead easy. Add your two fields, move your database to a backup location, and re-run manage.py syncdb. It will set up the new database for you. If you need to keep your old data, you are using a more complex database, or you want ...
0
2009-12-11T17:37:19Z
[ "python", "django", "sqlite3" ]
How to replace models.py in Django app in the production server
1,889,622
<p>I have a simple django app that is using only the admin. This is the model as is now in the server:</p> <pre><code>from django.db import models class School(models.Model): school = models.CharField(max_length=200) def __unicode__(self): return self.school class Lawyer(models.Model): first ...
-1
2009-12-11T17:33:14Z
1,889,653
<p>Run a <a href="http://docs.djangoproject.com/en/dev/ref/django-admin/#sqlall-appname-appname" rel="nofollow">manage.py sqlall </a> on your project</p> <p>This will dump the SQL create command</p> <p>From there, look at the dump for your new columns, and use this to help create your <a href="http://www.sqlite.org/l...
0
2009-12-11T17:37:47Z
[ "python", "django", "sqlite3" ]
How to replace models.py in Django app in the production server
1,889,622
<p>I have a simple django app that is using only the admin. This is the model as is now in the server:</p> <pre><code>from django.db import models class School(models.Model): school = models.CharField(max_length=200) def __unicode__(self): return self.school class Lawyer(models.Model): first ...
-1
2009-12-11T17:33:14Z
1,889,667
<p>Modifying a model on a live Django environment can be a bit of a hassle, depending on your approach.</p> <p>If you don't mind losing data, a simple <code>manage.py</code> command will do the trick:</p> <pre><code>python manage.py reset [app name] </code></pre> <p>If, however, you want to retain the data that's al...
0
2009-12-11T17:39:18Z
[ "python", "django", "sqlite3" ]
How to replace models.py in Django app in the production server
1,889,622
<p>I have a simple django app that is using only the admin. This is the model as is now in the server:</p> <pre><code>from django.db import models class School(models.Model): school = models.CharField(max_length=200) def __unicode__(self): return self.school class Lawyer(models.Model): first ...
-1
2009-12-11T17:33:14Z
1,890,348
<p>You can use <code>python manage.py sqlall &lt;appname&gt; | grep &lt;column name&gt;</code> to get the SQL definition of a particular column.</p> <p>Then, you can do something like: <code>ALTER TABLE my_table ADD COLUMN 'column_name' varchar(30);</code></p> <p>(In this case, the manage.py line above returned '<cod...
0
2009-12-11T19:29:57Z
[ "python", "django", "sqlite3" ]
How can I get the target platform info of a dll with Python 3.1.1?
1,889,694
<p>I have many dll files and I would like to select them into two different folders (PC and PPC). For this I need to know the target platform of the dll file or any other details about its platform.</p> <p>I use Python 3.1.1. I have tried the win32api which does not compatible with this Python version. So, I tried to ...
1
2009-12-11T17:42:51Z
1,900,108
<p>I found a solution based on the dll file structure. Here is the part of my code:</p> <pre><code>def DLLIdentifier( self ): ''' Microsoft Portable Executable and Common Object File Format Specification http://www.microsoft.com/whdc/system/platform/firmware/PECOFF.mspx After the MS DOS stub, at t...
0
2009-12-14T10:28:02Z
[ "python", "api", "dll", "winapi", "platform" ]
Code bacteria: evolving mathematical behavior
1,889,810
<p>It would not be my intention to put a link on my blog, but I don't have any other method to clarify what I really mean. The article is quite long, and it's in three parts (<a href="http://forthescience.org/blog/2009/05/15/pythonic-evolution-part-1/" rel="nofollow">1</a>,<a href="http://forthescience.org/blog/2009/05...
9
2009-12-11T18:00:27Z
1,889,827
<p>The free utility <a href="http://ccsl.mae.cornell.edu/eureqa" rel="nofollow">Eureqa</a> is similar in the sense that in can create fitting symbolic functions (much more complicated than simple linear regression, etc.) based on multivariate input data. But, it uses GA to come up with the functions, so I'm not sure i...
2
2009-12-11T18:02:57Z
[ "python", "genetic-programming", "evolutionary-algorithm" ]
Code bacteria: evolving mathematical behavior
1,889,810
<p>It would not be my intention to put a link on my blog, but I don't have any other method to clarify what I really mean. The article is quite long, and it's in three parts (<a href="http://forthescience.org/blog/2009/05/15/pythonic-evolution-part-1/" rel="nofollow">1</a>,<a href="http://forthescience.org/blog/2009/05...
9
2009-12-11T18:00:27Z
1,889,855
<p>If you are optimising the code, perhaps you are engaged in <b><a href="http://en.wikipedia.org/wiki/Genetic_programming" rel="nofollow">genetic programming</a></b>?</p>
10
2009-12-11T18:06:36Z
[ "python", "genetic-programming", "evolutionary-algorithm" ]
Code bacteria: evolving mathematical behavior
1,889,810
<p>It would not be my intention to put a link on my blog, but I don't have any other method to clarify what I really mean. The article is quite long, and it's in three parts (<a href="http://forthescience.org/blog/2009/05/15/pythonic-evolution-part-1/" rel="nofollow">1</a>,<a href="http://forthescience.org/blog/2009/05...
9
2009-12-11T18:00:27Z
1,889,891
<p>Are you familiar with <a href="http://en.wikipedia.org/wiki/Core%5FWar" rel="nofollow">Core Wars</a>? I remember there were a number of code evolvers written for the game which had some success. For example, <a href="http://www.cad.polito.it/ugp3//" rel="nofollow">MicroGP++</a> is an assembly code generator that can...
1
2009-12-11T18:12:27Z
[ "python", "genetic-programming", "evolutionary-algorithm" ]
Code bacteria: evolving mathematical behavior
1,889,810
<p>It would not be my intention to put a link on my blog, but I don't have any other method to clarify what I really mean. The article is quite long, and it's in three parts (<a href="http://forthescience.org/blog/2009/05/15/pythonic-evolution-part-1/" rel="nofollow">1</a>,<a href="http://forthescience.org/blog/2009/05...
9
2009-12-11T18:00:27Z
1,921,009
<p>Nice article, I would say you're talking about "gene expression programming" rather than "genetic programming", btw.</p>
2
2009-12-17T11:06:13Z
[ "python", "genetic-programming", "evolutionary-algorithm" ]
Sending the variable's content to my mailbox in Python?
1,889,912
<p>I have asked this question here about a Python command that fetches a URL of a web page and stores it in a variable. The first thing that I wanted to know then was whether or not the variable in this code contains the HTML code of a web-page:</p> <pre><code>from google.appengine.api import urlfetch url = "http://ww...
0
2009-12-11T18:14:51Z
1,890,049
<p>for info on sending Content-Type header, see here:<br> <a href="http://code.google.com/appengine/docs/python/urlfetch/overview.html#Request%5FHeaders" rel="nofollow">http://code.google.com/appengine/docs/python/urlfetch/overview.html#Request%5FHeaders</a></p>
1
2009-12-11T18:38:42Z
[ "python", "google-app-engine", "url", "header", "content-type" ]
Sending the variable's content to my mailbox in Python?
1,889,912
<p>I have asked this question here about a Python command that fetches a URL of a web page and stores it in a variable. The first thing that I wanted to know then was whether or not the variable in this code contains the HTML code of a web-page:</p> <pre><code>from google.appengine.api import urlfetch url = "http://ww...
0
2009-12-11T18:14:51Z
1,890,059
<p>If you look at the Google App Engine documentation for the <a href="http://code.google.com/appengine/docs/python/urlfetch/responseobjects.html" rel="nofollow">response object</a>, the result of <code>urlfetch.fetch()</code> contains the member <code>headers</code> which contains the HTTP response headers, as a mappi...
1
2009-12-11T18:40:51Z
[ "python", "google-app-engine", "url", "header", "content-type" ]
Setting Python path while developing library module
1,889,967
<p>I am developing a library and an application that uses the library in Python 2.6. I've placed a "mylib.pth" file in "site-packages" so that I can <code>import mylib</code> from within my application. </p> <p>I am using a DVCS so when I want to fix a bug or add a feature to the library I make a branch of the repos...
2
2009-12-11T18:25:09Z
1,889,990
<p>Is <a href="http://pypi.python.org/pypi/virtualenv" rel="nofollow">virtualenv</a> what you're looking for? From the description:</p> <blockquote> <p>Imagine you have an application that needs version 1 of LibFoo, but another application requires version 2. How can you use both these applications? If you ...
4
2009-12-11T18:29:02Z
[ "python" ]
Setting Python path while developing library module
1,889,967
<p>I am developing a library and an application that uses the library in Python 2.6. I've placed a "mylib.pth" file in "site-packages" so that I can <code>import mylib</code> from within my application. </p> <p>I am using a DVCS so when I want to fix a bug or add a feature to the library I make a branch of the repos...
2
2009-12-11T18:25:09Z
1,889,997
<p>Suggested reading: <a href="http://clemesha.org/blog/2009/jul/05/modern-python-hacker-tools-virtualenv-fabric-pip/" rel="nofollow">Tools of the Modern Python Hacker: Virtualenv, Fabric and Pip</a>. It addresses a number of problems with development and deployment of Python apps.</p>
4
2009-12-11T18:30:11Z
[ "python" ]
Setting Python path while developing library module
1,889,967
<p>I am developing a library and an application that uses the library in Python 2.6. I've placed a "mylib.pth" file in "site-packages" so that I can <code>import mylib</code> from within my application. </p> <p>I am using a DVCS so when I want to fix a bug or add a feature to the library I make a branch of the repos...
2
2009-12-11T18:25:09Z
1,890,000
<p>If you use setuptools, then you can say <code>setup.py develop</code> in your working tree, and it will do the .pth file manipulation for you.</p>
2
2009-12-11T18:30:53Z
[ "python" ]
Setting Python path while developing library module
1,889,967
<p>I am developing a library and an application that uses the library in Python 2.6. I've placed a "mylib.pth" file in "site-packages" so that I can <code>import mylib</code> from within my application. </p> <p>I am using a DVCS so when I want to fix a bug or add a feature to the library I make a branch of the repos...
2
2009-12-11T18:25:09Z
1,890,161
<p>Sure, you can alter <code>sys.path</code> to add the current directory (or a subdirectory of it) to the search path. <code>site.addsitedir</code> is a good way to do it. Since you'd be doing this from Python you can have any sort of logic you like for deciding which directory to add; you could base it on <code>os.pa...
1
2009-12-11T18:57:20Z
[ "python" ]
Setting Python path while developing library module
1,889,967
<p>I am developing a library and an application that uses the library in Python 2.6. I've placed a "mylib.pth" file in "site-packages" so that I can <code>import mylib</code> from within my application. </p> <p>I am using a DVCS so when I want to fix a bug or add a feature to the library I make a branch of the repos...
2
2009-12-11T18:25:09Z
1,890,181
<p>You might also consider using <a href="http://jacobian.org/writing/django-apps-with-buildout/" rel="nofollow">zc.buildout</a>. It allows you to create entry points with customized python paths.</p>
1
2009-12-11T19:01:00Z
[ "python" ]
Setting Python path while developing library module
1,889,967
<p>I am developing a library and an application that uses the library in Python 2.6. I've placed a "mylib.pth" file in "site-packages" so that I can <code>import mylib</code> from within my application. </p> <p>I am using a DVCS so when I want to fix a bug or add a feature to the library I make a branch of the repos...
2
2009-12-11T18:25:09Z
1,890,242
<p>I set my <code>PYTHONPATH</code> to point to the latest-and-greatest version. No editing.</p> <pre><code>export PYTHONPATH=.:/the/new/version </code></pre>
1
2009-12-11T19:11:26Z
[ "python" ]
Django, Python: Is there a simple way to convert PHP-style bracketed POST keys to multidimensional dict?
1,890,013
<p>Specifically, I got a form that calls a Django service (written using Piston, but I don't think that's relevant), sending via POST something like this:</p> <pre><code>edu_type[3][name] =&gt; a edu_type[3][spec] =&gt; b edu_type[3][start_year] =&gt; c edu_type[3][end_year] =&gt; d edu_type[4][0][name] =&gt; Cisco ed...
2
2009-12-11T18:33:04Z
1,890,336
<p>I am riding off of the previous response by Atli about using PHP's <code>json_encode</code>...</p> <p>A Python dict in its most basic form is syntactically identical to JSON. You could easily perform an <code>eval()</code> on a JSON structure to create a Python dict:</p> <pre><code>&gt;&gt;&gt; blob = """{ ... ...
0
2009-12-11T19:27:31Z
[ "php", "python", "django", "http", "post" ]
Django, Python: Is there a simple way to convert PHP-style bracketed POST keys to multidimensional dict?
1,890,013
<p>Specifically, I got a form that calls a Django service (written using Piston, but I don't think that's relevant), sending via POST something like this:</p> <pre><code>edu_type[3][name] =&gt; a edu_type[3][spec] =&gt; b edu_type[3][start_year] =&gt; c edu_type[3][end_year] =&gt; d edu_type[4][0][name] =&gt; Cisco ed...
2
2009-12-11T18:33:04Z
1,892,979
<p>okay, so this is ghetto as hell, but here goes:</p> <p>let's say your input is a list of tuples. say: input = [('edu_type[3][end_year]', 'd'), ...]</p> <pre><code>from collections import defaultdict from re import compile def defdict(): return defaultdict(defdict) edu_type = defdict() inputs = [(x.replace('...
0
2009-12-12T10:21:08Z
[ "php", "python", "django", "http", "post" ]
Django, Python: Is there a simple way to convert PHP-style bracketed POST keys to multidimensional dict?
1,890,013
<p>Specifically, I got a form that calls a Django service (written using Piston, but I don't think that's relevant), sending via POST something like this:</p> <pre><code>edu_type[3][name] =&gt; a edu_type[3][spec] =&gt; b edu_type[3][start_year] =&gt; c edu_type[3][end_year] =&gt; d edu_type[4][0][name] =&gt; Cisco ed...
2
2009-12-11T18:33:04Z
2,224,561
<p>Dottedish does something like what you want. <a href="http://pypi.python.org/pypi/dottedish" rel="nofollow">http://pypi.python.org/pypi/dottedish</a>. It doesn't really have a homepage but you can install it from pypi or download the source from github.</p> <pre><code>&gt;&gt;&gt; import dottedish &gt;&gt;&gt; dott...
1
2010-02-08T20:16:36Z
[ "php", "python", "django", "http", "post" ]
Django, Python: Is there a simple way to convert PHP-style bracketed POST keys to multidimensional dict?
1,890,013
<p>Specifically, I got a form that calls a Django service (written using Piston, but I don't think that's relevant), sending via POST something like this:</p> <pre><code>edu_type[3][name] =&gt; a edu_type[3][spec] =&gt; b edu_type[3][start_year] =&gt; c edu_type[3][end_year] =&gt; d edu_type[4][0][name] =&gt; Cisco ed...
2
2009-12-11T18:33:04Z
6,048,412
<p>I made a little parser in python to handle multidimensional dicts, you can find it at <a href="https://github.com/bernii/querystring-parser" rel="nofollow">https://github.com/bernii/querystring-parser</a></p>
3
2011-05-18T17:08:14Z
[ "php", "python", "django", "http", "post" ]
Response Code 202, Not a Qualified Error Code
1,890,216
<p>I'm working with an API which I post files to. However, when I receive the response, the HTTP status code is a 202. This is to be expected, but in addition the API will also respond with XML content.</p> <p>So in my try/except block urllib2.urlopen will result in a raised urllib2.HTTPError and destroying the XML co...
2
2009-12-11T19:06:57Z
1,890,286
<p><strong>Edit</strong></p> <p>Being silly, I forgot to inspect the exception that is returned by urllib2. It features all of the properties I've been waxing on about for httplib. This should do the trick for you:</p> <pre><code>try: urllib2.urlopen(req) except urllib2.HTTPError, e: print "Response code",e.c...
4
2009-12-11T19:19:49Z
[ "python" ]
Conditional statements in Eclipse templates
1,890,330
<p>Eclipse templates can automatically insert text and variables as you are coding. When variables are used with the ${variable} form, the value is inserted automatically.</p> <p>My question is whether you can add sections to these templates conditionally. Can you have a method definition template that will fill in mu...
2
2009-12-11T19:26:55Z
1,890,845
<p>Not currently possible in eclipse editor templates.</p> <p>You can define custom VariableResolvers that generate whatever you would like. However, I don't think that would do what you're looking for.</p> <p>A variable resolver can return "", you'd have to have basically the entire template in the resolver; not ter...
1
2009-12-11T21:01:21Z
[ "python", "eclipse", "templates", "pydev" ]
Conditional statements in Eclipse templates
1,890,330
<p>Eclipse templates can automatically insert text and variables as you are coding. When variables are used with the ${variable} form, the value is inserted automatically.</p> <p>My question is whether you can add sections to these templates conditionally. Can you have a method definition template that will fill in mu...
2
2009-12-11T19:26:55Z
2,016,906
<p>It can be done through Jython scripting in Pydev in the latest nightly build (which will be 1.5.4).</p> <p>See <a href="http://pydev.org/download.html" rel="nofollow">http://pydev.org/download.html</a> for details on getting it.</p> <p>Shortly, you can define a variable in scripting and program it in Jython to be ...
2
2010-01-06T22:42:20Z
[ "python", "eclipse", "templates", "pydev" ]
How does incr work with expiry times?
1,890,682
<p>In memcached (appengine api implementation), how does expiration interact with incr()? There isn't a time argument for incr(), but what happens if I add the key with another call rather than using the initial_value param, like so: </p> <pre><code>memcache.add('testcounter', 0, time=60*90) newcnt = memcache.incr('...
4
2009-12-11T20:29:06Z
1,891,946
<p>The expiration time is not affected by incr.</p> <p>That object will expire from the cache no later than 90 seconds after you add it regardless of the number of times you incr it.</p> <p>(and, of course, it may expire sooner)</p>
1
2009-12-12T01:51:11Z
[ "python", "google-app-engine", "memcached" ]
How does incr work with expiry times?
1,890,682
<p>In memcached (appengine api implementation), how does expiration interact with incr()? There isn't a time argument for incr(), but what happens if I add the key with another call rather than using the initial_value param, like so: </p> <pre><code>memcache.add('testcounter', 0, time=60*90) newcnt = memcache.incr('...
4
2009-12-11T20:29:06Z
1,894,323
<p>In the <a href="http://code.google.com/appengine/docs/python/memcache/overview.html" rel="nofollow">memcache overview</a> of GAE they say:</p> <p>"The app can provide an expiration time when a value is stored, as either a number of seconds <strong>relative to when the value is added</strong>, or as an absolute Unix...
4
2009-12-12T18:39:12Z
[ "python", "google-app-engine", "memcached" ]
Blocking behavior of PyGTK's main loop
1,890,715
<p>My intention was to use pyGTK's main loop to create a function that blocks while it waits for the user's input. The problem I've encountered is best explained in code:</p> <pre><code>#! /usr/bin/python import gtk def test(): retval = True def cb(widget): retval = False gtk.main_quit() ...
1
2009-12-11T20:34:13Z
1,890,738
<p>What is happening is that when python sees <code>foo = bar</code> as the first reference to <code>foo</code> in a function it assumes that it is a local variable. In python3k you can get around this by using the <a href="http://docs.python.org/dev/3.0/reference/simple%5Fstmts.html#the-nonlocal-statement" rel="nofoll...
2
2009-12-11T20:38:39Z
[ "python", "callback", "pygtk" ]
Blocking behavior of PyGTK's main loop
1,890,715
<p>My intention was to use pyGTK's main loop to create a function that blocks while it waits for the user's input. The problem I've encountered is best explained in code:</p> <pre><code>#! /usr/bin/python import gtk def test(): retval = True def cb(widget): retval = False gtk.main_quit() ...
1
2009-12-11T20:34:13Z
1,908,896
<p>This is the dialog pattern. Use a gtk.Dialog. <a href="http://www.pygtk.org/docs/pygtk/class-gtkdialog.html#method-gtkdialog--run" rel="nofollow">Dialog.run()</a> blocks exactly how you need it to, and returns the dialog's return code.</p>
2
2009-12-15T17:04:05Z
[ "python", "callback", "pygtk" ]
How to implement a stdin, stdout wrapper?
1,890,803
<p>I have an interactive program that runs stdin and stdout. I need to create wrapper that will send X to it's stdin, check that it prints Y and then redirects wrapper's stdin and stdout to program's stdin and stdout just like program would be executed directly.</p> <p>How to implement this ? X and Y can be hardcoded....
3
2009-12-11T20:52:56Z
1,890,822
<p>Assuming X and Y are files, and that you can invoke the program more than once:</p> <pre><code>#!/bin/bash test "`program &lt;X`" = "`cat Y`" &amp;&amp; program </code></pre> <p>Or, to fail more verbosely:</p> <pre><code>#!/bin/bash if [[ `program &lt;X` != `cat Y` ]]; then echo -e "Assertion that input X p...
1
2009-12-11T20:56:57Z
[ "python", "bash", "wrapper", "stdout", "stdin" ]
How to implement a stdin, stdout wrapper?
1,890,803
<p>I have an interactive program that runs stdin and stdout. I need to create wrapper that will send X to it's stdin, check that it prints Y and then redirects wrapper's stdin and stdout to program's stdin and stdout just like program would be executed directly.</p> <p>How to implement this ? X and Y can be hardcoded....
3
2009-12-11T20:52:56Z
1,890,832
<p><a href="http://en.wikipedia.org/wiki/Expect" rel="nofollow">Expect</a> is made for automating the running of other programs - essentially you write something like, in plain text,</p> <p>Start this program. When it prints out the word "username", send it my username. When it sends "password", send it my password.</...
3
2009-12-11T21:00:00Z
[ "python", "bash", "wrapper", "stdout", "stdin" ]
How to implement a stdin, stdout wrapper?
1,890,803
<p>I have an interactive program that runs stdin and stdout. I need to create wrapper that will send X to it's stdin, check that it prints Y and then redirects wrapper's stdin and stdout to program's stdin and stdout just like program would be executed directly.</p> <p>How to implement this ? X and Y can be hardcoded....
3
2009-12-11T20:52:56Z
1,890,843
<p>You can overwrite the sys module's stdin and stdout</p> <pre><code>import sys sys.stdin, sys.stdout = wrapper.stdin, wrapper.stdout </code></pre> <p>These need to be file objects opened for reading and writing respectively. The original stdin and stdout are found at</p> <pre><code>sys.stdin, sys.stdout = sys.__st...
0
2009-12-11T21:01:07Z
[ "python", "bash", "wrapper", "stdout", "stdin" ]
How to implement a stdin, stdout wrapper?
1,890,803
<p>I have an interactive program that runs stdin and stdout. I need to create wrapper that will send X to it's stdin, check that it prints Y and then redirects wrapper's stdin and stdout to program's stdin and stdout just like program would be executed directly.</p> <p>How to implement this ? X and Y can be hardcoded....
3
2009-12-11T20:52:56Z
1,893,650
<p>I'm a little confused as to what exactly you're trying to achieve; as I understand you wish to:</p> <ol> <li>Start the wrapper program specifying the input X, and expected output Y.</li> <li>Have the wrapper initiate the target program attaching input X to it's stdin, and verifying that it's output matches Y.</li> ...
0
2009-12-12T14:48:47Z
[ "python", "bash", "wrapper", "stdout", "stdin" ]
Inheritance and factory functions in Python and Django
1,891,004
<p>I'm creating a Django app that uses some inheritance in it's model, mainly because I need to assign everything a UUID and a reference so I know what class it was. Here's a simplified version of the base class:</p> <pre><code>class BaseElement(models.Model): uuid = models.CharField(max_length=64, editable=False...
5
2009-12-11T21:32:35Z
1,891,098
<p>I think you might have been better off overriding save in your BaseElement instead. Then on save you could set those fields. It'd be something like:</p> <pre><code>class MyBase(models.Model): uuid = models.CharField(max_length=64, editable=False, blank=True, default=lambda:unicode(uuid4())) objmodul...
2
2009-12-11T21:51:31Z
[ "python", "django", "inheritance" ]
Inheritance and factory functions in Python and Django
1,891,004
<p>I'm creating a Django app that uses some inheritance in it's model, mainly because I need to assign everything a UUID and a reference so I know what class it was. Here's a simplified version of the base class:</p> <pre><code>class BaseElement(models.Model): uuid = models.CharField(max_length=64, editable=False...
5
2009-12-11T21:32:35Z
1,896,343
<p>If you make <code>create()</code> a <code>@classmethod</code> instead of <code>@staticmethod</code>, you'll have access to the class object, which you can use instead of referring to it by name:</p> <pre><code>@classmethod def create(cls, *args, **kwargs): obj = cls(*args, **kwargs) obj.set_defaults() r...
7
2009-12-13T12:23:54Z
[ "python", "django", "inheritance" ]
Contructing python function callable from C , with input parameter having *output* sematics
1,891,021
<p>The use case is the following:</p> <ul> <li>Given a (fixed, not changeable) DLL implemented in C</li> <li>Wanted: a wrapper to this DLL implemented in python (chosen method: ctypes)</li> </ul> <p>Some of the functions in the DLL need synchronization primitives. To aim for maximum flexibility, the designers of the ...
1
2009-12-11T21:37:13Z
1,893,497
<p>You appear to be incorrectly defining the return type. It looks like your C callback returns an int, while the Python one you are declaring as return c_int, yet not explicitly returning anything (thus actually returning None). If you "return 0" it might stop crashing. You should do that or change the callback sig...
0
2009-12-12T13:50:59Z
[ "python", "callback", "ctypes", "void-pointers" ]
Contructing python function callable from C , with input parameter having *output* sematics
1,891,021
<p>The use case is the following:</p> <ul> <li>Given a (fixed, not changeable) DLL implemented in C</li> <li>Wanted: a wrapper to this DLL implemented in python (chosen method: ctypes)</li> </ul> <p>Some of the functions in the DLL need synchronization primitives. To aim for maximum flexibility, the designers of the ...
1
2009-12-11T21:37:13Z
3,673,343
<p>The segfault is due to incorrect pointer handling in your Python callback. You have more levels of pointer indirection than strict necessary, which is probably the source of your confusion. In the Python callback you set <code>p_p_i.contents</code>, but that only changes what the <em>Python ctypes object</em> poin...
0
2010-09-09T02:19:17Z
[ "python", "callback", "ctypes", "void-pointers" ]
Having models' declarations at two folders in Django
1,891,139
<p><strong>How can you have model declarations at two different directories in Django?</strong></p> <p>I have the model at the directory <strong>Code</strong> which contains "<strong>init</strong>.py", "models.py" and "admin.py". It is working properly alone.</p> <p>I want to have the directory <strong>History</stron...
0
2009-12-11T22:00:22Z
1,891,197
<p>Generally people just have one "models" directory, or even sometimes just one models file. If you get to the point that you feel you need 2 full directories for your models, it's probably better to start thinking about breaking your one app, into a couple of small apps instead generally. That being said, there's a n...
0
2009-12-11T22:10:40Z
[ "python", "django", "import", "models" ]
Having models' declarations at two folders in Django
1,891,139
<p><strong>How can you have model declarations at two different directories in Django?</strong></p> <p>I have the model at the directory <strong>Code</strong> which contains "<strong>init</strong>.py", "models.py" and "admin.py". It is working properly alone.</p> <p>I want to have the directory <strong>History</stron...
0
2009-12-11T22:00:22Z
1,891,203
<p>If the directory is called History, you should change <code>import history</code> to <code>import History</code>, as python imports are case-sensitive (on my Linux box, at least).</p>
0
2009-12-11T22:11:14Z
[ "python", "django", "import", "models" ]
Having models' declarations at two folders in Django
1,891,139
<p><strong>How can you have model declarations at two different directories in Django?</strong></p> <p>I have the model at the directory <strong>Code</strong> which contains "<strong>init</strong>.py", "models.py" and "admin.py". It is working properly alone.</p> <p>I want to have the directory <strong>History</stron...
0
2009-12-11T22:00:22Z
1,891,205
<p>Since it sounds like both of your directories are Django apps, and assuming you've put both of them in your <code>INSTALLED_APPS</code> list in <code>settings.py</code> you can refer to them using a string without having to import:</p> <pre><code># in code/models.py class Questions(models.Model): histories = m...
2
2009-12-11T22:11:22Z
[ "python", "django", "import", "models" ]
Python Exception Propagation
1,891,572
<p>I'm building a tool where as exceptions propagate upwards, new data about the context of the exception gets added to the exception. The issue is, by the time the exception gets to the top level, all of the extra context data is there, but only the very latest stack trace is shown. Is there an easy way to have an exc...
7
2009-12-11T23:37:42Z
1,891,615
<p>Python exceptions are a bit like java, there is a way to cause the exception to be rethrown without truncating the stack.</p> <p>Just use <code>raise</code> without an argument. The result it:</p> <pre><code>Traceback (most recent call last): File "./exc.py", line 11, in &lt;module&gt; b() File "./exc.py",...
20
2009-12-11T23:49:39Z
[ "python", "exception" ]
Where to put a Django template's dependent files?
1,891,884
<p>My Django templates use a lot of related stuff: images, style sheets, etc.</p> <p>Where should I put these file, or how should I refer to them in the template itself?</p> <p>For now I'm using the development server.</p> <p>I know it's a really common thing, but I can't really figure it out.</p>
4
2009-12-12T01:23:58Z
1,891,905
<p>I put them inside a folder named <code>static</code>, which is in the web project's top level folder. </p> <p>Example: </p> <blockquote> <p>/static/img/<br> /static/js/<br> /static/css/<br> /templates/<br> urls.py<br> settings.py </p> </blockquote> <p>I then have the following rule in my <code>urls.p...
5
2009-12-12T01:34:51Z
[ "python", "django", "django-templates" ]
Where to put a Django template's dependent files?
1,891,884
<p>My Django templates use a lot of related stuff: images, style sheets, etc.</p> <p>Where should I put these file, or how should I refer to them in the template itself?</p> <p>For now I'm using the development server.</p> <p>I know it's a really common thing, but I can't really figure it out.</p>
4
2009-12-12T01:23:58Z
1,892,235
<p>Maybe you can read the doc <a href="http://docs.djangoproject.com/en/dev/howto/static-files/#howto-static-files" rel="nofollow">http://docs.djangoproject.com/en/dev/howto/static-files/#howto-static-files</a></p>
2
2009-12-12T04:04:11Z
[ "python", "django", "django-templates" ]
Where to put a Django template's dependent files?
1,891,884
<p>My Django templates use a lot of related stuff: images, style sheets, etc.</p> <p>Where should I put these file, or how should I refer to them in the template itself?</p> <p>For now I'm using the development server.</p> <p>I know it's a really common thing, but I can't really figure it out.</p>
4
2009-12-12T01:23:58Z
1,892,503
<p>We put ours under /media. Everything that is specifically tied to the layout of the sites is further separated. Of course none of this static content is served by Django on the production site. They often aren't even on the same physical server.</p> <pre><code>/media /images - this is for content-specific image...
0
2009-12-12T05:59:28Z
[ "python", "django", "django-templates" ]
Sqlite3 "chained" query
1,892,111
<p>I need to create a configuration file from a data file that looks as follows:</p> <pre><code>MAN1_TIME '01-JAN-2010 00:00:00.0000 UTC' MAN1_RX 123.45 MAN1_RY 123.45 MAN1_RZ 123.45 MAN1_NEXT 'MAN2' MAN2_TIME '01-MAR-2010 00:00:00.0000 UTC' MAN2_RX 123.45 [...] MAN2_NEXT 'MANX' [...] MANX_TIME [...] </code></pre> <p...
0
2009-12-12T03:00:26Z
1,892,182
<p>Following OMG Ponies's comment, and <a href="http://sqllessons.com/categories.html" rel="nofollow">http://sqllessons.com/categories.html</a>, perhaps try something like this:</p> <pre><code>select MAN1.RX as MAN1_RX, MAN1.RY as MAN1_RY, MAN1.RZ as MAN1_RZ, MAN2.RX as MAN2_RX, MA...
0
2009-12-12T03:34:25Z
[ "python", "sql", "sqlite3" ]
Sqlite3 "chained" query
1,892,111
<p>I need to create a configuration file from a data file that looks as follows:</p> <pre><code>MAN1_TIME '01-JAN-2010 00:00:00.0000 UTC' MAN1_RX 123.45 MAN1_RY 123.45 MAN1_RZ 123.45 MAN1_NEXT 'MAN2' MAN2_TIME '01-MAR-2010 00:00:00.0000 UTC' MAN2_RX 123.45 [...] MAN2_NEXT 'MANX' [...] MANX_TIME [...] </code></pre> <p...
0
2009-12-12T03:00:26Z
2,937,368
<p>I found the answer to my own question in the <a href="http://www.sqlalchemy.org/docs/mappers.html#relationship-configuration" rel="nofollow">SQLAlchemy website</a>. From the documentation:</p> <blockquote> <p>The adjacency list pattern is a common relational pattern whereby a table contains a foreign key refe...
1
2010-05-30T02:59:33Z
[ "python", "sql", "sqlite3" ]
What does "result.status_code == 200" in Python mean?
1,892,161
<p>In this little piece of code, what is the fourth line all about? </p> <pre><code>from google.appengine.api import urlfetch url = "http://www.google.com/" result = urlfetch.fetch(url) if result.status_code == 200: doSomethingWithResult(result.content) </code></pre>
1
2009-12-12T03:26:03Z
1,892,164
<p>It's a HTTP status code, it means "OK" (EG: The server successfully answered the http request).</p> <p><a href="http://en.wikipedia.org/wiki/List%5Fof%5FHTTP%5Fstatus%5Fcodes" rel="nofollow">See a list of them here on wikipedia</a></p>
13
2009-12-12T03:27:09Z
[ "python", "http", "result" ]
What does "result.status_code == 200" in Python mean?
1,892,161
<p>In this little piece of code, what is the fourth line all about? </p> <pre><code>from google.appengine.api import urlfetch url = "http://www.google.com/" result = urlfetch.fetch(url) if result.status_code == 200: doSomethingWithResult(result.content) </code></pre>
1
2009-12-12T03:26:03Z
1,892,167
<p>200 is the HTTP status code for "OK", a successful response. (Other codes you may be familiar with are 404 Not Found, 403 Forbidden, and 500 Internal Server Error.)</p> <p>See <a href="http://www.w3.org/Protocols/rfc2616/rfc2616.html" rel="nofollow">RFC 2616</a> for more information.</p>
6
2009-12-12T03:28:10Z
[ "python", "http", "result" ]
What does "result.status_code == 200" in Python mean?
1,892,161
<p>In this little piece of code, what is the fourth line all about? </p> <pre><code>from google.appengine.api import urlfetch url = "http://www.google.com/" result = urlfetch.fetch(url) if result.status_code == 200: doSomethingWithResult(result.content) </code></pre>
1
2009-12-12T03:26:03Z
1,892,686
<p>Whoever wrote that should have used a constant instead of a magic number. The httplib module has all the http response codes.</p> <p>E.g.:</p> <pre><code>&gt;&gt;&gt; import httplib &gt;&gt;&gt; httplib.OK 200 &gt;&gt;&gt; httplib.NOT_FOUND 404 </code></pre>
4
2009-12-12T07:37:07Z
[ "python", "http", "result" ]
How to send EOF to Python sys.stdin from commandline? CTRL-D doesn't work
1,892,215
<p>I am writing to my Python process from the commandline on unix. I want to send EOF (or somehow flush the stdin buffer, so Python can read my input.)</p> <p>If I hit CTRL-C, I get a KeyboardError.</p> <p>If I hit CTRL-D, the program just stops.</p> <p>How do I flush the stdin buffer?</p>
5
2009-12-12T03:54:43Z
1,892,227
<p>If you use 'for l in sys.stdin', it is buffered.</p> <p>You can use:</p> <pre><code> while 1: l = sys.stdin.readline() </code></pre>
1
2009-12-12T04:00:44Z
[ "python", "unix", "command-line", "buffer" ]
How to send EOF to Python sys.stdin from commandline? CTRL-D doesn't work
1,892,215
<p>I am writing to my Python process from the commandline on unix. I want to send EOF (or somehow flush the stdin buffer, so Python can read my input.)</p> <p>If I hit CTRL-C, I get a KeyboardError.</p> <p>If I hit CTRL-D, the program just stops.</p> <p>How do I flush the stdin buffer?</p>
5
2009-12-12T03:54:43Z
1,892,639
<p>Control-D should NOT make your program "just stop" -- it should close standard input, and if your program deals with that properly, it may perfectly well continue if it needs to!</p> <p>For example, given the following <code>st.py</code>:</p> <pre><code>import sys def main(): inwas = [] for line in sys.stdin:...
11
2009-12-12T07:12:27Z
[ "python", "unix", "command-line", "buffer" ]
How to send EOF to Python sys.stdin from commandline? CTRL-D doesn't work
1,892,215
<p>I am writing to my Python process from the commandline on unix. I want to send EOF (or somehow flush the stdin buffer, so Python can read my input.)</p> <p>If I hit CTRL-C, I get a KeyboardError.</p> <p>If I hit CTRL-D, the program just stops.</p> <p>How do I flush the stdin buffer?</p>
5
2009-12-12T03:54:43Z
1,892,743
<p>I think I know what's happening. You are hitting <code>ctrl-D</code> without hitting <code>enter</code>. If you want to send a line to the program, just hit enter. If you hit <code>ctrl-D</code> without hitting <code>enter</code>, you can hit <code>ctrl-D</code> again and your program should see the line then. I...
2
2009-12-12T08:14:22Z
[ "python", "unix", "command-line", "buffer" ]
How to send EOF to Python sys.stdin from commandline? CTRL-D doesn't work
1,892,215
<p>I am writing to my Python process from the commandline on unix. I want to send EOF (or somehow flush the stdin buffer, so Python can read my input.)</p> <p>If I hit CTRL-C, I get a KeyboardError.</p> <p>If I hit CTRL-D, the program just stops.</p> <p>How do I flush the stdin buffer?</p>
5
2009-12-12T03:54:43Z
19,482,178
<pre><code>try: # You might be inside the while-loop foo = raw_input('Spam: ') # Or whatever... except EOFError: print 'And now for something completely different.' sys.exit() </code></pre>
1
2013-10-20T20:01:10Z
[ "python", "unix", "command-line", "buffer" ]
What are the various popularity metrics and sites for programming languages such as Ruby, Python, Java, etc?
1,892,254
<p>What are the various sites that offer metrics that compare Ruby, Python, Perl, Smalltalk etc. What are their respective metrics?</p> <p>Do any of them control or account for the time that Rails was introduced, and/or the adoption rates for various languages?</p> <p>Will someone please help me close this question? ...
1
2009-12-12T04:11:08Z
1,892,258
<p><a href="http://www.tiobe.com/index.php/content/paperinfo/tpci/index.html" rel="nofollow">TIOBE</a> attempts to rate the popularity of programming languages. Ruby is in the top 10 just below Perl. Therefore I would say that your investment is protected. As or what the index actually measures <a href="http://www.t...
4
2009-12-12T04:13:53Z
[ "c#", "asp.net", "python", "ruby", "smalltalk" ]
What are the various popularity metrics and sites for programming languages such as Ruby, Python, Java, etc?
1,892,254
<p>What are the various sites that offer metrics that compare Ruby, Python, Perl, Smalltalk etc. What are their respective metrics?</p> <p>Do any of them control or account for the time that Rails was introduced, and/or the adoption rates for various languages?</p> <p>Will someone please help me close this question? ...
1
2009-12-12T04:11:08Z
1,892,290
<p>I don't mean to be nasty but what you are saying sounds like this to me: "I enjoy programming in Ruby and really don't want to learn another technology. Is there a site that can tell me that Ruby is not going away anytime soon to put my mind at ease?".</p> <p>There is nothing wrong with that attitude but you have t...
6
2009-12-12T04:28:36Z
[ "c#", "asp.net", "python", "ruby", "smalltalk" ]
What are the various popularity metrics and sites for programming languages such as Ruby, Python, Java, etc?
1,892,254
<p>What are the various sites that offer metrics that compare Ruby, Python, Perl, Smalltalk etc. What are their respective metrics?</p> <p>Do any of them control or account for the time that Rails was introduced, and/or the adoption rates for various languages?</p> <p>Will someone please help me close this question? ...
1
2009-12-12T04:11:08Z
1,892,291
<p>Also, see <a href="http://trends.google.com/trends?q=ruby%2C+python%2C+php%2C+perl&amp;ctab=0&amp;geo=all&amp;date=all&amp;sort=0" rel="nofollow">Google trends</a> comparing number of searches for ruby, python, php and perl over time.</p>
1
2009-12-12T04:28:43Z
[ "c#", "asp.net", "python", "ruby", "smalltalk" ]
What are the various popularity metrics and sites for programming languages such as Ruby, Python, Java, etc?
1,892,254
<p>What are the various sites that offer metrics that compare Ruby, Python, Perl, Smalltalk etc. What are their respective metrics?</p> <p>Do any of them control or account for the time that Rails was introduced, and/or the adoption rates for various languages?</p> <p>Will someone please help me close this question? ...
1
2009-12-12T04:11:08Z
1,892,296
<p>I usually use Google Trends for this:<br> <a href="http://www.google.com/trends" rel="nofollow">http://www.google.com/trends</a></p> <p>The more popular an item is (in this case a language) the more that people are searching for it.</p> <p>If you look at this chart on Google Trends:<br> <a href="http://www.google....
0
2009-12-12T04:31:17Z
[ "c#", "asp.net", "python", "ruby", "smalltalk" ]
What are the various popularity metrics and sites for programming languages such as Ruby, Python, Java, etc?
1,892,254
<p>What are the various sites that offer metrics that compare Ruby, Python, Perl, Smalltalk etc. What are their respective metrics?</p> <p>Do any of them control or account for the time that Rails was introduced, and/or the adoption rates for various languages?</p> <p>Will someone please help me close this question? ...
1
2009-12-12T04:11:08Z
1,894,284
<p>One of the more interesting metrics is the <a href="http://radar.oreilly.com/2009/07/state-of-the-computer-book-mar-25.html" rel="nofollow">State of the Computer Book Market</a> posts that Mike Hendrickson posts on <a href="http://radar.oreilly.com/mikeh/" rel="nofollow">his O'Reilly Radar blog</a>. I tend to favor ...
1
2009-12-12T18:24:32Z
[ "c#", "asp.net", "python", "ruby", "smalltalk" ]
What are the various popularity metrics and sites for programming languages such as Ruby, Python, Java, etc?
1,892,254
<p>What are the various sites that offer metrics that compare Ruby, Python, Perl, Smalltalk etc. What are their respective metrics?</p> <p>Do any of them control or account for the time that Rails was introduced, and/or the adoption rates for various languages?</p> <p>Will someone please help me close this question? ...
1
2009-12-12T04:11:08Z
1,895,091
<p>Better than Google trends is Google insight. It allows you to limit queries to a given subject, like eg programming. And since all of smalltalk, ruby, python, and perl are also used in other context, I limited the search to programming.</p> <p><a href="http://www.google.com/insights/search/#cat=31&amp;q=smalltalk%2...
2
2009-12-12T23:50:31Z
[ "c#", "asp.net", "python", "ruby", "smalltalk" ]
What are the various popularity metrics and sites for programming languages such as Ruby, Python, Java, etc?
1,892,254
<p>What are the various sites that offer metrics that compare Ruby, Python, Perl, Smalltalk etc. What are their respective metrics?</p> <p>Do any of them control or account for the time that Rails was introduced, and/or the adoption rates for various languages?</p> <p>Will someone please help me close this question? ...
1
2009-12-12T04:11:08Z
1,895,183
<h3>Don't Worry</h3> <p>I also like Ruby<sup>1</sup>, and I worried about exactly the same thing.</p> <p>But a closer look at the same data allayed my fears.</p> <ul> <li>Ruby's <a href="http://www.tiobe.com/index.php/content/paperinfo/tpci/index.html" rel="nofollow">Tiobe Index</a> <strong>score has been fairly sta...
1
2009-12-13T00:33:20Z
[ "c#", "asp.net", "python", "ruby", "smalltalk" ]
How do derived class constructors work in python?
1,892,269
<p>I have the following base class:</p> <pre><code>class NeuralNetworkBase: def __init__(self, numberOfInputs, numberOfHiddenNeurons, numberOfOutputs): self.inputLayer = numpy.zeros(shape = (numberOfInputs)) self.hiddenLayer = numpy.zeros(shape = (numberOfHiddenNeurons)) self.outputLayer = ...
11
2009-12-12T04:16:26Z
1,892,279
<p>You will have to put this in the <code>__init__()</code> method of NeuralNetworkBackPropagation, that is to call the <code>__init__()</code> method of the parent class (NeuralNetworkBase):</p> <pre><code>NeuralNetworkBase.__init__(self, numberOfInputs, numberOfHiddenNeurons, numberOfOutputs) </code></pre> <p>The c...
4
2009-12-12T04:21:39Z
[ "python" ]
How do derived class constructors work in python?
1,892,269
<p>I have the following base class:</p> <pre><code>class NeuralNetworkBase: def __init__(self, numberOfInputs, numberOfHiddenNeurons, numberOfOutputs): self.inputLayer = numpy.zeros(shape = (numberOfInputs)) self.hiddenLayer = numpy.zeros(shape = (numberOfHiddenNeurons)) self.outputLayer = ...
11
2009-12-12T04:16:26Z
1,892,281
<blockquote> <p>Does python call by default the base class constructor's when running the derived class' one? Do I have to implicitly do it inside the derived class constructor?</p> </blockquote> <p>No and yes.</p> <p>This is consistent with the way Python handles other overridden methods - you have to expl...
20
2009-12-12T04:22:28Z
[ "python" ]
Why program functionally in Python?
1,892,324
<p>At work we used to program our Python in a pretty standard OO way. Lately, a couple guys got on the functional bandwagon. And their code now contains lots more lambdas, maps and reduces. I understand that functional languages are good for concurrency but does programming Python functionally really help with concur...
34
2009-12-12T04:46:23Z
1,892,345
<p>I program in Python everyday, and I have to say that too much 'bandwagoning' toward OO or functional could lead toward missing elegant solutions. I believe that both paradigms have their advantages to certain problems - and I think that's when you know what approach to use. Use a functional approach when it leaves y...
19
2009-12-12T04:56:44Z
[ "python", "functional-programming" ]
Why program functionally in Python?
1,892,324
<p>At work we used to program our Python in a pretty standard OO way. Lately, a couple guys got on the functional bandwagon. And their code now contains lots more lambdas, maps and reduces. I understand that functional languages are good for concurrency but does programming Python functionally really help with concur...
34
2009-12-12T04:46:23Z
1,892,394
<p>The standard functions filter(), map() and reduce() are used for various operations on a list and all of the three functions expect two arguments: A function and a list</p> <p>We could define a separate function and use it as an argument to filter() etc., and its probably a good idea if that function is used severa...
2
2009-12-12T05:19:36Z
[ "python", "functional-programming" ]
Why program functionally in Python?
1,892,324
<p>At work we used to program our Python in a pretty standard OO way. Lately, a couple guys got on the functional bandwagon. And their code now contains lots more lambdas, maps and reduces. I understand that functional languages are good for concurrency but does programming Python functionally really help with concur...
34
2009-12-12T04:46:23Z
1,892,585
<p>This answer is completely re-worked. It incorporates a lot of observations from the other answers.</p> <p>As you can see, there is a lot of strong feelings surrounding the use of functional programming constructs in Python. There are three major groups of ideas here.</p> <p>First, almost everybody but the people...
15
2009-12-12T06:41:06Z
[ "python", "functional-programming" ]
Why program functionally in Python?
1,892,324
<p>At work we used to program our Python in a pretty standard OO way. Lately, a couple guys got on the functional bandwagon. And their code now contains lots more lambdas, maps and reduces. I understand that functional languages are good for concurrency but does programming Python functionally really help with concur...
34
2009-12-12T04:46:23Z
1,892,614
<p><strong>Edit</strong>: I've been taken to task in the comments (in part, it seems, by fanatics of FP in Python, but not exclusively) for not providing more explanations/examples, so, expanding the answer to supply some.</p> <p><code>lambda</code>, even more so <code>map</code> (and <code>filter</code>), <strong>and...
66
2009-12-12T07:02:30Z
[ "python", "functional-programming" ]
Why program functionally in Python?
1,892,324
<p>At work we used to program our Python in a pretty standard OO way. Lately, a couple guys got on the functional bandwagon. And their code now contains lots more lambdas, maps and reduces. I understand that functional languages are good for concurrency but does programming Python functionally really help with concur...
34
2009-12-12T04:46:23Z
1,893,341
<p>Map and Filter have their place in OO programming. Right next to list comprehensions and generator functions.</p> <p>Reduce less so. The algorithm for reduce can rapidly suck down more time than it deserves; with a tiny bit of thinking, a manually-written reduce-loop will be more efficient than a reduce which app...
1
2009-12-12T12:58:01Z
[ "python", "functional-programming" ]
Why program functionally in Python?
1,892,324
<p>At work we used to program our Python in a pretty standard OO way. Lately, a couple guys got on the functional bandwagon. And their code now contains lots more lambdas, maps and reduces. I understand that functional languages are good for concurrency but does programming Python functionally really help with concur...
34
2009-12-12T04:46:23Z
1,894,941
<p>FP is important not only for concurrency; in fact, there's virtually no concurrency in the canonical Python implementation (maybe 3.x changes that?). in any case, FP lends itself well to concurrency because it leads to programs with no or fewer (explicit) states. states are troublesome for a few reasons. one is t...
23
2009-12-12T22:40:08Z
[ "python", "functional-programming" ]
Why program functionally in Python?
1,892,324
<p>At work we used to program our Python in a pretty standard OO way. Lately, a couple guys got on the functional bandwagon. And their code now contains lots more lambdas, maps and reduces. I understand that functional languages are good for concurrency but does programming Python functionally really help with concur...
34
2009-12-12T04:46:23Z
1,895,283
<p>Here's a short summary of positive answers when/why to program functionally.</p> <ul> <li>List comprehensions were imported from Haskell, a FP language. They are Pythonic. I'd prefer to write</li> </ul> <blockquote> <pre><code>y = [i*2 for i in k if i % 3 == 0] </code></pre> </blockquote> <p>than to use an impera...
7
2009-12-13T01:25:29Z
[ "python", "functional-programming" ]
Why program functionally in Python?
1,892,324
<p>At work we used to program our Python in a pretty standard OO way. Lately, a couple guys got on the functional bandwagon. And their code now contains lots more lambdas, maps and reduces. I understand that functional languages are good for concurrency but does programming Python functionally really help with concur...
34
2009-12-12T04:46:23Z
1,899,731
<p>The question, which seems to be mostly ignored here: </p> <blockquote> <p>does programming Python functionally really help with concurrency?</p> </blockquote> <p>No. The value FP brings to concurrency is in eliminating state in computation, which is ultimately responsible for the hard-to-grasp nastiness of unin...
9
2009-12-14T08:50:05Z
[ "python", "functional-programming" ]
Simple DB query on Google App Engine taking a lot of CPU time
1,892,325
<p>I'm fairly new to Google App Engine and Python, but I did just release my first real-world site with it. But now I'm getting problems with one path that is using significantly more CPU (and API CPU) time than the other paths. I've narrowed it down to a single datastore fetch that's causing the problem: <code>Carving...
0
2009-12-12T04:46:27Z
1,892,385
<p>Sometimes you'll get better performance if you do an indexed query, rather than a query of "all" elements in the model.</p> <p>Also, consider using memcache.</p>
0
2009-12-12T05:13:02Z
[ "python", "google-app-engine", "cpu-usage", "gae-datastore" ]