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
What is a suitable buffer for Python's struct module
1,732,660
<p>In Python I'm accessing a binary file by reading it into a string and then using <code>struct.unpack(...)</code>. Now I want to write to that string using <code>struct.pack_into(...)</code>, but I get the error <em>"Cannot use string as modifiable buffer"</em>. What would be a suitable buffer for use with the <code>...
8
2009-11-14T00:01:21Z
1,732,763
<p>As noted in another answer, <code>struct_pack</code> is probably all you need and should use. However, objects of type <a href="http://docs.python.org/library/array.html" rel="nofollow">array</a> support the buffer protocol and can be modified:</p> <pre><code>&gt;&gt;&gt; import array, struct &gt;&gt;&gt; a = arra...
6
2009-11-14T00:30:50Z
[ "python", "binary", "buffering" ]
What is a suitable buffer for Python's struct module
1,732,660
<p>In Python I'm accessing a binary file by reading it into a string and then using <code>struct.unpack(...)</code>. Now I want to write to that string using <code>struct.pack_into(...)</code>, but I get the error <em>"Cannot use string as modifiable buffer"</em>. What would be a suitable buffer for use with the <code>...
8
2009-11-14T00:01:21Z
1,732,765
<p>Two possibilities leap immediately to mind:</p> <ul> <li><p>You can use the Python <a href="http://docs.python.org/library/stringio.html" rel="nofollow">stringio</a> module to make a read/write buffer with file semantics.</p></li> <li><p>You can use the Python <a href="http://docs.python.org/library/array.html" rel...
0
2009-11-14T00:31:13Z
[ "python", "binary", "buffering" ]
Unzipping part of a .gz file using python
1,732,709
<p>So here's the problem. I have sample.gz file which is roughly 60KB in size. I want to decompress the first 2000 bytes of this file. I am running into CRC check failed error, I guess because the gzip CRC field appears at the end of file, and it requires the entire gzipped file to decompress. Is there a way to get aro...
4
2009-11-14T00:14:37Z
1,732,726
<p>I seems that you need to look into <a href="http://docs.python.org/library/zlib.html"><strong>Python zlib</strong></a> library instead</p> <p>The GZIP format relies on zlib, but introduces a a file-level compression concept along with CRC checking, and this appears to be what you do not want/need at the moment.</p>...
7
2009-11-14T00:19:33Z
[ "python", "gzip", "zlib" ]
Unzipping part of a .gz file using python
1,732,709
<p>So here's the problem. I have sample.gz file which is roughly 60KB in size. I want to decompress the first 2000 bytes of this file. I am running into CRC check failed error, I guess because the gzip CRC field appears at the end of file, and it requires the entire gzipped file to decompress. Is there a way to get aro...
4
2009-11-14T00:14:37Z
1,732,737
<p>I can't see any possible reason why you would want to decompress the first 2000 compressed bytes. Depending on the data, this may uncompress to any number of output bytes.</p> <p>Surely you want to uncompress the file, and stop when you have uncompressed as much of the file as you need, something like:</p> <pre><c...
6
2009-11-14T00:22:20Z
[ "python", "gzip", "zlib" ]
Unzipping part of a .gz file using python
1,732,709
<p>So here's the problem. I have sample.gz file which is roughly 60KB in size. I want to decompress the first 2000 bytes of this file. I am running into CRC check failed error, I guess because the gzip CRC field appears at the end of file, and it requires the entire gzipped file to decompress. Is there a way to get aro...
4
2009-11-14T00:14:37Z
16,504,428
<p>I also encounter this problem when I use my python script to read compressed files generated by gzip tool under Linux and the original files were lost. </p> <p>By reading the implementation of <a href="http://svn.python.org/projects/python/trunk/Lib/gzip.py" rel="nofollow">gzip.py</a> of Python, I found that gzip.G...
1
2013-05-12T05:17:00Z
[ "python", "gzip", "zlib" ]
Unzipping part of a .gz file using python
1,732,709
<p>So here's the problem. I have sample.gz file which is roughly 60KB in size. I want to decompress the first 2000 bytes of this file. I am running into CRC check failed error, I guess because the gzip CRC field appears at the end of file, and it requires the entire gzipped file to decompress. Is there a way to get aro...
4
2009-11-14T00:14:37Z
18,602,286
<p>The issue with the gzip module is not that it can't decompress the partial file, the error occurs only at the end when it tries to verify the checksum of the decompressed content. (The original checksum is stored at the end of the compressed file so the verification will never, ever work with a partial file.)</p> <...
6
2013-09-03T22:08:42Z
[ "python", "gzip", "zlib" ]
Lexical Analysis of Python Programming Language
1,732,743
<p>Does anyone know where a FLEX or LEX specification file for Python exists? For example, this is a lex specification for the ANSI C programming language: <a href="http://www.quut.com/c/ANSI-C-grammar-l-1998.html">http://www.quut.com/c/ANSI-C-grammar-l-1998.html</a></p> <p>FYI, I am trying to write code highlighting ...
6
2009-11-14T00:25:08Z
1,732,767
<p><a href="http://docs.python.org/reference/grammar.html" rel="nofollow">grammar.txt</a> is the official, complete Python grammar -- not directly <code>lex</code> compatible, but you should be able to massage it into a suitable form.</p>
3
2009-11-14T00:31:37Z
[ "python", "syntax-highlighting", "lex", "lexical-analysis" ]
Lexical Analysis of Python Programming Language
1,732,743
<p>Does anyone know where a FLEX or LEX specification file for Python exists? For example, this is a lex specification for the ANSI C programming language: <a href="http://www.quut.com/c/ANSI-C-grammar-l-1998.html">http://www.quut.com/c/ANSI-C-grammar-l-1998.html</a></p> <p>FYI, I am trying to write code highlighting ...
6
2009-11-14T00:25:08Z
1,732,777
<p>Have you considered using one of the existing code highlighters, like <a href="http://pygments.org/" rel="nofollow">Pygments</a>?</p>
0
2009-11-14T00:35:48Z
[ "python", "syntax-highlighting", "lex", "lexical-analysis" ]
Lexical Analysis of Python Programming Language
1,732,743
<p>Does anyone know where a FLEX or LEX specification file for Python exists? For example, this is a lex specification for the ANSI C programming language: <a href="http://www.quut.com/c/ANSI-C-grammar-l-1998.html">http://www.quut.com/c/ANSI-C-grammar-l-1998.html</a></p> <p>FYI, I am trying to write code highlighting ...
6
2009-11-14T00:25:08Z
1,732,804
<p>Lex is typically just used for tokenizing, not full parsing. Projects that use flex/lex for tokenizing typically use yacc/bison for the actual parsing.</p> <p>You may want to take a look at <a href="http://www.antlr.org/" rel="nofollow">ANTLR</a>, a more "modern" alternative to lexx &amp; yacc.</p> <p>I haven't be...
5
2009-11-14T00:44:47Z
[ "python", "syntax-highlighting", "lex", "lexical-analysis" ]
Reading Alpha of a PNG Pixel. Fast way via pure Python?
1,732,761
<p>I am having an issue with an embedded 64bit Python instance not liking PIL. Before i start exhausting more methods to get a compiled image editor to read the pixels for me (such as ImageMagick) i am hoping perhaps anyone here can think of a purely Python solution that will be comparable in speeds to the compiled cou...
1
2009-11-14T00:30:09Z
1,732,962
<p>Getting data out of a PNG requires unpacking data and decompressing it. These are likely going to be too slow in Python for your application. One possibility is to start with PyPNG and get rid of anything in it that you don't need. For example, it is probably storing all of the data it reads from the PNG, and som...
2
2009-11-14T01:54:34Z
[ "python", "png" ]
Reading Alpha of a PNG Pixel. Fast way via pure Python?
1,732,761
<p>I am having an issue with an embedded 64bit Python instance not liking PIL. Before i start exhausting more methods to get a compiled image editor to read the pixels for me (such as ImageMagick) i am hoping perhaps anyone here can think of a purely Python solution that will be comparable in speeds to the compiled cou...
1
2009-11-14T00:30:09Z
2,005,645
<p>When you say PyPNG is too slow, how slow is it? To put it another way, how fast would be fast enough? PyPNG doesn't do anything stupid to make itself slow, but it is written in Python.</p> <p>Make sure you're using read() to read the image row by row, and make sure you're using row[3::4] to extract the alpha chan...
0
2010-01-05T11:23:08Z
[ "python", "png" ]
UnicodeEncodeError on MySQL insert in Python
1,732,762
<p>I used lxml to parse some web page as below:</p> <pre><code>&gt;&gt;&gt; doc = lxml.html.fromstring(htmldata) &gt;&gt;&gt; element in doc.cssselect(sometag)[0] &gt;&gt;&gt; text = element.text_content() &gt;&gt;&gt; print text u'Waldenstr\xf6m' </code></pre> <p>Why it prints u'Waldenstr\xf6m' but not "Waldenström...
1
2009-11-14T00:30:47Z
1,732,778
<p>you want <code>text.encode('utf8')</code></p>
2
2009-11-14T00:36:28Z
[ "python", "mysql", "unicode" ]
UnicodeEncodeError on MySQL insert in Python
1,732,762
<p>I used lxml to parse some web page as below:</p> <pre><code>&gt;&gt;&gt; doc = lxml.html.fromstring(htmldata) &gt;&gt;&gt; element in doc.cssselect(sometag)[0] &gt;&gt;&gt; text = element.text_content() &gt;&gt;&gt; print text u'Waldenstr\xf6m' </code></pre> <p>Why it prints u'Waldenstr\xf6m' but not "Waldenström...
1
2009-11-14T00:30:47Z
1,732,850
<pre><code>&gt;&gt;&gt; print text u'Waldenstr\xf6m' </code></pre> <p>There is a difference between displaying something in the shell (which uses the <code>repr</code>) and printing it (which just spits out the string):</p> <pre><code>&gt;&gt;&gt; u'Waldenstr\xf6m' u'Waldenstr\xf6m' &gt;&gt;&gt; print u'Waldenstr\xf...
0
2009-11-14T01:02:33Z
[ "python", "mysql", "unicode" ]
PyQt display fullscreen image
1,732,935
<p>I'm using PyQt to capture my screen with QPixmap.grabWindow(QApplication.desktop().winId()) and I was wondering if there was a way I could display my screengrab fullscreen (no window borders, etc.) I'm trying to find a way to desaturate my display with PyQt</p>
3
2009-11-14T01:36:10Z
1,733,241
<p>Passing QtCore.Qt.FramelessWindowHint to the QWidget constructor in symphony with self.showFullScreen() in the image widget's code achieves this.</p>
7
2009-11-14T04:16:47Z
[ "python", "pyqt", "screenshot", "fullscreen" ]
Making BeautifulSoup ignore contents inside script tags
1,732,956
<p>I have been trying to get BeautifulSoup (3.1.0.1)to parse a html page that has a lot of javascript that generates html inside tags. One example fragment looks like this :</p> <pre><code>&lt;html&gt;&lt;head&gt;&lt;body&gt;&lt;div&gt; &lt;script type='text/javascript'&gt; if(ii &gt; 0) { html += '&lt;span id="hov...
1
2009-11-14T01:48:27Z
1,733,070
<p>I've faced this kind of problem before, and what I normally do is replace every occurrence of <code>&lt;script</code> with <code>&lt;!--</code> and <code>&lt;/script&gt;</code> with <code>--&gt;</code>. That way, all the <code>&lt;script&gt;&lt;/script&gt;</code> tags are commented out.</p>
0
2009-11-14T02:50:16Z
[ "python", "beautifulsoup", "html-parsing" ]
Making BeautifulSoup ignore contents inside script tags
1,732,956
<p>I have been trying to get BeautifulSoup (3.1.0.1)to parse a html page that has a lot of javascript that generates html inside tags. One example fragment looks like this :</p> <pre><code>&lt;html&gt;&lt;head&gt;&lt;body&gt;&lt;div&gt; &lt;script type='text/javascript'&gt; if(ii &gt; 0) { html += '&lt;span id="hov...
1
2009-11-14T01:48:27Z
1,733,941
<p>Reverting to BeautifulSoup <a href="http://www.crummy.com/software/BeautifulSoup/download/3.x/BeautifulSoup-3.0.7a.tar.gz" rel="nofollow">3.0.7a</a> solved this issue and many other html oddities that 3.1.0.1 has choked on. </p>
1
2009-11-14T10:56:52Z
[ "python", "beautifulsoup", "html-parsing" ]
Making BeautifulSoup ignore contents inside script tags
1,732,956
<p>I have been trying to get BeautifulSoup (3.1.0.1)to parse a html page that has a lot of javascript that generates html inside tags. One example fragment looks like this :</p> <pre><code>&lt;html&gt;&lt;head&gt;&lt;body&gt;&lt;div&gt; &lt;script type='text/javascript'&gt; if(ii &gt; 0) { html += '&lt;span id="hov...
1
2009-11-14T01:48:27Z
1,733,960
<p>That would work, but the point of BeautifulSoup is parsing whatever tag soup you throw at it, even if it's horribly ill-formed.</p>
0
2009-11-14T11:09:28Z
[ "python", "beautifulsoup", "html-parsing" ]
Twisted Spread suitable for multiplayer racing sim?
1,732,957
<p>Do you think that Twisted Spread may be suitable (in terms of performance) for a multiplayer racing simulator? The rest of the application is based on Python-Ogre.</p> <p>Can Perspective Broker run upon (reliable?) UDP?</p>
2
2009-11-14T01:49:39Z
1,732,990
<p>It's almost certainly a reasonable protocol to start with. Remember the cardinal rule of optimization: don't do it. Working with any TCP-based protocol is going to be considerably easier than working with any UDP-based protocol. This is initially much more important to the success of your project than whether it ...
5
2009-11-14T02:10:43Z
[ "python", "networking", "udp", "twisted", "multiplayer" ]
Twisted Spread suitable for multiplayer racing sim?
1,732,957
<p>Do you think that Twisted Spread may be suitable (in terms of performance) for a multiplayer racing simulator? The rest of the application is based on Python-Ogre.</p> <p>Can Perspective Broker run upon (reliable?) UDP?</p>
2
2009-11-14T01:49:39Z
12,451,815
<p>To your first question, yes, PB's performance can be perfectly adequate for a real-time game. Several games have been written using PB. For example, <a href="http://mv3d.com/trac/" rel="nofollow">MV3D</a> uses Twisted and Python-OGRE to present a shared physical simulation.</p> <p>To your second question, PB runs ...
3
2012-09-17T00:18:38Z
[ "python", "networking", "udp", "twisted", "multiplayer" ]
Python: next() function
1,733,004
<p>I'm learning Python from a book, and I came across this example:</p> <pre><code>M = [[1,2,3], [4,5,6], [7,8,9]] G = (sum(row) for row in M) # create a generator of row sums next(G) # Run the iteration protocol </code></pre> <p>Since I'm an absolute beginner, and the author hasn't provided any explanatio...
17
2009-11-14T02:17:05Z
1,733,017
<p>The expression <code>(sum(row) for row in M)</code> creates what's called a <strong>generator</strong>. This generator will evaluate the expression (<code>sum(row)</code>) once for each row in <code>M</code>. However, the generator doesn't do anything yet, we've just set it up.</p> <p>The statement <code>next(G)</c...
42
2009-11-14T02:21:49Z
[ "python", "sum", "next" ]
Python: next() function
1,733,004
<p>I'm learning Python from a book, and I came across this example:</p> <pre><code>M = [[1,2,3], [4,5,6], [7,8,9]] G = (sum(row) for row in M) # create a generator of row sums next(G) # Run the iteration protocol </code></pre> <p>Since I'm an absolute beginner, and the author hasn't provided any explanatio...
17
2009-11-14T02:17:05Z
1,733,180
<p>If you've come that far, then you should already know how a common for-in statement works.</p> <p>The following statement:</p> <pre><code>for row in M: print row </code></pre> <p>would see M as a sequence of 3 rows (sub sequences) consisting of 3 items each, and iterate through M, outputting each row on the matri...
8
2009-11-14T03:49:51Z
[ "python", "sum", "next" ]
Django error opening SQLite3 db file on when running off Apache
1,733,050
<p>I got this error:</p> <p>OperationalError at /</p> <p>unable to open database file</p> <p>Things I've tried so far are setting the absolute path of my dev.db file in the settings.py. I've tried adding www-data to my admin group and setting the group of my project folder to the admin, and setting the group to www-...
6
2009-11-14T02:41:44Z
2,073,142
<p>Just passed the last 30 minutes banging my head on this problem ..</p> <p><strong>Solution</strong></p> <p>In your settings.py:</p> <pre><code>DATABASE_NAME = '/absolute/path/to/your/database.db' </code></pre> <p>Setting rights:</p> <pre><code>chown www-data /absolute/path/to/your/ chown www-data /absolute/path...
7
2010-01-15T16:33:08Z
[ "python", "django", "ubuntu", "sqlite3" ]
pymedia.audio.sound - How do I get up and running with this module?
1,733,052
<p>Im trying to get my hands on this pymedia.audio.sound module and have attempted to get it several times from python.org, but I think I am doing something wrong like.</p> <p>Any help greatly appreciated.</p> <p>Im running Windows XP, Python 2.5 and its running fine, but how do I download and where do I extract the ...
0
2009-11-14T02:42:07Z
1,733,773
<p>The homepage for <a href="http://pymedia.org/" rel="nofollow">pymedia</a>. Download from <a href="http://sourceforge.net/projects/pymedia/files/pymedia/" rel="nofollow">here</a>.</p> <p>Extract the compressed tar file. Then run <code>python setup.py install</code> from the extracted directory.</p>
0
2009-11-14T09:14:44Z
[ "python" ]
Grokking Timsort
1,733,073
<p>There's a (relatively) new sort on the block called Timsort. It's been used as Python's list.sort, and is now going to be <a href="http://download.java.net/jdk7/docs/api/java/util/Arrays.html#sort%28java.lang.Object%5B%5D">the new Array.sort in Java 7</a>).</p> <p>There's <a href="http://svn.python.org/projects/pyt...
22
2009-11-14T02:52:18Z
1,733,137
<p>This change went through the <a href="http://mail.openjdk.java.net/pipermail/core-libs-dev/">core-libs mailing list</a> when it went in so there is some discussion and useful links there. Here's the <a href="http://cr.openjdk.java.net/~martin/webrevs/openjdk7/timsort/">web rev</a> with code review changes and also ...
8
2009-11-14T03:31:07Z
[ "java", "python", "algorithm", "sorting", "timsort" ]
Grokking Timsort
1,733,073
<p>There's a (relatively) new sort on the block called Timsort. It's been used as Python's list.sort, and is now going to be <a href="http://download.java.net/jdk7/docs/api/java/util/Arrays.html#sort%28java.lang.Object%5B%5D">the new Array.sort in Java 7</a>).</p> <p>There's <a href="http://svn.python.org/projects/pyt...
22
2009-11-14T02:52:18Z
1,734,276
<p>You should look at this blog post: <a href="http://corte.si/%2Fposts/code/timsort/index.html" rel="nofollow">Visualising Sorting Algorithms: Python's timsort</a></p> <p><img src="http://corte.si/%2Fposts/code/timsort/combo.png" alt="alt text"></p> <p><strong>Summary</strong>:</p> <blockquote> <p>The business-en...
12
2009-11-14T13:49:43Z
[ "java", "python", "algorithm", "sorting", "timsort" ]
Convert PyQt to PIL image
1,733,096
<p>I have an image in a QImage and I want to process it in PIL before I display it. While the ImageQT class lets me convert a PIL Image to a QImage, there doesn't appear to anything to go from a QImage to a PIL Image.</p>
7
2009-11-14T03:08:15Z
1,733,497
<p>You can convert a QImage into a Python string:</p> <pre><code>&gt;&gt;&gt; image = QImage(256, 256, QImage.Format_ARGB32) &gt;&gt;&gt; bytes = image.bits().asstring(image.numBytes()) &gt;&gt;&gt; len(bytes) 262144 </code></pre> <p>Converting from this to PIL should be easy.</p>
0
2009-11-14T06:32:03Z
[ "python", "pyqt", "python-imaging-library" ]
Convert PyQt to PIL image
1,733,096
<p>I have an image in a QImage and I want to process it in PIL before I display it. While the ImageQT class lets me convert a PIL Image to a QImage, there doesn't appear to anything to go from a QImage to a PIL Image.</p>
7
2009-11-14T03:08:15Z
1,756,587
<p>I convert it from QImage to PIL with this code:</p> <pre><code>img = QImage("/tmp/example.png") buffer = QBuffer() buffer.open(QIODevice.ReadWrite) img.save(buffer, "PNG") strio = cStringIO.StringIO() strio.write(buffer.data()) buffer.close() strio.seek(0) pil_im = Image.open(strio) </code></pre> <p>I tried many ...
10
2009-11-18T14:59:01Z
[ "python", "pyqt", "python-imaging-library" ]
Convert PyQt to PIL image
1,733,096
<p>I have an image in a QImage and I want to process it in PIL before I display it. While the ImageQT class lets me convert a PIL Image to a QImage, there doesn't appear to anything to go from a QImage to a PIL Image.</p>
7
2009-11-14T03:08:15Z
1,767,215
<p>Another route would be:</p> <ol> <li>Load the image data into a numpy array (<a href="https://github.com/scikit-image/scikit-image/blob/master/skimage/io/_plugins/pil_plugin.py#L15" rel="nofollow">example code</a> using PIL)</li> <li>Manipulate the image using numpy, scipy or scikits.image</li> <li>Load the data in...
2
2009-11-19T23:07:44Z
[ "python", "pyqt", "python-imaging-library" ]
Convert PyQt to PIL image
1,733,096
<p>I have an image in a QImage and I want to process it in PIL before I display it. While the ImageQT class lets me convert a PIL Image to a QImage, there doesn't appear to anything to go from a QImage to a PIL Image.</p>
7
2009-11-14T03:08:15Z
3,588,161
<pre><code>from PyQt4 import QtGui, QtCore img = QtGui.QImage("greyScaleImage.png") bytes=img.bits().asstring(img.numBytes()) from PIL import Image pilimg = Image.frombuffer("L",(img.width(),img.height()),bytes,'raw', "L", 0, 1) pilimg.show() </code></pre> <p>Thanks Eli Bendersky, your code was helpful.</p>
1
2010-08-27T21:12:46Z
[ "python", "pyqt", "python-imaging-library" ]
Convert PyQt to PIL image
1,733,096
<p>I have an image in a QImage and I want to process it in PIL before I display it. While the ImageQT class lets me convert a PIL Image to a QImage, there doesn't appear to anything to go from a QImage to a PIL Image.</p>
7
2009-11-14T03:08:15Z
3,604,934
<pre><code>#Code for converting grayscale QImage to PIL image from PyQt4 import QtGui, QtCore qimage1 = QtGui.QImage("t1.png") bytes=qimage1.bits().asstring(qimage1.numBytes()) from PIL import Image pilimg = Image.frombuffer("L",(qimage1.width(),qimage1.height()),bytes,'raw', "L", 0, 1) pilimg.show() </code></pre>
1
2010-08-30T23:19:29Z
[ "python", "pyqt", "python-imaging-library" ]
`from QTKit import *` causes a 'FAILED TO establish the default connection to the WindowServer' in PyObjC application
1,733,098
<p>I've been trying out PyObjC and I can't seem to get the QTKit imports to work. If I import QTKit like so: <code>from QTKit import *</code> I get a flood of errors:</p> <pre><code>[Session started at 2009-11-13 21:03:49 -0600.] _RegisterApplication(), FAILED TO establish the default connection to the WindowServer, ...
1
2009-11-14T03:08:36Z
1,733,429
<p>Take a look at <a href="http://orestis.gr/blog/2008/05/17/pyobjc-hello-world/" rel="nofollow">this tutorial</a>. Apparently QTKit cannot be imported until after the runloop has been established.</p>
1
2009-11-14T06:00:26Z
[ "python", "objective-c", "pyobjc" ]
marking duplicates in a csv file
1,733,166
<p>I'm stumped with a problem illustrated in the sample below:</p> <pre><code>"ID","NAME","PHONE","REF","DISCARD" 1,"JOHN",12345,, 2,"PETER",6232,, 3,"JON",12345,, 4,"PETERSON",6232,, 5,"ALEX",7854,, 6,"JON",12345,, </code></pre> <p>I want to detect duplicates in column "PHONE", and mark the subsequent duplicates usi...
2
2009-11-14T03:42:42Z
1,733,196
<p>Sounds like homework. Since this is a CSV file (and thus changing the record size is next to impossible) you are best off loading the whole file into memory and manipulating it there before writing it out to a new file. Create a list of strings which is the original lines of the file. Then create a map, insert into ...
0
2009-11-14T03:56:18Z
[ "python", "csv", "duplicates" ]
marking duplicates in a csv file
1,733,166
<p>I'm stumped with a problem illustrated in the sample below:</p> <pre><code>"ID","NAME","PHONE","REF","DISCARD" 1,"JOHN",12345,, 2,"PETER",6232,, 3,"JON",12345,, 4,"PETERSON",6232,, 5,"ALEX",7854,, 6,"JON",12345,, </code></pre> <p>I want to detect duplicates in column "PHONE", and mark the subsequent duplicates usi...
2
2009-11-14T03:42:42Z
1,733,198
<pre><code>from operator import itemgetter from itertools import groupby import csv verum = csv.reader(open('data.csv','rb')) verum.sort(key=itemgetter(2,0)) def grouper( verum ): for key, grp in groupby(verum,itemgetter(2)): # key = phone number, grp = records with that number first = grp.next() ...
0
2009-11-14T03:57:06Z
[ "python", "csv", "duplicates" ]
marking duplicates in a csv file
1,733,166
<p>I'm stumped with a problem illustrated in the sample below:</p> <pre><code>"ID","NAME","PHONE","REF","DISCARD" 1,"JOHN",12345,, 2,"PETER",6232,, 3,"JON",12345,, 4,"PETERSON",6232,, 5,"ALEX",7854,, 6,"JON",12345,, </code></pre> <p>I want to detect duplicates in column "PHONE", and mark the subsequent duplicates usi...
2
2009-11-14T03:42:42Z
1,733,203
<p>I know one thing. I know you don't have to read the entire file into memory to accomplish this.</p> <pre><code>import csv myfile = "C:\Users\Eduardo\Documents\TEST2.csv" dest = csv.writer(open("C:\Users\Eduardo\Documents\TESTFIXED.csv", "wb"), dialect="excel") phonedict = {} for row in cvs.reader(open(myfile, "...
0
2009-11-14T03:57:56Z
[ "python", "csv", "duplicates" ]
marking duplicates in a csv file
1,733,166
<p>I'm stumped with a problem illustrated in the sample below:</p> <pre><code>"ID","NAME","PHONE","REF","DISCARD" 1,"JOHN",12345,, 2,"PETER",6232,, 3,"JON",12345,, 4,"PETERSON",6232,, 5,"ALEX",7854,, 6,"JON",12345,, </code></pre> <p>I want to detect duplicates in column "PHONE", and mark the subsequent duplicates usi...
2
2009-11-14T03:42:42Z
1,733,573
<p>The only thing you have to keep in memory while this is running is a map of phone numbers to their IDs.</p> <pre><code>map = {} with open(r'c:\temp\input.csv', 'r') as fin: reader = csv.reader(fin) with open(r'c:\temp\output.csv', 'w') as fout: writer = csv.writer(fout) # omit this if the fi...
5
2009-11-14T07:11:01Z
[ "python", "csv", "duplicates" ]
marking duplicates in a csv file
1,733,166
<p>I'm stumped with a problem illustrated in the sample below:</p> <pre><code>"ID","NAME","PHONE","REF","DISCARD" 1,"JOHN",12345,, 2,"PETER",6232,, 3,"JON",12345,, 4,"PETERSON",6232,, 5,"ALEX",7854,, 6,"JON",12345,, </code></pre> <p>I want to detect duplicates in column "PHONE", and mark the subsequent duplicates usi...
2
2009-11-14T03:42:42Z
1,792,796
<p>I work with large 40k plus record csv files, the easiest way to get rid of dupes it with Access. 1. Create new database, 2, Tables tab Get external Data 3. Save Table. 4. Queries tab New find dupe wizard ( Match on phone field, show all fields and count) 5. Save Query ( export has .txt but name dupes.txt ) 6....
0
2009-11-24T20:40:43Z
[ "python", "csv", "duplicates" ]
ubuntu9.10 : how to use python's lib-dynload and site-packages directories?
1,733,364
<p>In ubuntu 9.10, in usr/lib/ there are the directories python2.4, python2.5, python2.6 and python3.0 </p> <p>Only python 2.6 is actually working.<br> python2.4 has only a lib-dynload directory,<br> python2.5 has only lib-dynload and site-packages,<br> python3.0 has only a dist-packages directory. </p> <p>Now i'm w...
2
2009-11-14T05:23:14Z
1,733,409
<p>Sounds like they're an accident from some package(s) you have installed.</p> <p>The Python version in use determines the locations searched to find installed Python packages/modules, and the "system version" of Python in Ubuntu 9.10 is 2.6, so that's what practically everything should be using. If you were to inst...
0
2009-11-14T05:48:16Z
[ "python", "ubuntu", "install" ]
ubuntu9.10 : how to use python's lib-dynload and site-packages directories?
1,733,364
<p>In ubuntu 9.10, in usr/lib/ there are the directories python2.4, python2.5, python2.6 and python3.0 </p> <p>Only python 2.6 is actually working.<br> python2.4 has only a lib-dynload directory,<br> python2.5 has only lib-dynload and site-packages,<br> python3.0 has only a dist-packages directory. </p> <p>Now i'm w...
2
2009-11-14T05:23:14Z
1,734,444
<p>j3ll3, in Ubuntu (or any DPKG-based Linux OS) you can ask the question "<strong>What package provides</strong> XYZ" by typing</p> <pre><code>dpkg -S /path/to/XYZ </code></pre> <p>So, for example, in Ubuntu 9.10,</p> <pre><code>dpkg -S /usr/lib/python2.5/lib-dynload/gdbm.so </code></pre> <p>returns</p> <pre><cod...
2
2009-11-14T14:54:28Z
[ "python", "ubuntu", "install" ]
ubuntu9.10 : how to use python's lib-dynload and site-packages directories?
1,733,364
<p>In ubuntu 9.10, in usr/lib/ there are the directories python2.4, python2.5, python2.6 and python3.0 </p> <p>Only python 2.6 is actually working.<br> python2.4 has only a lib-dynload directory,<br> python2.5 has only lib-dynload and site-packages,<br> python3.0 has only a dist-packages directory. </p> <p>Now i'm w...
2
2009-11-14T05:23:14Z
1,734,530
<p>The short answer to your question: when you install packages from source, you should use the packages' <code>setup.py</code> installer to install them automatically and correctly. This installer already knows where to properly install the modules so Python can find them. To use, simply call with the exact Python i...
0
2009-11-14T15:16:47Z
[ "python", "ubuntu", "install" ]
ubuntu9.10 : how to use python's lib-dynload and site-packages directories?
1,733,364
<p>In ubuntu 9.10, in usr/lib/ there are the directories python2.4, python2.5, python2.6 and python3.0 </p> <p>Only python 2.6 is actually working.<br> python2.4 has only a lib-dynload directory,<br> python2.5 has only lib-dynload and site-packages,<br> python3.0 has only a dist-packages directory. </p> <p>Now i'm w...
2
2009-11-14T05:23:14Z
1,744,710
<p>I'm not sure what you mean by "Only python 2.6 is actually working." Suppose you run the "terminal emulator" and get a command-line prompt. Is this what you mean:</p> <pre><code>% python -V Python 2.6 </code></pre> <p>In other words, when you run Python, you get version 2.6? Well, have you tried this:</p> <pre...
0
2009-11-16T20:38:35Z
[ "python", "ubuntu", "install" ]
How do I include unicode strings in Python doctests?
1,733,414
<p>I am working on some code that has to manipulate unicode strings. I am trying to write doctests for it, but am having trouble. The following is a minimal example that illustrates the problem:</p> <pre><code># -*- coding: utf-8 -*- def mylen(word): """ &gt;&gt;&gt; mylen(u"áéíóú") 5 """ return len(wor...
16
2009-11-14T05:51:24Z
1,733,459
<p>This appears to be a known and as yet unresolved issue in Python. See open issues <a href="http://bugs.python.org/issue2811" rel="nofollow">here</a> and <a href="http://bugs.python.org/issue1293741" rel="nofollow">here</a>.</p> <p>Not surprisingly, it can be modified to work OK in Python 3 since all strings are Un...
2
2009-11-14T06:16:27Z
[ "python", "unicode", "doctest" ]
How do I include unicode strings in Python doctests?
1,733,414
<p>I am working on some code that has to manipulate unicode strings. I am trying to write doctests for it, but am having trouble. The following is a minimal example that illustrates the problem:</p> <pre><code># -*- coding: utf-8 -*- def mylen(word): """ &gt;&gt;&gt; mylen(u"áéíóú") 5 """ return len(wor...
16
2009-11-14T05:51:24Z
1,734,503
<p>If you want unicode strings, you have to use unicode docstrings! Mind the <code>u</code>!</p> <pre><code># -*- coding: utf-8 -*- def mylen(word): u""" &lt;----- SEE 'u' HERE &gt;&gt;&gt; mylen(u"áéíóú") 5 """ return len(word) print mylen(u"áéíóú") </code></pre> <p>This will work -- as l...
14
2009-11-14T15:10:33Z
[ "python", "unicode", "doctest" ]
How do I include unicode strings in Python doctests?
1,733,414
<p>I am working on some code that has to manipulate unicode strings. I am trying to write doctests for it, but am having trouble. The following is a minimal example that illustrates the problem:</p> <pre><code># -*- coding: utf-8 -*- def mylen(word): """ &gt;&gt;&gt; mylen(u"áéíóú") 5 """ return len(wor...
16
2009-11-14T05:51:24Z
1,736,189
<p>My solution was to escape the unicode characters, like u'\xe1\xe9\xed\xf3\xfa'. Wasn't as easy to read though, but my tests only had a few non-ASCII characters so in those cases I put the description to the side as a comment, like "# n with tilde".</p>
1
2009-11-15T00:54:06Z
[ "python", "unicode", "doctest" ]
How do I include unicode strings in Python doctests?
1,733,414
<p>I am working on some code that has to manipulate unicode strings. I am trying to write doctests for it, but am having trouble. The following is a minimal example that illustrates the problem:</p> <pre><code># -*- coding: utf-8 -*- def mylen(word): """ &gt;&gt;&gt; mylen(u"áéíóú") 5 """ return len(wor...
16
2009-11-14T05:51:24Z
6,640,580
<p>Python 2.6.6 doesn't understand unicode output very well, but this can be fixed using:</p> <ul> <li>already described hack with <code>sys.setdefaultencoding("UTF-8")</code></li> <li>unicode docstring (already mentioned above too, thanks a lot)</li> <li>AND <code>print</code> statement.</li> </ul> <p>In my case thi...
3
2011-07-10T10:35:20Z
[ "python", "unicode", "doctest" ]
How do I include unicode strings in Python doctests?
1,733,414
<p>I am working on some code that has to manipulate unicode strings. I am trying to write doctests for it, but am having trouble. The following is a minimal example that illustrates the problem:</p> <pre><code># -*- coding: utf-8 -*- def mylen(word): """ &gt;&gt;&gt; mylen(u"áéíóú") 5 """ return len(wor...
16
2009-11-14T05:51:24Z
22,611,201
<p>As already mentioned, you need to ensure your docstrings are Unicode.</p> <p>If you can switch to Python 3, then it would work automatically there, as <em>both</em> the source encoding is already utf-8 and the default string type is Unicode.</p> <p>To achieve the same in Python 2, you need to keep the <code>coding...
1
2014-03-24T13:45:12Z
[ "python", "unicode", "doctest" ]
wxPython: Update wx.ListBox list
1,733,461
<p>I have a wx.ListBox in a python program, and I wan't to change out the list in it on a wx.Timer update. I have the timer working, I just don't know how to change out the list that it displays.</p>
7
2009-11-14T06:17:47Z
1,733,492
<p><a href="http://www.daniweb.com/code/snippet216484.html#">Here's an example</a> for modifying a ListBox. Generally, it uses the <code>Append</code> and <code>Clear</code> methods of ListBox. You can call those in your timer handler.</p> <p>Since <code>ListBox</code> derives from <code>ItemContainer</code>, see more...
8
2009-11-14T06:28:00Z
[ "python", "wxpython" ]
What is more efficient in python new array creation or in place array manipulation?
1,733,468
<p>Say I have an array with a couple hundred elements. I need to iterate of the array and replace one or more items in the array with some other item. Which strategy is more efficient in python in terms of speed (I'm not worried about memory)?</p> <p>For example: I have an array</p> <pre><code> my_array = [1,2,3,4,5,...
2
2009-11-14T06:19:47Z
1,733,478
<pre><code>arr[0] = x </code></pre> <p>replaces the 0th element with x. You can also replace whole slices.</p> <pre><code>&gt;&gt;&gt; arr = [1, 2, 3, 4, 5, 6] &gt;&gt;&gt; arr[0:3] = [8, 9, 99] &gt;&gt;&gt; arr [8, 9, 99, 4, 5, 6] &gt;&gt;&gt; </code></pre> <p>And generally it's unclear what you're trying to achiev...
3
2009-11-14T06:22:19Z
[ "python", "performance" ]
What is more efficient in python new array creation or in place array manipulation?
1,733,468
<p>Say I have an array with a couple hundred elements. I need to iterate of the array and replace one or more items in the array with some other item. Which strategy is more efficient in python in terms of speed (I'm not worried about memory)?</p> <p>For example: I have an array</p> <pre><code> my_array = [1,2,3,4,5,...
2
2009-11-14T06:19:47Z
1,733,535
<p>If you want to replace an item or a set of items in a list, you should never use your first option. Removing and adding to a list in the middle is slow (<a href="http://docs.python.org/tutorial/datastructures.html#using-lists-as-queues" rel="nofollow">reference</a>). Your second option is also fairly inefficient, si...
6
2009-11-14T06:49:58Z
[ "python", "performance" ]
What is more efficient in python new array creation or in place array manipulation?
1,733,468
<p>Say I have an array with a couple hundred elements. I need to iterate of the array and replace one or more items in the array with some other item. Which strategy is more efficient in python in terms of speed (I'm not worried about memory)?</p> <p>For example: I have an array</p> <pre><code> my_array = [1,2,3,4,5,...
2
2009-11-14T06:19:47Z
1,734,236
<p>If you're looking speed efficience and manipulate series of integers, You should use the standard array module instead:</p> <pre><code>&gt;&gt;&gt; import array &gt;&gt;&gt; my_array = array.array('i', [1,2,3,4,5,6]) &gt;&gt;&gt; my_array = my_array[3:] &gt;&gt;&gt; my_array.insert(0,123) &gt;&gt;&gt; my_array arra...
0
2009-11-14T13:31:23Z
[ "python", "performance" ]
What is more efficient in python new array creation or in place array manipulation?
1,733,468
<p>Say I have an array with a couple hundred elements. I need to iterate of the array and replace one or more items in the array with some other item. Which strategy is more efficient in python in terms of speed (I'm not worried about memory)?</p> <p>For example: I have an array</p> <pre><code> my_array = [1,2,3,4,5,...
2
2009-11-14T06:19:47Z
1,734,431
<p>The key thing is to avoid moving large numbers of list items more than absolutely have to. Slice assignment, as far as i'm aware, still involves moving the items around the slice, which is bad news.</p> <p>How do you recognise when you have a sequence of items which need to be replaced? I'll assume you have a funct...
0
2009-11-14T14:48:53Z
[ "python", "performance" ]
Writing a key-value store
1,733,619
<p>I am looking to write a Key/value store (probably in python) mostly just for experience, and because it's something I think that is a very useful product. I have a couple of questions. How, in general, are key/value pairs normally stored in memory and on disk? How would one go about loading the things stored on disk...
10
2009-11-14T07:42:57Z
1,733,637
<p>If you're doing a key/value store in Python for learning purposes, it might be easiest to start with the <a href="http://docs.python.org/library/pickle.html" rel="nofollow">pickle</a> module. It's a fast and convenient way to write an arbitrary Python data stream to a persistent store and read it back again.</p>
3
2009-11-14T07:53:43Z
[ "python", "key-value-store" ]
Writing a key-value store
1,733,619
<p>I am looking to write a Key/value store (probably in python) mostly just for experience, and because it's something I think that is a very useful product. I have a couple of questions. How, in general, are key/value pairs normally stored in memory and on disk? How would one go about loading the things stored on disk...
10
2009-11-14T07:42:57Z
1,733,650
<p>you can have a look at '<a href="http://en.wikipedia.org/wiki/Berkeley%5FDB" rel="nofollow">Berkley db</a>' to see how how it works, it is a key/value DB, so you can use it directly, or as it is open-source see how it handles persistence, transactions and paging of most referred pages.</p> <p>here are python bindin...
3
2009-11-14T08:05:42Z
[ "python", "key-value-store" ]
Writing a key-value store
1,733,619
<p>I am looking to write a Key/value store (probably in python) mostly just for experience, and because it's something I think that is a very useful product. I have a couple of questions. How, in general, are key/value pairs normally stored in memory and on disk? How would one go about loading the things stored on disk...
10
2009-11-14T07:42:57Z
1,733,699
<p>Amazon released a <a href="http://www.google.co.il/url?sa=t&amp;source=web&amp;ct=res&amp;cd=1&amp;ved=0CAcQFjAA&amp;url=http%3A%2F%2Fs3.amazonaws.com%2FAllThingsDistributed%2Fsosp%2Famazon-dynamo-sosp2007.pdf&amp;ei=E2j-SvHaOJSmsAbk68mRDA&amp;usg=AFQjCNEpBjuspsc5JvGcLtzw39GGRN-chA&amp;sig2=FjGnnpx1ChirGrNHNRtmeA" r...
2
2009-11-14T08:35:59Z
[ "python", "key-value-store" ]
Writing a key-value store
1,733,619
<p>I am looking to write a Key/value store (probably in python) mostly just for experience, and because it's something I think that is a very useful product. I have a couple of questions. How, in general, are key/value pairs normally stored in memory and on disk? How would one go about loading the things stored on disk...
10
2009-11-14T07:42:57Z
1,733,720
<p>It all depends on the level of complexity you want to dive into. Starting with a simple Python <code>dict</code> serialized to a file in a myriad of possible ways (of which pickle is probably the simplest), you can go as far as implementing a complete database system.</p> <p>Look up <code>redis</code> - it's a key/...
19
2009-11-14T08:44:52Z
[ "python", "key-value-store" ]
Writing a key-value store
1,733,619
<p>I am looking to write a Key/value store (probably in python) mostly just for experience, and because it's something I think that is a very useful product. I have a couple of questions. How, in general, are key/value pairs normally stored in memory and on disk? How would one go about loading the things stored on disk...
10
2009-11-14T07:42:57Z
1,733,752
<p>Have a look at Python's <a href="http://docs.python.org/library/shelve.html#module-shelve" rel="nofollow"><code>shelve</code></a> module which provides a persitent dictionary. It basically stores pickles in a database, usually dmb or BSDDB. Looking at how <code>shelve</code> works will give you some insights, and th...
4
2009-11-14T09:05:38Z
[ "python", "key-value-store" ]
Writing a key-value store
1,733,619
<p>I am looking to write a Key/value store (probably in python) mostly just for experience, and because it's something I think that is a very useful product. I have a couple of questions. How, in general, are key/value pairs normally stored in memory and on disk? How would one go about loading the things stored on disk...
10
2009-11-14T07:42:57Z
5,199,271
<p>First up, I know this question quite old.</p> <p>I'm the creator of aodbm ( <a href="http://sf.net/projects/aodbm/" rel="nofollow">http://sf.net/projects/aodbm/</a> ), which is a key-value store library. aodbm uses immutable B+Trees to store your data. So whenever a modification is made a new tree is appended to th...
0
2011-03-04T21:07:42Z
[ "python", "key-value-store" ]
Writing a key-value store
1,733,619
<p>I am looking to write a Key/value store (probably in python) mostly just for experience, and because it's something I think that is a very useful product. I have a couple of questions. How, in general, are key/value pairs normally stored in memory and on disk? How would one go about loading the things stored on disk...
10
2009-11-14T07:42:57Z
38,270,823
<p>I recommend to see the talk <a href="http://www.slideshare.net/leifwalsh/writeoptimization-in-external-memory-data-structures" rel="nofollow">Write optimization in external - memory data structures</a> (<a href="http://www.slideshare.net/leifwalsh/writeoptimization-in-external-memory-data-structures" rel="nofollow">...
0
2016-07-08T15:50:57Z
[ "python", "key-value-store" ]
run unit tests and coverage in certain python structure
1,734,001
<p>I have some funny noob problem.</p> <p>I try to run unit tests from commandline:</p> <pre><code>H:\PRO\pyEstimator&gt;python src\test\python\test_power_estimator.py Traceback (most recent call last): File "src\test\python\test_power_estimator.py", line 2, in &lt;module&gt; import src.main.python.power_estima...
1
2009-11-14T11:37:38Z
1,734,045
<p>The immediate issue you are facing is a misunderstanding of what is "local code" in Python (I am not sure if there is an official terminology, so I am making this one up) and how to import it.</p> <p>When you run <code>python src\test\python\test_power_estimator.py</code>, the first element in <code>sys.path</code>...
1
2009-11-14T11:54:57Z
[ "python", "unit-testing", "code-coverage", "python-coverage" ]
Is it possible for lxml to work in a case-insensitive manner?
1,734,125
<p>I'm trying to scrape META keywords and description tags from arbitrary websites. I obviusly have no control over said website, so have to take what I'm given. They have a variety of casings for the tag and attributes, which means I need to work case-insensitively. I can't believe that the lxml authors are as stubbor...
6
2009-11-14T12:35:07Z
1,734,185
<p>lxml is an XML parser. XML is case-sensitive. You are parsing HTML, so you should use an HTML parser. BeautifulSoup is very popular. It's only drawback is that it can be slow.</p>
1
2009-11-14T13:06:10Z
[ "python", "css-selectors", "lxml", "case-sensitive", "case-insensitive" ]
Is it possible for lxml to work in a case-insensitive manner?
1,734,125
<p>I'm trying to scrape META keywords and description tags from arbitrary websites. I obviusly have no control over said website, so have to take what I'm given. They have a variety of casings for the tag and attributes, which means I need to work case-insensitively. I can't believe that the lxml authors are as stubbor...
6
2009-11-14T12:35:07Z
1,734,220
<p><em>Values</em> of attributes <em>must</em> be case-sensitive.</p> <p>You can use arbitrary regular expression to select an element:</p> <pre><code>#!/usr/bin/env python from lxml import html doc = html.fromstring(''' &lt;meta name="Description"&gt; &lt;meta name="description"&gt; &lt;META name="descr...
5
2009-11-14T13:23:48Z
[ "python", "css-selectors", "lxml", "case-sensitive", "case-insensitive" ]
Is it possible for lxml to work in a case-insensitive manner?
1,734,125
<p>I'm trying to scrape META keywords and description tags from arbitrary websites. I obviusly have no control over said website, so have to take what I'm given. They have a variety of casings for the tag and attributes, which means I need to work case-insensitively. I can't believe that the lxml authors are as stubbor...
6
2009-11-14T12:35:07Z
9,264,530
<p>You can use</p> <pre class="lang-py prettyprint-override"><code>doc.cssselect.xpath("//meta[translate(@name, 'ABCDEFGHJIKLMNOPQRSTUVWXYZ', 'abcdefghjiklmnopqrstuvwxyz')='description']") </code></pre> <p>It translates the value of "name" to lowercase and then matches.</p> <p>See also:</p> <ul> <li><a href="ht...
0
2012-02-13T16:56:34Z
[ "python", "css-selectors", "lxml", "case-sensitive", "case-insensitive" ]
Problem getting started with GeoDjango
1,734,147
<p>As soon as I add "from django.contrib.gis.db import models" instead of "from django.db import models", Django stops recognizing the app and gives this error:</p> <pre><code>Error: App with label location could not be found. Are you sure your INSTALLED_APPS setting is correct? </code></pre> <p>The error goes away a...
1
2009-11-14T12:46:13Z
1,734,358
<p>If you have location on your INSTALLED_APPS and are getting this error, most likely you don't have the location app in your PYTHONPATH.</p>
0
2009-11-14T14:23:46Z
[ "python", "django", "django-models", "geodjango" ]
Problem getting started with GeoDjango
1,734,147
<p>As soon as I add "from django.contrib.gis.db import models" instead of "from django.db import models", Django stops recognizing the app and gives this error:</p> <pre><code>Error: App with label location could not be found. Are you sure your INSTALLED_APPS setting is correct? </code></pre> <p>The error goes away a...
1
2009-11-14T12:46:13Z
2,180,275
<p>I had encountered the same issue using <strong>Postgres 8.4</strong></p> <p>Links to <code>psycopg2</code> and <code>GeoDjango</code> given on GeoDjango installation instructions page rely on Postgres 8.3,</p> <p>So, if you use Postgres 8.4 you must install appropriate version of psycopg2 from <a href="http://www....
0
2010-02-01T21:41:47Z
[ "python", "django", "django-models", "geodjango" ]
Problem getting started with GeoDjango
1,734,147
<p>As soon as I add "from django.contrib.gis.db import models" instead of "from django.db import models", Django stops recognizing the app and gives this error:</p> <pre><code>Error: App with label location could not be found. Are you sure your INSTALLED_APPS setting is correct? </code></pre> <p>The error goes away a...
1
2009-11-14T12:46:13Z
4,134,160
<p>I was having the same problem after installing Django on Ubuntu 10 using Synaptic Package manager...</p> <p>Turns out it didn't install the required package "libgdal1". Manually selected it and GeoDjango works fine now.</p>
0
2010-11-09T13:32:17Z
[ "python", "django", "django-models", "geodjango" ]
Including package data with Distribute
1,734,373
<p>I'm trying to use Distribute for my project's <code>setup.py</code>. I want it to include all the files in the package folder, which are text and image files, but not .pyc files of course. I read that the files should either be tracked by CVS and SVN, or there should be a <code>MAINFEST.in</code>.</p> <p>So:</p> <...
2
2009-11-14T14:30:18Z
1,735,261
<p>I don't know if there is better documentation yet for <code>distribute</code> so you may have to refer to the documentation for <a href="http://peak.telecommunity.com/DevCenter/setuptools#including-data-files" rel="nofollow">setuptools</a> from which <code>distribute</code> was forked. In particular, see the sectio...
0
2009-11-14T19:13:28Z
[ "python", "distribution", "setuptools", "distribute" ]
Including package data with Distribute
1,734,373
<p>I'm trying to use Distribute for my project's <code>setup.py</code>. I want it to include all the files in the package folder, which are text and image files, but not .pyc files of course. I read that the files should either be tracked by CVS and SVN, or there should be a <code>MAINFEST.in</code>.</p> <p>So:</p> <...
2
2009-11-14T14:30:18Z
1,738,049
<p>I've change that behavior in Distutils (in Python trunk (2.7/3.2) ) </p> <p>Now all files mentioned in package_data will be included by default without having to write a MANIFEST.in file, and without having to use the magic behavior based on DVCS.</p> <p>Until then, I would recommend using an explicit MANIFEST.in...
5
2009-11-15T16:40:19Z
[ "python", "distribution", "setuptools", "distribute" ]
Manipulate screen buffer in python
1,734,575
<p>I know this is a long shot, but I was wondering if Python had a way to manipulate the screen buffer. Specifically, I want to be able to gray-out my desktop and highlight my windows when I press a key combination. Is this in the realm of possibility?</p>
1
2009-11-14T15:34:01Z
1,737,547
<p>From your question and the comments that followed, <a href="http://www.riverbankcomputing.co.uk/news" rel="nofollow">PyQt</a> would be a good choice, you would have a common code for the three platforms.</p> <p>You have to develop it as a GUI though, using the library functions, it also means you will have to rethi...
2
2009-11-15T13:34:12Z
[ "python", "screen", "buffer" ]
Manipulate screen buffer in python
1,734,575
<p>I know this is a long shot, but I was wondering if Python had a way to manipulate the screen buffer. Specifically, I want to be able to gray-out my desktop and highlight my windows when I press a key combination. Is this in the realm of possibility?</p>
1
2009-11-14T15:34:01Z
1,737,577
<p>Instead of "graying out" the desktop, try to overlay a gray, semi-transparent image over the entire screen and then make sure your window is on top of that. You may face a couple of minor limitations; for example, I don't know off the top of my head if it's possible to overlay the mac menubar (and I'm not sure you'd...
2
2009-11-15T13:54:32Z
[ "python", "screen", "buffer" ]
Each looping return a result
1,734,626
<p>I am a beginner and got an issue, really head around now.</p> <p>Here is the code:</p> <pre><code>n=3 #time step #f, v and r are arrays,eg [3,4,5] #r,v,f all have initial array which is when n=0 def force(): r=position() f=r*2 return f def position(n): v=velocity(n) for i in range(n): #Th...
0
2009-11-14T15:51:01Z
1,734,642
<p>You could use a list comprehension: </p> <pre><code>def position(n): v=velocity(n) return [v*i for i in range(n)] </code></pre> <p>Or, since you are using numpy:</p> <pre><code>v=np.array([1,2,3]) # array([1, 2, 3]) </code></pre> <p>you can use numpy broadcasting to express the entire calculation in one ...
0
2009-11-14T15:58:02Z
[ "python", "arrays", "numpy" ]
Each looping return a result
1,734,626
<p>I am a beginner and got an issue, really head around now.</p> <p>Here is the code:</p> <pre><code>n=3 #time step #f, v and r are arrays,eg [3,4,5] #r,v,f all have initial array which is when n=0 def force(): r=position() f=r*2 return f def position(n): v=velocity(n) for i in range(n): #Th...
0
2009-11-14T15:51:01Z
1,734,649
<p>You need to use append to add to the list.</p> <pre><code>def position(n): v=velocity(n) r = array() for i in range(n): #this part may wrong... r.append(v*i) #how can I return results when i=0,1...5? return r </code></pre>
0
2009-11-14T15:59:31Z
[ "python", "arrays", "numpy" ]
Each looping return a result
1,734,626
<p>I am a beginner and got an issue, really head around now.</p> <p>Here is the code:</p> <pre><code>n=3 #time step #f, v and r are arrays,eg [3,4,5] #r,v,f all have initial array which is when n=0 def force(): r=position() f=r*2 return f def position(n): v=velocity(n) for i in range(n): #Th...
0
2009-11-14T15:51:01Z
1,734,660
<p>You can use yield.<pre><code> def velocity(n): f=force for i in range(n): v=f*i yield(v)</p> <p>for vel in velocity(n): //do something </pre></code></p> <p>One working example. It will print the output of function test as soon as it yields. So you do not need to wait for the next iteration of the loo...
4
2009-11-14T16:03:11Z
[ "python", "arrays", "numpy" ]
Each looping return a result
1,734,626
<p>I am a beginner and got an issue, really head around now.</p> <p>Here is the code:</p> <pre><code>n=3 #time step #f, v and r are arrays,eg [3,4,5] #r,v,f all have initial array which is when n=0 def force(): r=position() f=r*2 return f def position(n): v=velocity(n) for i in range(n): #Th...
0
2009-11-14T15:51:01Z
1,735,011
<p>It looks like you're trying to do an Euler algorithm and getting a bit mixed up in the looping. Here's how I think it should look (and I'll assume this is for a game and not homework... if it is for homework you should state that clearly so we don't give the full answer, like I'm doing here.)</p> <p>This example i...
2
2009-11-14T17:49:39Z
[ "python", "arrays", "numpy" ]
How to read data from Game Port with Python?
1,734,779
<p>I like programming with robots and stuff. For this approach, I'm using the LPT port for output and the Gameport for input.</p> <p>For younger guys: Just some old fashioned USB Ports ;-)<br> <img src="http://img44.imageshack.us/img44/3650/da15dsubm.png" alt="Game Port"> <img src="http://img44.imageshack.us/img44/136...
1
2009-11-14T16:44:18Z
1,734,925
<p>I cannot really help you much. I don't work with joy/parallel port anymore and I forgot almost everything. What I can tell you is that under linux, there's a specific driver and device for the joystick port. You find information about it here (google cache, the main doc is down)</p> <p><a href="http://74.125.153.13...
2
2009-11-14T17:24:48Z
[ "python", "ubuntu" ]
How to read data from Game Port with Python?
1,734,779
<p>I like programming with robots and stuff. For this approach, I'm using the LPT port for output and the Gameport for input.</p> <p>For younger guys: Just some old fashioned USB Ports ;-)<br> <img src="http://img44.imageshack.us/img44/3650/da15dsubm.png" alt="Game Port"> <img src="http://img44.imageshack.us/img44/136...
1
2009-11-14T16:44:18Z
1,734,942
<p>Have you looked at pygame's joystick package: <a href="http://www.pygame.org/docs/ref/joystick.html" rel="nofollow">http://www.pygame.org/docs/ref/joystick.html</a> ?</p>
1
2009-11-14T17:28:49Z
[ "python", "ubuntu" ]
How to read data from Game Port with Python?
1,734,779
<p>I like programming with robots and stuff. For this approach, I'm using the LPT port for output and the Gameport for input.</p> <p>For younger guys: Just some old fashioned USB Ports ;-)<br> <img src="http://img44.imageshack.us/img44/3650/da15dsubm.png" alt="Game Port"> <img src="http://img44.imageshack.us/img44/136...
1
2009-11-14T16:44:18Z
1,736,421
<p>If your just looking for controller input (USB Joystick, Gamepad, etc) PyGame has an input module that works nicely.</p>
1
2009-11-15T03:00:55Z
[ "python", "ubuntu" ]
How to keep pyglet from clearing the screen?
1,734,801
<p>I want to draw a scene and sequentially add lines to it. But pyglet keeps updating without control :( , so all I get is blinks</p> <pre><code>from pyglet.gl import * window=pyglet.window.Window() def drawline(): ... @window.event def on_draw(): drawline() pyglet.app.run() </code></pre> <p>should I chan...
2
2009-11-14T16:52:02Z
1,735,178
<p>You'll need to draw your lines each time the window is redrawn as they won't be retained. You're probably better off using batches of vertex lists and adding to them. See <a href="http://www.pyglet.org/doc/programming%5Fguide/vertex%5Flists.html" rel="nofollow">here</a> and <a href="http://www.pyglet.org/doc/program...
2
2009-11-14T18:48:53Z
[ "python", "pyglet" ]
Why isn't psycopg2 executing any of my SQL functions? (IndexError: tuple index out of range)
1,734,814
<p>I'll take the simplest of the SQL functions as an example:</p> <pre><code>CREATE OR REPLACE FUNCTION skater_name_match(INTEGER,VARCHAR) RETURNS BOOL AS $$ SELECT $1 IN (SELECT skaters_skater.competitor_ptr_id FROM skaters_skater WHERE name||' '||surname ILIKE '%'||$2||'%' OR surname||' '||name ILIKE '%...
15
2009-11-14T16:55:28Z
1,734,847
<p>Index out of range implies you've tried to access (for example) the third element of a tuple which only has two elements. Note that Python's indexes start at 0, so a two-element tuple named myTuple would have elements myTuple[0] and myTuple[1], but no element myTuple[2].</p>
1
2009-11-14T17:02:12Z
[ "python", "sql", "django", "postgresql", "psycopg2" ]
Why isn't psycopg2 executing any of my SQL functions? (IndexError: tuple index out of range)
1,734,814
<p>I'll take the simplest of the SQL functions as an example:</p> <pre><code>CREATE OR REPLACE FUNCTION skater_name_match(INTEGER,VARCHAR) RETURNS BOOL AS $$ SELECT $1 IN (SELECT skaters_skater.competitor_ptr_id FROM skaters_skater WHERE name||' '||surname ILIKE '%'||$2||'%' OR surname||' '||name ILIKE '%...
15
2009-11-14T16:55:28Z
1,734,907
<p>Looks like you aren't committing the transaction:</p> <p>Try putting:</p> <pre> cursor.execute("COMMIT") </pre> <p>After the last line and see if that works.</p> <p>You can also set the isolation level to autocommit like:</p> <pre> connection.set_isolation_level(0) </pre> <p>More info on that in this <a href="...
3
2009-11-14T17:18:13Z
[ "python", "sql", "django", "postgresql", "psycopg2" ]
Why isn't psycopg2 executing any of my SQL functions? (IndexError: tuple index out of range)
1,734,814
<p>I'll take the simplest of the SQL functions as an example:</p> <pre><code>CREATE OR REPLACE FUNCTION skater_name_match(INTEGER,VARCHAR) RETURNS BOOL AS $$ SELECT $1 IN (SELECT skaters_skater.competitor_ptr_id FROM skaters_skater WHERE name||' '||surname ILIKE '%'||$2||'%' OR surname||' '||name ILIKE '%...
15
2009-11-14T16:55:28Z
1,735,731
<p>By default psycopg2 identifies argument placeholders using the <code>%</code> symbol (usually you'd have <code>%s</code> in the string). </p> <p>So, if you use <code>cursor.execute('... %s, %s ...', (arg1, arg2))</code> then those <code>%s</code> get turned into the values of arg1 and arg2 respectively.</p> <p>But...
27
2009-11-14T21:54:17Z
[ "python", "sql", "django", "postgresql", "psycopg2" ]
2 mysql instances in MAC
1,734,918
<p>i recently switched to mac. first and foremost i installed xampp. then for django-python-mysql connectivity, i "somehow" ended up installing a seperate MySQL. now the seperate mysql installation is active all the time and the Xampp one doesnt switch on unless i kill the other one.</p> <p>what i wanted to know is it...
0
2009-11-14T17:22:55Z
1,734,939
<p>You could change the listening port of one of the installations and they shouldn't conflict anymore with each other.</p> <p><strong>Update:</strong> You need to find the mysql configuration file <code>my.cnf</code> of the server which should get a new port (the one from xampp should be somewhere in the xampp folder...
1
2009-11-14T17:28:16Z
[ "python", "mysql", "django", "osx", "xampp" ]
How to normalize a NumPy array to within a certain range?
1,735,025
<p>After doing some processing on an audio or image array, it needs to be normalized within a range before it can be written back to a file. This can be done like so:</p> <pre><code># Normalize audio channels to between -1.0 and +1.0 audio[:,0] = audio[:,0]/abs(audio[:,0]).max() audio[:,1] = audio[:,1]/abs(audio[:,1]...
40
2009-11-14T17:52:38Z
1,735,064
<p>You can use the "i" (as in idiv, imul..) version, and it doesn't look half bad:</p> <pre><code>image /= (image.max()/255.0) </code></pre> <p>For the other case you can write a function to normalize an n-dimensional array by colums:</p> <pre><code>def normalize_columns(arr): rows, cols = arr.shape for col ...
9
2009-11-14T18:04:54Z
[ "python", "arrays", "numpy", "scipy", "convenience-methods" ]
How to normalize a NumPy array to within a certain range?
1,735,025
<p>After doing some processing on an audio or image array, it needs to be normalized within a range before it can be written back to a file. This can be done like so:</p> <pre><code># Normalize audio channels to between -1.0 and +1.0 audio[:,0] = audio[:,0]/abs(audio[:,0]).max() audio[:,1] = audio[:,1]/abs(audio[:,1]...
40
2009-11-14T17:52:38Z
1,735,122
<pre><code>audio /= np.max(np.abs(audio),axis=0) image *= (255.0/image.max()) </code></pre> <p>Using <code>/=</code> and <code>*=</code> allows you to eliminate an intermediate temporary array, thus saving some memory. Multiplication is less expensive than division, so </p> <pre><code>image *= 255.0/image.max() #...
48
2009-11-14T18:22:58Z
[ "python", "arrays", "numpy", "scipy", "convenience-methods" ]
How to normalize a NumPy array to within a certain range?
1,735,025
<p>After doing some processing on an audio or image array, it needs to be normalized within a range before it can be written back to a file. This can be done like so:</p> <pre><code># Normalize audio channels to between -1.0 and +1.0 audio[:,0] = audio[:,0]/abs(audio[:,0]).max() audio[:,1] = audio[:,1]/abs(audio[:,1]...
40
2009-11-14T17:52:38Z
21,195,655
<p>You can also rescale using <code>sklearn</code>. The advantages are that you can adjust normalize the standard deviation, in addition to mean-centering the data, and that you can do this on either axis, by features, or by records.</p> <pre><code>from sklearn.preprocessing import scale X = scale( X, axis=0, with_mea...
13
2014-01-17T20:53:11Z
[ "python", "arrays", "numpy", "scipy", "convenience-methods" ]
Setting Python Interpreter in Eclipse (Mac)
1,735,109
<p>How do I direct Eclipse to the Python interpreter on my Mac?</p> <p>I've looked in Library which contains the directory 'Python' then '2.3' and '2.5', however they contain nothing except 'Site-packages' - Which is weird considering I can go into the terminal and type <code>python</code>. I then installed the latest...
10
2009-11-14T18:18:32Z
1,735,148
<p>An alias to the python interpreter was likely installed into <code>/usr/local/bin</code>. So, to invoke python2.6, type <code>/usr/local/bin/python2.6</code> or, most likely, just <code>python2.6</code>. If you want python to invoke python2.6, try rearranging your <code>$PATH</code> so that <code>/usr/local/bin</c...
7
2009-11-14T18:37:09Z
[ "python", "eclipse", "osx" ]
Setting Python Interpreter in Eclipse (Mac)
1,735,109
<p>How do I direct Eclipse to the Python interpreter on my Mac?</p> <p>I've looked in Library which contains the directory 'Python' then '2.3' and '2.5', however they contain nothing except 'Site-packages' - Which is weird considering I can go into the terminal and type <code>python</code>. I then installed the latest...
10
2009-11-14T18:18:32Z
1,735,193
<p>Running $which python should help locate your Python installation. </p>
7
2009-11-14T18:54:14Z
[ "python", "eclipse", "osx" ]
Setting Python Interpreter in Eclipse (Mac)
1,735,109
<p>How do I direct Eclipse to the Python interpreter on my Mac?</p> <p>I've looked in Library which contains the directory 'Python' then '2.3' and '2.5', however they contain nothing except 'Site-packages' - Which is weird considering I can go into the terminal and type <code>python</code>. I then installed the latest...
10
2009-11-14T18:18:32Z
14,131,142
<p>I just solved this for my Mac and it was located in</p> <pre><code>/usr/bin/python2.7 </code></pre> <p>The way I found it is as follows:</p> <p>(1) I tried entering the following to see if I could find where Python was located</p> <pre><code>echo $PYTHONPATH </code></pre> <p>This had the location of a custom in...
1
2013-01-02T23:56:28Z
[ "python", "eclipse", "osx" ]
Production quality Python opensocial container and client?
1,735,180
<p>Is there any production quality library for developing opensocial containers and clients in python and django?</p>
0
2009-11-14T18:49:30Z
1,735,950
<p>Regarding containers, there's <a href="http://code.google.com/p/gae-opensocial/" rel="nofollow">GAE-opensocial</a> which can run in App Engine (should also be usable stand-alone); unfortunately it looks like <a href="http://code.google.com/p/django-opensocial/" rel="nofollow">django-opensocial</a> is dormant. For c...
3
2009-11-14T23:14:59Z
[ "python", "django", "opensocial" ]
How to create program startup parameters in python
1,735,202
<p>I'm just beginning to learn python and the program I'm writing requires parameters for it to run with a specific task. For example (programs name is Samtho)</p> <pre><code>samtho -i Mozilla_Firefox </code></pre> <p>How can I do that?</p>
0
2009-11-14T18:55:45Z
1,735,208
<p>Read the documentation on <a href="http://docs.python.org/library/optparse.html" rel="nofollow">optparse</a>. It is very powerful and will let you lots of parameters and create the help text.</p>
9
2009-11-14T18:58:27Z
[ "python", "parameters", "startup", "pydev" ]
How to create program startup parameters in python
1,735,202
<p>I'm just beginning to learn python and the program I'm writing requires parameters for it to run with a specific task. For example (programs name is Samtho)</p> <pre><code>samtho -i Mozilla_Firefox </code></pre> <p>How can I do that?</p>
0
2009-11-14T18:55:45Z
1,735,210
<p>You can use the modules <a href="http://docs.python.org/3.1/library/optparse.html" rel="nofollow"><code>optparse</code></a> and <a href="http://docs.python.org/3.1/library/getopt.html" rel="nofollow"><code>getopt</code></a> from the standard library. The former is more flexible and thus recommended.</p> <p>If you w...
6
2009-11-14T18:59:15Z
[ "python", "parameters", "startup", "pydev" ]
How to create program startup parameters in python
1,735,202
<p>I'm just beginning to learn python and the program I'm writing requires parameters for it to run with a specific task. For example (programs name is Samtho)</p> <pre><code>samtho -i Mozilla_Firefox </code></pre> <p>How can I do that?</p>
0
2009-11-14T18:55:45Z
1,735,211
<p>Use <code>sys.argv</code> to grab input arguments directly (<code>import sys</code> first). There are a bunch of different libraries (<code>optparse</code> and <code>getopt</code> builtin modules are popular) to help parse the arguments but doing raw matching might be easier depending on what complexity you need.</...
2
2009-11-14T18:59:29Z
[ "python", "parameters", "startup", "pydev" ]
How to create program startup parameters in python
1,735,202
<p>I'm just beginning to learn python and the program I'm writing requires parameters for it to run with a specific task. For example (programs name is Samtho)</p> <pre><code>samtho -i Mozilla_Firefox </code></pre> <p>How can I do that?</p>
0
2009-11-14T18:55:45Z
1,735,257
<p>if you don't mind venturing from the standard library, <a href="http://code.google.com/p/argparse/" rel="nofollow">argparse</a> is generally considered best-in-breed for parameter parsing.</p>
1
2009-11-14T19:12:20Z
[ "python", "parameters", "startup", "pydev" ]
How to create program startup parameters in python
1,735,202
<p>I'm just beginning to learn python and the program I'm writing requires parameters for it to run with a specific task. For example (programs name is Samtho)</p> <pre><code>samtho -i Mozilla_Firefox </code></pre> <p>How can I do that?</p>
0
2009-11-14T18:55:45Z
1,735,482
<p>I find <a href="http://github.com/simonw/optfunc" rel="nofollow">optfunc</a> the easiest library to use.</p> <pre><code>import optfunc, sys def samtho(i=''): "Usage: %prog -i &lt;option&gt;" print i if __name__ == '__main__': optfunc.run(samtho) </code></pre>
0
2009-11-14T20:25:11Z
[ "python", "parameters", "startup", "pydev" ]
Set Django model field with a method
1,735,240
<p>I'm trying to set <code>title_for_url</code> but it shows up in my database as "<code>&lt;property object at 0x027427E0&gt;</code>". What am I doing wrong?</p> <pre><code>from django.db import models class Entry(models.Model): def _get_title_for_url(self): title = "%s" % self.get_title_in_url_format()...
0
2009-11-14T19:08:42Z
1,735,264
<p>You can't use <code>property()</code> in a default:</p> <pre><code>.., default=property(_get_title_for_url)) </code></pre> <p>The default value should be a constant. If you need to compute a missing value, use a pre_save hook.</p>
0
2009-11-14T19:13:52Z
[ "python", "django" ]
Set Django model field with a method
1,735,240
<p>I'm trying to set <code>title_for_url</code> but it shows up in my database as "<code>&lt;property object at 0x027427E0&gt;</code>". What am I doing wrong?</p> <pre><code>from django.db import models class Entry(models.Model): def _get_title_for_url(self): title = "%s" % self.get_title_in_url_format()...
0
2009-11-14T19:08:42Z
1,735,681
<pre><code>title_for_url = models.CharField(max_length=100, editable=False, default=property(_get_title_for_url) </code></pre> <p>You couldn't do that way.. 'default' should be a value or a calable(with no args)... (property <strong>is not</strong> calable)</p> <p>In your case you need to update a save method:</p> <...
3
2009-11-14T21:30:04Z
[ "python", "django" ]
Set Django model field with a method
1,735,240
<p>I'm trying to set <code>title_for_url</code> but it shows up in my database as "<code>&lt;property object at 0x027427E0&gt;</code>". What am I doing wrong?</p> <pre><code>from django.db import models class Entry(models.Model): def _get_title_for_url(self): title = "%s" % self.get_title_in_url_format()...
0
2009-11-14T19:08:42Z
1,737,704
<p>This is the final version of what worked for me:</p> <pre><code>def save(self, *args, **kwargs): self.title = self.title.strip() self.title_for_url = self.get_title_in_url_format() super(Entry, self).save(*args, **kwargs) </code></pre>
0
2009-11-15T14:48:28Z
[ "python", "django" ]
Help with Python UnboundLocalError: local variable referenced before assignment
1,735,263
<p>I have post the similar question before,however,I think I may have misinterpreted my question,so may I just post my origin code here,and looking for someone can help me,I am really stuck now..thanks alot.</p> <pre><code>from numpy import * import math as M #initial condition All in SI unit G=6.673*10**-11 #Grav...
2
2009-11-14T19:13:42Z
1,735,311
<p>where do you call force in this code?</p> <p>In any event, the problem is in update_r. You reference vs in the first line of update_r even though vs is not defined in this function. Python is not looking at the vs defined above. Try adding</p> <pre><code>global vs </code></pre> <p>as the first line of update_r...
9
2009-11-14T19:25:10Z
[ "python", "numpy" ]
Help with Python UnboundLocalError: local variable referenced before assignment
1,735,263
<p>I have post the similar question before,however,I think I may have misinterpreted my question,so may I just post my origin code here,and looking for someone can help me,I am really stuck now..thanks alot.</p> <pre><code>from numpy import * import math as M #initial condition All in SI unit G=6.673*10**-11 #Grav...
2
2009-11-14T19:13:42Z
1,735,312
<p>In the first line of <code>update_r</code>, you have <code>vs,ve=update_v(n,vs,ve,ms,me,dt,fs,fe)</code>. Look at the function that you are calling. You are calling <code>update_v</code> with a bunch of parameters. One of these parameters is <code>vs</code>. However, that is the first time in that function that <cod...
5
2009-11-14T19:25:56Z
[ "python", "numpy" ]
Help with Python UnboundLocalError: local variable referenced before assignment
1,735,263
<p>I have post the similar question before,however,I think I may have misinterpreted my question,so may I just post my origin code here,and looking for someone can help me,I am really stuck now..thanks alot.</p> <pre><code>from numpy import * import math as M #initial condition All in SI unit G=6.673*10**-11 #Grav...
2
2009-11-14T19:13:42Z
1,735,367
<p>On line 39 you do</p> <pre><code>vs,ve=update_v(n,vs,ve,ms,me,dt,fs,fe) </code></pre> <p>while you are inside a function. Since you defined a <strong>global</strong> variable called <em>vs</em>, you would expect this to work. It would have worked if you had:</p> <pre><code>vs_new,ve_new = update_v(n,vs,ve,ms,me,...
0
2009-11-14T19:41:22Z
[ "python", "numpy" ]
Help with Python UnboundLocalError: local variable referenced before assignment
1,735,263
<p>I have post the similar question before,however,I think I may have misinterpreted my question,so may I just post my origin code here,and looking for someone can help me,I am really stuck now..thanks alot.</p> <pre><code>from numpy import * import math as M #initial condition All in SI unit G=6.673*10**-11 #Grav...
2
2009-11-14T19:13:42Z
15,329,200
<p>Put an additional <code>global</code> statement containing all your globals after each <code>def</code> statement. Otherwise, all globals are transformed into locals within your def without it.</p> <pre><code>def update_v(n,vs,ve,ms,me,dt,fs,fe): global vs, ve, ... </code></pre>
1
2013-03-10T23:53:48Z
[ "python", "numpy" ]
How do I use the quartz scheduler with Python?
1,735,266
<p>Is there a guide or tutorial on how to use the quartz Scheduler with Python.</p> <p>Is there an existing API for Python?</p>
0
2009-11-14T19:14:15Z
1,735,336
<p>Given that Quartz is a Java application/library, the simplest thing to do may be to run it within <a href="http://jython.org" rel="nofollow">Jython</a>.</p> <p>Failing that, and if you simply want to control the configuration of jobs from Python, perhaps the <a href="http://www.opensymphony.com/quartz/wikidocs/Conf...
0
2009-11-14T19:32:33Z
[ "python", "quartz-scheduler" ]