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 |
|---|---|---|---|---|---|---|---|---|---|
How to get started with Sessions in Google App Engine / Django? | 1,271,892 | <p>I'm new to Python / GAE / Django. I get that with GAE there are no in-memory sessions per se... but I think I want something equivalent. I <a href="http://docs.djangoproject.com/en/dev/topics/http/sessions/" rel="nofollow">read</a> that Django sessions <a href="http://code.google.com/appengine/articles/appengine%5Fh... | 5 | 2009-08-13T13:17:31Z | 3,899,191 | <p>I am using gaeutilities session now. However, the problem is that these created sessions are accessible only within the server-side codes. When I try to access them in django template tag, I could retrieve them out. Am I missing something?</p>
<p>Example: Client side (Django template tags)</p>
<pre><code> ... | 1 | 2010-10-10T05:54:13Z | [
"python",
"django",
"google-app-engine"
] |
How to get started with Sessions in Google App Engine / Django? | 1,271,892 | <p>I'm new to Python / GAE / Django. I get that with GAE there are no in-memory sessions per se... but I think I want something equivalent. I <a href="http://docs.djangoproject.com/en/dev/topics/http/sessions/" rel="nofollow">read</a> that Django sessions <a href="http://code.google.com/appengine/articles/appengine%5Fh... | 5 | 2009-08-13T13:17:31Z | 4,368,517 | <p>gaeuitlities includes a django middleware, however I haven't done django development in a while and can't 100% guarantee it's been kept up to date with django. I'm sure it won't take me long to fix if it there is an issue.</p>
<p><a href="https://github.com/joerussbowman/gaeutilities/blob/master/appengine_utilities... | 0 | 2010-12-06T16:19:48Z | [
"python",
"django",
"google-app-engine"
] |
accessing remote url's in Google App Engine | 1,271,908 | <p>I don't know the correct terminology to do a google search.
What I want is to make a POST http request to other url, for example
twitter, from within mi app in google app engine.</p>
<p>If the question is unclear please comment.
Thanks!</p>
<p>Manuel</p>
| 0 | 2009-08-13T13:22:04Z | 1,271,933 | <p>Google provides <a href="http://code.google.com/intl/de-DE/appengine/docs/python/urlfetch/" rel="nofollow">urlfetch</a> for this.</p>
| 3 | 2009-08-13T13:26:37Z | [
"python",
"google-app-engine",
"twitter",
"httprequest"
] |
BaseException.message deprecated in Python 2.6 | 1,272,138 | <p>I get a warning that BaseException.message is deprecated in Python 2.6 when I use the following user-defined exception:</p>
<pre><code>class MyException(Exception):
def __init__(self, message):
self.message = message
def __str__(self):
return repr(self.message)
</code></pre>
<p>This is th... | 121 | 2009-08-13T13:59:21Z | 1,272,176 | <p>Yes, it's deprecated in Python 2.6 because it's going away in Python 3.0</p>
<p>BaseException class does not provide a way to store error message anymore. You'll have to implement it yourself. You can do this with a subclass that uses a property for storing the message.</p>
<pre><code>class MyException(Exception):... | 26 | 2009-08-13T14:06:51Z | [
"python",
"exception",
"deprecated"
] |
BaseException.message deprecated in Python 2.6 | 1,272,138 | <p>I get a warning that BaseException.message is deprecated in Python 2.6 when I use the following user-defined exception:</p>
<pre><code>class MyException(Exception):
def __init__(self, message):
self.message = message
def __str__(self):
return repr(self.message)
</code></pre>
<p>This is th... | 121 | 2009-08-13T13:59:21Z | 1,272,197 | <pre><code>class MyException(Exception):
def __str__(self):
return repr(self.args[0])
e = MyException('asdf')
print e
</code></pre>
<p>This is your class in Python2.6 style. The new exception takes an arbitrary number of arguments.</p>
| 8 | 2009-08-13T14:09:43Z | [
"python",
"exception",
"deprecated"
] |
BaseException.message deprecated in Python 2.6 | 1,272,138 | <p>I get a warning that BaseException.message is deprecated in Python 2.6 when I use the following user-defined exception:</p>
<pre><code>class MyException(Exception):
def __init__(self, message):
self.message = message
def __str__(self):
return repr(self.message)
</code></pre>
<p>This is th... | 121 | 2009-08-13T13:59:21Z | 3,928,752 | <p>As far as I can tell, simply using a different name for the message attribute avoids the conflict with the base class, and thus stops the deprecation warning:</p>
<pre><code>class MyException(Exception):
def __init__(self, message):
self.msg = message
def __str__(self):
return repr(self.msg)
</code></pre>... | 3 | 2010-10-13T23:00:36Z | [
"python",
"exception",
"deprecated"
] |
BaseException.message deprecated in Python 2.6 | 1,272,138 | <p>I get a warning that BaseException.message is deprecated in Python 2.6 when I use the following user-defined exception:</p>
<pre><code>class MyException(Exception):
def __init__(self, message):
self.message = message
def __str__(self):
return repr(self.message)
</code></pre>
<p>This is th... | 121 | 2009-08-13T13:59:21Z | 6,029,838 | <h2>Solution - almost no coding needed</h2>
<ol>
<li>Just inherit your exception class from <code>Exception</code></li>
<li>and pass the message as the first parameter to the constructor</li>
</ol>
<p>Example:</p>
<pre><code>class MyException(Exception):
"""My documentation"""
try:
raise MyException('my det... | 107 | 2011-05-17T10:58:34Z | [
"python",
"exception",
"deprecated"
] |
BaseException.message deprecated in Python 2.6 | 1,272,138 | <p>I get a warning that BaseException.message is deprecated in Python 2.6 when I use the following user-defined exception:</p>
<pre><code>class MyException(Exception):
def __init__(self, message):
self.message = message
def __str__(self):
return repr(self.message)
</code></pre>
<p>This is th... | 121 | 2009-08-13T13:59:21Z | 28,226,376 | <h1>How to replicate the warning</h1>
<p>Let me clarify the problem, as one cannot replicate this with the question's sample code, this will replicate the warning:</p>
<pre><code>>>> error = Exception('foobarbaz')
>>> error.message
__main__:1: DeprecationWarning: BaseException.message has been depre... | 1 | 2015-01-29T23:06:04Z | [
"python",
"exception",
"deprecated"
] |
BaseException.message deprecated in Python 2.6 | 1,272,138 | <p>I get a warning that BaseException.message is deprecated in Python 2.6 when I use the following user-defined exception:</p>
<pre><code>class MyException(Exception):
def __init__(self, message):
self.message = message
def __str__(self):
return repr(self.message)
</code></pre>
<p>This is th... | 121 | 2009-08-13T13:59:21Z | 29,503,053 | <p>The advice to use str(myexception) leads to unicode problems in python 2.7, e.g.:</p>
<pre><code>str(Exception(u'δÏÏÏδÏ'))
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
UnicodeEncodeError: 'ascii' codec can't encode characters in position 0-5: ordinal not in range(128)
<... | 0 | 2015-04-07T23:14:44Z | [
"python",
"exception",
"deprecated"
] |
BaseException.message deprecated in Python 2.6 | 1,272,138 | <p>I get a warning that BaseException.message is deprecated in Python 2.6 when I use the following user-defined exception:</p>
<pre><code>class MyException(Exception):
def __init__(self, message):
self.message = message
def __str__(self):
return repr(self.message)
</code></pre>
<p>This is th... | 121 | 2009-08-13T13:59:21Z | 30,881,390 | <p>Continuing on from <a href="http://stackoverflow.com/a/6029838/1101109">geekQ's answer</a>, the preferred option is usually:</p>
<pre><code>str(my)
</code></pre>
<p>Because sometimes exceptions have more than one argument, so <code>my.args[0]</code> is not guaranteed to provide all the relevant information.</p>
<... | 0 | 2015-06-17T02:32:20Z | [
"python",
"exception",
"deprecated"
] |
BaseException.message deprecated in Python 2.6 | 1,272,138 | <p>I get a warning that BaseException.message is deprecated in Python 2.6 when I use the following user-defined exception:</p>
<pre><code>class MyException(Exception):
def __init__(self, message):
self.message = message
def __str__(self):
return repr(self.message)
</code></pre>
<p>This is th... | 121 | 2009-08-13T13:59:21Z | 34,137,629 | <p>pzrq's post says to use:</p>
<pre><code>str(e)
</code></pre>
<p>This was exactly what I needed.</p>
<p>(If you are in a unicode environment, it appears that:</p>
<pre><code>unicode(e)
</code></pre>
<p>will work, and it appears to work fine in a non-unicode environment)</p>
<p>Pzrq said a lot of other good stuf... | 0 | 2015-12-07T15:47:57Z | [
"python",
"exception",
"deprecated"
] |
Is it possible to add a network drive to %PATH% environment variable | 1,272,242 | <p>I have a python script calling an exe file. The exe file can be in the same folder as that of the python script or in a network drive. Is it possible to call the exe if it is in a remote drive/computer? Can this be done by setting the %PATH% variable</p>
| 0 | 2009-08-13T14:17:01Z | 1,272,313 | <p>Yes you can put a UNC path in your <code>%PATH%</code> env variable, and it will work if you have access to that path with your current session. </p>
| 1 | 2009-08-13T14:28:15Z | [
"python",
"windows",
"sysinternals"
] |
Is it possible to add a network drive to %PATH% environment variable | 1,272,242 | <p>I have a python script calling an exe file. The exe file can be in the same folder as that of the python script or in a network drive. Is it possible to call the exe if it is in a remote drive/computer? Can this be done by setting the %PATH% variable</p>
| 0 | 2009-08-13T14:17:01Z | 16,741,926 | <p>Although use of a UNC will often work in the %PATH% variable this is unsupported by Microsoft as it can cause problems such as service failures. This issue continues through Windows 7 / Server 2008R2.</p>
<p>Please reference <a href="http://support.microsoft.com/kb/978856" rel="nofollow">Microsoft KB Article ID: 9... | 2 | 2013-05-24T19:02:04Z | [
"python",
"windows",
"sysinternals"
] |
Batch output redirection when using start command for GUI app | 1,272,309 | <p>This is the scenario:</p>
<p>We have a Python script that starts a Windows batch file and redirects its output to a file. Afterwards it reads the file and then tries to delete it:</p>
<pre><code>os.system(C:\batch.bat >C:\temp.txt 2>&1)
os.remove(C:\temp.txt)
</code></pre>
<p>In the batch.bat we start a... | 0 | 2009-08-13T14:27:10Z | 1,272,393 | <p>I don't think Windows will let you delete an open file. Sounds like you're wanting to throw away the program's output; would redirecting to 'nul' instead do what you need?</p>
| 0 | 2009-08-13T14:41:45Z | [
"python",
"windows",
"batch-file",
"output-redirect"
] |
Batch output redirection when using start command for GUI app | 1,272,309 | <p>This is the scenario:</p>
<p>We have a Python script that starts a Windows batch file and redirects its output to a file. Afterwards it reads the file and then tries to delete it:</p>
<pre><code>os.system(C:\batch.bat >C:\temp.txt 2>&1)
os.remove(C:\temp.txt)
</code></pre>
<p>In the batch.bat we start a... | 0 | 2009-08-13T14:27:10Z | 1,272,480 | <p>As I understand it, this is the issue, and what he wants to do:</p>
<ol>
<li>Make <em>no</em> changes to the python code.</li>
<li><p>The Python code is written assuming that "temp.txt" is no longer being used when this function returns:</p>
<p>os.system(C:\batch.bat >C:\temp.txt 2>&1)</p></li>
<li><p>This is ... | 0 | 2009-08-13T14:53:37Z | [
"python",
"windows",
"batch-file",
"output-redirect"
] |
Batch output redirection when using start command for GUI app | 1,272,309 | <p>This is the scenario:</p>
<p>We have a Python script that starts a Windows batch file and redirects its output to a file. Afterwards it reads the file and then tries to delete it:</p>
<pre><code>os.system(C:\batch.bat >C:\temp.txt 2>&1)
os.remove(C:\temp.txt)
</code></pre>
<p>In the batch.bat we start a... | 0 | 2009-08-13T14:27:10Z | 1,272,848 | <p>Are you closing the file after you're done reading it? The following works at my end:</p>
<pre><code>import os
os.system('runbat.bat > runbat.log 2>&1')
f = open('runbat.log')
print f.read()
f.close()
os.remove('runbat.log')
</code></pre>
<p>but fails if I remove the <code>f.close()</code> line.</p>
| 0 | 2009-08-13T15:50:55Z | [
"python",
"windows",
"batch-file",
"output-redirect"
] |
Batch output redirection when using start command for GUI app | 1,272,309 | <p>This is the scenario:</p>
<p>We have a Python script that starts a Windows batch file and redirects its output to a file. Afterwards it reads the file and then tries to delete it:</p>
<pre><code>os.system(C:\batch.bat >C:\temp.txt 2>&1)
os.remove(C:\temp.txt)
</code></pre>
<p>In the batch.bat we start a... | 0 | 2009-08-13T14:27:10Z | 1,273,144 | <p>Why capture to a file if you're just deleting it immediately?</p>
<p>How about this:</p>
<pre><code>os.system(C:\batch.bat >nul 2>&1)
</code></pre>
<p>EDIT: Oops, I missed your comment about reading the file, I only noticed the code.</p>
| 0 | 2009-08-13T16:36:43Z | [
"python",
"windows",
"batch-file",
"output-redirect"
] |
Batch output redirection when using start command for GUI app | 1,272,309 | <p>This is the scenario:</p>
<p>We have a Python script that starts a Windows batch file and redirects its output to a file. Afterwards it reads the file and then tries to delete it:</p>
<pre><code>os.system(C:\batch.bat >C:\temp.txt 2>&1)
os.remove(C:\temp.txt)
</code></pre>
<p>In the batch.bat we start a... | 0 | 2009-08-13T14:27:10Z | 1,273,817 | <p>This is a bit hacky, but you could try it. It uses the <code>AT</code> command to run <code>the_programm.exe</code> up to a minute in the future (which it computes using the <code>%TIME%</code> environment variable and <code>SET</code> arithmetic).</p>
<p>batch.bat:</p>
<pre><code>@echo off
setlocal
:: store the c... | 2 | 2009-08-13T18:39:18Z | [
"python",
"windows",
"batch-file",
"output-redirect"
] |
Batch output redirection when using start command for GUI app | 1,272,309 | <p>This is the scenario:</p>
<p>We have a Python script that starts a Windows batch file and redirects its output to a file. Afterwards it reads the file and then tries to delete it:</p>
<pre><code>os.system(C:\batch.bat >C:\temp.txt 2>&1)
os.remove(C:\temp.txt)
</code></pre>
<p>In the batch.bat we start a... | 0 | 2009-08-13T14:27:10Z | 1,276,896 | <p>Finally I could find a proper solution:</p>
<p>I am not using a batch file anymore for starting the_programm.exe, but a Python script:</p>
<pre><code>from subprocess import Popen
if __name__ == '__main__':
Popen('C:/the_programm.exe', close_fds=True)
</code></pre>
<p>The close_fds parameter decoup... | 0 | 2009-08-14T09:23:00Z | [
"python",
"windows",
"batch-file",
"output-redirect"
] |
parsing CSV files backwards | 1,272,315 | <p>I have csv files with the following format:</p>
<pre><code>CSV FILE
"a" , "b" , "c" , "d"
hello, world , 1 , 2 , 3
1,2,3,4,5,6,7 , 2 , 456 , 87
h,1231232,3 , 3 , 45 , 44
</code></pre>
<p>The problem is that the first field has commas "," in it. I have no control over f... | 2 | 2009-08-13T14:28:26Z | 1,272,327 | <p>You could always do something with regex's, like (perl regex)</p>
<pre><code>#!/usr/bin/perl
use IO::File;
if (my $file = new IO::File("test.csv"))
{
foreach my $line (<$file>) {
$line =~ m/^(.*),(.*?),(.*?),(.*?)$/;
print "[$1][$2][$3][$4]\n";
}
} else {
print "Unable to open test.csv\n... | 1 | 2009-08-13T14:30:56Z | [
"python",
"parsing",
"csv",
"readline"
] |
parsing CSV files backwards | 1,272,315 | <p>I have csv files with the following format:</p>
<pre><code>CSV FILE
"a" , "b" , "c" , "d"
hello, world , 1 , 2 , 3
1,2,3,4,5,6,7 , 2 , 456 , 87
h,1231232,3 , 3 , 45 , 44
</code></pre>
<p>The problem is that the first field has commas "," in it. I have no control over f... | 2 | 2009-08-13T14:28:26Z | 1,272,329 | <p>Reverse the string first and then process it. </p>
<p>tmp = tmp[::-1]</p>
| 1 | 2009-08-13T14:31:05Z | [
"python",
"parsing",
"csv",
"readline"
] |
parsing CSV files backwards | 1,272,315 | <p>I have csv files with the following format:</p>
<pre><code>CSV FILE
"a" , "b" , "c" , "d"
hello, world , 1 , 2 , 3
1,2,3,4,5,6,7 , 2 , 456 , 87
h,1231232,3 , 3 , 45 , 44
</code></pre>
<p>The problem is that the first field has commas "," in it. I have no control over f... | 2 | 2009-08-13T14:28:26Z | 1,272,338 | <p>The <code>rsplit</code> string method splits a string starting from the right instead of the left, and so it's probably what you're looking for (it takes an argument specifying the max number of times to split):</p>
<pre><code>line = "hello, world , 1 , 2 , 3"
parts = line.rsplit(",", 3)
print parts # p... | 14 | 2009-08-13T14:32:41Z | [
"python",
"parsing",
"csv",
"readline"
] |
parsing CSV files backwards | 1,272,315 | <p>I have csv files with the following format:</p>
<pre><code>CSV FILE
"a" , "b" , "c" , "d"
hello, world , 1 , 2 , 3
1,2,3,4,5,6,7 , 2 , 456 , 87
h,1231232,3 , 3 , 45 , 44
</code></pre>
<p>The problem is that the first field has commas "," in it. I have no control over f... | 2 | 2009-08-13T14:28:26Z | 1,272,344 | <p>From the sample You have provided, it looks like "columns" are fixed size. First (the one with commas) is 16 characters long, so why don't You try reading the file line by line, then for each line reading the first 16 characters (as a value of first column), and the rest accordingly? After You have each value, You c... | 1 | 2009-08-13T14:33:15Z | [
"python",
"parsing",
"csv",
"readline"
] |
parsing CSV files backwards | 1,272,315 | <p>I have csv files with the following format:</p>
<pre><code>CSV FILE
"a" , "b" , "c" , "d"
hello, world , 1 , 2 , 3
1,2,3,4,5,6,7 , 2 , 456 , 87
h,1231232,3 , 3 , 45 , 44
</code></pre>
<p>The problem is that the first field has commas "," in it. I have no control over f... | 2 | 2009-08-13T14:28:26Z | 1,272,356 | <p>That's not then a CSV file, comma separated means just that.</p>
<p>How can you be certain that is not:</p>
<pre><code>CSV FILE
"a" , "b" , "c" , "d"
hello , world , 1 , 2 , 3
1 , 2 , 3 , 4 , 5,6,7,2,456,87
h , 1231232 , 3 , 3 , 45,44
</code... | 1 | 2009-08-13T14:35:21Z | [
"python",
"parsing",
"csv",
"readline"
] |
parsing CSV files backwards | 1,272,315 | <p>I have csv files with the following format:</p>
<pre><code>CSV FILE
"a" , "b" , "c" , "d"
hello, world , 1 , 2 , 3
1,2,3,4,5,6,7 , 2 , 456 , 87
h,1231232,3 , 3 , 45 , 44
</code></pre>
<p>The problem is that the first field has commas "," in it. I have no control over f... | 2 | 2009-08-13T14:28:26Z | 1,272,359 | <p>If you always expect the same number of columns, and only the first column can contain commas, just read anything and concatenate excess columns at the beginning.</p>
<p>The problem is that the interface is ambiguous, and you can try to circumvent this, but the better solution is to try to get the interface fixed (... | 0 | 2009-08-13T14:36:01Z | [
"python",
"parsing",
"csv",
"readline"
] |
parsing CSV files backwards | 1,272,315 | <p>I have csv files with the following format:</p>
<pre><code>CSV FILE
"a" , "b" , "c" , "d"
hello, world , 1 , 2 , 3
1,2,3,4,5,6,7 , 2 , 456 , 87
h,1231232,3 , 3 , 45 , 44
</code></pre>
<p>The problem is that the first field has commas "," in it. I have no control over f... | 2 | 2009-08-13T14:28:26Z | 1,272,361 | <p>I agree with mr beer. That is a badly formed csv file. Your best bet is to find other delimiters or stop overloading the commas or quote/escape the non field separating commas</p>
| 0 | 2009-08-13T14:36:03Z | [
"python",
"parsing",
"csv",
"readline"
] |
parsing CSV files backwards | 1,272,315 | <p>I have csv files with the following format:</p>
<pre><code>CSV FILE
"a" , "b" , "c" , "d"
hello, world , 1 , 2 , 3
1,2,3,4,5,6,7 , 2 , 456 , 87
h,1231232,3 , 3 , 45 , 44
</code></pre>
<p>The problem is that the first field has commas "," in it. I have no control over f... | 2 | 2009-08-13T14:28:26Z | 1,272,364 | <p>I don't fully understand why you want to read each line in reverse, but you could do this:</p>
<pre><code>import csv
file = open("mycsvfile.csv")
reversedLines = [line[::-1] for line in file]
file.close()
reader = csv.reader(reversedLines)
for backwardRow in reader:
lastField = backwardRow[0][::-1]
secondFi... | 3 | 2009-08-13T14:36:26Z | [
"python",
"parsing",
"csv",
"readline"
] |
Alternatives to mod_python's CGI handler | 1,272,325 | <p>I'm looking for the simplest way of using python and SQLAlchemy to produce some XML for a jQuery based HTTP client. Right now I'm using mod_python's CGI handler but I'm unhappy with the fact that I can't persist stuff like the SQLAlchemy session.</p>
<p>The mod_python publisher handler that is apparently capable of... | 2 | 2009-08-13T14:29:51Z | 1,272,579 | <p>You could always write your own handler, which is the way mod_python is normally intended to be used. You would have to set some HTTP headers (and you could have a look at the publisher handler's source code for inspiration on that), but otherwise I don't think it's much more complicated than what you've been trying... | 2 | 2009-08-13T15:08:43Z | [
"python",
"cgi",
"mod-python"
] |
Python looping to read and parse all in a directory | 1,272,405 | <pre><code>class __init__:
path = "articles/"
files = os.listdir(path)
files.reverse()
def iterate(Files, Path):
def handleXml(content):
months = ['', 'January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December']
pars... | 1 | 2009-08-13T14:43:53Z | 1,272,505 | <p>Could it be because of:</p>
<pre><code>del Files[5:]
</code></pre>
<p>It deletes the last 5 entries from the original list as well. Instead of using <code>del</code>, you can try:</p>
<pre><code>for file in Files[:5]:
#...
</code></pre>
| 1 | 2009-08-13T14:56:29Z | [
"python",
"xml",
"file-io",
"blogs"
] |
Python looping to read and parse all in a directory | 1,272,405 | <pre><code>class __init__:
path = "articles/"
files = os.listdir(path)
files.reverse()
def iterate(Files, Path):
def handleXml(content):
months = ['', 'January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December']
pars... | 1 | 2009-08-13T14:43:53Z | 1,274,818 | <p>As stated in the comments, the actual recursion is missing.<br />
Even if it is there in some other place of the code, the recursion call is the typical place where the things are wrong, and for this reason I would suggest you to double check it.</p>
<p>However, why don't you use <a href="http://docs.python.org/lib... | 0 | 2009-08-13T21:51:55Z | [
"python",
"xml",
"file-io",
"blogs"
] |
Using Python (Bash?) to get OS-level system information (CPU Speed) | 1,272,903 | <p>I want to repeat <a href="http://stackoverflow.com/questions/25552/using-java-to-get-os-level-system-information">this question</a> using python. Reason is I have access to 10 nodes in a cluster and each node is not identical. They range in performance and I want to find which is the best computer to use remotely ba... | 1 | 2009-08-13T15:59:16Z | 1,272,945 | <p>Take a look at the <a href="http://support.hyperic.com/display/SIGAR/Home" rel="nofollow">SIGAR</a> library which has an extensive API for collecting system data cross-platform. It also has libraries available in many languages (Python, Java, Erlang, Ruby, etc).</p>
| 1 | 2009-08-13T16:06:09Z | [
"python",
"performance",
"cpu-speed"
] |
How can I implement matlabs ``ismember()`` command in Python? | 1,273,041 | <p>here is my problem: I would like to create a boolean matrix B that contains <code>True</code> everywhere that matrix A has a value contained in vector v. One inconvenient solution would be:</p>
<pre><code>import numpy as np
>>> A = np.array([[0,1,2], [1,2,3], [2,3,4]])
array([[0, 1, 2],
[1, 2, 3],
... | 3 | 2009-08-13T16:19:09Z | 1,273,138 | <p>Here's a naive one-liner:</p>
<pre><code>[any (value in item for value in v) for item in A]
</code></pre>
<p>Sample output:</p>
<pre><code>>>> A = ( [0,1,2], [1,2,3], [2,3,4] )
>>> v = [1,2]
>>> [any (value in item for value in v) for item in A]
[True, True, True]
>>> v = [1]
&... | 1 | 2009-08-13T16:35:48Z | [
"python",
"arrays",
"matrix"
] |
How can I implement matlabs ``ismember()`` command in Python? | 1,273,041 | <p>here is my problem: I would like to create a boolean matrix B that contains <code>True</code> everywhere that matrix A has a value contained in vector v. One inconvenient solution would be:</p>
<pre><code>import numpy as np
>>> A = np.array([[0,1,2], [1,2,3], [2,3,4]])
array([[0, 1, 2],
[1, 2, 3],
... | 3 | 2009-08-13T16:19:09Z | 1,273,151 | <p>I don't know much numpy, be here's a raw python one:</p>
<pre><code>>>> A = [[0,1,2], [1,2,3], [2,3,4]]
>>> v = [1,2]
>>> B = [map(lambda val: val in v, a) for a in A]
>>>
>>> B
[[False, True, True], [True, True, False], [True, False, False]]
</code></pre>
<p><strong>Ed... | 4 | 2009-08-13T16:37:57Z | [
"python",
"arrays",
"matrix"
] |
How can I implement matlabs ``ismember()`` command in Python? | 1,273,041 | <p>here is my problem: I would like to create a boolean matrix B that contains <code>True</code> everywhere that matrix A has a value contained in vector v. One inconvenient solution would be:</p>
<pre><code>import numpy as np
>>> A = np.array([[0,1,2], [1,2,3], [2,3,4]])
array([[0, 1, 2],
[1, 2, 3],
... | 3 | 2009-08-13T16:19:09Z | 1,273,185 | <p>Using numpy primitives:</p>
<pre><code>>>> import numpy as np
>>> A = np.array([[0,1,2], [1,2,3], [2,3,4]])
>>> v = [1,2]
>>> print np.vectorize(lambda x: x in v)(A)
[[False True True]
[ True True False]
[ True False False]]
</code></pre>
<p>For non-tiny inputs convert v to... | 3 | 2009-08-13T16:44:12Z | [
"python",
"arrays",
"matrix"
] |
How can I implement matlabs ``ismember()`` command in Python? | 1,273,041 | <p>here is my problem: I would like to create a boolean matrix B that contains <code>True</code> everywhere that matrix A has a value contained in vector v. One inconvenient solution would be:</p>
<pre><code>import numpy as np
>>> A = np.array([[0,1,2], [1,2,3], [2,3,4]])
array([[0, 1, 2],
[1, 2, 3],
... | 3 | 2009-08-13T16:19:09Z | 1,273,194 | <p>I think the closest you'll get is <code>numpy.ismember1d</code>, but it won't work well with your example. I think your solution (<code>B = (A==v[0]) + (A==v[1])</code>) may actually be the best one.</p>
| 1 | 2009-08-13T16:45:24Z | [
"python",
"arrays",
"matrix"
] |
How can I implement matlabs ``ismember()`` command in Python? | 1,273,041 | <p>here is my problem: I would like to create a boolean matrix B that contains <code>True</code> everywhere that matrix A has a value contained in vector v. One inconvenient solution would be:</p>
<pre><code>import numpy as np
>>> A = np.array([[0,1,2], [1,2,3], [2,3,4]])
array([[0, 1, 2],
[1, 2, 3],
... | 3 | 2009-08-13T16:19:09Z | 1,273,815 | <p>Alas, <code>setmember1d</code> as it exists in numpy is broken when either array has duplicated elements (as A does here). Download <a href="http://projects.scipy.org/numpy/raw-attachment/ticket/872/setmember.py" rel="nofollow">this</a> version, call it e.g sem.py somewhere on your sys.path, add to it a first line ... | 3 | 2009-08-13T18:39:09Z | [
"python",
"arrays",
"matrix"
] |
How can I implement matlabs ``ismember()`` command in Python? | 1,273,041 | <p>here is my problem: I would like to create a boolean matrix B that contains <code>True</code> everywhere that matrix A has a value contained in vector v. One inconvenient solution would be:</p>
<pre><code>import numpy as np
>>> A = np.array([[0,1,2], [1,2,3], [2,3,4]])
array([[0, 1, 2],
[1, 2, 3],
... | 3 | 2009-08-13T16:19:09Z | 6,101,855 | <p>Since Numpy version 1.4 there's a new function, in1d() that's the equivalent of ismember() in matlab: <a href="http://docs.scipy.org/doc/numpy-1.6.0/reference/generated/numpy.in1d.html" rel="nofollow">http://docs.scipy.org/doc/numpy-1.6.0/reference/generated/numpy.in1d.html</a>. But as ars points out, it only return... | 1 | 2011-05-23T19:20:24Z | [
"python",
"arrays",
"matrix"
] |
Can't import Numpy in Python | 1,273,203 | <p>I'm trying to write some code that uses Numpy. However, I can't import it:</p>
<pre><code>Python 2.6.2 (r262, May 15 2009, 10:22:27)
[GCC 3.4.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import numpy
Traceback (most recent call last):
File "<stdin>", lin... | 16 | 2009-08-13T16:48:29Z | 1,273,217 | <p>Have you installed it?</p>
<p>On debian/ubuntu:</p>
<pre><code>aptitude install python-numpy
</code></pre>
<p>On windows:</p>
<p><a href="http://sourceforge.net/projects/numpy/files/NumPy/"><code>http://sourceforge.net/projects/numpy/files/NumPy/</code></a></p>
<p>On other systems:</p>
<p><a href="http://sourc... | 19 | 2009-08-13T16:50:53Z | [
"python",
"import",
"numpy"
] |
Can't import Numpy in Python | 1,273,203 | <p>I'm trying to write some code that uses Numpy. However, I can't import it:</p>
<pre><code>Python 2.6.2 (r262, May 15 2009, 10:22:27)
[GCC 3.4.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import numpy
Traceback (most recent call last):
File "<stdin>", lin... | 16 | 2009-08-13T16:48:29Z | 1,273,280 | <p>Your sys.path is kind of unusual, as each entry is prefixed with /usr/intel. I guess numpy is installed in the usual non-prefixed place, e.g. it. /usr/share/pyshared/numpy on my Ubuntu system.</p>
<p>Try <code>find / -iname '*numpy*'</code></p>
| 4 | 2009-08-13T16:59:40Z | [
"python",
"import",
"numpy"
] |
Can't import Numpy in Python | 1,273,203 | <p>I'm trying to write some code that uses Numpy. However, I can't import it:</p>
<pre><code>Python 2.6.2 (r262, May 15 2009, 10:22:27)
[GCC 3.4.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import numpy
Traceback (most recent call last):
File "<stdin>", lin... | 16 | 2009-08-13T16:48:29Z | 7,300,628 | <p>I was trying to import numpy in python 3.2.1 on windows 7. </p>
<p>Followed suggestions in above answer for numpy-1.6.1.zip as below after unzipping it</p>
<pre><code>cd numpy-1.6
python setup.py install
</code></pre>
<p>but got an error with a statement as below</p>
<pre><code>unable to find vcvarsall.bat
</cod... | 0 | 2011-09-04T16:38:19Z | [
"python",
"import",
"numpy"
] |
Can't import Numpy in Python | 1,273,203 | <p>I'm trying to write some code that uses Numpy. However, I can't import it:</p>
<pre><code>Python 2.6.2 (r262, May 15 2009, 10:22:27)
[GCC 3.4.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import numpy
Traceback (most recent call last):
File "<stdin>", lin... | 16 | 2009-08-13T16:48:29Z | 30,621,853 | <p><strong>To install it on Debian/Ubuntu:</strong></p>
<pre><code>sudo apt-get install python-numpy
</code></pre>
| 2 | 2015-06-03T13:40:35Z | [
"python",
"import",
"numpy"
] |
Disable assertions in Python | 1,273,211 | <p>How do I disable assertions in Python?</p>
<p>That is, if an assertion fails, I don't want it to throw an <code>AssertionError</code>, but to keep going.</p>
| 37 | 2009-08-13T16:49:37Z | 1,273,224 | <p>Running in optimized mode should do it.</p>
<pre><code>python -OO module.py
</code></pre>
| 3 | 2009-08-13T16:52:09Z | [
"python",
"debugging",
"assert"
] |
Disable assertions in Python | 1,273,211 | <p>How do I disable assertions in Python?</p>
<p>That is, if an assertion fails, I don't want it to throw an <code>AssertionError</code>, but to keep going.</p>
| 37 | 2009-08-13T16:49:37Z | 1,273,225 | <p>Use <code>python -O</code>:</p>
<pre><code>$ python -O
>>> assert False
>>>
</code></pre>
| 7 | 2009-08-13T16:52:12Z | [
"python",
"debugging",
"assert"
] |
Disable assertions in Python | 1,273,211 | <p>How do I disable assertions in Python?</p>
<p>That is, if an assertion fails, I don't want it to throw an <code>AssertionError</code>, but to keep going.</p>
| 37 | 2009-08-13T16:49:37Z | 1,273,233 | <p>Call Python with the -O flag:</p>
<p>test.py:</p>
<pre><code>assert(False)
print 'Done'
</code></pre>
<p>Output:</p>
<pre><code>C:\temp\py>C:\Python26\python.exe test.py
Traceback (most recent call last):
File "test.py", line 1, in <module>
assert(False)
AssertionError
C:\temp\py>C:\Python26\p... | 46 | 2009-08-13T16:53:41Z | [
"python",
"debugging",
"assert"
] |
Disable assertions in Python | 1,273,211 | <p>How do I disable assertions in Python?</p>
<p>That is, if an assertion fails, I don't want it to throw an <code>AssertionError</code>, but to keep going.</p>
| 37 | 2009-08-13T16:49:37Z | 21,325,317 | <p>Both of the two answers already given are valid (call Python with either <code>-O</code> or <code>-OO</code> on the command line).</p>
<p>Here is the difference between them:</p>
<ul>
<li><p><code>-O</code> Turn on basic optimizations. This changes the filename extension
for compiled (bytecode) files from .pyc to ... | 9 | 2014-01-24T05:45:49Z | [
"python",
"debugging",
"assert"
] |
Disable assertions in Python | 1,273,211 | <p>How do I disable assertions in Python?</p>
<p>That is, if an assertion fails, I don't want it to throw an <code>AssertionError</code>, but to keep going.</p>
| 37 | 2009-08-13T16:49:37Z | 29,741,912 | <p>You should <em>NOT</em> disable (most) assertions. In safety-critical software, they can save lives (or the mission, if it is unmanned). They also save a lot of developer time, and catch untested errors during deployment.</p>
<p>Instead, guard some (few) expensive assertion checks by something like:</p>
<pre><code... | 0 | 2015-04-20T07:41:51Z | [
"python",
"debugging",
"assert"
] |
django problem uploading and saving documents | 1,273,285 | <p>I am working on a django app. One part would involve uploading files (e.g. spreadsheet or whatever). I am getting this error:</p>
<pre><code>IOError at /fileupload/
[Errno 13] Permission denied: 'fyi.xml'
</code></pre>
<p>Where 'fileupload' was the django app name and 'fyi.xml' was the test document I was uploa... | 1 | 2009-08-13T17:00:26Z | 1,273,533 | <p>Maybe try changing:</p>
<pre><code>destination = open('fyi.xml', 'wb+')
</code></pre>
<p>to something like:</p>
<pre><code>upload_dir = settings.MEDIA_ROOT # or wherever
destination = open(os.path.join(upload_dir, 'fyi.xml'), 'wb+')
</code></pre>
<p>If it is an SELinux issue, perhaps this page would help:</p>
<... | 0 | 2009-08-13T17:46:04Z | [
"python",
"django",
"file",
"permissions"
] |
Python Twisted: restricting access by IP address | 1,273,297 | <p>What would be the best method to restrict access to my XMLRPC server by IP address? I see the class CGIScript in web/twcgi.py has a render method that is accessing the request... but I am not sure how to gain access to this request in my server. I saw an example where someone patched twcgi.py to set environment va... | 2 | 2009-08-13T17:03:13Z | 1,273,455 | <p>I'd use a firewall on windows, or <code>iptables</code> on linux.</p>
| 0 | 2009-08-13T17:30:25Z | [
"python",
"twisted"
] |
Python Twisted: restricting access by IP address | 1,273,297 | <p>What would be the best method to restrict access to my XMLRPC server by IP address? I see the class CGIScript in web/twcgi.py has a render method that is accessing the request... but I am not sure how to gain access to this request in my server. I saw an example where someone patched twcgi.py to set environment va... | 2 | 2009-08-13T17:03:13Z | 1,305,810 | <p>Okay, another answer is to get the ip address from the transport, inside any protocol:</p>
<p><code>d = </code> <a href="http://twistedmatrix.com/documents/current/api/twisted.internet.interfaces.ITCPTransport.html#getHost" rel="nofollow"><code>self.transport.getHost</code></a> <code>() ; print d.type, d.host, d.po... | 2 | 2009-08-20T12:21:16Z | [
"python",
"twisted"
] |
Python Twisted: restricting access by IP address | 1,273,297 | <p>What would be the best method to restrict access to my XMLRPC server by IP address? I see the class CGIScript in web/twcgi.py has a render method that is accessing the request... but I am not sure how to gain access to this request in my server. I saw an example where someone patched twcgi.py to set environment va... | 2 | 2009-08-13T17:03:13Z | 1,308,789 | <p>When a connection is established, a factory's buildProtocol is called to create a new protocol instance to handle that connection. buildProtocol is passed the address of the peer which established the connection and buildProtocol may return None to have the connection closed immediately.</p>
<p>So, for example, yo... | 5 | 2009-08-20T21:02:34Z | [
"python",
"twisted"
] |
How to skip empty dates (weekends) in a financial Matplotlib Python graph? | 1,273,472 | <pre><code>ax.plot_date((dates, dates), (highs, lows), '-')
</code></pre>
<p>I'm currently using this command to plot financial highs and lows using <a href="http://en.wikipedia.org/wiki/Matplotlib">Matplotlib</a>. It works great, but how do I remove the blank spaces in the x-axis left by days without market data, suc... | 9 | 2009-08-13T17:33:29Z | 1,273,603 | <p>I think you need to "artificially synthesize" the exact form of plot you want by using <code>xticks</code> to set the tick labels to the strings representing the dates (of course placing the ticks at equispaced intervals even though the dates you're representing aren't equispaced) and then using a plain <code>plot</... | 3 | 2009-08-13T17:56:33Z | [
"python",
"graph",
"matplotlib",
"financial"
] |
How to skip empty dates (weekends) in a financial Matplotlib Python graph? | 1,273,472 | <pre><code>ax.plot_date((dates, dates), (highs, lows), '-')
</code></pre>
<p>I'm currently using this command to plot financial highs and lows using <a href="http://en.wikipedia.org/wiki/Matplotlib">Matplotlib</a>. It works great, but how do I remove the blank spaces in the x-axis left by days without market data, suc... | 9 | 2009-08-13T17:33:29Z | 1,273,671 | <p>One of the advertised features of <a href="http://pytseries.sourceforge.net/" rel="nofollow">scikits.timeseries</a> is "Create time series plots with intelligently spaced axis labels". </p>
<p>You can see some example plots <a href="http://pytseries.sourceforge.net/lib.plotting.examples.html" rel="nofollow">here</... | 4 | 2009-08-13T18:10:05Z | [
"python",
"graph",
"matplotlib",
"financial"
] |
How to skip empty dates (weekends) in a financial Matplotlib Python graph? | 1,273,472 | <pre><code>ax.plot_date((dates, dates), (highs, lows), '-')
</code></pre>
<p>I'm currently using this command to plot financial highs and lows using <a href="http://en.wikipedia.org/wiki/Matplotlib">Matplotlib</a>. It works great, but how do I remove the blank spaces in the x-axis left by days without market data, suc... | 9 | 2009-08-13T17:33:29Z | 1,275,389 | <p>I will typically use <a href="http://en.wikipedia.org/wiki/NumPy" rel="nofollow">NumPy</a>'s NaN (not a number) for values that are invalid or not present. They are represented by Matplotlib as gaps in the plot and NumPy is part of pylab/Matplotlib.</p>
<pre><code>>>> import pylab
>>> xs = pylab.... | 6 | 2009-08-14T00:18:51Z | [
"python",
"graph",
"matplotlib",
"financial"
] |
How to skip empty dates (weekends) in a financial Matplotlib Python graph? | 1,273,472 | <pre><code>ax.plot_date((dates, dates), (highs, lows), '-')
</code></pre>
<p>I'm currently using this command to plot financial highs and lows using <a href="http://en.wikipedia.org/wiki/Matplotlib">Matplotlib</a>. It works great, but how do I remove the blank spaces in the x-axis left by days without market data, suc... | 9 | 2009-08-13T17:33:29Z | 2,335,781 | <p>There's an example of how to do this on the Matplotlib site:</p>
<p><a href="http://matplotlib.sourceforge.net/examples/api/date_index_formatter.html">http://matplotlib.sourceforge.net/examples/api/date_index_formatter.html</a></p>
| 6 | 2010-02-25T16:44:17Z | [
"python",
"graph",
"matplotlib",
"financial"
] |
Porting a Python app that uses Psyco to Mac | 1,273,546 | <p>I'm trying to port my Python app from Windows to Mac. My app uses Psyco. How exactly do I install Psyco on Mac?</p>
<p>Keep in mind I'm a Mac newbie.</p>
| 0 | 2009-08-13T17:48:27Z | 1,273,631 | <p>The <a href="http://psyco.sourceforge.net/" rel="nofollow">News</a> page shows that a Mac port is still being written. Learn how to install from source code using Make. Apply that patch, compile, and install.</p>
| -1 | 2009-08-13T18:03:25Z | [
"python",
"osx",
"psyco"
] |
Porting a Python app that uses Psyco to Mac | 1,273,546 | <p>I'm trying to port my Python app from Windows to Mac. My app uses Psyco. How exactly do I install Psyco on Mac?</p>
<p>Keep in mind I'm a Mac newbie.</p>
| 0 | 2009-08-13T17:48:27Z | 1,273,646 | <p>First, you need Apple's XCode installed (well, specifically you only need the gcc compiler that comes with it, but installing the whole thing is simpler;-). If you want the latest and greatest, sign up for <a href="http://developer.apple.com/" rel="nofollow">ADC</a> at the lowest (free!-) level and download from the... | 2 | 2009-08-13T18:06:07Z | [
"python",
"osx",
"psyco"
] |
Exporting keyframes in blender python | 1,273,588 | <p>I'm trying to export animation from blender, here's what I've done so far:<br />
--- This is just to give you an idea of what I'm doing and I've left out a lot to keep it short.<br />
--- If it's too confusing or if it's needed I could post the whole source.</p>
<pre><code># Get the armature
arm = ob.getData()
... | 2 | 2009-08-13T17:54:31Z | 1,676,436 | <p>The channel data should be applied on top of the bind pose matrix.</p>
<p>The complete formula is the following:</p>
<p><strong>Mr = Ms * B0*P0 * B1*P1 <em>...</em> Bn*Pn</strong></p>
<p>where:</p>
<p><strong>Mr</strong> = result matrix for a bone 'n'</p>
<p><strong>Ms</strong> = skeleton->world matrix</p>
<p>... | 2 | 2009-11-04T20:37:17Z | [
"python",
"3d",
"blender"
] |
parsing month year pairs into datetime | 1,273,811 | <p>Let's say i have 2 strings 'Jan-2010' and 'Mar-2010' and i want to parse it such that it returns 2 datetime objects: 1-Jan-2010 and 31-Mar-2010 (i.e. the last day). </p>
<p>What would be the best strategy in python? Should i just split the string into tokens or use regular expressions and then use the calendar fun... | 4 | 2009-08-13T18:38:56Z | 1,273,950 | <pre><code>from datetime import datetime, timedelta
def first_day(some_date):
return some_date.replace(day=1, hour=0, minute=0, second=0, microsecond=0)
def next_month(some_date):
return first_day(first_day(some_date) + timedelta(days=31))
def last_day(some_date):
return next_month(some_date) - timedelta... | 2 | 2009-08-13T19:02:00Z | [
"python",
"datetime"
] |
parsing month year pairs into datetime | 1,273,811 | <p>Let's say i have 2 strings 'Jan-2010' and 'Mar-2010' and i want to parse it such that it returns 2 datetime objects: 1-Jan-2010 and 31-Mar-2010 (i.e. the last day). </p>
<p>What would be the best strategy in python? Should i just split the string into tokens or use regular expressions and then use the calendar fun... | 4 | 2009-08-13T18:38:56Z | 1,273,953 | <p><code>strptime</code> does the string parsing into dates on your behalf:</p>
<pre><code>def firstofmonth(MmmYyyy):
return datetime.datetime.strptime(MmmYyyy, '%b-%Y').date()
</code></pre>
<p>much better than messing around with tokenization, regexp, &c!-).</p>
<p>To get the date of the last day of the month... | 5 | 2009-08-13T19:02:52Z | [
"python",
"datetime"
] |
parsing month year pairs into datetime | 1,273,811 | <p>Let's say i have 2 strings 'Jan-2010' and 'Mar-2010' and i want to parse it such that it returns 2 datetime objects: 1-Jan-2010 and 31-Mar-2010 (i.e. the last day). </p>
<p>What would be the best strategy in python? Should i just split the string into tokens or use regular expressions and then use the calendar fun... | 4 | 2009-08-13T18:38:56Z | 1,274,043 | <p>Riffing on Alex Martelli's:</p>
<pre><code>import datetime
def lastofmonthHelper(MmmYyyy): # Takes a date
return MmmYyyy.replace(year=MmmYyyy.year+(MmmYyyy.month==12), month=MmmYyyy.month%12 + 1, day=1) - datetime.timedelta(days=1)
>>> for month in range(1,13):
... t = datetime.date(2009,month,1)
..... | 0 | 2009-08-13T19:20:46Z | [
"python",
"datetime"
] |
parsing month year pairs into datetime | 1,273,811 | <p>Let's say i have 2 strings 'Jan-2010' and 'Mar-2010' and i want to parse it such that it returns 2 datetime objects: 1-Jan-2010 and 31-Mar-2010 (i.e. the last day). </p>
<p>What would be the best strategy in python? Should i just split the string into tokens or use regular expressions and then use the calendar fun... | 4 | 2009-08-13T18:38:56Z | 1,274,102 | <p>I highly recommend using the python timeseries module, which you can download and read about here: </p>
<p><a href="http://pytseries.sourceforge.net/" rel="nofollow">http://pytseries.sourceforge.net/</a> </p>
<p>You should also use the dateutil package for parsing the date string, which you can find here: </p>
<... | 3 | 2009-08-13T19:30:57Z | [
"python",
"datetime"
] |
parsing month year pairs into datetime | 1,273,811 | <p>Let's say i have 2 strings 'Jan-2010' and 'Mar-2010' and i want to parse it such that it returns 2 datetime objects: 1-Jan-2010 and 31-Mar-2010 (i.e. the last day). </p>
<p>What would be the best strategy in python? Should i just split the string into tokens or use regular expressions and then use the calendar fun... | 4 | 2009-08-13T18:38:56Z | 11,325,538 | <p>i know it's long time gone, but if someone needs:</p>
<pre><code>from dateutil import rrule
from dateutil import parser
from datetime import datetime
first_day = parser.parse('Jan-2010',default=datetime(1,1,1))
last_day = rrule.rrule(rrule.MONTHLY,count=1,bymonthday=-1, bysetpos=1,dtstart=parser.parse('Mar-2010')... | 1 | 2012-07-04T08:46:43Z | [
"python",
"datetime"
] |
What is the correct way to generate a json from file in GoogleAppEngine? | 1,274,035 | <p>I'm quite new to python and GAE, can anyone please provide some help/sample code for doing the following simple task? I managed to read a simple file and output it as a webpage but I need some slightly more complicated logic. Here is the pseudo code:</p>
<pre><code> open file;
for each line in file {
store f... | 1 | 2009-08-13T19:19:05Z | 1,274,374 | <p>Here's a generator-based solution with a few nice features:</p>
<ul>
<li>Tolerates multiple blank lines between albums in text file </li>
<li>Tolerates leading/trailing blank lines in text file </li>
<li>Uses only an album's worth of memory at a time </li>
<li>Demonstrates a lot of neato things you can do with P... | 3 | 2009-08-13T20:26:52Z | [
"python",
"google-app-engine",
"file-io"
] |
What is the correct way to generate a json from file in GoogleAppEngine? | 1,274,035 | <p>I'm quite new to python and GAE, can anyone please provide some help/sample code for doing the following simple task? I managed to read a simple file and output it as a webpage but I need some slightly more complicated logic. Here is the pseudo code:</p>
<pre><code> open file;
for each line in file {
store f... | 1 | 2009-08-13T19:19:05Z | 1,274,429 | <pre><code>from django.utils import simplejson
def albums(f):
"" yields lists of strings which are the
stripped lines for an album (blocks of
nonblank lines separated by blocks of
blank ones.
"""
while True:
# skip leading blank lines if any
for line in f:
if not line: return
l... | 1 | 2009-08-13T20:37:32Z | [
"python",
"google-app-engine",
"file-io"
] |
Why isn't assertRaises catching my Attribute Error using python unittest? | 1,274,047 | <p>I'm trying to run this test: <code>self.assertRaises(AttributeError, branch[0].childrennodes)</code>, and <code>branch[0</code>] does not have an attribute <code>childrennodes</code>, so it should be throwing an <code>AttributeError</code>, which the <code>assertRaises</code> should catch, but when I run the test, t... | 18 | 2009-08-13T19:21:28Z | 1,274,141 | <p>I think its because assert raises only accepts a callable. It evalutes to see if the callable raises an exception, not if the statement itself does.</p>
<pre><code>self.assertRaises(AttributeError, getattr, branch[0], "childrennodes")
</code></pre>
<p>should work.</p>
<p>EDIT:</p>
<p>As THC4k correctly says it g... | 19 | 2009-08-13T19:38:39Z | [
"python",
"django",
"unit-testing"
] |
Why isn't assertRaises catching my Attribute Error using python unittest? | 1,274,047 | <p>I'm trying to run this test: <code>self.assertRaises(AttributeError, branch[0].childrennodes)</code>, and <code>branch[0</code>] does not have an attribute <code>childrennodes</code>, so it should be throwing an <code>AttributeError</code>, which the <code>assertRaises</code> should catch, but when I run the test, t... | 18 | 2009-08-13T19:21:28Z | 2,267,788 | <p>When the test is running, before calling self.assertRaises, Python needs to find the value of all the method's arguments. In doing so, it evaluates <code>branch[0].children_nodes</code>, which raises an AttributeError. Since we haven't invoked assertRaises yet, this exception is not caught, causing the test to fail.... | 47 | 2010-02-15T17:41:07Z | [
"python",
"django",
"unit-testing"
] |
Why isn't assertRaises catching my Attribute Error using python unittest? | 1,274,047 | <p>I'm trying to run this test: <code>self.assertRaises(AttributeError, branch[0].childrennodes)</code>, and <code>branch[0</code>] does not have an attribute <code>childrennodes</code>, so it should be throwing an <code>AttributeError</code>, which the <code>assertRaises</code> should catch, but when I run the test, t... | 18 | 2009-08-13T19:21:28Z | 38,149,257 | <p>pytest also has a similar decorator:</p>
<pre><code>from pytest import raises
def test_raising():
with raises(AttributeError):
branch[0].childrennodes
</code></pre>
| 1 | 2016-07-01T15:38:41Z | [
"python",
"django",
"unit-testing"
] |
How can I write 'n <<= 1' (Python) in PHP? | 1,274,493 | <p>I have the Python expression <code>n <<= 1</code> </p>
<p>How do you express this in PHP?</p>
| 1 | 2009-08-13T20:50:16Z | 1,274,505 | <p>It's the same operator in php. <code>$n <<= 1;</code></p>
| 5 | 2009-08-13T20:52:23Z | [
"php",
"python",
"operators",
"bitwise-operators"
] |
How can I write 'n <<= 1' (Python) in PHP? | 1,274,493 | <p>I have the Python expression <code>n <<= 1</code> </p>
<p>How do you express this in PHP?</p>
| 1 | 2009-08-13T20:50:16Z | 1,274,508 | <p><code>$n <<= 1;</code> is valid php</p>
| 2 | 2009-08-13T20:52:52Z | [
"php",
"python",
"operators",
"bitwise-operators"
] |
How can I write 'n <<= 1' (Python) in PHP? | 1,274,493 | <p>I have the Python expression <code>n <<= 1</code> </p>
<p>How do you express this in PHP?</p>
| 1 | 2009-08-13T20:50:16Z | 1,274,556 | <p>That statement is short for</p>
<pre><code>n = n << 1;
</code></pre>
<p>the << operator is means a bitwise shift left, by n positions. Its counterpart is >>, which means shift right by n. To visualize, say you have the value 5, and you want to shift it left by 2 positions. In binary:</p>
<pre><code>00... | 6 | 2009-08-13T21:02:51Z | [
"php",
"python",
"operators",
"bitwise-operators"
] |
How can I create a list of files in the current directory and its subdirectories with a given extension? | 1,274,506 | <p>I'm trying to generate a text file that has a list of all files in the current directory and all of its sub-directories with the extension <code>".asp"</code>. What would be the best way to do this?</p>
| 5 | 2009-08-13T20:52:27Z | 1,274,528 | <p>You'll want to use os.walk which will make that trivial.</p>
<pre><code>import os
asps = []
for root, dirs, files in os.walk(r'C:\web'):
for file in files:
if file.endswith('.asp'):
asps.append(file)
</code></pre>
| 11 | 2009-08-13T20:57:08Z | [
"python"
] |
How can I create a list of files in the current directory and its subdirectories with a given extension? | 1,274,506 | <p>I'm trying to generate a text file that has a list of all files in the current directory and all of its sub-directories with the extension <code>".asp"</code>. What would be the best way to do this?</p>
| 5 | 2009-08-13T20:52:27Z | 1,274,530 | <p>walk the tree with <a href="http://docs.python.org/library/os.html#os.walk" rel="nofollow"><code>os.walk</code></a> and filter content with <a href="http://docs.python.org/library/glob.html" rel="nofollow"><code>glob</code></a>:</p>
<pre><code>import os
import glob
asps = []
for root, dirs, files in os.walk('/path... | 3 | 2009-08-13T20:57:42Z | [
"python"
] |
I'm trying to figure out how to use dbus with pidgin | 1,274,869 | <p>My problem is I'm not sure how to interface them. Do I need to have pidgin installed in a particular way in order for dbus to interface with it? and if not does the pidgin gui have to be running in order for dbus to utilize it?</p>
| 4 | 2009-08-13T22:01:29Z | 1,274,904 | <p>As per <a href="http://forums.devshed.com/python-programming-11/dbus-with-pidgin-help-with-changing-messages-from-pointer-518436.html">this</a> source you could do the following :</p>
<pre><code>#!/usr/bin/env python
def cb_func(account, rec, message):
#change message here somehow?
print message
import d... | 5 | 2009-08-13T22:12:43Z | [
"python",
"dbus"
] |
I'm trying to figure out how to use dbus with pidgin | 1,274,869 | <p>My problem is I'm not sure how to interface them. Do I need to have pidgin installed in a particular way in order for dbus to interface with it? and if not does the pidgin gui have to be running in order for dbus to utilize it?</p>
| 4 | 2009-08-13T22:01:29Z | 1,283,474 | <pre><code>import dbus
from dbus.mainloop.glib import DBusGMainLoop
main_loop = DBusGMainLoop()
session_bus = dbus.SessionBus(mainloop = main_loop)
obj = session_bus.get_object("im.pidgin.purple.PurpleService", "/im/pidgin/purple/PurpleObject")
purple = dbus.Interface(obj, "im.pidgin.purple.PurpleInterface")
</code></... | 4 | 2009-08-16T04:57:29Z | [
"python",
"dbus"
] |
I'm trying to figure out how to use dbus with pidgin | 1,274,869 | <p>My problem is I'm not sure how to interface them. Do I need to have pidgin installed in a particular way in order for dbus to interface with it? and if not does the pidgin gui have to be running in order for dbus to utilize it?</p>
| 4 | 2009-08-13T22:01:29Z | 1,587,278 | <p>A really useful tool to use when getting started with using DBUS to interface with Pidgin is <a href="https://fedorahosted.org/d-feet/" rel="nofollow">D-Feet</a>. You can see all the available methods you can call and even execute them directly from the GUI.</p>
| 2 | 2009-10-19T06:49:00Z | [
"python",
"dbus"
] |
I'm trying to figure out how to use dbus with pidgin | 1,274,869 | <p>My problem is I'm not sure how to interface them. Do I need to have pidgin installed in a particular way in order for dbus to interface with it? and if not does the pidgin gui have to be running in order for dbus to utilize it?</p>
| 4 | 2009-08-13T22:01:29Z | 1,589,096 | <p>You do not need to do any special configuration of Pidgin to use D-Bus, however it must be running if you want to use it. You can check the script I'm using to control Pidgin status from the NetworkManager-dispatcher (<a href="http://github.com/abbot/shredder/blob/master/pidgin-netstatus.py" rel="nofollow">part 1</a... | 0 | 2009-10-19T14:45:52Z | [
"python",
"dbus"
] |
I'm trying to figure out how to use dbus with pidgin | 1,274,869 | <p>My problem is I'm not sure how to interface them. Do I need to have pidgin installed in a particular way in order for dbus to interface with it? and if not does the pidgin gui have to be running in order for dbus to utilize it?</p>
| 4 | 2009-08-13T22:01:29Z | 21,430,579 | <p>The code below has an example of showing the buddy list when it is hidden and another example of starting an IM conversation with a specific contact.</p>
<pre><code>import dbus
BUS_ARGS = ('im.pidgin.purple.PurpleService', '/im/pidgin/purple/PurpleObject')
obj = dbus.SessionBus().get_object(*BUS_ARGS)
purple = dbus... | 2 | 2014-01-29T12:03:22Z | [
"python",
"dbus"
] |
Returning None or a tuple and unpacking | 1,274,875 | <p>I am always annoyed by this fact:</p>
<pre><code>$ cat foo.py
def foo(flag):
if flag:
return (1,2)
else:
return None
first, second = foo(True)
first, second = foo(False)
$ python foo.py
Traceback (most recent call last):
File "foo.py", line 8, in <module>
first, second = foo(Fa... | 13 | 2009-08-13T22:03:19Z | 1,274,887 | <p>Well, you could do...</p>
<pre><code>first,second = foo(True) or (None,None)
first,second = foo(False) or (None,None)
</code></pre>
<p>but as far as I know there's no simpler way to expand None to fill in the entirety of a tuple.</p>
| 14 | 2009-08-13T22:06:25Z | [
"python",
"design",
"return-value"
] |
Returning None or a tuple and unpacking | 1,274,875 | <p>I am always annoyed by this fact:</p>
<pre><code>$ cat foo.py
def foo(flag):
if flag:
return (1,2)
else:
return None
first, second = foo(True)
first, second = foo(False)
$ python foo.py
Traceback (most recent call last):
File "foo.py", line 8, in <module>
first, second = foo(Fa... | 13 | 2009-08-13T22:03:19Z | 1,274,888 | <p>I don't think there's a trick. You can simplify your calling code to:</p>
<pre><code>values = foo(False)
if values:
first, second = values
</code></pre>
<p>or even:</p>
<pre><code>values = foo(False)
first, second = values or (first_default, second_default)
</code></pre>
<p>where first_default and second_def... | 7 | 2009-08-13T22:07:16Z | [
"python",
"design",
"return-value"
] |
Returning None or a tuple and unpacking | 1,274,875 | <p>I am always annoyed by this fact:</p>
<pre><code>$ cat foo.py
def foo(flag):
if flag:
return (1,2)
else:
return None
first, second = foo(True)
first, second = foo(False)
$ python foo.py
Traceback (most recent call last):
File "foo.py", line 8, in <module>
first, second = foo(Fa... | 13 | 2009-08-13T22:03:19Z | 1,274,908 | <p>I don't see what is wrong with returning (None,None). It is much cleaner than the solutions suggested here which involve far more changes in your code. </p>
<p>It also doesn't make sense that you want None to automagically be split into 2 variables.</p>
| 16 | 2009-08-13T22:14:14Z | [
"python",
"design",
"return-value"
] |
Returning None or a tuple and unpacking | 1,274,875 | <p>I am always annoyed by this fact:</p>
<pre><code>$ cat foo.py
def foo(flag):
if flag:
return (1,2)
else:
return None
first, second = foo(True)
first, second = foo(False)
$ python foo.py
Traceback (most recent call last):
File "foo.py", line 8, in <module>
first, second = foo(Fa... | 13 | 2009-08-13T22:03:19Z | 1,274,932 | <p>You should be careful with the <code>x or y</code> style of solution. They work, but they're a bit broader than your original specification. Essentially, what if <code>foo(True)</code> returns an empty tuple <code>()</code>? As long as you know that it's OK to treat that as <code>(None, None)</code>, you're good ... | 2 | 2009-08-13T22:19:29Z | [
"python",
"design",
"return-value"
] |
Returning None or a tuple and unpacking | 1,274,875 | <p>I am always annoyed by this fact:</p>
<pre><code>$ cat foo.py
def foo(flag):
if flag:
return (1,2)
else:
return None
first, second = foo(True)
first, second = foo(False)
$ python foo.py
Traceback (most recent call last):
File "foo.py", line 8, in <module>
first, second = foo(Fa... | 13 | 2009-08-13T22:03:19Z | 1,274,945 | <pre><code>def foo(flag):
return ((1,2) if flag else (None, None))
</code></pre>
| 1 | 2009-08-13T22:22:15Z | [
"python",
"design",
"return-value"
] |
Returning None or a tuple and unpacking | 1,274,875 | <p>I am always annoyed by this fact:</p>
<pre><code>$ cat foo.py
def foo(flag):
if flag:
return (1,2)
else:
return None
first, second = foo(True)
first, second = foo(False)
$ python foo.py
Traceback (most recent call last):
File "foo.py", line 8, in <module>
first, second = foo(Fa... | 13 | 2009-08-13T22:03:19Z | 1,275,055 | <p>I think there is a problem of <strong>abstraction</strong>. </p>
<p>A function should maintain some level of abstraction, that helps in reducing complexity of the code.<br />
In this case, either the function is not maintaining the right abstraction, either the caller is not respecting it.</p>
<p>The function cou... | 11 | 2009-08-13T22:45:50Z | [
"python",
"design",
"return-value"
] |
Returning None or a tuple and unpacking | 1,274,875 | <p>I am always annoyed by this fact:</p>
<pre><code>$ cat foo.py
def foo(flag):
if flag:
return (1,2)
else:
return None
first, second = foo(True)
first, second = foo(False)
$ python foo.py
Traceback (most recent call last):
File "foo.py", line 8, in <module>
first, second = foo(Fa... | 13 | 2009-08-13T22:03:19Z | 1,275,323 | <p>How about this:</p>
<pre><code>$ cat foo.py
def foo(flag):
if flag:
return (1,2)
else:
return (None,)*2
first, second = foo(True)
first, second = foo(False)
</code></pre>
<p><strong>Edit:</strong> Just to be clear, the only change is to replace <code>return None</code> with <code>return (... | 1 | 2009-08-13T23:54:49Z | [
"python",
"design",
"return-value"
] |
Returning None or a tuple and unpacking | 1,274,875 | <p>I am always annoyed by this fact:</p>
<pre><code>$ cat foo.py
def foo(flag):
if flag:
return (1,2)
else:
return None
first, second = foo(True)
first, second = foo(False)
$ python foo.py
Traceback (most recent call last):
File "foo.py", line 8, in <module>
first, second = foo(Fa... | 13 | 2009-08-13T22:03:19Z | 1,275,693 | <p>OK, I would just return (None, None), but as long as we are in whacko-land (heh), here is a way using a subclass of tuple. In the else case, you don't return None, but instead return an empty container, which seems to be in the spirit of things. The container's "iterator" unpacks None values when empty. Demonstra... | 1 | 2009-08-14T02:07:09Z | [
"python",
"design",
"return-value"
] |
collapsing whitespace in a string | 1,274,906 | <p>I have a string that kind of looks like this:</p>
<pre><code>"stuff . // : /// more-stuff .. .. ...$%$% stuff -> DD"
</code></pre>
<p>and I want to strip off all punctuation, make everything uppercase and collapse all whitespace so that it looks like this:</p>
<pre><code>"STUFF MORE STUFF STUFF DD"
</code><... | 3 | 2009-08-13T22:13:50Z | 1,274,913 | <pre><code>result = rex.sub(' ', string) # this produces a string with tons of whitespace padding
result = rex.sub('', result) # this reduces all those spaces
</code></pre>
<p>Because you typo'd and forgot to use rex_s for the second call instead. Also, you need to substitute at least one space back in or you'll end u... | 3 | 2009-08-13T22:15:08Z | [
"python",
"regex"
] |
collapsing whitespace in a string | 1,274,906 | <p>I have a string that kind of looks like this:</p>
<pre><code>"stuff . // : /// more-stuff .. .. ...$%$% stuff -> DD"
</code></pre>
<p>and I want to strip off all punctuation, make everything uppercase and collapse all whitespace so that it looks like this:</p>
<pre><code>"STUFF MORE STUFF STUFF DD"
</code><... | 3 | 2009-08-13T22:13:50Z | 1,274,918 | <p>Here's a single-step approach (but the uppercasing actually uses a string method -- much simpler!-):</p>
<pre><code>rex = re.compile(r'\W+')
result = rex.sub(' ', strarg).upper()
</code></pre>
<p>where <code>strarg</code> is the string argument (<em>don't</em> use names that shadow builtins or standard library mod... | 14 | 2009-08-13T22:15:59Z | [
"python",
"regex"
] |
collapsing whitespace in a string | 1,274,906 | <p>I have a string that kind of looks like this:</p>
<pre><code>"stuff . // : /// more-stuff .. .. ...$%$% stuff -> DD"
</code></pre>
<p>and I want to strip off all punctuation, make everything uppercase and collapse all whitespace so that it looks like this:</p>
<pre><code>"STUFF MORE STUFF STUFF DD"
</code><... | 3 | 2009-08-13T22:13:50Z | 1,275,019 | <p>Do you have to use regular expressions? Do you feel you must do it in one line?</p>
<pre><code>>>> import string
>>> s = "stuff . // : /// more-stuff .. .. ...$%$% stuff -> DD"
>>> s2 = ''.join(c for c in s if c in string.letters + ' ')
>>> ' '.join(s2.split())
'stuff more... | 1 | 2009-08-13T22:38:39Z | [
"python",
"regex"
] |
collapsing whitespace in a string | 1,274,906 | <p>I have a string that kind of looks like this:</p>
<pre><code>"stuff . // : /// more-stuff .. .. ...$%$% stuff -> DD"
</code></pre>
<p>and I want to strip off all punctuation, make everything uppercase and collapse all whitespace so that it looks like this:</p>
<pre><code>"STUFF MORE STUFF STUFF DD"
</code><... | 3 | 2009-08-13T22:13:50Z | 1,275,406 | <pre><code>s = "$$$aa1bb2 cc-dd ee_ff ggg."
re.sub(r'\W+', ' ', s).upper()
# ' AA1BB2 CC DD EE_FF GGG '
</code></pre>
<p>Is _ punctuation?</p>
<pre><code>re.sub(r'[_\W]+', ' ', s).upper()
# ' AA1BB2 CC DD EE FF GGG '
</code></pre>
<p>Don't want the leading and trailing space?</p>
<pre><code>re.sub(r'[_\W]+', ' ', s... | 3 | 2009-08-14T00:23:59Z | [
"python",
"regex"
] |
collapsing whitespace in a string | 1,274,906 | <p>I have a string that kind of looks like this:</p>
<pre><code>"stuff . // : /// more-stuff .. .. ...$%$% stuff -> DD"
</code></pre>
<p>and I want to strip off all punctuation, make everything uppercase and collapse all whitespace so that it looks like this:</p>
<pre><code>"STUFF MORE STUFF STUFF DD"
</code><... | 3 | 2009-08-13T22:13:50Z | 22,213,412 | <p>works in python3 this will retain the same whitespace character you collapsed. So if you have a tab and a space next to each other they wont collapse into a single character.</p>
<pre><code>def collapse_whitespace_characters(raw_text):
ret = ''
if len(raw_text) > 1:
prev_char = raw_text[0]
... | 1 | 2014-03-06T02:05:22Z | [
"python",
"regex"
] |
Eliminate part of a file in python | 1,274,941 | <p>In the below file I have 3 occurrences of '.1'. I want to eliminate the last one and write the rest of file to a new file. Kindly suggest some way to do it in PYTHON and thank you all.</p>
<blockquote>
<p>d1dlwa_ a.1.1.1 (A:) Protozoan/bacterial hemoglobin {Ciliate (Paramecium caudatum) [TaxId: 5885]}
slfeqlggq... | 1 | 2009-08-13T22:21:00Z | 1,274,958 | <p>If the file's not too horrendously huge, by far the simplest approach is:</p>
<pre><code>f = open('oldfile', 'r')
data = f.read()
f.close()
data = data.replace('.1.1.1', '.1.1')
f = open('newfile', 'w')
f.write(data)
f.close()
</code></pre>
<p>If the file IS horrendously huge, you'll need to read it and write it... | 7 | 2009-08-13T22:24:35Z | [
"python",
"file"
] |
Eliminate part of a file in python | 1,274,941 | <p>In the below file I have 3 occurrences of '.1'. I want to eliminate the last one and write the rest of file to a new file. Kindly suggest some way to do it in PYTHON and thank you all.</p>
<blockquote>
<p>d1dlwa_ a.1.1.1 (A:) Protozoan/bacterial hemoglobin {Ciliate (Paramecium caudatum) [TaxId: 5885]}
slfeqlggq... | 1 | 2009-08-13T22:21:00Z | 1,274,960 | <p>You can have something like this :</p>
<pre><code>
line = line.split(" ")
line[0] = line[0][0:line[0].rindex(".")]
print " ".join(line)
</code></pre>
<p>Not the prettiest code, but from my console tests, it works.</p>
| 0 | 2009-08-13T22:24:51Z | [
"python",
"file"
] |
Eliminate part of a file in python | 1,274,941 | <p>In the below file I have 3 occurrences of '.1'. I want to eliminate the last one and write the rest of file to a new file. Kindly suggest some way to do it in PYTHON and thank you all.</p>
<blockquote>
<p>d1dlwa_ a.1.1.1 (A:) Protozoan/bacterial hemoglobin {Ciliate (Paramecium caudatum) [TaxId: 5885]}
slfeqlggq... | 1 | 2009-08-13T22:21:00Z | 1,274,969 | <p>Works with any size file:</p>
<pre><code>open('newfile', 'w').writelines(line.replace('.1.1.1', '.1.1')
for line in open('oldfile'))
</code></pre>
| 4 | 2009-08-13T22:28:23Z | [
"python",
"file"
] |
Does django's Form class maintain state? | 1,275,009 | <p>I'm building my first form with django, and I'm seeing some behavior that I really did not expect at all. I defined a form class:</p>
<pre><code>class AssignmentFilterForm(forms.Form):
filters = []
filter = forms.ChoiceField()
def __init__(self, *args, **kwargs):
super(forms.Form, self).__init__(*args, **kwargs)
... | 0 | 2009-08-13T22:35:35Z | 1,275,057 | <p>You're appending to the PER-CLASS variable self.filters. Make it into a PER-INSTANCE variable instead, by doing <code>self.filters = []</code> at the start of <code>__init__</code>.</p>
| 1 | 2009-08-13T22:46:18Z | [
"python",
"django"
] |
Does django's Form class maintain state? | 1,275,009 | <p>I'm building my first form with django, and I'm seeing some behavior that I really did not expect at all. I defined a form class:</p>
<pre><code>class AssignmentFilterForm(forms.Form):
filters = []
filter = forms.ChoiceField()
def __init__(self, *args, **kwargs):
super(forms.Form, self).__init__(*args, **kwargs)
... | 0 | 2009-08-13T22:35:35Z | 1,275,174 | <p>This is actually a feature of Python that catches a lot of people.</p>
<p>When you define variables on the class as you have with <code>filters = []</code> the right half of the expression is evaluated when the class is initially defined. So when your code is first run it will create a new list in memory and return... | 7 | 2009-08-13T23:12:50Z | [
"python",
"django"
] |
Does django's Form class maintain state? | 1,275,009 | <p>I'm building my first form with django, and I'm seeing some behavior that I really did not expect at all. I defined a form class:</p>
<pre><code>class AssignmentFilterForm(forms.Form):
filters = []
filter = forms.ChoiceField()
def __init__(self, *args, **kwargs):
super(forms.Form, self).__init__(*args, **kwargs)
... | 0 | 2009-08-13T22:35:35Z | 1,275,451 | <p>As answered above, you need to initialize filters as an instance variable:</p>
<pre><code>def __init__(...):
self.filters = []
self.filters.append(...)
# ...
</code></pre>
<p>If you want to know more about how the Form class works, you should read this page in the Django wiki:</p>
<ul>
<li><a href="ht... | 0 | 2009-08-14T00:37:13Z | [
"python",
"django"
] |
Does django's Form class maintain state? | 1,275,009 | <p>I'm building my first form with django, and I'm seeing some behavior that I really did not expect at all. I defined a form class:</p>
<pre><code>class AssignmentFilterForm(forms.Form):
filters = []
filter = forms.ChoiceField()
def __init__(self, *args, **kwargs):
super(forms.Form, self).__init__(*args, **kwargs)
... | 0 | 2009-08-13T22:35:35Z | 1,276,608 | <p>To clarify from some of the other answers:</p>
<p>The fields are, and must be, class variables. They get all sorts of things done to them by the metaclass, and this is the correct way to define them.</p>
<p>However, your <code>filters</code> variable does not need to be a class var. It can quite easily be an insta... | 0 | 2009-08-14T08:05:47Z | [
"python",
"django"
] |
Does django's Form class maintain state? | 1,275,009 | <p>I'm building my first form with django, and I'm seeing some behavior that I really did not expect at all. I defined a form class:</p>
<pre><code>class AssignmentFilterForm(forms.Form):
filters = []
filter = forms.ChoiceField()
def __init__(self, *args, **kwargs):
super(forms.Form, self).__init__(*args, **kwargs)
... | 0 | 2009-08-13T22:35:35Z | 1,284,510 | <p>I picked up the book Pro Django which answers this question. It's a great book by the way, and I highly recommend it!</p>
<p>The solution is to make BOTH the choice field and my helper var both instance variables:</p>
<pre><code>class AssignmentFilterForm(forms.Form):
def __init__(self, pg, request = None):
super... | 1 | 2009-08-16T15:15:13Z | [
"python",
"django"
] |
How to use Staticgenerator with Django + Apache + mod_python | 1,275,270 | <p>I have currently an enviroment with Django + Apache via mod_python. How can I use <a href="http://superjared.com/projects/static-generator/" rel="nofollow" title="Staticgenerator">Staticgenerator</a> without nginx, just with Apache and mod_python? Thank you.</p>
| 2 | 2009-08-13T23:35:37Z | 1,275,299 | <p>Perhaps this page from the webfaction forum will help:</p>
<ul>
<li><a href="http://forum.webfaction.com/viewtopic.php?id=1945" rel="nofollow">http://forum.webfaction.com/viewtopic.php?id=1945</a></li>
</ul>
| 0 | 2009-08-13T23:48:10Z | [
"python",
"django",
"apache",
"mod-python"
] |
How to use Staticgenerator with Django + Apache + mod_python | 1,275,270 | <p>I have currently an enviroment with Django + Apache via mod_python. How can I use <a href="http://superjared.com/projects/static-generator/" rel="nofollow" title="Staticgenerator">Staticgenerator</a> without nginx, just with Apache and mod_python? Thank you.</p>
| 2 | 2009-08-13T23:35:37Z | 2,000,049 | <p><a href="http://superjared.com/projects/static-generator/" rel="nofollow">Staticgenerator</a> is designed to be used with a front-end http server. The example configuration as shown on the <a href="http://github.com/JaredKuolt/staticgenerator" rel="nofollow">Github Staticgenerator</a> page is using <a href="http://n... | 0 | 2010-01-04T15:01:10Z | [
"python",
"django",
"apache",
"mod-python"
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.