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
Would you use numpy if you were just manipulating a sequence of binary values?
2,301,018
<p>Is there any advantage to using numpy when you're doing a large number of operations on lists of binary values? How about integers within a small range (like just the numbers 1,2, and 3?)</p>
3
2010-02-20T04:17:43Z
2,301,041
<p>If the number of input values is huge, or if you are doing a lot of operations, you might want to try <a href="http://pypi.python.org/pypi/bitarray/0.3.5" rel="nofollow">bitarray</a>. Or, see the <code>bool</code>/<code>int8</code>/<code>uint8</code> dtype in Numpy's ndarray:</p> <pre><code>In [1]: import numpy as...
1
2010-02-20T04:24:44Z
[ "python", "numpy", "scipy", "bit-manipulation" ]
Would you use numpy if you were just manipulating a sequence of binary values?
2,301,018
<p>Is there any advantage to using numpy when you're doing a large number of operations on lists of binary values? How about integers within a small range (like just the numbers 1,2, and 3?)</p>
3
2010-02-20T04:17:43Z
2,302,191
<p>Eliminating the loops is the the source of the performance gain (10x):</p> <pre><code>import profile import numpy as NP def np_test(a2darray) : row_sums = NP.sum(a2darray, axis=1) return NP.sum(row_sums) def stdlib_test2(a2dlist) : return sum([sum(row) for row in a2dlist]) A = NP.random.randint(1, 6, 1e7)....
3
2010-02-20T12:40:18Z
[ "python", "numpy", "scipy", "bit-manipulation" ]
PySerial App runs in shell, by not py script
2,301,127
<p>I have a very simple python script that uses pySerial to send data over the serial port to my Arduino. When I execute this line-by-line in the python shell, it works just fine, but when I put it in a ".py" file, and try to run it, nothing happens. Though the serial lights on my UART do flash. So something is gett...
4
2010-02-20T05:06:29Z
2,301,629
<p>Maybe be stupid, but try to type only "myscript.py" in cmd.exe, if you are on Windows. I've noticed that on Windows, you do not need to type "python" before script name. This is of course for standard CPython installation on Windows.</p>
0
2010-02-20T08:56:04Z
[ "python", "shell", "serial-port", "arduino", "pyserial" ]
PySerial App runs in shell, by not py script
2,301,127
<p>I have a very simple python script that uses pySerial to send data over the serial port to my Arduino. When I execute this line-by-line in the python shell, it works just fine, but when I put it in a ".py" file, and try to run it, nothing happens. Though the serial lights on my UART do flash. So something is gett...
4
2010-02-20T05:06:29Z
2,308,078
<p>OK, I've figured it out!</p> <p>It's necessary to use code like this before performing the write:</p> <pre><code>time.sleep(1) ser.setDTR(level=0) time.sleep(1) </code></pre> <p>Otherwise, the arduino automatically resets upon receiving a serial connection for some reason. yay!</p>
7
2010-02-22T00:14:32Z
[ "python", "shell", "serial-port", "arduino", "pyserial" ]
PySerial App runs in shell, by not py script
2,301,127
<p>I have a very simple python script that uses pySerial to send data over the serial port to my Arduino. When I execute this line-by-line in the python shell, it works just fine, but when I put it in a ".py" file, and try to run it, nothing happens. Though the serial lights on my UART do flash. So something is gett...
4
2010-02-20T05:06:29Z
4,176,063
<p>I've noticed that if you're on Windows 64-bit then the pyserial simply does not work. I'm using Python 2.7, and after installing the x86 version via the administrator account, and using the mentioned code above </p> <pre><code>time.sleep(1) ser.setDTR(level=0) time.sleep(1) </code></pre> <p>appended before the w...
1
2010-11-14T03:27:19Z
[ "python", "shell", "serial-port", "arduino", "pyserial" ]
PySerial App runs in shell, by not py script
2,301,127
<p>I have a very simple python script that uses pySerial to send data over the serial port to my Arduino. When I execute this line-by-line in the python shell, it works just fine, but when I put it in a ".py" file, and try to run it, nothing happens. Though the serial lights on my UART do flash. So something is gett...
4
2010-02-20T05:06:29Z
14,660,689
<p>May I suggest one more sleep, this time, after you close the serial port.</p> <pre><code>import serial ser = serial.Serial('COM3',9600,timeout=.2) ser.write('A') ser.close() time.sleep(3000) //for a first test, give a whopping 3 seconds //sleep(100), 100 ms (0.1 second) may be enough in final product </code>...
0
2013-02-02T09:55:53Z
[ "python", "shell", "serial-port", "arduino", "pyserial" ]
PySerial App runs in shell, by not py script
2,301,127
<p>I have a very simple python script that uses pySerial to send data over the serial port to my Arduino. When I execute this line-by-line in the python shell, it works just fine, but when I put it in a ".py" file, and try to run it, nothing happens. Though the serial lights on my UART do flash. So something is gett...
4
2010-02-20T05:06:29Z
35,908,067
<p>In my case the following worked.</p> <pre><code> time.sleep(1) ser.setDTR(level=1) time.sleep(1) </code></pre>
0
2016-03-10T05:11:01Z
[ "python", "shell", "serial-port", "arduino", "pyserial" ]
Creating HTML in python
2,301,163
<p>I am looking for a way to create html files dynamically in python. I am writing a gallery script, which iterates over directories, collecting file meta data. I intended to then use this data to automatically create a picture gallery, based on html. Something very simple, just a table of pictures. </p> <p>I real...
19
2010-02-20T05:18:18Z
2,301,169
<p>Use a templating engine such as <a href="http://genshi.edgewall.org/">Genshi</a> or <a href="http://jinja.pocoo.org/2/">Jinja2</a>.</p>
8
2010-02-20T05:21:27Z
[ "python", "html" ]
Creating HTML in python
2,301,163
<p>I am looking for a way to create html files dynamically in python. I am writing a gallery script, which iterates over directories, collecting file meta data. I intended to then use this data to automatically create a picture gallery, based on html. Something very simple, just a table of pictures. </p> <p>I real...
19
2010-02-20T05:18:18Z
2,301,176
<p>I think, if i understand you correct, you can see <a href="http://wiki.python.org/moin/Templating">here</a>.</p>
9
2010-02-20T05:22:29Z
[ "python", "html" ]
Creating HTML in python
2,301,163
<p>I am looking for a way to create html files dynamically in python. I am writing a gallery script, which iterates over directories, collecting file meta data. I intended to then use this data to automatically create a picture gallery, based on html. Something very simple, just a table of pictures. </p> <p>I real...
19
2010-02-20T05:18:18Z
2,302,474
<p>Templating, as suggested in other answers, is probably the best answer (I wrote an early, quirky templating module called <a href="http://code.activestate.com/recipes/52305/" rel="nofollow">yaptu</a>, but modern mature ones as suggested in other answers will probably make you happier;-).</p> <p>However, though it's...
1
2010-02-20T14:18:47Z
[ "python", "html" ]
Creating HTML in python
2,301,163
<p>I am looking for a way to create html files dynamically in python. I am writing a gallery script, which iterates over directories, collecting file meta data. I intended to then use this data to automatically create a picture gallery, based on html. Something very simple, just a table of pictures. </p> <p>I real...
19
2010-02-20T05:18:18Z
23,926,002
<p><a href="https://github.com/Knio/dominate">Dominate</a> is a Python library for creating HTML documents and fragments directly in code without using templating. You could create a simple image gallery with something like this:</p> <pre class="lang-py prettyprint-override"><code>import glob from dominate import docu...
9
2014-05-29T05:02:55Z
[ "python", "html" ]
How to efficiently parse emails without touching attachments using Python
2,301,213
<p>I'm playing with Python imaplib (Python 2.6) to fetch emails from GMail. Everything I fetch an email with method <a href="http://docs.python.org/library/imaplib.html#imaplib.IMAP4.fetch">http://docs.python.org/library/imaplib.html#imaplib.IMAP4.fetch</a> I get whole email. I need only text part and also parse names ...
6
2010-02-20T05:40:31Z
2,301,409
<p>I'm afraid you're out of luck. According to <a href="http://www.coderanch.com/t/475359/Other-JSE-JEE-APIs/java/IMAP-javax-mail-Fetching-Only" rel="nofollow">this post</a>, there are only two parts to the email - the header and the body. The body is where the attachments are if there are any and you have to download ...
1
2010-02-20T07:09:15Z
[ "python", "parsing", "gmail", "imap", "imaplib" ]
How to efficiently parse emails without touching attachments using Python
2,301,213
<p>I'm playing with Python imaplib (Python 2.6) to fetch emails from GMail. Everything I fetch an email with method <a href="http://docs.python.org/library/imaplib.html#imaplib.IMAP4.fetch">http://docs.python.org/library/imaplib.html#imaplib.IMAP4.fetch</a> I get whole email. I need only text part and also parse names ...
6
2010-02-20T05:40:31Z
2,303,457
<p>Take a look at this recipe: <a href="http://code.activestate.com/recipes/498189/" rel="nofollow">http://code.activestate.com/recipes/498189/</a></p> <p>I adapted it slightly to print the From, Subject, Date, name of attachments, and message body (just plaintext for now -- its trivial to add html messages).</p> <p>...
4
2010-02-20T19:54:16Z
[ "python", "parsing", "gmail", "imap", "imaplib" ]
How to efficiently parse emails without touching attachments using Python
2,301,213
<p>I'm playing with Python imaplib (Python 2.6) to fetch emails from GMail. Everything I fetch an email with method <a href="http://docs.python.org/library/imaplib.html#imaplib.IMAP4.fetch">http://docs.python.org/library/imaplib.html#imaplib.IMAP4.fetch</a> I get whole email. I need only text part and also parse names ...
6
2010-02-20T05:40:31Z
3,454,587
<p>You can get only the plain text of the email by doing something like:</p> <pre><code>connection.fetch(id, '(BODY[1])') </code></pre> <p>For the gmail messages I've seen, section 1 has the plaintext, including multipart junk. This may not be so robust.</p> <p>I don't know how to get the name of the attachment with...
2
2010-08-11T00:59:34Z
[ "python", "parsing", "gmail", "imap", "imaplib" ]
python - syntax error
2,301,214
<p>Hi:) I am not able to figure out what the error in the program is could you please help me out with it. Thank you..:)</p> <p>The input file contains the following:</p> <pre><code>3. भारत का इतिहास काफी समृद्ध एवं विस्तृत है। 57. जैसे à¤...
0
2010-02-20T05:42:09Z
2,301,494
<p>If you have syntax error, your editor may be showing it before even running it? I any case why don't you try removing that char where error is being indicated, because I am not able to replicate problem, after copying your code.</p>
0
2010-02-20T07:52:12Z
[ "python", "nlp" ]
python - syntax error
2,301,214
<p>Hi:) I am not able to figure out what the error in the program is could you please help me out with it. Thank you..:)</p> <p>The input file contains the following:</p> <pre><code>3. भारत का इतिहास काफी समृद्ध एवं विस्तृत है। 57. जैसे à¤...
0
2010-02-20T05:42:09Z
2,301,536
<p>What is posted here does not have the error. Note that what is posted has TWO space characters between the + and the u in <code>output += word[-1] + u'(%d) ' % counter</code>. What is probably happening is that you have a whitespace character other than a space in there. A possibility is NBSP (U+00A0) aka "no-break...
3
2010-02-20T08:08:25Z
[ "python", "nlp" ]
Python multiple threads accessing same file
2,301,458
<p>I have two threads, one which writes to a file, and another which periodically moves the file to a different location. The writes always calls <code>open</code> before writing a message, and calls <code>close</code> after writing the message. The mover uses shutil.move to do the move.</p> <p>I see that after the fi...
10
2010-02-20T07:38:57Z
2,301,462
<p>When two threads access the same resources, weird things happen. To avoid that, always lock the resource. Python has the convenient <code>threading.Lock</code> for that, as well as some other tools (see documentation of the <code>threading</code> module).</p>
7
2010-02-20T07:40:59Z
[ "python", "file", "multithreading" ]
Python multiple threads accessing same file
2,301,458
<p>I have two threads, one which writes to a file, and another which periodically moves the file to a different location. The writes always calls <code>open</code> before writing a message, and calls <code>close</code> after writing the message. The mover uses shutil.move to do the move.</p> <p>I see that after the fi...
10
2010-02-20T07:38:57Z
2,301,471
<p>Check out <a href="http://www.evanfosmark.com/2009/01/cross-platform-file-locking-support-in-python/" rel="nofollow">http://www.evanfosmark.com/2009/01/cross-platform-file-locking-support-in-python/</a></p> <p>You can use a simple lock with his code, as written by Evan Fosmark in an older StackOverflow question:</p...
3
2010-02-20T07:43:56Z
[ "python", "file", "multithreading" ]
Python multiple threads accessing same file
2,301,458
<p>I have two threads, one which writes to a file, and another which periodically moves the file to a different location. The writes always calls <code>open</code> before writing a message, and calls <code>close</code> after writing the message. The mover uses shutil.move to do the move.</p> <p>I see that after the fi...
10
2010-02-20T07:38:57Z
2,302,427
<p>Locking is a possible solution, but I prefer the general architecture of having each external resource (including a file) dealt with by a single, separate thread. Other threads send work requests to the dedicated thread on a <a href="http://docs.python.org/library/queue.html?highlight=queue.queue#Queue.Queue">Queue...
22
2010-02-20T14:02:37Z
[ "python", "file", "multithreading" ]
Python API for VirtualBox
2,301,534
<p>I have made a command-line interface for virtualbox such that the virtualbox can be controlled from a remote machine. now I am trying to implement the commmand-line interface using python virtualbox api. For that I have downloaded the pyvb package (python api documentation shows functions that can be used for implem...
3
2010-02-20T08:07:21Z
2,436,668
<p>You might want to check the official Python API from Virtualbox. pyvb seems like a wrapper written by a third party.</p> <p>The virtualbox sdk contains Python examples and full API documentation. </p>
3
2010-03-13T00:09:20Z
[ "python", "api", "virtualbox" ]
cannot import name formats
2,301,703
<p>what does it mean? i ve googled but found nothing =/</p> <pre><code>ImportError at /admin/ cannot import name formats Request Method: GET Request URL: http://127.0.0.1:8000/admin/ Exception Type: ImportError Exception Value: cannot import name formats Exception Location: /usr/lib/python2.6/site-packages/d...
1
2010-02-20T09:40:27Z
2,302,320
<p>What that line is trying to do (see <a href="http://code.djangoproject.com/browser/django/trunk/django/contrib/admin/util.py" rel="nofollow">the sources</a>) is</p> <pre><code>3 from django.utils import formats </code></pre> <p>If you don't have the parent directory of the <code>django/</code> directory on your ...
1
2010-02-20T13:25:38Z
[ "python", "django", "admin" ]
Read a file in reverse order using python
2,301,789
<p>How to read a file in reverse order using python? I want to read a file from last line to first line.</p>
59
2010-02-20T10:09:26Z
2,301,792
<pre><code>for line in reversed(open("filename").readlines()): print line.rstrip() </code></pre> <p>And in Python 3:</p> <pre><code>for line in reversed(list(open("filename"))): print(line.rstrip()) </code></pre>
46
2010-02-20T10:10:52Z
[ "python", "file", "reverse" ]
Read a file in reverse order using python
2,301,789
<p>How to read a file in reverse order using python? I want to read a file from last line to first line.</p>
59
2010-02-20T10:09:26Z
2,301,802
<pre><code>for line in reversed(open("file").readlines()): print line.rstrip() </code></pre> <p>If you are on linux, you can use <code>tac</code> command.</p> <pre><code>$ tac file </code></pre> <p>2 recipes you can find in ActiveState <a href="http://code.activestate.com/recipes/276149/">here</a> and <a href="h...
7
2010-02-20T10:13:43Z
[ "python", "file", "reverse" ]
Read a file in reverse order using python
2,301,789
<p>How to read a file in reverse order using python? I want to read a file from last line to first line.</p>
59
2010-02-20T10:09:26Z
2,301,867
<pre class="lang-py prettyprint-override"><code>import re def filerev(somefile, buffer=0x20000): somefile.seek(0, os.SEEK_END) size = somefile.tell() lines = [''] rem = size % buffer pos = max(0, (size // buffer - 1) * buffer) while pos &gt;= 0: somefile.seek(pos, os.SEEK_SET) data = somefile.read(...
8
2010-02-20T10:36:27Z
[ "python", "file", "reverse" ]
Read a file in reverse order using python
2,301,789
<p>How to read a file in reverse order using python? I want to read a file from last line to first line.</p>
59
2010-02-20T10:09:26Z
2,302,010
<p>I had to do this some time ago and used the below code. It pipes to the shell. I am afraid i do not have the complete script anymore. If you are on a unixish operating system, you can use "tac", however on e.g. Mac OSX tac command does not work, use tail -r. The below code snippet tests for which platform you're on,...
-2
2010-02-20T11:26:23Z
[ "python", "file", "reverse" ]
Read a file in reverse order using python
2,301,789
<p>How to read a file in reverse order using python? I want to read a file from last line to first line.</p>
59
2010-02-20T10:09:26Z
10,192,782
<p>Here you can find my my implementation, you can limit the ram usage by changing the "buffer" variable, there is a bug that the program prints an empty line in the beginning.</p> <p>And also ram usage may be increase if there is no new lines for more than buffer bytes, "leak" variable will increase until seeing a ne...
2
2012-04-17T14:04:34Z
[ "python", "file", "reverse" ]
Read a file in reverse order using python
2,301,789
<p>How to read a file in reverse order using python? I want to read a file from last line to first line.</p>
59
2010-02-20T10:09:26Z
23,646,049
<p>A correct, efficient answer written as a generator.</p> <pre><code>import os def reverse_readline(filename, buf_size=8192): """a generator that returns the lines of a file in reverse order""" with open(filename) as fh: segment = None offset = 0 fh.seek(0, os.SEEK_END) file_s...
62
2014-05-14T05:09:51Z
[ "python", "file", "reverse" ]
Read a file in reverse order using python
2,301,789
<p>How to read a file in reverse order using python? I want to read a file from last line to first line.</p>
59
2010-02-20T10:09:26Z
26,747,854
<p>How about something like this:</p> <pre><code>import os def readlines_reverse(filename): with open(filename) as qfile: qfile.seek(0, os.SEEK_END) position = qfile.tell() line = '' while position &gt;= 0: qfile.seek(position) next_char = qfile.read(1) ...
7
2014-11-05T00:42:49Z
[ "python", "file", "reverse" ]
Read a file in reverse order using python
2,301,789
<p>How to read a file in reverse order using python? I want to read a file from last line to first line.</p>
59
2010-02-20T10:09:26Z
29,809,661
<h1>a simple function to create a second file reversed (linux only):</h1> <pre><code>import os def tac(file1, file2): print(os.system('tac %s &gt; %s' % (file1,file2))) </code></pre> <h1>how to use</h1> <pre><code>tac('ordered.csv', 'reversed.csv') f = open('reversed.csv') </code></pre>
2
2015-04-22T21:57:47Z
[ "python", "file", "reverse" ]
Read a file in reverse order using python
2,301,789
<p>How to read a file in reverse order using python? I want to read a file from last line to first line.</p>
59
2010-02-20T10:09:26Z
33,686,287
<pre><code>def reverse_lines(filename): y=open(filename).readlines() return y[::-1] </code></pre>
0
2015-11-13T05:05:54Z
[ "python", "file", "reverse" ]
Read a file in reverse order using python
2,301,789
<p>How to read a file in reverse order using python? I want to read a file from last line to first line.</p>
59
2010-02-20T10:09:26Z
38,724,468
<p>Always use <code>with</code> when working with files as it handles everything for you:</p> <pre><code>with open('filename', 'r') as f: for line in reversed(f.readlines()): print line </code></pre> <p>Or in Python 3:</p> <pre><code>with open('filename', 'r') as f: for line in reversed(list(f.readli...
1
2016-08-02T15:19:59Z
[ "python", "file", "reverse" ]
why my facebook content can't come back. i used pyfacebook
2,301,800
<p>i follow this article step by step <a href="http://wiki.developers.facebook.com/index.php/User:PyFacebook_Tutorial#Add_the_middleware" rel="nofollow">http://wiki.developers.facebook.com/index.php/User:PyFacebook_Tutorial#Add_the_middleware</a></p> <p>1。</p> <p><img src="http://omploader.org/vM20zMA" alt="alt t...
0
2010-02-20T10:13:05Z
2,301,821
<p>If I understand you correctly, you need to login in facebook since its your openID provider (it is required that you are logged in to it when attempting to login elsewhere using that account).</p>
0
2010-02-20T10:19:36Z
[ "python", "django", "pyfacebook" ]
why my facebook content can't come back. i used pyfacebook
2,301,800
<p>i follow this article step by step <a href="http://wiki.developers.facebook.com/index.php/User:PyFacebook_Tutorial#Add_the_middleware" rel="nofollow">http://wiki.developers.facebook.com/index.php/User:PyFacebook_Tutorial#Add_the_middleware</a></p> <p>1。</p> <p><img src="http://omploader.org/vM20zMA" alt="alt t...
0
2010-02-20T10:13:05Z
2,301,981
<p>I answered this question from you before. You can't use localhost or 127.0.0.1 or any local address as the canvas URL. You must use an <strong>external</strong> IP address that Facebook can see.</p>
1
2010-02-20T11:17:52Z
[ "python", "django", "pyfacebook" ]
Python - appending word position nos. to Unicode text
2,301,918
<p>:) I have a code which appends word positions to the words from the source file but the output is not coming as desired:</p> <p>The input file contains the following:</p> <pre><code>3. भारत का इतिहास काफी समृद्ध एवं विस्तृत है। 57. जैसे...
2
2010-02-20T10:55:23Z
2,301,987
<p>Try changing:</p> <pre><code>counter = 1 for line in words: # etc... </code></pre> <p>to:</p> <pre><code>for line in words: counter = 1 # etc... </code></pre> <p>This will reset the counter to 1 for each new line.</p>
0
2010-02-20T11:18:56Z
[ "python", "nlp" ]
Python - appending word position nos. to Unicode text
2,301,918
<p>:) I have a code which appends word positions to the words from the source file but the output is not coming as desired:</p> <p>The input file contains the following:</p> <pre><code>3. भारत का इतिहास काफी समृद्ध एवं विस्तृत है। 57. जैसे...
2
2010-02-20T10:55:23Z
2,302,209
<p>I think your code should something like:</p> <pre><code># the input part is fine as is lines = text.split('\n') outlines = [] for line in lines: lout = [] counter = 1 for i, word in enumerate(lines.split()): if i == 0: # leave 1st word of line alone, it's a marker: lout.append(word)...
2
2010-02-20T12:47:12Z
[ "python", "nlp" ]
Python - appending word position nos. to Unicode text
2,301,918
<p>:) I have a code which appends word positions to the words from the source file but the output is not coming as desired:</p> <p>The input file contains the following:</p> <pre><code>3. भारत का इतिहास काफी समृद्ध एवं विस्तृत है। 57. जैसे...
2
2010-02-20T10:55:23Z
2,302,229
<p>This code will give you the desired output. I added a check for the number at the start of the line, which should not be numbered.</p> <p>I adapted your original code, which was (mostly) working. You just needed to reset the counter at the end of an input line, and add a newline to your output as well.</p> <pre><c...
1
2010-02-20T12:55:22Z
[ "python", "nlp" ]
What is the easiest way to implement a Comet serverside backend?
2,302,145
<p>PHP as an Apache module or otherwise, <a href="http://stackoverflow.com/questions/603201/using-comet-with-php">would start one thread per pending request</a> so it doesn't scale well.</p> <p>Are Java and Python my only other options?</p> <p>As a complete newbie to Python, is Twisted easy to use?</p>
1
2010-02-20T12:20:02Z
2,302,158
<p>Investigate <a href="http://nodejs.org/" rel="nofollow">node.js</a>. It's an evented server-side framework using JavaScript. It will not block communication with your browsers, since it's event-driven.</p>
1
2010-02-20T12:25:54Z
[ "php", "python", "http", "comet", "push" ]
What is the easiest way to implement a Comet serverside backend?
2,302,145
<p>PHP as an Apache module or otherwise, <a href="http://stackoverflow.com/questions/603201/using-comet-with-php">would start one thread per pending request</a> so it doesn't scale well.</p> <p>Are Java and Python my only other options?</p> <p>As a complete newbie to Python, is Twisted easy to use?</p>
1
2010-02-20T12:20:02Z
2,302,215
<p>Twisted is very powerful but not easy to use, especially for a newbie.</p> <p><a href="http://simonwillison.net/2009/Sep/10/tornado/" rel="nofollow">tornado</a> is another async server in Python, less general than Twisted (you would not use it for a network <em>client</em> for example) but simpler to use to impleme...
2
2010-02-20T12:49:36Z
[ "php", "python", "http", "comet", "push" ]
What is the easiest way to implement a Comet serverside backend?
2,302,145
<p>PHP as an Apache module or otherwise, <a href="http://stackoverflow.com/questions/603201/using-comet-with-php">would start one thread per pending request</a> so it doesn't scale well.</p> <p>Are Java and Python my only other options?</p> <p>As a complete newbie to Python, is Twisted easy to use?</p>
1
2010-02-20T12:20:02Z
2,303,913
<p>My experience, been absolutely newbie with Twisted is that you can implement Comet easily with It. I've used <a href="http://divmod.org/trac/wiki/DivmodNevow/Athena" rel="nofollow">Athena</a>, which is included in <a href="http://divmod.org/trac/wiki/DivmodNevow" rel="nofollow">Nevow</a>. Nevow is built on top of Tw...
1
2010-02-20T21:57:59Z
[ "php", "python", "http", "comet", "push" ]
Alternate row coloring in Scintilla
2,302,165
<p>I'm using <a href="http://wiki.wxwindows.org/WxStyledTextCtrl" rel="nofollow">wxStyledTextCtrl</a> from wxPython, a wrapper around the <a href="http://www.scintilla.org/" rel="nofollow">Scintilla</a> component.</p> <p>Is there any way to get alternate row coloring on it (odd rows in one background color and even ro...
4
2010-02-20T12:29:28Z
2,302,590
<p>The background of lines can be changed, for example by markers (which is used for stuff like bookmarks or breakpoints, current execution point and the like in IDEs), but there is no built-in mode for changing the background colour of every other line.</p> <p>You could simulate this by setting a special marker with ...
6
2010-02-20T15:07:39Z
[ "python", "wxpython", "scintilla" ]
Editing the raw HTML inside a TinyMCE control
2,302,171
<p>I have a Django website in which I use <code>django-tinymce</code> to edit HTML fields with a TinyMCE control.</p> <p>TinyMCE practically gives me a WYSIWYG way to edit HTML. My question is, can I get access to edit the underlying HTML directly? I was thinking, maybe there's some button I can enbale which will togg...
5
2010-02-20T12:31:57Z
2,302,243
<p>Simply add the <code>code</code> button to one of the toolbars, e.g. with this configuration for django-tinymce:</p> <pre><code>TINYMCE_DEFAULT_CONFIG = { # your other configuration 'theme_advanced_buttons3_add': 'code', } </code></pre> <p><a href="http://wiki.moxiecode.com/index.php/TinyMCE%3aControl_refe...
10
2010-02-20T12:59:59Z
[ "python", "django", "tinymce", "django-tinymce" ]
skipping unknown items while Serializing using json
2,302,252
<p>I'm trying to serialize obj using json (Python). I wish to skip json's unknown type I know I can add my own encoder, but what I'm interested in is to just skip the unknown type. I don't want to use <code>None</code> instead. I have tried </p> <pre><code>icon=QIcon() arr=["blablal",icon] str1=simplejson...
2
2010-02-20T13:05:22Z
2,302,300
<p>Ok so i found the problem </p> <p>icon isn't a key but a value if icon was used as a key in a dict it would have been ignored</p>
0
2010-02-20T13:17:19Z
[ "python", "json" ]
How can INFO and DEBUG logging message be sent to stdout and higher level message to stderr
2,302,315
<p>Is there an easy way with python's logging module to send messages with a DEBUG or INFO level and the one with a higher level to different streams?</p> <p>Is it a good idea anyway?</p>
11
2010-02-20T13:21:36Z
2,302,323
<p>Yes. You must define multiple handlers for your logging.</p> <p><a href="http://docs.python.org/library/logging.html#logging-to-multiple-destinations" rel="nofollow">http://docs.python.org/library/logging.html#logging-to-multiple-destinations</a></p> <p><a href="http://docs.python.org/library/logging.handlers.htm...
6
2010-02-20T13:27:36Z
[ "python", "logging" ]
How can INFO and DEBUG logging message be sent to stdout and higher level message to stderr
2,302,315
<p>Is there an easy way with python's logging module to send messages with a DEBUG or INFO level and the one with a higher level to different streams?</p> <p>Is it a good idea anyway?</p>
11
2010-02-20T13:21:36Z
2,302,336
<p>Not necessarily a good idea (it could be confusing to see info and debug messages mixed in with normal output!), but feasible, since you can have multiple handler objects and a custom <a href="http://docs.python.org/library/logging.html?highlight=logging#filter-objects" rel="nofollow">filter</a> for each of them, in...
3
2010-02-20T13:33:10Z
[ "python", "logging" ]
How can INFO and DEBUG logging message be sent to stdout and higher level message to stderr
2,302,315
<p>Is there an easy way with python's logging module to send messages with a DEBUG or INFO level and the one with a higher level to different streams?</p> <p>Is it a good idea anyway?</p>
11
2010-02-20T13:21:36Z
9,323,805
<p>right from the updated docs, it cover this case pretty well now.</p> <p><a href="http://docs.python.org/howto/logging.html#logging-advanced-tutorial" rel="nofollow">http://docs.python.org/howto/logging.html#logging-advanced-tutorial</a></p> <pre><code>import sys # Add this. import logging # create logger logger =...
2
2012-02-17T06:21:41Z
[ "python", "logging" ]
How can INFO and DEBUG logging message be sent to stdout and higher level message to stderr
2,302,315
<p>Is there an easy way with python's logging module to send messages with a DEBUG or INFO level and the one with a higher level to different streams?</p> <p>Is it a good idea anyway?</p>
11
2010-02-20T13:21:36Z
16,607,139
<p>I had the same problem and wrote a custom logging handler called SplitStreamHandler:</p> <pre><code>import sys import logging class SplitStreamHandler(logging.Handler): def __init__(self): logging.Handler.__init__(self) def emit(self, record): # mostly copy-paste from logging.StreamHandler...
4
2013-05-17T10:45:53Z
[ "python", "logging" ]
How can INFO and DEBUG logging message be sent to stdout and higher level message to stderr
2,302,315
<p>Is there an easy way with python's logging module to send messages with a DEBUG or INFO level and the one with a higher level to different streams?</p> <p>Is it a good idea anyway?</p>
11
2010-02-20T13:21:36Z
31,459,386
<pre><code>import logging import sys class LessThanFilter(logging.Filter): def __init__(self, exclusive_maximum, name=""): super(LessThanFilter, self).__init__(name) self.max_level = exclusive_maximum def filter(self, record): #non-zero return means we log this message return 1...
6
2015-07-16T16:09:26Z
[ "python", "logging" ]
How can INFO and DEBUG logging message be sent to stdout and higher level message to stderr
2,302,315
<p>Is there an easy way with python's logging module to send messages with a DEBUG or INFO level and the one with a higher level to different streams?</p> <p>Is it a good idea anyway?</p>
11
2010-02-20T13:21:36Z
31,741,661
<pre><code>#!/usr/bin/env python3 # -*- coding: utf-8 -*- import logging import sys class LessThenFilter(logging.Filter): def __init__(self, level): self._level = level logging.Filter.__init__(self) def filter(self, rec): return rec.levelno &lt; self._level log = logging.getLogger() l...
-1
2015-07-31T08:35:33Z
[ "python", "logging" ]
How can I fix the error on this Python code?
2,302,360
<p>I have this superclass:</p> <p>import wx</p> <pre><code>class Plugin(wx.Panel): def __init__(self, parent, *args, **kwargs): wx.Panel.__init__(self, parent, *args, **kwargs) self.colorOver = ((89,89,89)) self.colorLeave = ((110,110,110)) self.SetBackgroundColour(self.colorLeave)...
0
2010-02-20T13:41:52Z
2,302,384
<p>Make the subclass</p> <pre><code>class noisePlugin(plugin.Plugin): def __init__(self, *a, **k): plugin.Plugin.__init__(self, *a, **k) self.name = "noise" </code></pre> <p>Whenever you want to use <code>self.</code>something you have to be <strong>within a method</strong>, not at class level out...
3
2010-02-20T13:50:32Z
[ "python", "wxpython" ]
How can I fix the error on this Python code?
2,302,360
<p>I have this superclass:</p> <p>import wx</p> <pre><code>class Plugin(wx.Panel): def __init__(self, parent, *args, **kwargs): wx.Panel.__init__(self, parent, *args, **kwargs) self.colorOver = ((89,89,89)) self.colorLeave = ((110,110,110)) self.SetBackgroundColour(self.colorLeave)...
0
2010-02-20T13:41:52Z
2,302,385
<p>What makes you think this works?</p> <pre><code>class noisePlugin(plugin.Plugin): self.name = "noise" </code></pre> <p>Why didn't you copy the </p> <pre><code>class Plugin(wx.Panel): def __init__(self, parent, *args, **kwargs): </code></pre> <p>That comes before <code>self.name=</code>?</p>
0
2010-02-20T13:50:56Z
[ "python", "wxpython" ]
How can I fix the error on this Python code?
2,302,360
<p>I have this superclass:</p> <p>import wx</p> <pre><code>class Plugin(wx.Panel): def __init__(self, parent, *args, **kwargs): wx.Panel.__init__(self, parent, *args, **kwargs) self.colorOver = ((89,89,89)) self.colorLeave = ((110,110,110)) self.SetBackgroundColour(self.colorLeave)...
0
2010-02-20T13:41:52Z
2,302,603
<p>For the pattern you seem to be trying for (where the name is associated more with the class than with the instance), this is often a better idiom to follow:</p> <pre><code>class A(object): name = 'parent' def __init__(self, ...): ... etc class B(A): name = 'child' def __init__(self, ...): ...
0
2010-02-20T15:11:28Z
[ "python", "wxpython" ]
Django: Unpack argument list for use in aggregate query
2,302,433
<p>I am attempting to create a semi-dynamic aggregate function that will return the sums of all fields within a list. The assumption is that running get_query_set() will return a filtered query that contains all the fields in the list and some others that may not play so well with a Sum aggregate (date fields, char fie...
0
2010-02-20T14:04:34Z
8,601,692
<p>Since this work, I put that as an answer, so people will find it easily when googling:</p> <pre><code>qs = cl.get_query_set() qs = qs.aggregate(*[Sum(field) for field in tuple]) </code></pre>
2
2011-12-22T09:19:35Z
[ "python", "sql", "django", "django-models" ]
Error while executing "paster shell example.ini" in reddit.com
2,302,470
<p>Friends!!! I am frustated since last five days working on implementing reddit.com on a ubuntu 9.10 machine.</p> <p>Yes, I know that reddit.com has been tested on ubuntu intrepid. But now i want to install it on U9.10</p> <p>I have installed postgresql database, created user copied the files, and installed all the...
1
2010-02-20T14:16:31Z
4,176,420
<p>Newer version of python-webhelpers doesn't have asset_tag.py, you need to install an older version (0.6.4) for Pylons 0.9.6:</p> <p>wget <a href="http://pypi.python.org/packages/source/W/WebHelpers/WebHelpers-0.6.4.tar.gz" rel="nofollow">http://pypi.python.org/packages/source/W/WebHelpers/WebHelpers-0.6.4.tar.gz</a...
4
2010-11-14T06:14:06Z
[ "python", "web-applications", "pylons", "reddit" ]
What's the way to keep the dictionary parameter order in Python?
2,302,663
<p><PRE> def createNode(doc_, **param_): cache = {'p':'property','l':'label','td':'totalDelay','rd':'routeDelay','ld':'logicDelay'} for index in param_: newIndex = cache[index] value = param_[index] print newIndex, '=', value</p> <p>doc = 10 createNode(doc, p='path', l='ifft4k_radix4_n...
1
2010-02-20T15:32:53Z
2,302,668
<p>Dictionaries don't preserve the order of the keys. You could use a list of tuples instead of a dictionary.</p>
3
2010-02-20T15:35:23Z
[ "python", "parameter-passing" ]
What's the way to keep the dictionary parameter order in Python?
2,302,663
<p><PRE> def createNode(doc_, **param_): cache = {'p':'property','l':'label','td':'totalDelay','rd':'routeDelay','ld':'logicDelay'} for index in param_: newIndex = cache[index] value = param_[index] print newIndex, '=', value</p> <p>doc = 10 createNode(doc, p='path', l='ifft4k_radix4_n...
1
2010-02-20T15:32:53Z
2,302,683
<p>A regular dictionary won't do, you'll have to use an ordered dictionary instead. Check out these links:</p> <ol> <li><a href="http://www.python.org/dev/peps/pep-0372/" rel="nofollow">PEP 372: Adding an ordered dictionary to collections</a></li> <li><a href="http://stackoverflow.com/questions/455059/using-an-ordered...
6
2010-02-20T15:40:39Z
[ "python", "parameter-passing" ]
What's the way to keep the dictionary parameter order in Python?
2,302,663
<p><PRE> def createNode(doc_, **param_): cache = {'p':'property','l':'label','td':'totalDelay','rd':'routeDelay','ld':'logicDelay'} for index in param_: newIndex = cache[index] value = param_[index] print newIndex, '=', value</p> <p>doc = 10 createNode(doc, p='path', l='ifft4k_radix4_n...
1
2010-02-20T15:32:53Z
2,302,791
<blockquote> <p>I need to keep the order of the parameter, I mean, property comes first, then label until I get reouteDelay last.</p> </blockquote> <p>Then you're simply doing things in the wrong order -- no need for ordered dictionaries! Try, instead, a tuple of pairs for <em>cache</em>, as follows:</p> <pr...
7
2010-02-20T16:13:37Z
[ "python", "parameter-passing" ]
Fast python XML validator with XPath support
2,302,709
<p>I need to read a large XML (65 Mb), validate it against a xsd, and run XPath queries on it. Below, I've given an lxml version of that. It takes a lot of time (over 5 minutes) to run the query but validation seems to be pretty quick. </p> <p>I've a couple of questions. How would a performance minded Python programme...
4
2010-02-20T15:52:03Z
2,302,786
<p>I wonder if you can rewrite the xpath expression to run faster? One thing that may work is to avoid building the name_list nodeset (if you don't need it later) and have the nodes counted inside of lxml. Something like this:</p> <pre><code>start = datetime.now() name_list_len = root.xpath("count(/book/author/name/te...
0
2010-02-20T16:12:30Z
[ "python", "xml", "validation", "xpath", "xsd" ]
Fast python XML validator with XPath support
2,302,709
<p>I need to read a large XML (65 Mb), validate it against a xsd, and run XPath queries on it. Below, I've given an lxml version of that. It takes a lot of time (over 5 minutes) to run the query but validation seems to be pretty quick. </p> <p>I've a couple of questions. How would a performance minded Python programme...
4
2010-02-20T15:52:03Z
2,306,922
<p>The <a href="http://codespeak.net/lxml/performance.html" rel="nofollow">lxml benchmarks</a> are quite useful. It appears to me that extracting element nodes using XPath is fast but extracting text could be slow. Below, I've three solutions that are pretty fast.</p> <pre><code>def bench_lxml_xpath_direct(root): # Ve...
0
2010-02-21T18:33:07Z
[ "python", "xml", "validation", "xpath", "xsd" ]
Pass error on socket
2,302,761
<p>I am writing a general Client-Server socket program where the client sends commands to the Server, which executes it and sends the result to the Client. <br><br> However if there is an <b>error</b> while executing a command, I want to be able to <b>inform the Client</b> of an error. I know I could send the String "E...
1
2010-02-20T16:05:55Z
2,302,787
<p>Typically when doing client-server communication you need to establish some kind of protocol. One very simple protocol is to send the String "COMMAND" before you send any commands and the String "ERROR" before you send any errors. This doubles the number of Strings you have to send but gives more flexibility.</p> ...
0
2010-02-20T16:12:41Z
[ "java", "python", "sockets" ]
Pass error on socket
2,302,761
<p>I am writing a general Client-Server socket program where the client sends commands to the Server, which executes it and sends the result to the Client. <br><br> However if there is an <b>error</b> while executing a command, I want to be able to <b>inform the Client</b> of an error. I know I could send the String "E...
1
2010-02-20T16:05:55Z
2,302,805
<p>You're already (necessarily) establishing some format or protocol whereby strings are being sent back and forth -- either you're somehow terminating each string, or sending its length first, or the like. (TCP is intrinsically just a stream so without such a protocol there would be no way the recipient could possibl...
0
2010-02-20T16:19:05Z
[ "java", "python", "sockets" ]
Is it possible to bind an on click event on a wx.StaticText?
2,302,886
<p>I have this code:</p> <pre><code>import wx class Plugin(wx.Panel): def __init__(self, parent, *args, **kwargs): panel = wx.Panel.__init__(self, parent, *args, **kwargs) self.colorOver = ((89,89,89)) self.colorLeave = ((110,110,110)) self.colorFont = ((131,131,131)) self....
4
2010-02-20T16:49:39Z
2,303,313
<p>I dont know if it is possible to bind a wx.EVT_LEFT_DOWN to a StaticText widget. You could use a button to call self.Hide(). Maybe a BitmapButton if you want a custom look.</p> <pre><code>class myPanel(wx.Panel): def __init__(self, parent, *args, **kwargs): wx.Panel.__init__(self, parent, *args, **kwar...
4
2010-02-20T19:10:28Z
[ "python", "wxpython" ]
Is it possible to bind an on click event on a wx.StaticText?
2,302,886
<p>I have this code:</p> <pre><code>import wx class Plugin(wx.Panel): def __init__(self, parent, *args, **kwargs): panel = wx.Panel.__init__(self, parent, *args, **kwargs) self.colorOver = ((89,89,89)) self.colorLeave = ((110,110,110)) self.colorFont = ((131,131,131)) self....
4
2010-02-20T16:49:39Z
2,303,450
<p>I seem to recall having to put the static text inside a frame or some object that could receive events, but was made to be invisible. Then, the click event on the text gets passed to the parent. I used to have a special derived class for clickable labels.</p>
3
2010-02-20T19:50:36Z
[ "python", "wxpython" ]
Dump django debug output to a file?
2,302,926
<p>I noticed in the django <a href="http://docs.djangoproject.com/en/dev/ref/settings/#admins" rel="nofollow">documentation</a> that when DEBUG is False it will mail your configured ADMINS the full exception information.</p> <p>Is there an easy way to dump the full exception information this to a file?</p>
1
2010-02-20T17:03:06Z
2,303,351
<p>No, but you can <a href="http://www.djangosnippets.org/" rel="nofollow">find</a> or <a href="http://docs.djangoproject.com/en/dev/topics/http/middleware/#process-exception" rel="nofollow">write middleware</a> to catch it.</p>
1
2010-02-20T19:18:33Z
[ "python", "django", "debugging" ]
How to test whether a variable has been initialized before using it?
2,303,005
<p>So let's say you've got an application with a variable that you will be creating an instance of when you load it independently (ie when you use <code>if __name__ == '__main__'</code>). </p> <p>Also, there is a method that is to be called for when a client imports the application for use within another application....
2
2010-02-20T17:34:46Z
2,303,016
<p>You can try <code>if 'varname' in locals()</code> (you probably also have to check <code>globals()</code>, and maybe some other places), or just read from the variable and catch the <code>NameError</code> exception which will be thrown when it doesn't exist.</p> <p>But if you just want the else-case of <code>if __n...
3
2010-02-20T17:40:31Z
[ "python" ]
How to test whether a variable has been initialized before using it?
2,303,005
<p>So let's say you've got an application with a variable that you will be creating an instance of when you load it independently (ie when you use <code>if __name__ == '__main__'</code>). </p> <p>Also, there is a method that is to be called for when a client imports the application for use within another application....
2
2010-02-20T17:34:46Z
2,303,018
<p>It's an error to access a variable before it is initialized. An uninitialized variable's value isn't None; accessing it just raises an exception.</p> <p>You can catch the exception if you like:</p> <pre><code>&gt;&gt;&gt; try: ... foo = x ... except NameError: ... x = 5 ... foo = 1 </code></pre> <p>In a ...
11
2010-02-20T17:41:11Z
[ "python" ]
How to output huge dependency relationships diagram of Plone with Graphviz?
2,303,079
<p>I wrote a tool for find dependency relationships behind a Python project. It is <a href="http://code.google.com/p/python-gluttony/">Gluttony</a>. I run it on Plone, the result is impressive. I output the diagram with Networkx, and it looks like this:</p> <p><img src="http://python-gluttony.googlecode.com/files/p...
5
2010-02-20T17:59:44Z
2,303,115
<p>If you can produce an image: Graphviz tends to create <strong>huge</strong> files. Zoom in.</p> <p>For me graphviz regularly crashes on your file. It seems to max out on 32 kPixels per side and your file would be larger, resulting in an integer overflow.</p> <p>Try splitting the file up into multiple sub-graphs (A...
1
2010-02-20T18:09:41Z
[ "python", "diagram", "graphviz", "plone" ]
How to output huge dependency relationships diagram of Plone with Graphviz?
2,303,079
<p>I wrote a tool for find dependency relationships behind a Python project. It is <a href="http://code.google.com/p/python-gluttony/">Gluttony</a>. I run it on Plone, the result is impressive. I output the diagram with Networkx, and it looks like this:</p> <p><img src="http://python-gluttony.googlecode.com/files/p...
5
2010-02-20T17:59:44Z
2,305,913
<p>The command <code>dot plone.dot -Tsvg &gt; plone.svg</code> renders this scalable vecor graphic:</p> <p><img src="http://dl.dropbox.com/u/138632/plone.svg" alt="alt text"> </p> <p>I can open <a href="http://dl.dropbox.com/u/138632/plone.svg" rel="nofollow">the .svg file</a> fine in <a href="http://www.inkscape.org...
2
2010-02-21T12:52:46Z
[ "python", "diagram", "graphviz", "plone" ]
Using Property Builtin with GAE Datastore's Model
2,303,090
<p>I want to make attributes of GAE Model properties. The reason is for cases like to turn the value into uppercase before storing it. For a plain Python class, I would do something like:</p> <pre><code>Foo(db.Model): def get_attr(self): return self.something def set_attr(self, value): self.somet...
0
2010-02-20T18:02:58Z
2,303,191
<p>Subclassing GAE's <a href="http://code.google.com/appengine/docs/python/datastore/propertyclass.html" rel="nofollow">Property</a> class is especially helpful if you want more than one "field" with similar behavior, in one or more models. Don't worry, <code>get_value_for_datastore</code> and <code>make_value_from_da...
3
2010-02-20T18:34:40Z
[ "python", "google-app-engine", "gae-datastore" ]
Using Property Builtin with GAE Datastore's Model
2,303,090
<p>I want to make attributes of GAE Model properties. The reason is for cases like to turn the value into uppercase before storing it. For a plain Python class, I would do something like:</p> <pre><code>Foo(db.Model): def get_attr(self): return self.something def set_attr(self, value): self.somet...
0
2010-02-20T18:02:58Z
2,333,317
<p>What you want is a <a href="http://blog.notdot.net/2009/9/Custom-Datastore-Properties-1-DerivedProperty" rel="nofollow">DerivedProperty</a>. The procedure for writing one is outlined in that post - it's similar to what Alex describes, but by overriding <strong>get</strong> instead of get_value_for_datastore, you avo...
1
2010-02-25T10:43:25Z
[ "python", "google-app-engine", "gae-datastore" ]
What does Django do with `MEDIA_ROOT`?
2,303,254
<p>What does Django do with <code>MEDIA_ROOT</code> exactly? I never understood it. Since Django itself doesn't serve static media, and you have to set up apache or something similar for it, why does it care in which directory it sits?</p>
8
2010-02-20T18:53:41Z
2,303,269
<p>It appears to be used by some classes in Django as a default -- for instance, <a href="http://docs.djangoproject.com/en/dev/topics/files/#the-built-in-filesystem-storage-class" rel="nofollow">FileSystemStorage</a> uses it as the default place to store files.</p>
2
2010-02-20T18:59:13Z
[ "python", "django" ]
What does Django do with `MEDIA_ROOT`?
2,303,254
<p>What does Django do with <code>MEDIA_ROOT</code> exactly? I never understood it. Since Django itself doesn't serve static media, and you have to set up apache or something similar for it, why does it care in which directory it sits?</p>
8
2010-02-20T18:53:41Z
2,305,649
<p>You're not the only one who wonders; check out <a href="http://code.djangoproject.com/ticket/10650">Django ticket #10650</a>. Based on the comments by Django developers there, I think this pretty much sums up what <code>MEDIA_ROOT</code> is used for:</p> <blockquote> <p>Unfortunately, Django is also at fault for...
8
2010-02-21T11:09:01Z
[ "python", "django" ]
What does Django do with `MEDIA_ROOT`?
2,303,254
<p>What does Django do with <code>MEDIA_ROOT</code> exactly? I never understood it. Since Django itself doesn't serve static media, and you have to set up apache or something similar for it, why does it care in which directory it sits?</p>
8
2010-02-20T18:53:41Z
8,542,155
<p>When you creates a model with ImageField or FileField attributes, you should pass the upload_to argument. That is a relative path will be appended to your MEDIA_ROOT path and there will be save and retrieve that files.</p>
2
2011-12-17T02:29:09Z
[ "python", "django" ]
Python class methods
2,303,414
<p>In Python, which is the best way (style wise) to allow public access to an object's variables?</p> <p>There are lots of options I've seen from different languages, I was wondering which of these (if any) is the preferred Python method? These are the options I'm currently torn between:</p> <ol> <li>Allow direct acc...
3
2010-02-20T19:40:15Z
2,303,425
<p>Don't bother using accessors until they're necessary; converting a simple attribute to a property is quick and easy, and doesn't need modification of client code.</p> <p>When I write a property, I use <code>_get_FOO()</code> and <code>_set_FOO()</code> for the accessors, and <code>_FOO</code> for the attribute itse...
4
2010-02-20T19:45:03Z
[ "python", "class" ]
Python class methods
2,303,414
<p>In Python, which is the best way (style wise) to allow public access to an object's variables?</p> <p>There are lots of options I've seen from different languages, I was wondering which of these (if any) is the preferred Python method? These are the options I'm currently torn between:</p> <ol> <li>Allow direct acc...
3
2010-02-20T19:40:15Z
2,303,427
<p>Just allow direct access to any variables that you wish to expose as the public API. If you need to change the behavior you can always turn it into a property later on.</p> <p>Notice that this is orthogonal to information hiding. <code>obj.get_some_implementation_detail()</code> is no better than <code>obj.some_imp...
2
2010-02-20T19:45:17Z
[ "python", "class" ]
Python class methods
2,303,414
<p>In Python, which is the best way (style wise) to allow public access to an object's variables?</p> <p>There are lots of options I've seen from different languages, I was wondering which of these (if any) is the preferred Python method? These are the options I'm currently torn between:</p> <ol> <li>Allow direct acc...
3
2010-02-20T19:40:15Z
2,303,432
<p>There are no "private" variables in Python. Check section 9.6 of this document <a href="http://docs.python.org/tutorial/classes.html" rel="nofollow">http://docs.python.org/tutorial/classes.html</a></p> <p>There is a convention though, that the users of the class should treat variables with names, starting with unde...
3
2010-02-20T19:46:08Z
[ "python", "class" ]
Python class methods
2,303,414
<p>In Python, which is the best way (style wise) to allow public access to an object's variables?</p> <p>There are lots of options I've seen from different languages, I was wondering which of these (if any) is the preferred Python method? These are the options I'm currently torn between:</p> <ol> <li>Allow direct acc...
3
2010-02-20T19:40:15Z
2,303,437
<p>You can use</p> <p><strong>Getters and setters (Java like)</strong></p> <pre><code>class SomeClass(object): ... def get_x(self): return self._x def set_x(self, x): self._x = x c = SomeClass() print c.get_x() c.set_x(10) </code></pre> <p><strong>Properties (C# like)</strong></p> <pre><code>class S...
-1
2010-02-20T19:48:36Z
[ "python", "class" ]
How to install python module as a command line application under windows?
2,303,434
<p>I need to install a python module in the site packages that also will be used as a command line application. Suppose I have a module like:</p> <p>app.py</p> <pre><code>def main(): print 'Dummy message' if __name__ == '__main__': main() </code></pre> <p>setup.py</p> <pre><code> import distutils try: f...
2
2010-02-20T19:47:00Z
2,303,443
<p>Put the following in <code>dummy.cmd</code>:</p> <pre><code>python.exe -m dummy </code></pre> <p>Or is it <code>dummy.app</code>...</p> <p>Oh well, it's one of those.</p>
0
2010-02-20T19:49:51Z
[ "python" ]
How to install python module as a command line application under windows?
2,303,434
<p>I need to install a python module in the site packages that also will be used as a command line application. Suppose I have a module like:</p> <p>app.py</p> <pre><code>def main(): print 'Dummy message' if __name__ == '__main__': main() </code></pre> <p>setup.py</p> <pre><code> import distutils try: f...
2
2010-02-20T19:47:00Z
2,303,462
<p>You can use the options in setup.py to declare command line scripts. Please refer to <a href="http://www.oreillynet.com/onlamp/blog/2008/01/setuptools_tip_script_creation.html" rel="nofollow">this article</a>. On Windows, the script will be created in "C:\Python26\Scripts" (if you didn't change the path) - lots of t...
2
2010-02-20T19:55:23Z
[ "python" ]
django database many2many relationship errors
2,303,498
<p>hi i am using the following models to build a database </p> <pre><code>from django.db import models from django.contrib import admin class Team(models.Model): """Model docstring""" slug = models.SlugField(max_length=200) Team_ID = models.AutoField(primary_key=True) Team_Name = models.CharField(max...
0
2010-02-20T20:02:15Z
2,304,172
<p>Mmh do you really have to use your own primary key fields? If you don't specify a primary key field, than Django automatically creates a field called <code>id</code>. I don't see a a benefit from naming the fields e.g. <code>match_id</code>, especially as you want to access this field later, it will look like <code>...
1
2010-02-20T23:22:31Z
[ "python", "database", "django", "postgresql", "django-models" ]
Is there any purpose for a python application use C other than performance?
2,303,683
<p>If Python was so fast as C, the latter would be present in python apps/libraries?</p> <p>Example: if Python was fast as C would PIL be written completely in Python?</p>
1
2010-02-20T20:55:52Z
2,303,685
<p>To access "legacy" C libraries and OS facilities.</p>
7
2010-02-20T20:56:41Z
[ "python", "c", "performance", "bytecode" ]
Is there any purpose for a python application use C other than performance?
2,303,683
<p>If Python was so fast as C, the latter would be present in python apps/libraries?</p> <p>Example: if Python was fast as C would PIL be written completely in Python?</p>
1
2010-02-20T20:55:52Z
2,303,703
<p>It makes sense to use C modules in Python for:</p> <ul> <li>Performance</li> <li>Libraries that won't be ported to Python (because of performance reasons, for example) or that use OS-specific functions</li> <li>Scripting. For example, many games use Python, Lua and other languages as scripting languages. Therefore ...
2
2010-02-20T21:01:03Z
[ "python", "c", "performance", "bytecode" ]
Is there any purpose for a python application use C other than performance?
2,303,683
<p>If Python was so fast as C, the latter would be present in python apps/libraries?</p> <p>Example: if Python was fast as C would PIL be written completely in Python?</p>
1
2010-02-20T20:55:52Z
2,303,734
<p>While you can of course use <a href="http://docs.python.org/library/ctypes.html?highlight=ctypes#module-ctypes" rel="nofollow">ctypes</a> to access existing C code, you might not necessarily <em>want</em> to, in sufficiently complex cases: when you're coding to an interface designed for (and implemented in) C, not d...
5
2010-02-20T21:08:20Z
[ "python", "c", "performance", "bytecode" ]
Is there any purpose for a python application use C other than performance?
2,303,683
<p>If Python was so fast as C, the latter would be present in python apps/libraries?</p> <p>Example: if Python was fast as C would PIL be written completely in Python?</p>
1
2010-02-20T20:55:52Z
2,303,876
<p>To access hardware.</p>
0
2010-02-20T21:50:14Z
[ "python", "c", "performance", "bytecode" ]
Attempting to use gevent library in Python: "ImportError: cannot import name core"
2,303,745
<p>I'm attempting to use the <a href="http://code.google.com/p/gevent/" rel="nofollow">gevent</a> library in a Python app I'm writing. However, both easy_install and installing it manually appears to be failing. Any suggestions?</p> <pre><code>Python 2.6.2 (r262:71600, Aug 5 2009, 10:31:21) [GCC 4.1.2 20080704 (Red...
3
2010-02-20T21:10:57Z
2,304,755
<p>I've answered your question on the <a href="http://groups.google.com/group/gevent/browse_thread/thread/d3a10f70cb1008cd" rel="nofollow">mailing list</a>.</p> <p>BTW, are you using version 0.10.0 of gevent? It's ancient! The latest one is <a href="http://pypi.python.org/pypi/gevent" rel="nofollow">0.12.0</a>.</p>
0
2010-02-21T04:23:55Z
[ "python", "gevent" ]
Attempting to use gevent library in Python: "ImportError: cannot import name core"
2,303,745
<p>I'm attempting to use the <a href="http://code.google.com/p/gevent/" rel="nofollow">gevent</a> library in a Python app I'm writing. However, both easy_install and installing it manually appears to be failing. Any suggestions?</p> <pre><code>Python 2.6.2 (r262:71600, Aug 5 2009, 10:31:21) [GCC 4.1.2 20080704 (Red...
3
2010-02-20T21:10:57Z
2,312,205
<p>The error was caused simply by trying to run a script from the project source directory. Changing to any other directory and doing an "import" worked fine. <a href="http://groups.google.com/group/gevent/t/d3a10f70cb1008cd" rel="nofollow">More information here</a> on the gevent mailing list.</p>
1
2010-02-22T16:11:00Z
[ "python", "gevent" ]
GAE Chat Data Persistance in Memcache
2,303,751
<p>I'm writing a chat feature (like the Faceboook.com one) for a Google App Engine site. I need a way to keep track of what users have new messages. I'm currently trying to use Memcache:</p> <pre><code>class Message(): def __init__(self, from_user_key, message_text) self.from_user_key = from_user_key ...
1
2010-02-20T21:13:07Z
2,303,836
<p>The problem isn't so much about how to share data between "pages" but how will the usability of the service will be impacted by using <code>memcache</code>.</p> <p>There are no guarantees associated with data persistence in memcache: one moment its there, the other it might not.</p>
3
2010-02-20T21:36:34Z
[ "python", "google-app-engine", "chat" ]
django having multiple one many to many relations that references same model
2,303,778
<p>i have a model that is having multiple many to many relation to another model it is as follows:</p> <pre><code>class Match(models.Model): """Model docstring""" Match_Id = models.AutoField(primary_key=True) Team_one = models.ManyToManyField('Team',related_name='Team one',symmetrical=False,) Team_two = mode...
2
2010-02-20T21:19:27Z
2,303,841
<p>Are you sure <code>Team_one</code> and <code>Team_two</code> should be ManyToMany fields? Surely, a match only has a single team on each side - in which case these should both be ForeignKeys.</p>
1
2010-02-20T21:38:09Z
[ "python", "database", "django", "django-models" ]
django having multiple one many to many relations that references same model
2,303,778
<p>i have a model that is having multiple many to many relation to another model it is as follows:</p> <pre><code>class Match(models.Model): """Model docstring""" Match_Id = models.AutoField(primary_key=True) Team_one = models.ManyToManyField('Team',related_name='Team one',symmetrical=False,) Team_two = mode...
2
2010-02-20T21:19:27Z
2,304,001
<p>Using spaces in <code>related_name</code> attribute makes me uneasy, but I think the real problem is connected to the use of <code>to_field</code> attribute on the <code>winner</code> field. As far as I know you can set database relations only to <code>unique</code> fields. It doesn't really make sense to relate to ...
1
2010-02-20T22:29:44Z
[ "python", "database", "django", "django-models" ]
Specifying python interpreter from virtualenv in emacs
2,303,956
<p>Today I've been trying to bring more of the Python related modes into my Emacs configuration but I haven't had much luck.</p> <p>First what I've noticed is that depending on how Emacs is launched (terminal vs from the desktop), the interpreter it decides to use is different.</p> <ul> <li><p>launched from KDE menu:...
11
2010-02-20T22:12:01Z
2,307,435
<p>So it seems that python-shell does the right thing by picking up the environment settings, whereas py-shell does not. python-shell is provided by python.el and py-shell is provided by python-mode.el , There's bug reports etc related to this, so I'm just not going to use py-shell for now. Figured I'd close the loop o...
8
2010-02-21T20:50:44Z
[ "python", "emacs", "virtualenv" ]
Specifying python interpreter from virtualenv in emacs
2,303,956
<p>Today I've been trying to bring more of the Python related modes into my Emacs configuration but I haven't had much luck.</p> <p>First what I've noticed is that depending on how Emacs is launched (terminal vs from the desktop), the interpreter it decides to use is different.</p> <ul> <li><p>launched from KDE menu:...
11
2010-02-20T22:12:01Z
6,253,448
<p>There is a <a href="https://github.com/aculich/virtualenv.el" rel="nofollow">virtualenv mode for Emacs</a>. It requires Emacs 23.1 or higher.</p> <blockquote> <p>This is a minor mode for setting the virtual environment for the Python shell using virtualenv and supports both python-mode.el and python.el.</p>...
4
2011-06-06T14:22:09Z
[ "python", "emacs", "virtualenv" ]
Numeric data collection from an mp3 in python
2,303,958
<p>Anyone know how I can plot numeric data from an mp3 in real time?</p> <p>For example the script plays a mp3 and as its playing prints 3 sets of numeric data.</p>
0
2010-02-20T22:12:14Z
2,304,611
<p>You could use the <a href="http://home.gna.org/veusz/" rel="nofollow">Veusz</a> python package that supports realtime plotting of data.</p>
0
2010-02-21T03:11:41Z
[ "python", "mp3", "numeric", "graphical-programming" ]
Get zip code based on IP Address with Python
2,303,966
<p>Is it possible to find the zip code based on a users IP address using python / django (not geodjango)? I assume I would have to use a web service, but I would really like to just be able to query a database if possible. </p> <p>I am using geopy right now, so it would be cool if I could integrate that somehow. </...
3
2010-02-20T22:17:15Z
2,303,976
<p>You can't collect a real zip code from an IP address as these are assigned by ISP's when you route threw their connection.</p>
-1
2010-02-20T22:19:08Z
[ "python", "django", "geolocation" ]
Get zip code based on IP Address with Python
2,303,966
<p>Is it possible to find the zip code based on a users IP address using python / django (not geodjango)? I assume I would have to use a web service, but I would really like to just be able to query a database if possible. </p> <p>I am using geopy right now, so it would be cool if I could integrate that somehow. </...
3
2010-02-20T22:17:15Z
2,303,987
<p><a href="http://www.ip2location.com/python.aspx" rel="nofollow">http://www.ip2location.com/python.aspx</a></p> <pre><code>import IP2Location; IP2LocObj = IP2Location.IP2Location(); IP2LocObj.open("data/IP-COUNTRY-SAMPLE.BIN"); rec = IP2LocObj.get_all("19.5.10.1"); print rec.zipcode </code></pre> <p>I don't have ...
1
2010-02-20T22:23:01Z
[ "python", "django", "geolocation" ]
Print out the output of os.popen() without buffering in python
2,304,072
<p>Let's say that I have a process that prints out some data something like this ruby code. </p> <pre><code>1.upto(10) { |i| puts i puts "\n" sleep 0.6 } </code></pre> <p>I want to have a python code that spawns this process, and read data from it to print it out. </p> <pre><code>import os import sys ...
3
2010-02-20T22:53:38Z
2,304,115
<p>The data is being buffered by ruby. Use something like</p> <pre><code>$stdout.flush </code></pre> <p>to make it flush. I'm not sure if that's the correct ruby command to do that.</p> <hr> <p>Obligatory:</p> <p>Use <code>subprocess</code> module. <code>os.popen</code> <a href="http://docs.python.org/library/subp...
5
2010-02-20T23:03:25Z
[ "python", "ruby", "popen", "flush" ]
_ElementInterface instance has no attribute 'tostring'
2,304,082
<p>The code below generates this error. I can't figure out why. If ElementTree has parse, why doesn't it have tostring? <a href="http://docs.python.org/library/xml.etree.elementtree.html#xml.etree.ElementTree.ElementTree" rel="nofollow">http://docs.python.org/library/xml.etree.elementtree.html#xml.etree.ElementTree.Ele...
4
2010-02-20T22:56:52Z
2,304,131
<p>The docs you've linked to do not support the existence of a <code>ElementTree.tostring()</code> method.</p> <p>Also, your call to <code>tree.parse()</code> rebinds <code>node</code>.</p>
-1
2010-02-20T23:08:28Z
[ "python" ]
_ElementInterface instance has no attribute 'tostring'
2,304,082
<p>The code below generates this error. I can't figure out why. If ElementTree has parse, why doesn't it have tostring? <a href="http://docs.python.org/library/xml.etree.elementtree.html#xml.etree.ElementTree.ElementTree" rel="nofollow">http://docs.python.org/library/xml.etree.elementtree.html#xml.etree.ElementTree.Ele...
4
2010-02-20T22:56:52Z
2,304,154
<p>tostring() is actually a function of the ElementTree module not a method of the ElementTree wrapper class.</p> <pre><code>&gt;&gt;&gt; import xml.etree.ElementTree as ET &gt;&gt;&gt; x = ET.fromstring('&lt;xml&gt;&lt;one&gt;one&lt;/one&gt;&lt;/xml&gt;') &gt;&gt;&gt; x &lt;Element xml at 7f749572f710&gt; &gt;&g...
4
2010-02-20T23:14:55Z
[ "python" ]
_ElementInterface instance has no attribute 'tostring'
2,304,082
<p>The code below generates this error. I can't figure out why. If ElementTree has parse, why doesn't it have tostring? <a href="http://docs.python.org/library/xml.etree.elementtree.html#xml.etree.ElementTree.ElementTree" rel="nofollow">http://docs.python.org/library/xml.etree.elementtree.html#xml.etree.ElementTree.Ele...
4
2010-02-20T22:56:52Z
2,304,157
<p><code>tostring</code> is a method of the <code>xml.etree.ElementTree</code> module, not the confusingly similarly-named <code>xml.etree.ElementTree.ElementTree</code> class.</p> <pre><code>from xml.etree.ElementTree import ElementTree from xml.etree.ElementTree import tostring tree = ElementTree() node = tree.pars...
8
2010-02-20T23:15:45Z
[ "python" ]
MySQLdb within python2.5 virtualenv
2,304,539
<p>I have a Fedora 11 box with MySQL server. Fedora 11 uses python 2.6 internally and python 2.6 is automatically installed on the box. I have created a python virtual-env for version 2.5.5, so that I can run turbogears 1.x application. I have MySQLdb rpm installed on the box (and it works fine with python 2.6).</p>...
3
2010-02-21T02:28:10Z
2,324,284
<pre><code>_mysql.c:36:23: error: my_config.h: No such file or directory _mysql.c:38:19: error: mysql.h: No such file or directory _mysql.c:39:26: error: mysqld_error.h: No such file or directory _mysql.c:40:20: error: errmsg.h: No such file or directory </code></pre> <p>Please install MySQL header files, probably <a ...
6
2010-02-24T07:19:44Z
[ "python", "mysql", "virtualenv" ]
MySQLdb within python2.5 virtualenv
2,304,539
<p>I have a Fedora 11 box with MySQL server. Fedora 11 uses python 2.6 internally and python 2.6 is automatically installed on the box. I have created a python virtual-env for version 2.5.5, so that I can run turbogears 1.x application. I have MySQLdb rpm installed on the box (and it works fine with python 2.6).</p>...
3
2010-02-21T02:28:10Z
2,331,071
<p>Works! Thanks for all your help.</p> <p>I installed mysql-devel package (yum install mysql-devel) on the box.</p> <p>Then did easy_install MySQL-python from within virtual-env (python 2.5.5), and the compilation/installation was successful (with some warnings).</p> <p>Thanks.</p>
1
2010-02-25T01:59:15Z
[ "python", "mysql", "virtualenv" ]
MySQLdb within python2.5 virtualenv
2,304,539
<p>I have a Fedora 11 box with MySQL server. Fedora 11 uses python 2.6 internally and python 2.6 is automatically installed on the box. I have created a python virtual-env for version 2.5.5, so that I can run turbogears 1.x application. I have MySQLdb rpm installed on the box (and it works fine with python 2.6).</p>...
3
2010-02-21T02:28:10Z
14,585,479
<p>Just to mention for the others that might end up here too, </p> <p>I solved this error in installing mysql-devel</p> <pre><code>$ yum install mysql-devel.x86_64 </code></pre> <p>Hope this helps</p>
0
2013-01-29T14:41:22Z
[ "python", "mysql", "virtualenv" ]