title
stringlengths
10
172
question_id
int64
469
40.1M
question_body
stringlengths
22
48.2k
question_score
int64
-44
5.52k
question_date
stringlengths
20
20
answer_id
int64
497
40.1M
answer_body
stringlengths
18
33.9k
answer_score
int64
-38
8.38k
answer_date
stringlengths
20
20
tags
listlengths
1
5
Is there a string-collapse library function in python?
1,249,786
<p>Is there a cross-platform library function that would collapse a multiline string into a single-line string with no repeating spaces?</p> <p>I've come up with some snip below, but I wonder if there is a standard function which I could just import which is perhaps even optimized in C?</p> <pre><code>def collapse(in...
4
2009-08-08T20:18:54Z
1,249,850
<p>The built-in <code>string.split()</code> method will split on runs of whitespace, so you can use that and then join the resulting list using spaces, like this:</p> <pre><code>' '.join(my_string.split()) </code></pre> <p>Here's a complete test script:</p> <pre><code>TEST = """This is a test\twith a mix of...
12
2009-08-08T20:43:34Z
[ "python", "string", "line-breaks" ]
Is there a string-collapse library function in python?
1,249,786
<p>Is there a cross-platform library function that would collapse a multiline string into a single-line string with no repeating spaces?</p> <p>I've come up with some snip below, but I wonder if there is a standard function which I could just import which is perhaps even optimized in C?</p> <pre><code>def collapse(in...
4
2009-08-08T20:18:54Z
1,249,870
<p>You had the right idea, you just needed to read the python manual a little more closely:</p> <pre><code>import re somewhitespace = re.compile(r'\s+') TEST = """This is a test\twith a mix of\ttabs, newlines and repeating whitespace""" somewhitespace.sub(' ', TEST) 'This is a test with a mix of tabs, n...
4
2009-08-08T20:52:26Z
[ "python", "string", "line-breaks" ]
Convert Python exception information to string for logging
1,249,795
<p>I try logging exceptions in Python 2.5, but I can't do it. All formatting functions do something else than what I want.</p> <p>I came up with this:</p> <pre><code>def logexception(type, value, traceback): print traceback.format_exception(type, value, traceback) sys.excepthook = logexception </code></pre> <p>bu...
5
2009-08-08T20:23:17Z
1,249,812
<p>you can use <a href="http://code.activestate.com/recipes/466332/" rel="nofollow">this very simpe logging solution</a></p> <p>or <a href="http://onlamp.com/pub/a/python/2005/06/02/logging.html?page=last" rel="nofollow">this one</a> </p>
-1
2009-08-08T20:27:54Z
[ "python", "exception" ]
Convert Python exception information to string for logging
1,249,795
<p>I try logging exceptions in Python 2.5, but I can't do it. All formatting functions do something else than what I want.</p> <p>I came up with this:</p> <pre><code>def logexception(type, value, traceback): print traceback.format_exception(type, value, traceback) sys.excepthook = logexception </code></pre> <p>bu...
5
2009-08-08T20:23:17Z
1,249,821
<p>Why should that <code>traceback</code> argument have a <code>format_exception</code> method just like the function in the traceback module whose name it's usurping, and if it had one why would that method require the same object on which it's called to be passed in as the last argument as well?</p> <p>I suspect you...
5
2009-08-08T20:31:00Z
[ "python", "exception" ]
If a python module says its dependent on debhelper and cdbs is there no way to get it to run on a nondebian linux?
1,249,873
<p>I want to try python purple but I don't have debian. Is there a way to get it to run on either windows or a different linux?</p>
-1
2009-08-08T20:53:35Z
1,249,896
<p>I suppose compiling from source (if availiable) or looking for dbhelper and cbds install files for your distribution</p>
0
2009-08-08T21:04:23Z
[ "python", "linux", "debian", "cdbs" ]
Alter namespace prefixing with ElementTree in Python
1,249,876
<p>By default, when you call ElementTree.parse(someXMLfile) the Python ElementTree library prefixes every parsed node with it's namespace URI in Clark's Notation:</p> <pre> {http://example.org/namespace/spec}mynode </pre> <p>This makes accessing specific nodes by name a huge pain later in the code.</p> <p>I've r...
18
2009-08-08T20:56:03Z
1,255,792
<p>You don't specifically need to use <code>iterparse</code>. Instead, the following script:</p> <pre><code>from cStringIO import StringIO import xml.etree.ElementTree as ET NS_MAP = { 'http://www.red-dove.com/ns/abc' : 'rdc', 'http://www.adobe.com/2006/mxml' : 'mx', 'http://www.red-dove.com/ns/def' : 'ot...
5
2009-08-10T16:12:30Z
[ "python", "xml", "namespaces", "elementtree" ]
Alter namespace prefixing with ElementTree in Python
1,249,876
<p>By default, when you call ElementTree.parse(someXMLfile) the Python ElementTree library prefixes every parsed node with it's namespace URI in Clark's Notation:</p> <pre> {http://example.org/namespace/spec}mynode </pre> <p>This makes accessing specific nodes by name a huge pain later in the code.</p> <p>I've r...
18
2009-08-08T20:56:03Z
1,904,289
<p>xml.etree.ElementTree doesn't appear to have fixtag, well, not according to the documentation. However I've looked at some source code for fixtag and you do:</p> <pre><code>import xml.etree.ElementTree as ET for event, elem in ET.iterparse(inFile, events=("start", "end")): namespace, looktag = string.split(ele...
2
2009-12-14T23:31:43Z
[ "python", "xml", "namespaces", "elementtree" ]
Getting Data into LLNL VisIt via Python
1,250,063
<p>Without using VisIt's python library visit-writer.py, how can I import my data into VisIt? I'm aware of many <a href="https://wci.llnl.gov/codes/visit/FAQ.html#12" rel="nofollow">alternative file formats</a> but I can't find a simple library that takes my arrays of data and just writes it as a file. Specifically, my...
1
2009-08-08T22:40:55Z
1,250,137
<p>From skimming the VisIt manual on "<a href="https://wci.llnl.gov/codes/visit/1.5.4/GettingDataIntoVisIt1.5.4.pdf" rel="nofollow">Getting Data Into VisIt</a>", it seems like there are three basic ways to create VisIt-compatible data files:</p> <ol> <li>For scalar data on a uniform grid, it is probably easiest to for...
2
2009-08-08T23:28:37Z
[ "python", "visualization" ]
Getting Data into LLNL VisIt via Python
1,250,063
<p>Without using VisIt's python library visit-writer.py, how can I import my data into VisIt? I'm aware of many <a href="https://wci.llnl.gov/codes/visit/FAQ.html#12" rel="nofollow">alternative file formats</a> but I can't find a simple library that takes my arrays of data and just writes it as a file. Specifically, my...
1
2009-08-08T22:40:55Z
15,512,281
<p>There's also a package called <a href="http://documen.tician.de/pyvisfile/" rel="nofollow">pyvisfile</a> that is made to do this. I haven't tried it but it claims to work. </p>
1
2013-03-19T23:12:24Z
[ "python", "visualization" ]
Manipulate MP3 programmatically: Muting certain parts?
1,250,086
<p>I'm trying to write a batch process that can take an MP3 file and mute certain parts of it, ideally in Python or Java.</p> <p>Take this example: Given a 2 minute MP3, I want to mute the time between 1:20 and 1:30. When saved back to a file, the rest of the MP3 will play normally -- only that portion will be silent....
3
2009-08-08T22:57:12Z
1,250,130
<p>SoX is a multi-platform sound editing tool and I've used it a lot in the past. More info at <a href="http://sox.sourceforge.net/" rel="nofollow">http://sox.sourceforge.net/</a></p> <p>I don't think you can mute a section of an MP3 file with a single command though. You could split the file into 3 parts, mute the mi...
1
2009-08-08T23:26:16Z
[ "java", "python", "audio", "mp3" ]
Manipulate MP3 programmatically: Muting certain parts?
1,250,086
<p>I'm trying to write a batch process that can take an MP3 file and mute certain parts of it, ideally in Python or Java.</p> <p>Take this example: Given a 2 minute MP3, I want to mute the time between 1:20 and 1:30. When saved back to a file, the rest of the MP3 will play normally -- only that portion will be silent....
3
2009-08-08T22:57:12Z
1,250,132
<p><a href="http://audacity.sourceforge.net/" rel="nofollow">Audacity</a> (available for Windows, Mac, Linux) <a href="http://wiki.audacityteam.org/index.php?title=Scripting" rel="nofollow">has a plugin</a> (currently for Windows only) that allows it to be scripted. The target language is Perl, but perhaps Python would...
0
2009-08-08T23:26:51Z
[ "java", "python", "audio", "mp3" ]
Manipulate MP3 programmatically: Muting certain parts?
1,250,086
<p>I'm trying to write a batch process that can take an MP3 file and mute certain parts of it, ideally in Python or Java.</p> <p>Take this example: Given a 2 minute MP3, I want to mute the time between 1:20 and 1:30. When saved back to a file, the rest of the MP3 will play normally -- only that portion will be silent....
3
2009-08-08T22:57:12Z
1,685,790
<p>Or use <a href="http://www.xuggle.com/xuggler" rel="nofollow">Xuggler</a> to decode the MP3 file, mute out the audio you care about, and then re-encode.</p>
0
2009-11-06T06:26:16Z
[ "java", "python", "audio", "mp3" ]
Manipulate MP3 programmatically: Muting certain parts?
1,250,086
<p>I'm trying to write a batch process that can take an MP3 file and mute certain parts of it, ideally in Python or Java.</p> <p>Take this example: Given a 2 minute MP3, I want to mute the time between 1:20 and 1:30. When saved back to a file, the rest of the MP3 will play normally -- only that portion will be silent....
3
2009-08-08T22:57:12Z
5,060,666
<p>One (somehow pretentious) idea: record a mute (silent) mp3 in bitrate that your mp3 is. Then, copy all the frames from original mp3 up to the point when you want your silence to start. Then, copy as much muted frames you need from your 'silence file'. Then, copy the rest from the original file.</p> <p>You'll ha...
1
2011-02-20T22:53:42Z
[ "java", "python", "audio", "mp3" ]
AttributeError: 'module' object has no attribute
1,250,103
<p>I have two python modules:</p> <p>a.py</p> <pre><code>import b def hello(): print "hello" print "a.py" print hello() print b.hi() </code></pre> <p>b.py</p> <pre><code>import a def hi(): print "hi" </code></pre> <p>When I run <code>a.py</code>, I get:</p> <pre><code>AttributeError: 'module' object has no...
75
2009-08-08T23:12:20Z
1,250,119
<p>The problem is the circular dependency between the modules. <code>a</code> imports <code>b</code> and <code>b</code> imports <code>a</code>. But one of them needs to be loaded first - in this case python ends up initializing module <code>a</code> before <code>b</code> and <code>b.hi()</code> doesn't exist yet when y...
20
2009-08-08T23:19:41Z
[ "python", "attributeerror" ]
AttributeError: 'module' object has no attribute
1,250,103
<p>I have two python modules:</p> <p>a.py</p> <pre><code>import b def hello(): print "hello" print "a.py" print hello() print b.hi() </code></pre> <p>b.py</p> <pre><code>import a def hi(): print "hi" </code></pre> <p>When I run <code>a.py</code>, I get:</p> <pre><code>AttributeError: 'module' object has no...
75
2009-08-08T23:12:20Z
1,250,135
<p>You have mutual top-level imports, which is almost always a bad idea.</p> <p>If you really must have mutual imports in Python, the way to do it is to import them within a function:</p> <pre><code># In b.py: def cause_a_to_do_something(): import a a.do_something() </code></pre> <p>Now a.py can safely do <c...
83
2009-08-08T23:27:29Z
[ "python", "attributeerror" ]
AttributeError: 'module' object has no attribute
1,250,103
<p>I have two python modules:</p> <p>a.py</p> <pre><code>import b def hello(): print "hello" print "a.py" print hello() print b.hi() </code></pre> <p>b.py</p> <pre><code>import a def hi(): print "hi" </code></pre> <p>When I run <code>a.py</code>, I get:</p> <pre><code>AttributeError: 'module' object has no...
75
2009-08-08T23:12:20Z
3,124,164
<p>I have also seen this error when inadvertently naming a module with the same name as one of the standard Python modules. E.g. I had a module called <code>commands</code> which is also a Python library module. This proved to be difficult to track down as it worked correctly on my local development environment but f...
39
2010-06-26T14:18:21Z
[ "python", "attributeerror" ]
AttributeError: 'module' object has no attribute
1,250,103
<p>I have two python modules:</p> <p>a.py</p> <pre><code>import b def hello(): print "hello" print "a.py" print hello() print b.hi() </code></pre> <p>b.py</p> <pre><code>import a def hi(): print "hi" </code></pre> <p>When I run <code>a.py</code>, I get:</p> <pre><code>AttributeError: 'module' object has no...
75
2009-08-08T23:12:20Z
29,687,721
<p>I got this error by referencing an enum which was imported in a wrong way, e.g.:</p> <pre><code>from package import MyEnumClass # ... # in some method: return MyEnumClass.Member </code></pre> <p>Correct import:</p> <pre><code>from package.MyEnumClass import MyEnumClass </code></pre> <p>Hope that helps someone</p...
8
2015-04-16T23:32:08Z
[ "python", "attributeerror" ]
AttributeError: 'module' object has no attribute
1,250,103
<p>I have two python modules:</p> <p>a.py</p> <pre><code>import b def hello(): print "hello" print "a.py" print hello() print b.hi() </code></pre> <p>b.py</p> <pre><code>import a def hi(): print "hi" </code></pre> <p>When I run <code>a.py</code>, I get:</p> <pre><code>AttributeError: 'module' object has no...
75
2009-08-08T23:12:20Z
38,021,582
<p>I experienced this error because the module was not actually imported. The code looked like this:</p> <pre><code>import a.b, a.c # ... something(a.b) something(a.c) something(a.d) # My addition, which failed. </code></pre> <p>The last line resulted in an <code>AttributeError</code>. The cause was that I had fai...
0
2016-06-24T20:26:45Z
[ "python", "attributeerror" ]
parsing XML file in python with cElementTree: dealing with errors and line number in the file
1,250,192
<p>I am using the <code>cElementTree</code> library to parse XML files in Python. Everything is working fine</p> <p>But I would like to provide full error messages for the user when a value in the XML is not correct.</p> <p>For example, let's suppose I have the following XML:</p> <pre><code>&lt;A name="xxxx" href="y...
2
2009-08-08T23:58:13Z
1,250,347
<p>The equivalent library that you should be using is <a href="http://lxml.de/" rel="nofollow">lxml</a>. lxml is a wrapper on very fast c libraries libxml2 and libxslt and is generally considered superior to the built in ones.</p> <p>It, luckly, tries to keep to the element tree api and extend it in lxml.etree.</p> <...
4
2009-08-09T01:33:30Z
[ "python", "error-handling", "line-numbers", "celementtree" ]
What is the importance of an IDE when programming in Python?
1,250,295
<p>I'm a beginning Python programmer, just getting my feet wet in the language and its tools and native practices. In the past, I've used languages that were tightly integrated into IDEs, and indeed I had never before considered that it was even <em>possible</em> to program outside of such a tool.</p> <p>However, much...
5
2009-08-09T01:02:37Z
1,250,317
<p>The IDE you use is a personal and subjective thing, but it definitely matters. Personally, for writing short scripts or working with python interactively, I use PyDee available at <a href="http://pydee.googlecode.com/" rel="nofollow">http://pydee.googlecode.com/</a> . It is well done, fairly lightweight, but with ...
1
2009-08-09T01:14:31Z
[ "python", "ide" ]
What is the importance of an IDE when programming in Python?
1,250,295
<p>I'm a beginning Python programmer, just getting my feet wet in the language and its tools and native practices. In the past, I've used languages that were tightly integrated into IDEs, and indeed I had never before considered that it was even <em>possible</em> to program outside of such a tool.</p> <p>However, much...
5
2009-08-09T01:02:37Z
1,250,364
<ol> <li>How important is an IDE to normal Python development?</li> </ol> <p>Not very, IMHO. It's a lightweight language with much less boilerplate and simpler idioms than in some other languages, so there's less need for an IDE for that part. </p> <p>The standard interactive interpreter provides help and introspecti...
3
2009-08-09T01:44:01Z
[ "python", "ide" ]
What is the importance of an IDE when programming in Python?
1,250,295
<p>I'm a beginning Python programmer, just getting my feet wet in the language and its tools and native practices. In the past, I've used languages that were tightly integrated into IDEs, and indeed I had never before considered that it was even <em>possible</em> to program outside of such a tool.</p> <p>However, much...
5
2009-08-09T01:02:37Z
1,250,375
<p>IDEs arent <em>very</em> useful in Python; powerful editors such as Emacs and Vim seem very popular among Python programmers. This may confuse e.g. Java programmers, because in Java each file generally requires boilerplate code, such as a <code>package</code> statement, getters and setters. Python is much more light...
9
2009-08-09T01:50:58Z
[ "python", "ide" ]
What is the importance of an IDE when programming in Python?
1,250,295
<p>I'm a beginning Python programmer, just getting my feet wet in the language and its tools and native practices. In the past, I've used languages that were tightly integrated into IDEs, and indeed I had never before considered that it was even <em>possible</em> to program outside of such a tool.</p> <p>However, much...
5
2009-08-09T01:02:37Z
1,250,429
<p>A matter of habit and personal preferences. Me, I use vim (I have to admit emacs is at least as powerful, but my fingers are deeply trained by over 30 years of vi, and any other editor gives me the jitters, <em>especially</em> when it tries to imitate vi and never really manages to get it 100% right;-), occasionally...
4
2009-08-09T02:40:03Z
[ "python", "ide" ]
What is the importance of an IDE when programming in Python?
1,250,295
<p>I'm a beginning Python programmer, just getting my feet wet in the language and its tools and native practices. In the past, I've used languages that were tightly integrated into IDEs, and indeed I had never before considered that it was even <em>possible</em> to program outside of such a tool.</p> <p>However, much...
5
2009-08-09T01:02:37Z
1,252,287
<p>(1) IDEs are less important than for other languages, but if you find one that is useful, it still makes things easier. Without IDEs -- what are doing? Always running Python from command line?</p> <p>(2-3) On my Mac there's included IDLE which I keep always open for its Python shell (it's colored unlike the one in ...
0
2009-08-09T21:05:18Z
[ "python", "ide" ]
What is the importance of an IDE when programming in Python?
1,250,295
<p>I'm a beginning Python programmer, just getting my feet wet in the language and its tools and native practices. In the past, I've used languages that were tightly integrated into IDEs, and indeed I had never before considered that it was even <em>possible</em> to program outside of such a tool.</p> <p>However, much...
5
2009-08-09T01:02:37Z
1,273,578
<p>In contrast to the other answers i think that IDE's are very important especially for script languages. Almost all code is bad documentated and an IDE with a good debugger gives you much insides about what is really going on what datatypes are assigned to this values. Is this a hash of lists of hashes or a list of h...
1
2009-08-13T17:53:21Z
[ "python", "ide" ]
How to store regular expressions in the Google App Engine datastore?
1,250,313
<p>Regular Expressions are usually expressed as strings, but they also have properties (ie. single line, multi line, ignore case). How would you store them? And for compiled regular expressions, how to store it?</p> <p>Please note that we can write custom property classes: <a href="http://googleappengine.blogspot.com/...
1
2009-08-09T01:12:44Z
1,250,339
<p>I'm not sure if Python supprts it, but in .net regex, you can specify these options within the regex itself:</p> <pre><code>(?si)^a.*z$ </code></pre> <p>would specify single-line, ignore case.</p> <p>Indeed, the Python docs describe such a mechanism here: <a href="http://docs.python.org/library/re.html" rel="nofo...
3
2009-08-09T01:26:54Z
[ "python", "google-app-engine", "gae-datastore", "customproperty" ]
How to store regular expressions in the Google App Engine datastore?
1,250,313
<p>Regular Expressions are usually expressed as strings, but they also have properties (ie. single line, multi line, ignore case). How would you store them? And for compiled regular expressions, how to store it?</p> <p>Please note that we can write custom property classes: <a href="http://googleappengine.blogspot.com/...
1
2009-08-09T01:12:44Z
1,250,377
<p>I wouldn't try to store the compiled regex. The data in a compiled regex is not designed to be stored, and is not guaranteed to be picklable or serializable. Just store the string and re-compile (the re module will do this for you behind the scenes anyway).</p>
3
2009-08-09T01:52:14Z
[ "python", "google-app-engine", "gae-datastore", "customproperty" ]
How to store regular expressions in the Google App Engine datastore?
1,250,313
<p>Regular Expressions are usually expressed as strings, but they also have properties (ie. single line, multi line, ignore case). How would you store them? And for compiled regular expressions, how to store it?</p> <p>Please note that we can write custom property classes: <a href="http://googleappengine.blogspot.com/...
1
2009-08-09T01:12:44Z
1,251,370
<p>You can either store the text, as suggested above, or you can pickle and unpickle the compiled RE. For example, see <a href="http://appengine-cookbook.appspot.com/recipe/pickledproperty/" rel="nofollow">PickledProperty</a> on the cookbook.</p> <p>Due to the (lack of) speed of Pickle, particularly on App Engine wher...
2
2009-08-09T13:26:06Z
[ "python", "google-app-engine", "gae-datastore", "customproperty" ]
How to pickle numpy's Inf objects?
1,250,367
<p>When trying to pickle the object Inf as defined in numpy (I think), the dumping goes Ok but the loading fails:</p> <pre><code>&gt;&gt;&gt; cPickle.dump(Inf, file("c:/temp/a.pcl",'wb')) &gt;&gt;&gt; cPickle.load(file("c:/temp/a.pcl",'rb')) Traceback (most recent call last): File "&lt;pyshell#257&gt;", line 1, in &...
2
2009-08-09T01:45:21Z
1,250,392
<p>If you specify a pickle protocol more than zero, it will work. Protocol is often specified as -1, meaning use the latest and greatest protocol:</p> <pre><code>&gt;&gt;&gt; cPickle.dump(Inf, file("c:/temp/a.pcl",'wb'), -1) &gt;&gt;&gt; cPickle.load(file("c:/temp/a.pcl",'rb')) 1.#INF -- may be plat...
5
2009-08-09T02:12:38Z
[ "python", "numpy", "pickle" ]
How to pickle numpy's Inf objects?
1,250,367
<p>When trying to pickle the object Inf as defined in numpy (I think), the dumping goes Ok but the loading fails:</p> <pre><code>&gt;&gt;&gt; cPickle.dump(Inf, file("c:/temp/a.pcl",'wb')) &gt;&gt;&gt; cPickle.load(file("c:/temp/a.pcl",'rb')) Traceback (most recent call last): File "&lt;pyshell#257&gt;", line 1, in &...
2
2009-08-09T01:45:21Z
1,416,922
<p>Try this solution at SourceForge which will work for any arbitrary Python object:</p> <p>y_serial.py module :: warehouse Python objects with SQLite</p> <p>"Serialization + persistance :: in a few lines of code, compress and annotate Python objects into SQLite; then later retrieve them chronologically by keywords w...
0
2009-09-13T05:23:41Z
[ "python", "numpy", "pickle" ]
How to find the url using the referer and the href in Python?
1,250,371
<p>Suppose I have</p> <pre><code>window_location = 'http://stackoverflow.com/questions/ask' href = '/users/48465/jader-dias' </code></pre> <p>I want to obtain</p> <pre><code>link = 'http://stackoverflow.com/users/48465/jader-dias' </code></pre> <p>How do I do it in Python?</p> <p>It have to work just as it works i...
1
2009-08-09T01:47:29Z
1,250,374
<pre><code>&gt;&gt;&gt; import urlparse &gt;&gt;&gt; urlparse.urljoin('http://stackoverflow.com/questions/ask', ... '/users/48465/jader-dias') 'http://stackoverflow.com/users/48465/jader-dias' </code></pre> <p>From the doc page of <a href="http://docs.python.org/library/urlparse.html#urlparse.urljoin"...
6
2009-08-09T01:50:42Z
[ "python", "regex", "string", "url", "href" ]
Creating alternative login to Google Users for Google app engine
1,250,437
<p>How does one handle logging in and out/creating users, without using Google Users? I'd like a few more options then just email and password. Is it just a case of making a user model with the fields I need? Is that secure enough?</p> <p>Alternatively, is there a way to get the user to log in using the Google ID, but...
4
2009-08-09T02:46:19Z
1,250,451
<p>I recommend using OpenID, see <a href="http://googlecode.blogspot.com/2009/07/google-apps-openid-identity-hub-for.html" rel="nofollow">here</a> for more -- just like Stack Overflow does!-)</p>
8
2009-08-09T02:53:37Z
[ "python", "google-app-engine", "model-view-controller", "gae-datastore" ]
Creating alternative login to Google Users for Google app engine
1,250,437
<p>How does one handle logging in and out/creating users, without using Google Users? I'd like a few more options then just email and password. Is it just a case of making a user model with the fields I need? Is that secure enough?</p> <p>Alternatively, is there a way to get the user to log in using the Google ID, but...
4
2009-08-09T02:46:19Z
1,251,369
<p>If you roll your own user model, you're going to need to do your own session handling as well; the App Engine Users API creates login sessions for you behind the scenes. </p> <p>Also, while this should be obvious, you shouldn't store the user's password in plaintext; store an SHA-1 hash and compare it to a hash of...
1
2009-08-09T13:25:27Z
[ "python", "google-app-engine", "model-view-controller", "gae-datastore" ]
How do you enable auto-scrolling on GtkSourceView2?
1,250,566
<p>I am having a problem with GtkSourceView used from Python.</p> <p>Two major problems: 1) When a user types text into the GtkSourceView, and types past the bottom of the visible text, the GtkSourceView does not autoscroll to the users cursor. This wouldnt be so bad, except: 2) The arrow keys, page up and page down k...
0
2009-08-09T04:02:11Z
1,301,796
<p>Ok I just figured this out.</p> <p>I was adding the GtkSourceView2 into a GtkScrolledWindow. Only, it was adding a ViewPort first via ScrolledWindow.add_with_viewport(). This disables part of the scrolling behavior via keyboard. Instead, use ScrolledWindow.add(), and the ViewPort is skipped and the GtkAdjustments t...
0
2009-08-19T18:29:32Z
[ "python", "gtk" ]
Decompressing a .bz2 file in Python
1,250,688
<p>So, this is a seemingly simple question, but I'm apparently very very dull. I have a little script that downloads all the .bz2 files from a webpage, but for some reason the decompressing of that file is giving me a MAJOR headache.</p> <p>I'm quite a Python newbie, so the answer is probably quite obvious, please hel...
4
2009-08-09T05:01:42Z
1,250,700
<p>You're opening and reading the compressed file as if it was a textfile made up of lines. DON'T! It's NOT.</p> <pre><code>uncompressedData = bz2.BZ2File(zipFile).read() </code></pre> <p>seems to be closer to what you're angling for.</p> <p><strong>Edit</strong>: the OP has shown a few more things he's tried (tho...
14
2009-08-09T05:06:29Z
[ "python", "decompression", "decompress" ]
Decompressing a .bz2 file in Python
1,250,688
<p>So, this is a seemingly simple question, but I'm apparently very very dull. I have a little script that downloads all the .bz2 files from a webpage, but for some reason the decompressing of that file is giving me a MAJOR headache.</p> <p>I'm quite a Python newbie, so the answer is probably quite obvious, please hel...
4
2009-08-09T05:01:42Z
1,250,948
<blockquote> <p>openZip = open(zipFile, "r")</p> </blockquote> <p>If you're running on Windows, you may want to do say <strong>openZip = open(zipFile, "rb")</strong> here since the file is likely to contain CR/LF combinations, and you don't want them to be translated.</p> <blockquote> <p>newLine = openZip.readlin...
8
2009-08-09T08:23:04Z
[ "python", "decompression", "decompress" ]
Decompressing a .bz2 file in Python
1,250,688
<p>So, this is a seemingly simple question, but I'm apparently very very dull. I have a little script that downloads all the .bz2 files from a webpage, but for some reason the decompressing of that file is giving me a MAJOR headache.</p> <p>I'm quite a Python newbie, so the answer is probably quite obvious, please hel...
4
2009-08-09T05:01:42Z
3,637,469
<p>This was very helpful. 44 of 2300 files gave an end of file missing error, on Windows open. Adding the b(inary) flag to open fixed the problem.</p> <pre><code>for line in bz2.BZ2File(filename, 'rb', 10000000) : </code></pre> <p>works well. (the 10M is the buffering size that works well with the large files involve...
5
2010-09-03T15:55:57Z
[ "python", "decompression", "decompress" ]
Network Support for Pygame
1,250,739
<p>I am making a simple multiplayer economic game in pygame. It consists of turns of a certain length, at the end of which, data is sent to the central server. A few quick calculations are done on the data and the results are sent back to the players. My question is how I should implement the network support. I was loo...
3
2009-08-09T05:31:05Z
1,251,235
<p>Twisted would certainly be a good idea. <a href="https://launchpad.net/game">Here</a> is example code that integrates twisted and pygame.</p>
5
2009-08-09T11:49:52Z
[ "python", "twisted", "pygame", "pyro" ]
Network Support for Pygame
1,250,739
<p>I am making a simple multiplayer economic game in pygame. It consists of turns of a certain length, at the end of which, data is sent to the central server. A few quick calculations are done on the data and the results are sent back to the players. My question is how I should implement the network support. I was loo...
3
2009-08-09T05:31:05Z
1,255,178
<p>I've nothing against Twisted and PyRo, but the sort of simple messages you're going to be sending don't require anything like that and might be overcomplicated by using some sort of framework. Pickling an object and sending it over a socket is actually a very easy operation and well worth trying, even if you do even...
1
2009-08-10T14:23:19Z
[ "python", "twisted", "pygame", "pyro" ]
Network Support for Pygame
1,250,739
<p>I am making a simple multiplayer economic game in pygame. It consists of turns of a certain length, at the end of which, data is sent to the central server. A few quick calculations are done on the data and the results are sent back to the players. My question is how I should implement the network support. I was loo...
3
2009-08-09T05:31:05Z
9,494,305
<p>There are a number of plug-and-play libraries tailored specifically to work nicely with PyGame on the <a href="http://pygame.org" rel="nofollow">pygame.org</a> website.</p> <p>These include PodSixNet, PygLibs.net, and my own Mastermind (which is, at the risk of self-aggrandizement, lightweight, easy to use, and com...
0
2012-02-29T06:05:49Z
[ "python", "twisted", "pygame", "pyro" ]
Python Class vs. Module Attributes
1,250,779
<p>I'm interested in hearing some discussion about class attributes in Python. For example, what is a good use case for class attributes? For the most part, I can not come up with a case where a class attribute is preferable to using a module level attribute. If this is true, then why have them around?</p> <p>The prob...
12
2009-08-09T06:04:50Z
1,250,801
<p>Class attributes are often used to allow overriding defaults in subclasses. For example, BaseHTTPRequestHandler has class constants sys_version and server_version, the latter defaulting to <code>"BaseHTTP/" + __version__</code>. SimpleHTTPRequestHandler overrides server_version to <code>"SimpleHTTP/" + __version__</...
2
2009-08-09T06:25:04Z
[ "python", "attributes", "class-design", "module" ]
Python Class vs. Module Attributes
1,250,779
<p>I'm interested in hearing some discussion about class attributes in Python. For example, what is a good use case for class attributes? For the most part, I can not come up with a case where a class attribute is preferable to using a module level attribute. If this is true, then why have them around?</p> <p>The prob...
12
2009-08-09T06:04:50Z
1,251,052
<p>Encapsulation is a good principle: when an attribute is inside the class it pertains to instead of being in the global scope, this gives additional information to people reading the code.</p> <p>In your situations 1-4, I would thus avoid globals as much as I can, and prefer using class attributes, which allow one t...
1
2009-08-09T09:51:08Z
[ "python", "attributes", "class-design", "module" ]
Python Class vs. Module Attributes
1,250,779
<p>I'm interested in hearing some discussion about class attributes in Python. For example, what is a good use case for class attributes? For the most part, I can not come up with a case where a class attribute is preferable to using a module level attribute. If this is true, then why have them around?</p> <p>The prob...
12
2009-08-09T06:04:50Z
1,251,929
<p>#4: I <em>never</em> use class attributes to initialize default instance attributes (the ones you normally put in <code>__init__</code>). For example:</p> <pre><code>class Obj(object): def __init__(self): self.users = 0 </code></pre> <p>and never:</p> <pre><code>class Obj(object): users = 0 </co...
7
2009-08-09T18:29:25Z
[ "python", "attributes", "class-design", "module" ]
Python Class vs. Module Attributes
1,250,779
<p>I'm interested in hearing some discussion about class attributes in Python. For example, what is a good use case for class attributes? For the most part, I can not come up with a case where a class attribute is preferable to using a module level attribute. If this is true, then why have them around?</p> <p>The prob...
12
2009-08-09T06:04:50Z
1,252,241
<blockquote> <p>what is a good use case for class attributes</p> </blockquote> <p><strong>Case 0.</strong> Class methods are just class attributes. This is not just a technical similarity - you can access and modify class methods at runtime by assigning callables to them.</p> <p><strong>Case 1.</strong> A module ca...
3
2009-08-09T20:44:43Z
[ "python", "attributes", "class-design", "module" ]
python urllib, how to watch messages?
1,250,965
<p>How can I watch the messages being sent back and for on urllib shttp requests? If it were simple http I would just watch the socket traffic but of course that won't work for https. Is there a debug flag I can set that will do this?</p> <pre><code>import urllib params = urllib.urlencode({'spam': 1, 'eggs': 2, 'bac...
2
2009-08-09T08:42:45Z
1,251,248
<p>No, there's no debug flag to watch this.</p> <p>You can use your favorite debugger. It is the easiest option. Just add a breakpoint in the urlopen function and you're done.</p> <p>Another option would be to write your own download function:</p> <pre><code>def graburl(url, **params): print "LOG: Going to %s wi...
1
2009-08-09T11:55:40Z
[ "python", "https", "urllib" ]
python urllib, how to watch messages?
1,250,965
<p>How can I watch the messages being sent back and for on urllib shttp requests? If it were simple http I would just watch the socket traffic but of course that won't work for https. Is there a debug flag I can set that will do this?</p> <pre><code>import urllib params = urllib.urlencode({'spam': 1, 'eggs': 2, 'bac...
2
2009-08-09T08:42:45Z
1,251,324
<p>You can always do a little bit of mokeypatching</p> <pre><code>import httplib # override the HTTPS request class class DebugHTTPS(httplib.HTTPS): real_putheader = httplib.HTTPS.putheader def putheader(self, *args, **kwargs): print 'putheader(%s,%s)' % (args, kwargs) result = self.real_puth...
2
2009-08-09T12:53:00Z
[ "python", "https", "urllib" ]
Any reason why socket.send() hangs?
1,250,979
<p>I'm writing an mini FTP server in Python that exposes an underlying database as if it was FTP. The flow is something like this:</p> <pre><code>sock.send("150 Here's the file you wanted\r\n") proc = Popen2(...) for parts in data: data_sock.send(parts) proc.kill() sock.send("226 There's the file you wanted\r\n")...
1
2009-08-09T08:57:13Z
1,250,984
<p>I've encountered similar issues on the client side on uploads, which seem to trace to the modem/router choking -- the only workround I have at the moment is to throttle the transmission rate (send 128 bytes, sleep ~50ms, repeat).</p>
0
2009-08-09T09:03:33Z
[ "python", "sockets", "ftp" ]
Any reason why socket.send() hangs?
1,250,979
<p>I'm writing an mini FTP server in Python that exposes an underlying database as if it was FTP. The flow is something like this:</p> <pre><code>sock.send("150 Here's the file you wanted\r\n") proc = Popen2(...) for parts in data: data_sock.send(parts) proc.kill() sock.send("226 There's the file you wanted\r\n")...
1
2009-08-09T08:57:13Z
1,251,551
<p>Hard to say from this code fragment and not knowing the client, but is it possible that your sending of 150 (indicating a new data channel), not 125 (indicating use of existing data channel) confuses the client and it simply does not start reading the data?</p> <p>Have you had a look of <a href="http://code.google....
1
2009-08-09T15:08:28Z
[ "python", "sockets", "ftp" ]
Any reason why socket.send() hangs?
1,250,979
<p>I'm writing an mini FTP server in Python that exposes an underlying database as if it was FTP. The flow is something like this:</p> <pre><code>sock.send("150 Here's the file you wanted\r\n") proc = Popen2(...) for parts in data: data_sock.send(parts) proc.kill() sock.send("226 There's the file you wanted\r\n")...
1
2009-08-09T08:57:13Z
1,251,610
<p>One reason a client could stop reading the data is that somebody unplugged the client (or disconnected its Ethernet cable) during the transfer. In that case, TCP will keep (unsuccessfully) resending packets for several minutes, getting no response, until it gives up. There are other possible reasons as well.</p> ...
0
2009-08-09T15:44:13Z
[ "python", "sockets", "ftp" ]
Writing Windows GUI applications with embedded Python scripts
1,251,260
<p>What would be the optimal way to develop a basic graphical application for Windows based on a Python console script? It would be great if the solution could be distributed as a standalone directory, containing the <code>.exe</code> file.</p>
1
2009-08-09T12:04:01Z
1,251,275
<p>I would recommend that you use IronPython, which is Microsoft's implementation of Python for the .NET framework.</p>
3
2009-08-09T12:15:28Z
[ "python", "windows", "user-interface" ]
Writing Windows GUI applications with embedded Python scripts
1,251,260
<p>What would be the optimal way to develop a basic graphical application for Windows based on a Python console script? It would be great if the solution could be distributed as a standalone directory, containing the <code>.exe</code> file.</p>
1
2009-08-09T12:04:01Z
1,251,299
<p>As far as I understand your question, you want to write a graphical windows application in Python, to do this I suggest using wxPython and then py2exe to create a standalone exe that can run on any machine without requiring python to be installed</p> <p>The following tutorial shows everything step by step: <a href=...
8
2009-08-09T12:31:52Z
[ "python", "windows", "user-interface" ]
Writing Windows GUI applications with embedded Python scripts
1,251,260
<p>What would be the optimal way to develop a basic graphical application for Windows based on a Python console script? It would be great if the solution could be distributed as a standalone directory, containing the <code>.exe</code> file.</p>
1
2009-08-09T12:04:01Z
1,253,389
<p><a href="http://docs.python.org/library/tkinter.html" rel="nofollow">Tkinter</a> is quick and easy to use. Tkinter is in the Python standard library.</p>
2
2009-08-10T06:34:18Z
[ "python", "windows", "user-interface" ]
Difference between returning modified class and using type()
1,251,294
<p>I guess it's more of a python question than a django one, but I couldn't replicate this behavior anywhere else, so I'll use exact code that doesn't work as expected.</p> <p>I was working on some dynamic forms in django, when I found this factory function snippet:</p> <pre><code>def get_employee_form(employee): ...
3
2009-08-09T12:28:12Z
1,251,343
<p>I just tried this with straight non-django classes and it worked. So it's not a Python issue, but a Django issue.</p> <p>And in this case (although I'm not 100% sure), it's a question of what the Form class does during class creation. I think it has a meta class, and that this meta class will finalize the form init...
3
2009-08-09T13:05:37Z
[ "python", "django", "class", "types" ]
Difference between returning modified class and using type()
1,251,294
<p>I guess it's more of a python question than a django one, but I couldn't replicate this behavior anywhere else, so I'll use exact code that doesn't work as expected.</p> <p>I was working on some dynamic forms in django, when I found this factory function snippet:</p> <pre><code>def get_employee_form(employee): ...
3
2009-08-09T12:28:12Z
1,251,567
<p>Lennart's hypothesis is correct: a metaclass is indeed the culprit. No need to guess, just look at <a href="http://code.djangoproject.com/browser/django/trunk/django/forms/forms.py" rel="nofollow">the sources</a>: the metaclass is <code>DeclarativeFieldsMetaclass</code> currently at line 53 of that file, and adds at...
5
2009-08-09T15:21:58Z
[ "python", "django", "class", "types" ]
Difference between returning modified class and using type()
1,251,294
<p>I guess it's more of a python question than a django one, but I couldn't replicate this behavior anywhere else, so I'll use exact code that doesn't work as expected.</p> <p>I was working on some dynamic forms in django, when I found this factory function snippet:</p> <pre><code>def get_employee_form(employee): ...
3
2009-08-09T12:28:12Z
1,400,444
<p>It's worth noting that this code snippet is a very poor means to the desired end, and involves a common misunderstanding about Django Form objects - that a Form object should map one-to-one with an HTML form. The correct way to do something like this (which doesn't require messing with any metaclass magic) is to use...
1
2009-09-09T15:38:15Z
[ "python", "django", "class", "types" ]
Read from socket: Is it guaranteed to at least get x bytes?
1,251,392
<p>I have a rare bug that seems to occur reading a socket.</p> <p>It seems, that during reading of data sometimes I get only 1-3 bytes of a data package that is bigger than this.</p> <p>As I learned from pipe-programming, there I always get at least 512 bytes as long as the sender provides enough data.</p> <p>Also m...
4
2009-08-09T13:35:11Z
1,251,406
<p>As far as I know, this behaviour is perfectly reasonable. Sockets may, and probably <strong>will</strong> fragment your data as they transmit it. You should be prepared to handle such cases by applying appropriate buffering techniques.</p> <p>On other hand, if you are transmitting the data on the localhost and you ...
9
2009-08-09T13:45:38Z
[ "python", "sockets", "network-protocols" ]
Read from socket: Is it guaranteed to at least get x bytes?
1,251,392
<p>I have a rare bug that seems to occur reading a socket.</p> <p>It seems, that during reading of data sometimes I get only 1-3 bytes of a data package that is bigger than this.</p> <p>As I learned from pipe-programming, there I always get at least 512 bytes as long as the sender provides enough data.</p> <p>Also m...
4
2009-08-09T13:35:11Z
1,251,407
<p>From the Linux man page of recv <a href="http://linux.about.com/library/cmd/blcmdl2%5Frecv.htm" rel="nofollow">http://linux.about.com/library/cmd/blcmdl2_recv.htm</a>: </p> <blockquote> <p>The receive calls normally return any data available, up to the requested amount, rather than waiting for receipt of t...
1
2009-08-09T13:45:40Z
[ "python", "sockets", "network-protocols" ]
Read from socket: Is it guaranteed to at least get x bytes?
1,251,392
<p>I have a rare bug that seems to occur reading a socket.</p> <p>It seems, that during reading of data sometimes I get only 1-3 bytes of a data package that is bigger than this.</p> <p>As I learned from pipe-programming, there I always get at least 512 bytes as long as the sender provides enough data.</p> <p>Also m...
4
2009-08-09T13:35:11Z
1,251,410
<p>If the sender sends 515 bytes, and your BUFSIZE is 512, then the first recv will return 512 bytes, and the next will return 3 bytes... Could this be what's happening?</p> <p>(This is just one case amongst many which will result in a 3-byte recv from a larger send...)</p>
1
2009-08-09T13:47:29Z
[ "python", "sockets", "network-protocols" ]
Read from socket: Is it guaranteed to at least get x bytes?
1,251,392
<p>I have a rare bug that seems to occur reading a socket.</p> <p>It seems, that during reading of data sometimes I get only 1-3 bytes of a data package that is bigger than this.</p> <p>As I learned from pipe-programming, there I always get at least 512 bytes as long as the sender provides enough data.</p> <p>Also m...
4
2009-08-09T13:35:11Z
1,251,512
<p>I assume you're using TCP. TCP is a stream based protocol with no idea of packets or message boundaries.</p> <p>This means when you do a read you may get less bytes than you request. If your data is 128k for example you may only get 24k on your first read requiring you to read again to get the rest of the data.</p...
13
2009-08-09T14:43:25Z
[ "python", "sockets", "network-protocols" ]
Read from socket: Is it guaranteed to at least get x bytes?
1,251,392
<p>I have a rare bug that seems to occur reading a socket.</p> <p>It seems, that during reading of data sometimes I get only 1-3 bytes of a data package that is bigger than this.</p> <p>As I learned from pipe-programming, there I always get at least 512 bytes as long as the sender provides enough data.</p> <p>Also m...
4
2009-08-09T13:35:11Z
1,251,533
<p>This is just the way TCP works. You aren't going to get all of your data at once. There are just too many timing issues between sender and receiver including the senders operating system, NIC, routers, switches, the wires themselves, the receivers NIC, OS, etc. There are buffers in the hardware, and in the OS.</p> ...
3
2009-08-09T14:55:53Z
[ "python", "sockets", "network-protocols" ]
Read from socket: Is it guaranteed to at least get x bytes?
1,251,392
<p>I have a rare bug that seems to occur reading a socket.</p> <p>It seems, that during reading of data sometimes I get only 1-3 bytes of a data package that is bigger than this.</p> <p>As I learned from pipe-programming, there I always get at least 512 bytes as long as the sender provides enough data.</p> <p>Also m...
4
2009-08-09T13:35:11Z
1,253,120
<p>The simple answer to your question, "Read from socket: Is it guaranteed to at least get x bytes?", is <strong>no</strong>. Look at the doc strings for these socket methods:</p> <pre><code>&gt;&gt;&gt; import socket &gt;&gt;&gt; s = socket.socket() &gt;&gt;&gt; print s.recv.__doc__ recv(buffersize[, flags]) -&gt; da...
5
2009-08-10T04:39:06Z
[ "python", "sockets", "network-protocols" ]
Read from socket: Is it guaranteed to at least get x bytes?
1,251,392
<p>I have a rare bug that seems to occur reading a socket.</p> <p>It seems, that during reading of data sometimes I get only 1-3 bytes of a data package that is bigger than this.</p> <p>As I learned from pipe-programming, there I always get at least 512 bytes as long as the sender provides enough data.</p> <p>Also m...
4
2009-08-09T13:35:11Z
1,484,627
<p>If you are still interested, patterns like this :</p> <pre><code># 4 bytes are needed here ...... # read remainder of datagram... </code></pre> <p>may create the silly window thing.</p> <p>Check <a href="http://tangentsoft.net/wskfaq/intermediate.html#silly-window" rel="nofollow">this</a> out</p>
1
2009-09-27T22:15:33Z
[ "python", "sockets", "network-protocols" ]
Where is the hidden parameter?
1,251,427
<p>I have this function call here:</p> <pre><code>import test_hosts test_hosts.LocalTestHost(mst, port, local_ip, remote_if_mac, remote_if_ip, service_port) </code></pre> <p>and when I run it, the interpreter fails, and says I'm passing 6 parameters to a function that receives 7 parameters.</p> <p><code>LocalTestHo...
1
2009-08-09T13:55:32Z
1,251,442
<p>I've seen these issues before, but it was because of preceding code being crafted in such a way that it syntactically correct but was not as I had intended.</p> <p>This snippet isn't enough to reproduce the problem for me, at least not on 2.5.1 on OS X.</p>
1
2009-08-09T14:02:20Z
[ "python" ]
Where is the hidden parameter?
1,251,427
<p>I have this function call here:</p> <pre><code>import test_hosts test_hosts.LocalTestHost(mst, port, local_ip, remote_if_mac, remote_if_ip, service_port) </code></pre> <p>and when I run it, the interpreter fails, and says I'm passing 6 parameters to a function that receives 7 parameters.</p> <p><code>LocalTestHo...
1
2009-08-09T13:55:32Z
1,251,483
<p>Another idea: you are inadvertently calling an older version of the code. Make sure you don't have a .pyc file lying around somewhere.</p>
2
2009-08-09T14:24:37Z
[ "python" ]
Where is the hidden parameter?
1,251,427
<p>I have this function call here:</p> <pre><code>import test_hosts test_hosts.LocalTestHost(mst, port, local_ip, remote_if_mac, remote_if_ip, service_port) </code></pre> <p>and when I run it, the interpreter fails, and says I'm passing 6 parameters to a function that receives 7 parameters.</p> <p><code>LocalTestHo...
1
2009-08-09T13:55:32Z
1,252,170
<p>The snippets of code you pasted look fine. As others correctly said, to find the problem you should find the smallest amount of code that still has the bug.</p> <p>My suggestion would be to </p> <p>(1) check that module <code>test_hosts</code> is written for your version of Python and that it's indeed the file bei...
3
2009-08-09T20:19:08Z
[ "python" ]
Where is the hidden parameter?
1,251,427
<p>I have this function call here:</p> <pre><code>import test_hosts test_hosts.LocalTestHost(mst, port, local_ip, remote_if_mac, remote_if_ip, service_port) </code></pre> <p>and when I run it, the interpreter fails, and says I'm passing 6 parameters to a function that receives 7 parameters.</p> <p><code>LocalTestHo...
1
2009-08-09T13:55:32Z
1,260,842
<p>My god, I was an idiot. I need to start reading the error messages more thoroughly.</p> <p>The code that actually caused the problem wasn't in here actually. It was several lines inside the constructor. Here it is:</p> <pre><code>class LocalTestHost: def __init__(self, mst, port, local_ip, remote_if_mac, remo...
1
2009-08-11T14:46:00Z
[ "python" ]
Catmull-Rom splines in python
1,251,438
<p>Is there a library or function in python to compute Catmull-Rom spline from three points ?</p> <p>What I need in the end are the x,y coordinates of points along the spline, provided that they are always equidistant of a given amount t along the spline (say, the spline curve is 3 units long and I want the x,y coordi...
2
2009-08-09T14:00:21Z
1,251,478
<p>There's this: <a href="http://www.exch.demon.co.uk/jj%5Fcatmull.htm" rel="nofollow">jj_catmull</a>, which seems to be in Python, maybe you can find what you need there.</p>
1
2009-08-09T14:20:28Z
[ "python", "math", "spline" ]
Catmull-Rom splines in python
1,251,438
<p>Is there a library or function in python to compute Catmull-Rom spline from three points ?</p> <p>What I need in the end are the x,y coordinates of points along the spline, provided that they are always equidistant of a given amount t along the spline (say, the spline curve is 3 units long and I want the x,y coordi...
2
2009-08-09T14:00:21Z
1,295,081
<p>3 points ? Catmull-Rom is defined for 4 points, say p_1 p0 p1 p2; a cubic curve goes from p0 to p1, and outer points p_1 and p2 determine the slopes at p0 and p1. To draw a curve through some points in an array P, do something like this:</p> <pre><code>for j in range( 1, len(P)-2 ): # skip the ends for t in r...
6
2009-08-18T16:39:30Z
[ "python", "math", "spline" ]
Catmull-Rom splines in python
1,251,438
<p>Is there a library or function in python to compute Catmull-Rom spline from three points ?</p> <p>What I need in the end are the x,y coordinates of points along the spline, provided that they are always equidistant of a given amount t along the spline (say, the spline curve is 3 units long and I want the x,y coordi...
2
2009-08-09T14:00:21Z
39,167,367
<p>As mentioned previously you do need 4 points for catmull-rom, and the endpoints are an issue. I was looking at applying these myself instead of natural cubic splines (which the potential overshoots beyond the known data range is impractical in my application). Similar to @denis's code, here is something that might h...
1
2016-08-26T13:21:03Z
[ "python", "math", "spline" ]
Python imports: Will changing a variable in "child" change variable in "parent"/other children?
1,251,611
<p>Suppose you have 3 modules, a.py, b.py, and c.py:</p> <p>a.py:</p> <pre><code>v1 = 1 v2 = 2 etc. </code></pre> <p>b.py:</p> <pre><code>from a import * </code></pre> <p>c.py:</p> <pre><code>from a import * v1 = 0 </code></pre> <p>Will c.py change v1 in a.py and b.py? If not, is there a way to do it?</p>
2
2009-08-09T15:44:15Z
1,251,616
<p>Yes, you just need to access it correctly (and don't use import *, it's evil)</p> <p>c.py:</p> <pre><code>import a print a.v1 # prints 1 a.v1 = 0 print a.v1 # prints 0 </code></pre>
1
2009-08-09T15:46:31Z
[ "python", "import" ]
Python imports: Will changing a variable in "child" change variable in "parent"/other children?
1,251,611
<p>Suppose you have 3 modules, a.py, b.py, and c.py:</p> <p>a.py:</p> <pre><code>v1 = 1 v2 = 2 etc. </code></pre> <p>b.py:</p> <pre><code>from a import * </code></pre> <p>c.py:</p> <pre><code>from a import * v1 = 0 </code></pre> <p>Will c.py change v1 in a.py and b.py? If not, is there a way to do it?</p>
2
2009-08-09T15:44:15Z
1,251,647
<p>The <code>from ... import *</code> form is basically intended for handy interactive use at the interpreter prompt: you'd be well advised to never use it in other situations, as it will give you nothing but problems.</p> <p>In fact, the in-house style guide at my employer goes further, recommending to always import ...
2
2009-08-09T16:03:07Z
[ "python", "import" ]
Python imports: Will changing a variable in "child" change variable in "parent"/other children?
1,251,611
<p>Suppose you have 3 modules, a.py, b.py, and c.py:</p> <p>a.py:</p> <pre><code>v1 = 1 v2 = 2 etc. </code></pre> <p>b.py:</p> <pre><code>from a import * </code></pre> <p>c.py:</p> <pre><code>from a import * v1 = 0 </code></pre> <p>Will c.py change v1 in a.py and b.py? If not, is there a way to do it?</p>
2
2009-08-09T15:44:15Z
1,251,653
<p>All that a statement like:</p> <pre><code>v1 = 0 </code></pre> <p>can do is bind the name <code>v1</code> to the object <code>0</code>. It can't affect a different module.</p> <p>If I'm using unfamiliar terms there, and I guess I probably am, I strongly recommend you read Fredrik Lundh's excellent article <a hre...
5
2009-08-09T16:05:49Z
[ "python", "import" ]
How to enumerate an object's properties in Python?
1,251,692
<p>I C# we do it through reflection. In Javascript it is simple as:</p> <pre><code>for(var propertyName in objectName) var currentPropertyValue = objectName[propertyName]; </code></pre> <p>How to do it in Python?</p>
66
2009-08-09T16:33:02Z
1,251,702
<pre><code>for property, value in vars(theObject).iteritems(): print property, ": ", value </code></pre> <p>Be aware that in some rare cases there's a <code>__slots__</code> property, such classes often have no <code>__dict__</code>.</p>
77
2009-08-09T16:37:09Z
[ "python", "reflection", "properties" ]
How to enumerate an object's properties in Python?
1,251,692
<p>I C# we do it through reflection. In Javascript it is simple as:</p> <pre><code>for(var propertyName in objectName) var currentPropertyValue = objectName[propertyName]; </code></pre> <p>How to do it in Python?</p>
66
2009-08-09T16:33:02Z
1,251,704
<p><a href="http://docs.python.org/library/functions.html#dir"><code>dir()</code></a> is the simple way. See here:</p> <p><a href="http://www.ibm.com/developerworks/library/l-pyint.html">Guide To Python Introspection</a></p>
27
2009-08-09T16:37:48Z
[ "python", "reflection", "properties" ]
How to enumerate an object's properties in Python?
1,251,692
<p>I C# we do it through reflection. In Javascript it is simple as:</p> <pre><code>for(var propertyName in objectName) var currentPropertyValue = objectName[propertyName]; </code></pre> <p>How to do it in Python?</p>
66
2009-08-09T16:33:02Z
1,251,705
<p>The <code>__dict__</code> property of the object is a dictionary of all its other defined properties. Note that Python classes can override <a href="http://docs.python.org/reference/datamodel.html#object.__getattr__" rel="nofollow"><strong>getattr</strong></a> and make things that look like properties but are not in...
10
2009-08-09T16:37:50Z
[ "python", "reflection", "properties" ]
How to enumerate an object's properties in Python?
1,251,692
<p>I C# we do it through reflection. In Javascript it is simple as:</p> <pre><code>for(var propertyName in objectName) var currentPropertyValue = objectName[propertyName]; </code></pre> <p>How to do it in Python?</p>
66
2009-08-09T16:33:02Z
1,251,789
<p>See <a href="http://docs.python.org/library/inspect.html#inspect.getmembers"><code>inspect.getmembers(object[, predicate])</code></a>.</p> <blockquote> <p>Return all the members of an object in a list of (name, value) pairs sorted by name. If the optional predicate argument is supplied, only members for which the...
54
2009-08-09T17:23:08Z
[ "python", "reflection", "properties" ]
How to enumerate an object's properties in Python?
1,251,692
<p>I C# we do it through reflection. In Javascript it is simple as:</p> <pre><code>for(var propertyName in objectName) var currentPropertyValue = objectName[propertyName]; </code></pre> <p>How to do it in Python?</p>
66
2009-08-09T16:33:02Z
17,024,180
<p>georg scholly shorter version </p> <pre><code>print vars(theObject) </code></pre>
6
2013-06-10T12:44:16Z
[ "python", "reflection", "properties" ]
Is it possible to update an entry on Google App Engine datastore through the object's dictionary?
1,252,092
<p>I tried the following code and it didn't work:</p> <pre><code>class SourceUpdate(webapp.RequestHandler): def post(self): id = int(self.request.get('id')) source = Source.get_by_id(id) for property in self.request.arguments(): if property != 'id': source.__dict__[property] = self.request....
0
2009-08-09T19:51:03Z
1,252,100
<p>You're bypassing the <code>__setattr__</code>-like functionality that the models' metaclass (<code>type(type(source))</code>) is normally using to deal with attribute-setting properly. Change your inner loop to:</p> <pre><code>for property in self.request.arguments(): if property != 'id': setattr(source, pro...
2
2009-08-09T19:55:12Z
[ "python", "google-app-engine", "gae-datastore" ]
Is it possible to update an entry on Google App Engine datastore through the object's dictionary?
1,252,092
<p>I tried the following code and it didn't work:</p> <pre><code>class SourceUpdate(webapp.RequestHandler): def post(self): id = int(self.request.get('id')) source = Source.get_by_id(id) for property in self.request.arguments(): if property != 'id': source.__dict__[property] = self.request....
0
2009-08-09T19:51:03Z
1,253,590
<p>Instead of directly setting model values from the request, you might want to look into using Django forms. They're bundled with App Engine, and facilitate validating form data and storing it in the datastore, as well as generating the form HTML. There's an article on how to use them with the App Engine datastore <a ...
2
2009-08-10T07:51:09Z
[ "python", "google-app-engine", "gae-datastore" ]
Printing Python version in output
1,252,163
<p>How can I print version number for the current Python installation in the output? </p>
151
2009-08-09T20:15:39Z
1,252,164
<p>Try</p> <pre><code>import sys print(sys.version) </code></pre> <p>This prints the full version information string. If you only want the python version number, then <a href="http://stackoverflow.com/questions/1252163/printing-python-version-in-output/1252175#1252175">Bastien Léonard's solution</a> is the best. You...
189
2009-08-09T20:16:47Z
[ "python" ]
Printing Python version in output
1,252,163
<p>How can I print version number for the current Python installation in the output? </p>
151
2009-08-09T20:15:39Z
1,252,165
<pre><code>import platform print(platform.python_version()) </code></pre> <p>or</p> <pre><code>import sys print("The Python version is %s.%s.%s" % sys.version_info[:3]) </code></pre> <p>Edit: I had totally missed the platform.python_version() medthod.</p>
21
2009-08-09T20:17:32Z
[ "python" ]
Printing Python version in output
1,252,163
<p>How can I print version number for the current Python installation in the output? </p>
151
2009-08-09T20:15:39Z
1,252,175
<pre><code>&gt;&gt;&gt; import platform &gt;&gt;&gt; platform.python_version() '2.6.2' </code></pre>
73
2009-08-09T20:21:00Z
[ "python" ]
Printing Python version in output
1,252,163
<p>How can I print version number for the current Python installation in the output? </p>
151
2009-08-09T20:15:39Z
11,734,305
<p>Try </p> <pre><code>python --version </code></pre> <p>or</p> <pre><code>python -V </code></pre> <p>This will return a current python version in terminal.</p>
20
2012-07-31T06:24:33Z
[ "python" ]
Printing Python version in output
1,252,163
<p>How can I print version number for the current Python installation in the output? </p>
151
2009-08-09T20:15:39Z
17,145,598
<pre><code>import sys </code></pre> <p>expanded version </p> <pre><code>sys.version_info sys.version_info(major=3, minor=2, micro=2, releaselevel='final', serial=0) </code></pre> <p>specific</p> <pre><code>maj_ver = sys.version_info.major repr(maj_ver) '3' </code></pre> <p>or </p> <pre><code>print(sys.v...
10
2013-06-17T10:42:34Z
[ "python" ]
How to check null value for UserProperty in Google App Engine
1,252,196
<p>In Google App Engine, datastore modelling, I would like to ask how can I check for null value of a property with class UserProperty? for example: I have this code:</p> <pre><code>class Entry(db.Model): title = db.StringProperty() description = db.StringProperty() author = db.UserProperty() editor = db.UserP...
5
2009-08-09T20:29:00Z
1,252,322
<pre><code>query = db.GqlQuery("SELECT * FROM Entry WHERE editor &gt; :1",None) </code></pre> <p>However, you can't <code>ORDER BY</code> one column <em>and</em> have an inequality condition on another column: that's a well-known GAE limitation and has nothing to do with the property being a UserProperty nor with the ...
13
2009-08-09T21:21:05Z
[ "python", "google-app-engine", "gae-datastore" ]
PIL Image.resize() not resizing the picture
1,252,218
<p>I have some strange problem with PIL not resizing the image.</p> <pre><code>def handle_uploaded_image(i, u): # resize image from PIL import Image img = Image.open(i) if img.mode not in ('L', 'RGB'): img = img.convert('RGB') width, height = img.size if width == height: img.thumbn...
19
2009-08-09T20:36:35Z
1,252,229
<p><code>resize()</code> returns a resized copy of an image. It doesn't modify the original. The correct way to use it is:</p> <pre><code>img = img.resize((150, newheight), image.ANTIALIAS) </code></pre> <p><a href="http://effbot.org/imagingbook/image.htm">source</a></p> <p>I think what you are looking for is the Im...
56
2009-08-09T20:39:53Z
[ "python", "django", "resize", "python-imaging-library" ]
Django + Jquery, expanding AJAX div
1,252,275
<p>How can I, when a user clicks a link, open a div right underneath the link which loads it's content via AJAX? </p> <p>Thanks for the help; I cannot find out how to. Just statically filling the div on the server side while loading the page works fine, but it's too much content for that. </p> <p>I'm kind of looking ...
4
2009-08-09T20:58:47Z
1,252,295
<p>Something like this will work</p> <pre><code>&lt;html&gt; &lt;head&gt; &lt;script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"&gt;&lt;/script&gt; &lt;script type="text/javascript"&gt; function loadDiv() { $.get("test.php", function(data){ $('#thediv').html(da...
1
2009-08-09T21:08:58Z
[ "jquery", "python", "django" ]
Django + Jquery, expanding AJAX div
1,252,275
<p>How can I, when a user clicks a link, open a div right underneath the link which loads it's content via AJAX? </p> <p>Thanks for the help; I cannot find out how to. Just statically filling the div on the server side while loading the page works fine, but it's too much content for that. </p> <p>I'm kind of looking ...
4
2009-08-09T20:58:47Z
1,252,311
<p><a href="http://docs.jquery.com/Ajax/load">jQuery.load</a> does exactly that:</p> <pre><code>$("div#my-container").load("/url/to/content/ #content-id") </code></pre> <p>this fetches the content from <code>/url/to/content/</code>, filters it by <code>#content-id</code> and injects the result into <code>div#my-conta...
12
2009-08-09T21:13:59Z
[ "jquery", "python", "django" ]
Python and web-tags regex
1,252,316
<p>i have need webpage-content. I need to get some data from it. It looks like:</p> <blockquote> <p>&lt; div class="deg">DATA&lt; /div></p> </blockquote> <p>As i understand, i have to use regex, but i can't choose one.</p> <p>I tried the code below but had no any results. Please, correct me:</p> <pre><code>regexH...
1
2009-08-09T21:16:30Z
1,252,329
<p>If you want the div tags included in the matched item:</p> <pre><code>regexpHandler = re.compile('(&lt;div class="deg"&gt;.*?&lt;/div&gt;)') </code></pre> <p>If you don't want the div tags included, only the DATA portion:</p> <pre><code>regexpHandler = re.compile('&lt;div class="deg"&gt;(.*?)&lt;/div&gt;') </code...
3
2009-08-09T21:25:09Z
[ "python", "regex" ]
Python and web-tags regex
1,252,316
<p>i have need webpage-content. I need to get some data from it. It looks like:</p> <blockquote> <p>&lt; div class="deg">DATA&lt; /div></p> </blockquote> <p>As i understand, i have to use regex, but i can't choose one.</p> <p>I tried the code below but had no any results. Please, correct me:</p> <pre><code>regexH...
1
2009-08-09T21:16:30Z
1,252,331
<p>I suggest using a good HTML parser (such as <a href="http://www.crummy.com/software/BeautifulSoup/">BeautifulSoup</a> -- but for your purposes, i.e. with well-formed HTML as input, the ones that come with the Python standard library, such as <a href="http://docs.python.org/library/htmlparser.html">HTMLParser</a>, sh...
6
2009-08-09T21:26:14Z
[ "python", "regex" ]
Python and web-tags regex
1,252,316
<p>i have need webpage-content. I need to get some data from it. It looks like:</p> <blockquote> <p>&lt; div class="deg">DATA&lt; /div></p> </blockquote> <p>As i understand, i have to use regex, but i can't choose one.</p> <p>I tried the code below but had no any results. Please, correct me:</p> <pre><code>regexH...
1
2009-08-09T21:16:30Z
1,253,254
<p>you can use simple string functions in Python, no need for regex</p> <pre><code>mystr = """&lt; div class="deg"&gt;DATA&lt; /div&gt;""" if "div" in mystr and "class" in mystr and "deg" in mystr: s = mystr.split("&gt;") for n,item in enumerate(s): if "deg" in item: print s[n+1][:s[n+1].in...
0
2009-08-10T05:40:46Z
[ "python", "regex" ]
Python and web-tags regex
1,252,316
<p>i have need webpage-content. I need to get some data from it. It looks like:</p> <blockquote> <p>&lt; div class="deg">DATA&lt; /div></p> </blockquote> <p>As i understand, i have to use regex, but i can't choose one.</p> <p>I tried the code below but had no any results. Please, correct me:</p> <pre><code>regexH...
1
2009-08-09T21:16:30Z
1,254,768
<p>While it is ok to use rexex for quick and dirty html processing a much better and cleaner way is to use a html parser like <a href="http://codespeak.net/lxml" rel="nofollow">lxml.html</a> and to query the parsed tree with <a href="http://codespeak.net/lxml/xpathxslt.html" rel="nofollow">XPath</a> or <a href="http://...
0
2009-08-10T13:06:44Z
[ "python", "regex" ]
Is there an object unique identifier in Python
1,252,357
<p>This would be similar to the java.lang.Object.hashcode() method.</p> <p>I need to store objects I have no control over in a set, and make sure that only if two objects are actually the same object (not contain the same values) will the values be overwritten. </p>
31
2009-08-09T21:40:30Z
1,252,364
<pre><code>id(x) </code></pre> <p>will do the trick for you. But I'm curious, what's wrong about the set of objects (which does combine objects by value)? </p> <p>For your particular problem I would probably keep the set of ids or of wrapper objects. A wrapper object will contain one reference and compare by <code>x=...
49
2009-08-09T21:42:32Z
[ "python" ]
Is there an object unique identifier in Python
1,252,357
<p>This would be similar to the java.lang.Object.hashcode() method.</p> <p>I need to store objects I have no control over in a set, and make sure that only if two objects are actually the same object (not contain the same values) will the values be overwritten. </p>
31
2009-08-09T21:40:30Z
1,252,369
<p>That's what "<code>is</code>" is for.</p> <p>Instead of testing "<code>if a == b</code>", which tests for the same value, </p> <p>test "<code>if a is b</code>", which will test for the same identifier.</p>
12
2009-08-09T21:43:35Z
[ "python" ]
Is there an object unique identifier in Python
1,252,357
<p>This would be similar to the java.lang.Object.hashcode() method.</p> <p>I need to store objects I have no control over in a set, and make sure that only if two objects are actually the same object (not contain the same values) will the values be overwritten. </p>
31
2009-08-09T21:40:30Z
1,252,386
<p>As ilya n mentions, id(x) produces a unique identifier for an object.</p> <p>But your question is confusing, since Java's hashCode method doesn't give a unique identifier. Java's hashCode works like most hash functions: it always returns the same value for the same object, two objects that are equal always get equ...
2
2009-08-09T21:48:00Z
[ "python" ]
Is there an object unique identifier in Python
1,252,357
<p>This would be similar to the java.lang.Object.hashcode() method.</p> <p>I need to store objects I have no control over in a set, and make sure that only if two objects are actually the same object (not contain the same values) will the values be overwritten. </p>
31
2009-08-09T21:40:30Z
27,936,874
<p>You don't have to compare objects before placing them in a set. set() semantics already takes care of this. </p> <pre><code> class A(object): a = 10 b = 20 def __hash__(self): return hash((self.a, self.b)) a1 = A() a2 = A() a3 = A() a4 = a1 s = set([a1,a2,a3,a4]) s =...
-1
2015-01-14T06:17:13Z
[ "python" ]
sort dictionary by another dictionary
1,252,481
<p>I've been having a problem with making sorted lists from dictionaries. I have this list</p> <pre><code>list = [ d = {'file_name':'thisfile.flt', 'item_name':'box', 'item_height':'8.7', 'item_width':'10.5', 'item_depth':'2.2', 'texture_file': 'red.jpg'}, d = {'file_name':'thatfile.flt', 'item_name':'teapot'...
2
2009-08-09T22:26:25Z
1,252,500
<p>The first code box has invalid Python syntax (I suspect the <code>d =</code> parts are extraneous...?) as well as unwisely trampling on the built-in name <code>list</code>.</p> <p>Anyway, given for example:</p> <pre><code>d = {'file_name':'thisfile.flt', 'item_name':'box', 'item_height':'8.7', 'item_width':'...
7
2009-08-09T22:34:31Z
[ "python", "sorting", "dictionary" ]
Which path module or class do Python folks use instead of os.path?
1,252,639
<p>Just wondering how many people use a path module in Python such as Jason Orendorff's one, instead of using <code>os.path</code> for joining and splitting paths? Have you used:</p> <ul> <li><a href="http://wiki.python.org/moin/PathModule" rel="nofollow">Jason's path module</a> (updated for PEP 355)</li> <li><a href=...
5
2009-08-10T00:03:40Z
1,252,644
<p>I can pick up a Python program and interpret the current standard method without hesitation - it's explicit and there's no ambiguity:</p> <pre><code>os.path.join(build_dir, os.path.basename(source_file)) </code></pre> <p>Python's dynamic typing makes the first method rather difficult to comprehend when reading:</p...
11
2009-08-10T00:10:48Z
[ "python", "path" ]
Which path module or class do Python folks use instead of os.path?
1,252,639
<p>Just wondering how many people use a path module in Python such as Jason Orendorff's one, instead of using <code>os.path</code> for joining and splitting paths? Have you used:</p> <ul> <li><a href="http://wiki.python.org/moin/PathModule" rel="nofollow">Jason's path module</a> (updated for PEP 355)</li> <li><a href=...
5
2009-08-10T00:03:40Z
1,252,978
<p>Dividing strings to join paths may seem like a "neat trick" but it's precisely that kind of thing that Python programmers like to avoid (and btw, programmers in most other langauges.) The os.path module is widely used and easily understood by all. Doing funky things with overloaded operators on the other hand is con...
-1
2009-08-10T03:17:49Z
[ "python", "path" ]
Which path module or class do Python folks use instead of os.path?
1,252,639
<p>Just wondering how many people use a path module in Python such as Jason Orendorff's one, instead of using <code>os.path</code> for joining and splitting paths? Have you used:</p> <ul> <li><a href="http://wiki.python.org/moin/PathModule" rel="nofollow">Jason's path module</a> (updated for PEP 355)</li> <li><a href=...
5
2009-08-10T00:03:40Z
5,792,853
<p>A simple but useful trick is this:</p> <blockquote> <p>import os</p> <p>Path = os.path.join</p> </blockquote> <p>Then, instead of this:</p> <blockquote> <p>os.path.join(build_dir, os.path.basename(source_file))</p> </blockquote> <p>You can do this:</p> <blockquote> <p>Path(build_dir, Path(source_file...
1
2011-04-26T15:44:47Z
[ "python", "path" ]