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
converting wav to mp3 (and vice versa) using GStreamer
2,172,000
<p>I am using Python bindings for Gstreamer and am using the following pipeline to convert a wav file to mp3. I used one of the suggestions <a href="http://stackoverflow.com/questions/1246131/python-library-for-converting-files-to-mp3-and-setting-their-quality">in this question</a> , with some modifications (as I was g...
1
2010-01-31T14:24:37Z
3,074,143
<p>your pipeline is correct - or more specifically, your choice of elements and properties is correct.</p> <p>the problem is most likely in another part of your code. have you set the pipeline to gst.STATE_PLAYING?</p> <pre><code>pipeline = gst.parse_launch("filesrc location=C:\\music.wav ! decodebin ! audioconvert !...
1
2010-06-19T03:01:33Z
[ "python", "gstreamer" ]
converting wav to mp3 (and vice versa) using GStreamer
2,172,000
<p>I am using Python bindings for Gstreamer and am using the following pipeline to convert a wav file to mp3. I used one of the suggestions <a href="http://stackoverflow.com/questions/1246131/python-library-for-converting-files-to-mp3-and-setting-their-quality">in this question</a> , with some modifications (as I was g...
1
2010-01-31T14:24:37Z
3,178,617
<p>If you didn't get this working I suggest using ffmpeg to convert your files, it's very efficient and opensource, you can find a compiled windows version with WinFF which you can manipulate through the command line.</p>
0
2010-07-05T10:04:45Z
[ "python", "gstreamer" ]
Python regex for matching bb code
2,172,046
<p>I'm writing a very simple bbcode parse. If i want to replace <code>hello i'm a [b]bold[/b] text</code>, i have success with replacing this regex</p> <p><code>r'\[b\](.*)\[\/b\]'</code></p> <p>with this </p> <p><code>&lt;strong&gt;\g&lt;1&gt;&lt;/strong&gt;</code></p> <p>to get <code>hello, i'm a &lt;strong&gt;bo...
2
2010-01-31T14:36:16Z
2,172,057
<p>You shouldn't use regular expressions to parse non-regular languages (like matching tags). Look into a parser instead.</p> <p>Edit - a quick Google search takes me <a href="http://www.willmcgugan.com/blog/tech/2007/3/10/bbcode-python-module/" rel="nofollow">here</a>.</p>
7
2010-01-31T14:40:13Z
[ "python", "regex" ]
Python regex for matching bb code
2,172,046
<p>I'm writing a very simple bbcode parse. If i want to replace <code>hello i'm a [b]bold[/b] text</code>, i have success with replacing this regex</p> <p><code>r'\[b\](.*)\[\/b\]'</code></p> <p>with this </p> <p><code>&lt;strong&gt;\g&lt;1&gt;&lt;/strong&gt;</code></p> <p>to get <code>hello, i'm a &lt;strong&gt;bo...
2
2010-01-31T14:36:16Z
2,172,059
<p>Just change your regular expression from:</p> <pre><code>r'\[b\](.*)\[\/b\]' </code></pre> <p>to</p> <pre><code>r'\[b\](.*?)\[\/b\]' </code></pre> <p>The <code>*</code> qualifier is greedy, appending a <code>?</code> to it you make it performing as a non-greedy qualifier.</p> <p>Here's a more complete explainat...
5
2010-01-31T14:40:33Z
[ "python", "regex" ]
Where is gsl_cdf_beta_Pinv() in PyGSL?
2,172,128
<p>I'm trying to use the distribution functions in a Python program (the random functions I've got figured out; I'm looking specifically for gsl_cdf_beta_Pinv()) and I can't find it. Can someone tell me how I can use these or a fast alternative in a program?</p> <p>Thanks,</p> <p>Mark Ch.</p>
0
2010-01-31T15:04:04Z
2,172,737
<p>It's defined in this <a href="http://sage.math.washington.edu/home/cwitty/sage/devel/sage-main/sage/gsl/probability_distribution.pyx" rel="nofollow">Cython source file</a> (for module <code>probability_distribution</code>) as being mediated by the method <code>cum_distribution_function_inv</code> of an instance of c...
1
2010-01-31T18:15:37Z
[ "python", "gsl", "pygsl" ]
Why I can't extend bool in Python?
2,172,189
<pre><code>&gt;&gt;&gt; class BOOL(bool): ... print "why?" ... why? Traceback (most recent call last): File "&lt;stdin&gt;", line 1, in &lt;module&gt; TypeError: Error when calling the metaclass bases type 'bool' is not an acceptable base type </code></pre> <p><strong>I thought Python trusted the programmer...
21
2010-01-31T15:22:39Z
2,172,195
<p>Here is a post that explains the reasoning behind the decision: <a href="http://mail.python.org/pipermail/python-dev/2004-February/042537.html">http://mail.python.org/pipermail/python-dev/2004-February/042537.html</a></p> <p>The idea is that <code>bool</code> has a specific purpose - to be <code>True</code> or to ...
9
2010-01-31T15:25:07Z
[ "python", "boolean", "restriction" ]
Why I can't extend bool in Python?
2,172,189
<pre><code>&gt;&gt;&gt; class BOOL(bool): ... print "why?" ... why? Traceback (most recent call last): File "&lt;stdin&gt;", line 1, in &lt;module&gt; TypeError: Error when calling the metaclass bases type 'bool' is not an acceptable base type </code></pre> <p><strong>I thought Python trusted the programmer...
21
2010-01-31T15:22:39Z
2,172,198
<p>Because <code>bool</code> is supposed to only have two values -- <code>True</code> and <code>False</code>. If you were able to subclass <code>bool</code>, you could define arbitrary numbers of values for it, and that's definitely not what you want to happen.</p> <p>A better question is: why do you want to extend bo...
4
2010-01-31T15:26:15Z
[ "python", "boolean", "restriction" ]
Why I can't extend bool in Python?
2,172,189
<pre><code>&gt;&gt;&gt; class BOOL(bool): ... print "why?" ... why? Traceback (most recent call last): File "&lt;stdin&gt;", line 1, in &lt;module&gt; TypeError: Error when calling the metaclass bases type 'bool' is not an acceptable base type </code></pre> <p><strong>I thought Python trusted the programmer...
21
2010-01-31T15:22:39Z
2,172,204
<p>Guido's take on it:</p> <blockquote> <p>I thought about this last night, and realized that you shouldn't be allowed to subclass bool at all! A subclass would only be useful when it has instances, but the mere existance of an instance of a subclass of bool would break the invariant that True and Fal...
33
2010-01-31T15:27:10Z
[ "python", "boolean", "restriction" ]
Why I can't extend bool in Python?
2,172,189
<pre><code>&gt;&gt;&gt; class BOOL(bool): ... print "why?" ... why? Traceback (most recent call last): File "&lt;stdin&gt;", line 1, in &lt;module&gt; TypeError: Error when calling the metaclass bases type 'bool' is not an acceptable base type </code></pre> <p><strong>I thought Python trusted the programmer...
21
2010-01-31T15:22:39Z
2,172,214
<p>If you are using Python 3, and you want to have a class that can be evaluated as a boolean, but also contain other functionality, implement <a href="http://docs.python.org/py3k/reference/datamodel.html#object.__bool__" rel="nofollow"><strong><code>__bool__</code></strong></a> in your class.</p> <p>In Python 2 the s...
4
2010-01-31T15:30:15Z
[ "python", "boolean", "restriction" ]
Why I can't extend bool in Python?
2,172,189
<pre><code>&gt;&gt;&gt; class BOOL(bool): ... print "why?" ... why? Traceback (most recent call last): File "&lt;stdin&gt;", line 1, in &lt;module&gt; TypeError: Error when calling the metaclass bases type 'bool' is not an acceptable base type </code></pre> <p><strong>I thought Python trusted the programmer...
21
2010-01-31T15:22:39Z
2,172,697
<p>Since the OP mentions in a comment:</p> <blockquote> <p>I want <code>1 and 2</code> to return an instance of my class.</p> </blockquote> <p>I think it's important to point out that this is entirely impossible: Python does not let you <em>alter</em> built-in types (and, in particular, their special methods). L...
9
2010-01-31T18:03:42Z
[ "python", "boolean", "restriction" ]
Best python UI package for simple graph simulations (TSP simulation, etc...)
2,172,302
<p>I've never done any UI programming in python before. What is the best (read most intuitive, easy to use, functional) UI package for python for doing simulations? </p> <p>I'll be doing a simulation of TSP right now. So I'll have a graph (nodes and edges) where the edges are rapidly changing, along with some selec...
2
2010-01-31T16:01:26Z
2,172,385
<p>I am not sure what you mean by "simulations" since the type of UI you want to do depends on what you simulate. But if you want to visualize graphs, <a href="http://networkx.lanl.gov/" rel="nofollow">networkx</a> is pretty cool.</p>
3
2010-01-31T16:25:21Z
[ "python", "user-interface" ]
Best python UI package for simple graph simulations (TSP simulation, etc...)
2,172,302
<p>I've never done any UI programming in python before. What is the best (read most intuitive, easy to use, functional) UI package for python for doing simulations? </p> <p>I'll be doing a simulation of TSP right now. So I'll have a graph (nodes and edges) where the edges are rapidly changing, along with some selec...
2
2010-01-31T16:01:26Z
2,172,398
<p>If you have graphs, you should definitely check out <a href="http://networkx.lanl.gov/pygraphviz/" rel="nofollow">PyGraphviz</a> (the interface is pretty similar to the aforementioned networkx)</p>
0
2010-01-31T16:30:45Z
[ "python", "user-interface" ]
Best python UI package for simple graph simulations (TSP simulation, etc...)
2,172,302
<p>I've never done any UI programming in python before. What is the best (read most intuitive, easy to use, functional) UI package for python for doing simulations? </p> <p>I'll be doing a simulation of TSP right now. So I'll have a graph (nodes and edges) where the edges are rapidly changing, along with some selec...
2
2010-01-31T16:01:26Z
2,172,413
<p>Colleagues of mine are working on a similar-sounding setup to you - they use <a href="http://matplotlib.sourceforge.net/" rel="nofollow">http://matplotlib.sourceforge.net/</a> and PyQt - PyQt can add a matplotlib object easily as a widget so the two integrate very well. A tutorial for PyQt is available here: <a href...
1
2010-01-31T16:35:44Z
[ "python", "user-interface" ]
Best python UI package for simple graph simulations (TSP simulation, etc...)
2,172,302
<p>I've never done any UI programming in python before. What is the best (read most intuitive, easy to use, functional) UI package for python for doing simulations? </p> <p>I'll be doing a simulation of TSP right now. So I'll have a graph (nodes and edges) where the edges are rapidly changing, along with some selec...
2
2010-01-31T16:01:26Z
2,172,428
<p>Such a simulation could be easily coded using:</p> <ol> <li>networkx - for the graph data structures and algorithms</li> <li>matplotlib - which is used by networkx to visualize graphs</li> <li>Some GUI framework - PyQt, for instance, for the display and interaction with the user</li> </ol> <p>What's cool is that t...
2
2010-01-31T16:39:11Z
[ "python", "user-interface" ]
How to create folders using file names and then move files into folders?
2,172,420
<p>I have hundreds of text files in a folder named using this kind of naming convention:</p> <pre><code>Bandname1 - song1.txt Bandname1 - song2.txt Bandname2 - song1.txt Bandname2 - song2.txt Bandname2 - song3.txt Bandname3 - song1.txt ..etc. </code></pre> <p>I would like to create folders for different bands and mov...
4
2010-01-31T16:36:51Z
2,172,442
<p>How about this:</p> <pre><code>for f in *.txt do band=$(echo "$f" | cut -d'-' -f1 | trim) if [ -d "$band" ] then mkdir "$band" fi mv "$f" "$band" done </code></pre>
0
2010-01-31T16:42:11Z
[ "python", "perl", "bash", "unix", "batch-file" ]
How to create folders using file names and then move files into folders?
2,172,420
<p>I have hundreds of text files in a folder named using this kind of naming convention:</p> <pre><code>Bandname1 - song1.txt Bandname1 - song2.txt Bandname2 - song1.txt Bandname2 - song2.txt Bandname2 - song3.txt Bandname3 - song1.txt ..etc. </code></pre> <p>I would like to create folders for different bands and mov...
4
2010-01-31T16:36:51Z
2,172,459
<p>You asked for a specific script, but if this is for organizing your music, you might want to check out <strong><a href="http://easytag.sourceforge.net/" rel="nofollow">EasyTAG</a></strong>. It has extremely specific and powerful rules that you can customize to organize your music however you want:</p> <p><img src="...
1
2010-01-31T16:46:32Z
[ "python", "perl", "bash", "unix", "batch-file" ]
How to create folders using file names and then move files into folders?
2,172,420
<p>I have hundreds of text files in a folder named using this kind of naming convention:</p> <pre><code>Bandname1 - song1.txt Bandname1 - song2.txt Bandname2 - song1.txt Bandname2 - song2.txt Bandname2 - song3.txt Bandname3 - song1.txt ..etc. </code></pre> <p>I would like to create folders for different bands and mov...
4
2010-01-31T16:36:51Z
2,172,537
<p><strong>gregseth</strong>'s answer will work, just replace <code>trim</code> with <code>xargs</code>. You could also eliminate the <code>if</code> test by just using <code>mkdir -p</code>, for example:</p> <pre><code>for f in *.txt; do band=$(echo "$f" | cut -d'-' -f1 | xargs) mkdir -p "$band" mv "$f" ...
1
2010-01-31T17:06:18Z
[ "python", "perl", "bash", "unix", "batch-file" ]
How to create folders using file names and then move files into folders?
2,172,420
<p>I have hundreds of text files in a folder named using this kind of naming convention:</p> <pre><code>Bandname1 - song1.txt Bandname1 - song2.txt Bandname2 - song1.txt Bandname2 - song2.txt Bandname2 - song3.txt Bandname3 - song1.txt ..etc. </code></pre> <p>I would like to create folders for different bands and mov...
4
2010-01-31T16:36:51Z
2,172,542
<pre><code>ls |perl -lne'$f=$_; s/(.+?) - [^-]*\.txt/$1/; mkdir unless -d; rename $f, "$_/$f"' </code></pre>
-1
2010-01-31T17:08:57Z
[ "python", "perl", "bash", "unix", "batch-file" ]
How to create folders using file names and then move files into folders?
2,172,420
<p>I have hundreds of text files in a folder named using this kind of naming convention:</p> <pre><code>Bandname1 - song1.txt Bandname1 - song2.txt Bandname2 - song1.txt Bandname2 - song2.txt Bandname2 - song3.txt Bandname3 - song1.txt ..etc. </code></pre> <p>I would like to create folders for different bands and mov...
4
2010-01-31T16:36:51Z
2,172,597
<p>This Python program assumes that the source files are in <code>data</code> and that the new directory structure should be in <code>target</code> (and that it already exists).</p> <p>The key point is that <code>os.path.walk</code> will traverse the <code>data</code> directory structure and call <code>myVisitor</code...
0
2010-01-31T17:28:15Z
[ "python", "perl", "bash", "unix", "batch-file" ]
How to create folders using file names and then move files into folders?
2,172,420
<p>I have hundreds of text files in a folder named using this kind of naming convention:</p> <pre><code>Bandname1 - song1.txt Bandname1 - song2.txt Bandname2 - song1.txt Bandname2 - song2.txt Bandname2 - song3.txt Bandname3 - song1.txt ..etc. </code></pre> <p>I would like to create folders for different bands and mov...
4
2010-01-31T16:36:51Z
2,172,657
<p>It's not necessary to use trim or xargs:</p> <pre><code>for f in *.txt; do band=${f% - *} mkdir -p "$band" mv "$f" "$band" done </code></pre>
3
2010-01-31T17:50:29Z
[ "python", "perl", "bash", "unix", "batch-file" ]
How to create folders using file names and then move files into folders?
2,172,420
<p>I have hundreds of text files in a folder named using this kind of naming convention:</p> <pre><code>Bandname1 - song1.txt Bandname1 - song2.txt Bandname2 - song1.txt Bandname2 - song2.txt Bandname2 - song3.txt Bandname3 - song1.txt ..etc. </code></pre> <p>I would like to create folders for different bands and mov...
4
2010-01-31T16:36:51Z
2,173,960
<p>with Perl</p> <pre><code>use File::Copy move; while (my $file= &lt;*.txt&gt; ){ my ($band,$others) = split /\s+-\s+/ ,$file ; mkdir $band; move($file, $band); } </code></pre>
2
2010-02-01T00:05:47Z
[ "python", "perl", "bash", "unix", "batch-file" ]
Why is my simple python gtk+cairo program running so slowly/stutteringly?
2,172,525
<p>My program draws circles moving on the window. I think I must be missing some basic gtk/cairo concept because it seems to be running too slowly/stutteringly for what I am doing. Any ideas? Thanks for any help!</p> <pre><code>#!/usr/bin/python import gtk import gtk.gdk as gdk import math import random import gobje...
9
2010-01-31T17:04:13Z
2,172,729
<p>I don't see anything fundamentally wrong with your code. To narrow the problem down I tried a different approach that may be minimally faster, but the difference is almost negligible:</p> <pre><code>class Area(gtk.DrawingArea): def do_expose_event(self, event): cr = self.window.cairo_create() #...
1
2010-01-31T18:14:25Z
[ "python", "animation", "gtk", "pygtk", "cairo" ]
Why is my simple python gtk+cairo program running so slowly/stutteringly?
2,172,525
<p>My program draws circles moving on the window. I think I must be missing some basic gtk/cairo concept because it seems to be running too slowly/stutteringly for what I am doing. Any ideas? Thanks for any help!</p> <pre><code>#!/usr/bin/python import gtk import gtk.gdk as gdk import math import random import gobje...
9
2010-01-31T17:04:13Z
2,173,992
<p>One of the problems is that you are drawing the same basic object again and again. I'm not sure about GTK+ buffering behavior, but also keep in mind that basic function calls incur a cost in Python. I've added a frame counter to your program, and I with your code, I got around 30fps max.</p> <p>There are several th...
10
2010-02-01T00:16:56Z
[ "python", "animation", "gtk", "pygtk", "cairo" ]
Why is my simple python gtk+cairo program running so slowly/stutteringly?
2,172,525
<p>My program draws circles moving on the window. I think I must be missing some basic gtk/cairo concept because it seems to be running too slowly/stutteringly for what I am doing. Any ideas? Thanks for any help!</p> <pre><code>#!/usr/bin/python import gtk import gtk.gdk as gdk import math import random import gobje...
9
2010-01-31T17:04:13Z
3,011,596
<p>I have got the same problem in program was written on C#. Before you leaves <code>Expose</code> event, try to write <code>cr.dispose()</code>.</p>
0
2010-06-10T04:14:48Z
[ "python", "animation", "gtk", "pygtk", "cairo" ]
Where can i get OpenCV for python?
2,172,573
<p>Where can i get OpenCV for python?What are the pre-requisites?? i tried to install opencv-python through synaptic package manager but Python says </p> <blockquote> <p>No module named CVtypes</p> </blockquote>
7
2010-01-31T17:20:57Z
2,172,581
<p>Tried the official website? <a href="http://opencv.willowgarage.com/wiki/Welcome" rel="nofollow">http://opencv.willowgarage.com/wiki/Welcome</a></p>
0
2010-01-31T17:23:14Z
[ "python", "opencv" ]
Where can i get OpenCV for python?
2,172,573
<p>Where can i get OpenCV for python?What are the pre-requisites?? i tried to install opencv-python through synaptic package manager but Python says </p> <blockquote> <p>No module named CVtypes</p> </blockquote>
7
2010-01-31T17:20:57Z
2,202,369
<p>CVTypes is a third party implementation that essentially wraps python around objects written in C, the language that OpenCV is written in (along with C++). If you want to use that, you will have to download and install it separately, as it is not part of the standard repositories of Ubuntu's Synaptic package manager...
5
2010-02-04T19:01:28Z
[ "python", "opencv" ]
Where can i get OpenCV for python?
2,172,573
<p>Where can i get OpenCV for python?What are the pre-requisites?? i tried to install opencv-python through synaptic package manager but Python says </p> <blockquote> <p>No module named CVtypes</p> </blockquote>
7
2010-01-31T17:20:57Z
3,831,773
<p>OpenCV over time has accumulated numerous Python bindings, mostly due to the strange way arrays are represented in OpenCV (IMHO). Here is a short list:</p> <ul> <li><a href="http://code.google.com/p/pyopencv/" rel="nofollow">PyOpenCV</a></li> <li><a href="http://stefanv.github.com/scikits.image/api/scikits.image.op...
4
2010-09-30T14:51:49Z
[ "python", "opencv" ]
Where can i get OpenCV for python?
2,172,573
<p>Where can i get OpenCV for python?What are the pre-requisites?? i tried to install opencv-python through synaptic package manager but Python says </p> <blockquote> <p>No module named CVtypes</p> </blockquote>
7
2010-01-31T17:20:57Z
4,110,918
<p>check your <code>openCV</code> version. Version 2 needs a simple</p> <pre><code>import cv </code></pre> <p>you may have a look at the <code>samples/python</code> folder.</p>
0
2010-11-05T23:18:43Z
[ "python", "opencv" ]
Where can i get OpenCV for python?
2,172,573
<p>Where can i get OpenCV for python?What are the pre-requisites?? i tried to install opencv-python through synaptic package manager but Python says </p> <blockquote> <p>No module named CVtypes</p> </blockquote>
7
2010-01-31T17:20:57Z
10,070,758
<p>get it from <a href="http://www.lfd.uci.edu/~gohlke/pythonlibs/#opencv" rel="nofollow">here</a> unofficial binary packages.</p> <p>by the way, they provide unofficial packages for many other projects</p>
2
2012-04-09T08:33:01Z
[ "python", "opencv" ]
Where can i get OpenCV for python?
2,172,573
<p>Where can i get OpenCV for python?What are the pre-requisites?? i tried to install opencv-python through synaptic package manager but Python says </p> <blockquote> <p>No module named CVtypes</p> </blockquote>
7
2010-01-31T17:20:57Z
16,901,672
<p>this webpage explains in great depth on the installation <a href="http://opencvpython.blogspot.com/2012/05/install-opencv-in-windows-for-python.html" rel="nofollow">http://opencvpython.blogspot.com/2012/05/install-opencv-in-windows-for-python.html</a></p> <p>after the installation try out the samples provided by op...
-1
2013-06-03T16:42:08Z
[ "python", "opencv" ]
Python: automated change in variable contents
2,172,654
<p>I have a Python function which receives numerous variables, and builds an SQL query out of them:</p> <pre><code>def myfunc(name=None, abbr=None, grade=None, ...) </code></pre> <p>These values should build an SQL query. For that purpose, Those who equal <code>None</code> should be changed to <code>NULL</code>, and ...
1
2010-01-31T17:50:08Z
2,172,663
<p>The best way to form a SQL query is not by string-formatting -- the <code>execute</code> method of a <code>cursor</code> object takes a query string <em>with placeholders</em> and a sequence (or dict, depending on the exact implementation you have of the DB API) with the values to substitute there; it will then perf...
5
2010-01-31T17:54:44Z
[ "python", "variables", "psycopg2" ]
Python: automated change in variable contents
2,172,654
<p>I have a Python function which receives numerous variables, and builds an SQL query out of them:</p> <pre><code>def myfunc(name=None, abbr=None, grade=None, ...) </code></pre> <p>These values should build an SQL query. For that purpose, Those who equal <code>None</code> should be changed to <code>NULL</code>, and ...
1
2010-01-31T17:50:08Z
2,172,675
<p>You could define <code>myfunc</code> as follows:</p> <pre><code>def myfunc(*args, **kwargs) </code></pre> <p>Where kwargs is a dictionary holding all named parameters passed to the function.</p> <p>To get the value of a query parameter, you would use <code>kwargs.get(name_of_parameter, 'NULL')</code>. To build th...
0
2010-01-31T17:57:30Z
[ "python", "variables", "psycopg2" ]
Python: automated change in variable contents
2,172,654
<p>I have a Python function which receives numerous variables, and builds an SQL query out of them:</p> <pre><code>def myfunc(name=None, abbr=None, grade=None, ...) </code></pre> <p>These values should build an SQL query. For that purpose, Those who equal <code>None</code> should be changed to <code>NULL</code>, and ...
1
2010-01-31T17:50:08Z
2,272,147
<p>The correct way to pass arguments to psycopg2 is to use placeholders and <a href="http://initd.org/psycopg/docs/usage.html#passing-parameters-to-sql-queries" rel="nofollow">let the driver handle the values</a>. None are converted to NULL automatically and the correct string escaping is performed. </p> <p>Concatenat...
0
2010-02-16T10:34:40Z
[ "python", "variables", "psycopg2" ]
How to do a JOIN in SQLAlchemy on 3 tables, where one of them is mapping between other two?
2,173,031
<p>Suppose I have the following tables:</p> <ul> <li><code>Articles</code> with fields <code>article_id</code>, <code>title</code></li> <li><code>Tags</code> with fields <code>tag_id</code>, <code>name</code></li> <li><code>ArticleTags</code> with fields <code>article_id</code>, <code>tag_id</code></li> </ul> <p>And ...
9
2010-01-31T19:36:18Z
2,173,083
<p>Assuming that you set the ForeignKey constraints correctly and created mappers:</p> <pre><code>q = Session.query(Articles).filter(Articles.article_id == ArticleTags.article_id).\ filter(ArticleTags.tag_id == Tags.tag_id).\ filter(Tags.name == 'tag_name') </code></pre> <p>If you have setup a Many-to-Many re...
9
2010-01-31T19:55:49Z
[ "python", "sql", "sqlalchemy" ]
How to create nested lists in python?
2,173,087
<p>I know you can create easily nested lists in python like this:</p> <pre><code>[[1,2],[3,4]] </code></pre> <p>But how to create a 3x3x3 matrix of zeroes?</p> <pre><code>[[[0] * 3 for i in range(0, 3)] for j in range (0,3)] </code></pre> <p>or </p> <pre><code>[[[0]*3]*3]*3 </code></pre> <p>Doesn't seem right. Th...
6
2010-01-31T19:58:25Z
2,173,098
<p>Just nest the multiplication syntax:</p> <pre><code>[[[0] * 3] * 3] * 3 </code></pre> <p>It's therefore simple to express this operation using <a href="http://en.wikipedia.org/wiki/Fold_%28higher-order_function%29" rel="nofollow">folds</a></p> <pre><code>def zeros(dimensions): return reduce(lambda x, d: [x] *...
-3
2010-01-31T20:01:31Z
[ "python", "list", "arrays", "matrix", "nested-lists" ]
How to create nested lists in python?
2,173,087
<p>I know you can create easily nested lists in python like this:</p> <pre><code>[[1,2],[3,4]] </code></pre> <p>But how to create a 3x3x3 matrix of zeroes?</p> <pre><code>[[[0] * 3 for i in range(0, 3)] for j in range (0,3)] </code></pre> <p>or </p> <pre><code>[[[0]*3]*3]*3 </code></pre> <p>Doesn't seem right. Th...
6
2010-01-31T19:58:25Z
2,173,118
<p>NumPy addresses this problem</p> <p><a href="http://www.scipy.org/Tentative_NumPy_Tutorial#head-d3f8e5fe9b903f3c3b2a5c0dfceb60d71602cf93" rel="nofollow">http://www.scipy.org/Tentative_NumPy_Tutorial#head-d3f8e5fe9b903f3c3b2a5c0dfceb60d71602cf93</a></p> <pre><code>&gt;&gt;&gt; a = array( [2,3,4] ) &gt;&gt;&gt; a ar...
1
2010-01-31T20:06:51Z
[ "python", "list", "arrays", "matrix", "nested-lists" ]
How to create nested lists in python?
2,173,087
<p>I know you can create easily nested lists in python like this:</p> <pre><code>[[1,2],[3,4]] </code></pre> <p>But how to create a 3x3x3 matrix of zeroes?</p> <pre><code>[[[0] * 3 for i in range(0, 3)] for j in range (0,3)] </code></pre> <p>or </p> <pre><code>[[[0]*3]*3]*3 </code></pre> <p>Doesn't seem right. Th...
6
2010-01-31T19:58:25Z
2,173,119
<p>In case a matrix is actually what you are looking for, consider the numpy package.</p> <p><a href="http://docs.scipy.org/doc/numpy/reference/generated/numpy.zeros.html#numpy.zeros" rel="nofollow">http://docs.scipy.org/doc/numpy/reference/generated/numpy.zeros.html#numpy.zeros</a></p> <p>This will give you a 3x3x3 ...
9
2010-01-31T20:06:55Z
[ "python", "list", "arrays", "matrix", "nested-lists" ]
How to create nested lists in python?
2,173,087
<p>I know you can create easily nested lists in python like this:</p> <pre><code>[[1,2],[3,4]] </code></pre> <p>But how to create a 3x3x3 matrix of zeroes?</p> <pre><code>[[[0] * 3 for i in range(0, 3)] for j in range (0,3)] </code></pre> <p>or </p> <pre><code>[[[0]*3]*3]*3 </code></pre> <p>Doesn't seem right. Th...
6
2010-01-31T19:58:25Z
2,173,120
<p>List comprehensions are just syntactic sugar for adding expressiveness to list initialization; in your case, I would not use them at all, and go for a simple nested loop.</p> <p>On a completely different level: <strong>do you think the <a href="http://docs.scipy.org/doc/numpy/reference/arrays.ndarray.html#arrays-nd...
1
2010-01-31T20:07:43Z
[ "python", "list", "arrays", "matrix", "nested-lists" ]
How to create nested lists in python?
2,173,087
<p>I know you can create easily nested lists in python like this:</p> <pre><code>[[1,2],[3,4]] </code></pre> <p>But how to create a 3x3x3 matrix of zeroes?</p> <pre><code>[[[0] * 3 for i in range(0, 3)] for j in range (0,3)] </code></pre> <p>or </p> <pre><code>[[[0]*3]*3]*3 </code></pre> <p>Doesn't seem right. Th...
6
2010-01-31T19:58:25Z
2,321,345
<p>Or use the nest function defined <a href="http://code.activestate.com/recipes/577061-nest-a-flat-list/" rel="nofollow">here</a>, combined with repeat(0) from the itertools module:</p> <pre><code>nest(itertools.repeat(0),[3,3,3]) </code></pre>
0
2010-02-23T20:11:01Z
[ "python", "list", "arrays", "matrix", "nested-lists" ]
How can I draw nodes and edges in PyQT?
2,173,146
<p>In PyQT, how can I plot small "Nodes" at given points and connect them with edges? All of the PyQT tutorials I find are "plot a button! plot a checkbox!"</p> <p>Huge thanks in advance </p>
9
2010-01-31T20:17:35Z
2,173,152
<p>You can find an excellent tutorial <a href="http://www.commandprompt.com/community/pyqt/c7391" rel="nofollow">here</a> (and it doesn't "plot" buttons or checkboxes -- it draws lines, just as you want!).</p>
3
2010-01-31T20:20:28Z
[ "python", "user-interface", "graph", "pyqt" ]
How can I draw nodes and edges in PyQT?
2,173,146
<p>In PyQT, how can I plot small "Nodes" at given points and connect them with edges? All of the PyQT tutorials I find are "plot a button! plot a checkbox!"</p> <p>Huge thanks in advance </p>
9
2010-01-31T20:17:35Z
2,178,282
<p>If you want to be able to interact with the objects displayed in the plot, you will be better off using a <a href="http://doc.trolltech.com/4.6/qgraphicsscene.html" rel="nofollow" title="QGraphicsScene">QGraphicsScene</a>. It handles zooming and panning and can contain other <a href="http://doc.trolltech.com/4.6/qgr...
3
2010-02-01T16:32:37Z
[ "python", "user-interface", "graph", "pyqt" ]
How can I draw nodes and edges in PyQT?
2,173,146
<p>In PyQT, how can I plot small "Nodes" at given points and connect them with edges? All of the PyQT tutorials I find are "plot a button! plot a checkbox!"</p> <p>Huge thanks in advance </p>
9
2010-01-31T20:17:35Z
27,369,913
<p>It has been a pain to find a good explanation for this (as of by the end of 2014 already), and since this question asks exactely what I was looking for, I'll post a transcription (from C++ to Python) of what I found in <a href="http://www.qtcentre.org/archive/index.php/t-56257.html" rel="nofollow">this post</a>.</p>...
2
2014-12-09T01:16:42Z
[ "python", "user-interface", "graph", "pyqt" ]
Is there any way to create a class property in Python?
2,173,206
<p>The following doesn't work for some reason:</p> <pre><code>&gt;&gt;&gt; class foo(object): ... @property ... @classmethod ... def bar(cls): ... return "asdf" ... &gt;&gt;&gt; foo.bar &lt;property object at 0x1da8d0&gt; &gt;&gt;&gt; foo.bar + '\n' Traceback (most recent call last): File "&...
8
2010-01-31T20:36:28Z
2,173,321
<p>If you want the descriptor <code>property</code> to trigger when you get an attribute from object X, then you must put the descriptor in <code>type(X)</code>. So if X is a class, the descriptor must go in the class's type, also known as the class's metaclass -- no "trickery" involved, it's just a matter of complete...
6
2010-01-31T21:05:28Z
[ "python", "class", "properties", "class-method" ]
Python Iteration Problem!
2,173,238
<p>I have this code here, it is supposed to remove the common letters from both the lists n1 and n2. But when i run this code it only runs once as in it removes only 'a' from both n1 and n2 and doesnt remove 'k'.</p> <p>Just to clarify this code should always work on only 2 words.</p> <pre><code>name1 = "abdjek" name...
4
2010-01-31T20:41:58Z
2,173,291
<p>It's working here for me. That is, if I add print statements thus:</p> <pre><code>name1 = "abdjek" name2 = "doarhsnk" n1l = list(name1) n2l = list(name2) print "Lists before loop:" print n1l print n2l for i in range(len(n1l)): for j in range(len(n2l)): if n1l[i] == n2l[j]: n1l.pop(i) ...
0
2010-01-31T20:54:44Z
[ "python", "iteration" ]
Python Iteration Problem!
2,173,238
<p>I have this code here, it is supposed to remove the common letters from both the lists n1 and n2. But when i run this code it only runs once as in it removes only 'a' from both n1 and n2 and doesnt remove 'k'.</p> <p>Just to clarify this code should always work on only 2 words.</p> <pre><code>name1 = "abdjek" name...
4
2010-01-31T20:41:58Z
2,173,312
<p>I suggest a much simpler approach:</p> <pre><code>def removecommon(name1, name2): common = set(name1).intersection(name2) res1 = ''.join(n for n in name1 if n not in common) res2 = ''.join(n for n in name2 if n not in common) return res1, res2 n1, n2 = removecommon('naveen', 'darshana') print n1, n2 </code...
5
2010-01-31T21:02:49Z
[ "python", "iteration" ]
Python Iteration Problem!
2,173,238
<p>I have this code here, it is supposed to remove the common letters from both the lists n1 and n2. But when i run this code it only runs once as in it removes only 'a' from both n1 and n2 and doesnt remove 'k'.</p> <p>Just to clarify this code should always work on only 2 words.</p> <pre><code>name1 = "abdjek" name...
4
2010-01-31T20:41:58Z
2,173,319
<p>A more <em>pythonic</em> approach would be to use <code>set</code>s and list comprehensions.</p> <pre><code>name1 = "naveen"; name2 = "darshana" name1_set=set(name1) name2_set=set(name2) clean1=[x for x in name1 if x not in name2_set] clean2=[x for x in name2 if x not in name1_set] clean1.extend(['0']*(len(name...
2
2010-01-31T21:05:07Z
[ "python", "iteration" ]
Python Iteration Problem!
2,173,238
<p>I have this code here, it is supposed to remove the common letters from both the lists n1 and n2. But when i run this code it only runs once as in it removes only 'a' from both n1 and n2 and doesnt remove 'k'.</p> <p>Just to clarify this code should always work on only 2 words.</p> <pre><code>name1 = "abdjek" name...
4
2010-01-31T20:41:58Z
2,173,394
<p>Your code might not be working as you expect it to, as it is removing paired letters. For instance, you see an a, you then remove both a's from your words... </p>
0
2010-01-31T21:21:08Z
[ "python", "iteration" ]
Python Iteration Problem!
2,173,238
<p>I have this code here, it is supposed to remove the common letters from both the lists n1 and n2. But when i run this code it only runs once as in it removes only 'a' from both n1 and n2 and doesnt remove 'k'.</p> <p>Just to clarify this code should always work on only 2 words.</p> <pre><code>name1 = "abdjek" name...
4
2010-01-31T20:41:58Z
2,173,448
<p>Your code most probably fails because you pop common letters from anywhere in the list, but append the replacements ("0" and "1") to the <em>end</em> of the list. They should be at position <em>i</em> and <em>j</em>, respectively.</p> <p>So the loop should probably look like this:</p> <pre><code>for i in range(len...
0
2010-01-31T21:36:31Z
[ "python", "iteration" ]
Python Iteration Problem!
2,173,238
<p>I have this code here, it is supposed to remove the common letters from both the lists n1 and n2. But when i run this code it only runs once as in it removes only 'a' from both n1 and n2 and doesnt remove 'k'.</p> <p>Just to clarify this code should always work on only 2 words.</p> <pre><code>name1 = "abdjek" name...
4
2010-01-31T20:41:58Z
2,181,995
<p>Here's some quite (IMHO quite elegant) code that runs in O(n). If word 1 has N occurrences of the letter x, it removes the first N x's from word 2 (and vice versa) -- I think this is what you want, but I could be wrong.</p> <pre><code>from collections import defaultdict def build(s, chars_s, chars_t): """Retur...
0
2010-02-02T05:06:55Z
[ "python", "iteration" ]
In Python, what is a preferred naming convention for the backing store of an internal property?
2,173,409
<p>Say you have a public method in Python whose primary purpose is to retrieve the value of an underlying data attribute (i.e. internal backing store). The method may have lazy evaluation logic, etc. A property is an example of such a method.</p> <p>Then it is natural to use the same name for the method and data attri...
7
2010-01-31T21:25:18Z
2,173,429
<p>Why would you make it a property if it is for internal use? If it's for internal use, just access the attribute directly.</p> <p>But then you would still use one underscore, but call it something else. But again, the whole point of making it a property is lost in this case.</p>
1
2010-01-31T21:30:14Z
[ "python", "properties" ]
In Python, what is a preferred naming convention for the backing store of an internal property?
2,173,409
<p>Say you have a public method in Python whose primary purpose is to retrieve the value of an underlying data attribute (i.e. internal backing store). The method may have lazy evaluation logic, etc. A property is an example of such a method.</p> <p>Then it is natural to use the same name for the method and data attri...
7
2010-01-31T21:25:18Z
15,162,614
<p>The preferred convention is to use a single leading underscore.</p> <p>This is the <a href="http://www.python.org/dev/peps/pep-0008/" rel="nofollow">PEP 8</a> recommendation for private attributes.</p> <p>See this example in the docstring for property():</p> <pre><code>&gt;&gt;&gt; help(property) Help on class pr...
3
2013-03-01T16:45:13Z
[ "python", "properties" ]
two conflicting meanings of builtins in python 3 (python 3.1, python 3k, python3000)
2,173,425
<p>I just posted below query to comp.lang.python, but i feel this kind of question has some kind of right-of-way here on Stack Overflow, too, so be it repeated. the essence: why does ‘builtins’ have two distinct interpretations in Python 3?</p> <p>I would be very gladly accept any commentaries about what this sent...
3
2010-01-31T21:29:39Z
2,173,457
<p><code>getattr(__builtins__, '__dict__', __builtins__)</code> should give you the dict that you want to update to "export names to the global namespace", whether <code>__builtins__</code> is a dict (then it doesn't have a <code>__dict__</code> attribute so <code>getattr</code> returns the third argument, which is the...
1
2010-01-31T21:38:38Z
[ "python", "python-3.x", "builtins" ]
In PyQt, how can signals and slots be used to connect a dropdownlist to a function?
2,173,449
<p>In PyQt, there's a concept of signals and slots to connect objects to one another's functions, but I can't seem to find them referenced to functions not associated with other objects. For example, I want a dropdown list to have algorithm A or algorithm B run.</p> <p>How does PyQt accomplish this functionality?</p>...
4
2010-01-31T21:37:07Z
2,173,542
<p>Do you want the effect of changing the drop down list to call a function?</p> <p>Connect the dropdown list's appropriate signal to your function.</p> <p>For example with the <a href="http://doc.trolltech.com/4.4/qcombobox.html#currentIndexChanged" rel="nofollow">QComboBox</a> currentIndexChanged() signal. Connect ...
3
2010-01-31T21:59:30Z
[ "python", "user-interface", "pyqt" ]
Returning binomal as a tuple
2,173,451
<p>I want to save the results of my function binomal_aux to a tuple but I don't have an idea how to, here is my code I have right now.</p> <pre><code>def binomal (n): i=0 for i in range(n): binomal_aux(n,i) #want this to be in a tuple so, binomal (2) = (1,2,1) return def binomal_aux (n,k): ...
0
2010-01-31T21:37:30Z
2,173,466
<pre><code>def binomal (n): return tuple(binomal_aux(n,i) for i in range(n+1)) </code></pre>
0
2010-01-31T21:41:17Z
[ "python", "recursion", "tuples" ]
Returning binomal as a tuple
2,173,451
<p>I want to save the results of my function binomal_aux to a tuple but I don't have an idea how to, here is my code I have right now.</p> <pre><code>def binomal (n): i=0 for i in range(n): binomal_aux(n,i) #want this to be in a tuple so, binomal (2) = (1,2,1) return def binomal_aux (n,k): ...
0
2010-01-31T21:37:30Z
2,173,481
<p>In your <code>binomal</code> function, just make the tuple you want to return.</p> <pre><code>def binomal(n): return tuple(binomal_aux(n, i) for i in range(n+1)) </code></pre> <p>Note also that the correct spelling is <code>binom</code><em>i</em><code>al</code>.</p>
2
2010-01-31T21:43:47Z
[ "python", "recursion", "tuples" ]
Returning binomal as a tuple
2,173,451
<p>I want to save the results of my function binomal_aux to a tuple but I don't have an idea how to, here is my code I have right now.</p> <pre><code>def binomal (n): i=0 for i in range(n): binomal_aux(n,i) #want this to be in a tuple so, binomal (2) = (1,2,1) return def binomal_aux (n,k): ...
0
2010-01-31T21:37:30Z
2,173,523
<p>Alternate way:</p> <pre><code>def binomal(n): from itertools import combinations return tuple(len(list(combinations(range(n), r=t))) for t in range(n + 1)) </code></pre>
0
2010-01-31T21:52:50Z
[ "python", "recursion", "tuples" ]
Python lib for generating 3d charts?
2,173,484
<p>Is there any charting lib for python that can generate 3d charts like <a href="http://www.geatbx.com/docu/fcnindex-msh_f6_1-15.gif" rel="nofollow">this one</a>?</p>
2
2010-01-31T21:44:01Z
2,173,496
<p><a href="http://matplotlib.sourceforge.net/" rel="nofollow">http://matplotlib.sourceforge.net/</a></p>
5
2010-01-31T21:46:09Z
[ "python", "charts" ]
Python lib for generating 3d charts?
2,173,484
<p>Is there any charting lib for python that can generate 3d charts like <a href="http://www.geatbx.com/docu/fcnindex-msh_f6_1-15.gif" rel="nofollow">this one</a>?</p>
2
2010-01-31T21:44:01Z
2,173,499
<p>There are many possibilities, I believe <a href="http://mayavi.sourceforge.net/" rel="nofollow">mayavi</a> may be the most popular (if you give more specs about what you're trying to do and what your constraints are you may get more accurate suggestions).</p>
5
2010-01-31T21:46:57Z
[ "python", "charts" ]
How do I encode WSGI output in UTF-8?
2,173,592
<p>I want to send an HTML page to the web browser encoded as UTF-8. However the following example fails:</p> <pre><code>from wsgiref.simple_server import make_server def app(environ, start_response): output = "&lt;html&gt;&lt;body&gt;&lt;p&gt;Räksmörgås&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;".encode('utf-8') ...
2
2010-01-31T22:14:46Z
2,173,655
<p>You need to return the page as a list:</p> <pre><code>def app(environ, start_response): output = "&lt;html&gt;&lt;body&gt;&lt;p&gt;Räksmörgås&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;".encode('utf-8') start_response('200 OK', [ ('Content-Type', 'text/html; charset=utf-8'), ('Content-Length', st...
5
2010-01-31T22:32:25Z
[ "python", "python-3.x", "wsgi", "wsgiref" ]
How do I encode WSGI output in UTF-8?
2,173,592
<p>I want to send an HTML page to the web browser encoded as UTF-8. However the following example fails:</p> <pre><code>from wsgiref.simple_server import make_server def app(environ, start_response): output = "&lt;html&gt;&lt;body&gt;&lt;p&gt;Räksmörgås&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;".encode('utf-8') ...
2
2010-01-31T22:14:46Z
20,687,023
<p>edit</p> <pre><code>vim /usr/lib/python2.7/site.py encoding = "ascii" # Default value set by _PyUnicode_Init() </code></pre> <p>to</p> <pre><code>encoding = "utf-8" </code></pre> <p>reboot system</p> <p>para forcar o python 2.7 a trabalhar com utf-8 como padrão pois o mod_wsgi busca a codificacao padrao do py...
0
2013-12-19T16:39:10Z
[ "python", "python-3.x", "wsgi", "wsgiref" ]
python chaco axis labels time formatting
2,173,632
<p>In Enthought's Chaco, the <code>TimeFormatter</code> class is used to format the time string of the tick labels. is there a way to specify the time format (something like <code>time.strftime()</code>). </p> <p>the source code now hard-codes the format when displaying month and day of the month to the american styl...
5
2010-01-31T22:26:05Z
2,246,394
<p>Honestly, the easiest way is going to be to monkeypatch the TimeFormatter's _formats dictionary:</p> <pre><code>from enthought.chaco.scales.formatters import TimeFormatter TimeFormatter._formats['days'] = ('%d/%m', '%d%a',) </code></pre> <p>If you don't want to do this, then you need to subclass TimeFormatter. Th...
4
2010-02-11T17:47:23Z
[ "python", "chaco" ]
how to sort 2d array by row in python?
2,173,797
<p>i have 2d array,dimension 3x10,and i want to sort by values in 2nd row,from lowest to highest value,any useful tip?</p>
12
2010-01-31T23:11:51Z
2,173,841
<p>Well, if you're talking about standard python lists, this is easy: <code>mylist[1].sort()</code>. For example:</p> <pre><code>&gt;&gt;&gt; from random import randint &gt;&gt;&gt; a_list = [[randint(1,15) for _ in range(10)] for _ in range(3)] &gt;&gt;&gt; print a_list [[3, 12, 3, 12, 13, 5, 12, 2, 1, 13], [3, 8, 7,...
0
2010-01-31T23:22:56Z
[ "python" ]
how to sort 2d array by row in python?
2,173,797
<p>i have 2d array,dimension 3x10,and i want to sort by values in 2nd row,from lowest to highest value,any useful tip?</p>
12
2010-01-31T23:11:51Z
2,173,843
<p>Python, per se, has no "2d array" -- it has (1d) lists as built-ins, and (1d) arrays in standard library module <a href="http://docs.python.org/library/array.html?highlight=array#module-array">array</a>. There are third-party libraries such as <code>numpy</code> which do provide Python-usable multi-dimensional arra...
18
2010-01-31T23:23:40Z
[ "python" ]
how to sort 2d array by row in python?
2,173,797
<p>i have 2d array,dimension 3x10,and i want to sort by values in 2nd row,from lowest to highest value,any useful tip?</p>
12
2010-01-31T23:11:51Z
2,173,873
<p>How does your "2D array" look like?</p> <p>For example:</p> <pre><code>&gt;&gt;&gt; a = [ [12, 18, 6, 3], [ 4, 3, 1, 2], [15, 8, 9, 6] ] &gt;&gt;&gt; a.sort(key=lambda x: x[1]) &gt;&gt;&gt; a [[4, 3, 1, 2], [15, 8, 9, 6], [12, 18, 6, 3]] </code></pre> <p>But I guess you want something li...
21
2010-01-31T23:30:31Z
[ "python" ]
how to sort 2d array by row in python?
2,173,797
<p>i have 2d array,dimension 3x10,and i want to sort by values in 2nd row,from lowest to highest value,any useful tip?</p>
12
2010-01-31T23:11:51Z
2,173,973
<p>Rather than use <code>lambda x: x[1]</code> you can use operator.itemgetter as the key to the sort or sorted functions. itemgetter(n) creates a function that gets the nth item from a list.</p> <pre><code>&gt;&gt;&gt; matrix = [ [4,5,6], [1,2,3], [7,0,9]] &gt;&gt;&gt; from operator import itemgetter &gt;&gt;&gt; so...
5
2010-02-01T00:12:37Z
[ "python" ]
how to sort 2d array by row in python?
2,173,797
<p>i have 2d array,dimension 3x10,and i want to sort by values in 2nd row,from lowest to highest value,any useful tip?</p>
12
2010-01-31T23:11:51Z
15,521,961
<p>This is a little function I wrote for this purpose:</p> <pre><code>def sorted_table(data, column=0, reverse=False): return sorted(data, cmp=lambda a,b: cmp(a[column], b[column]), reverse=reverse) </code></pre> <p>Actually, I had a bit more complex requirement, which is to sort the table by two columns. It turn...
0
2013-03-20T11:14:45Z
[ "python" ]
Can't get wx.BufferedDC to draw anything
2,173,821
<p>I've got a problem with DCs. I'm trying to make an application that will draw many lines on the screens and needs to update really fast, and since I don't want flickering, I decided to give buffered dcs a shot. But when I run this code, it doesn't draw anything. What am I doing wrong?</p> <pre><code>import wx clas...
1
2010-01-31T23:17:47Z
2,174,017
<p>A BufferedDC is copied to the screen only when the object is destroy. Since you never destroy <code>self.bdc</code>, of course its contents will never be copied to the screen. So, you need to arrange to let go of <code>self.bdc</code> (maybe just replace it with a new BufferedDc instance: i.e., redo the assignment...
1
2010-02-01T00:27:53Z
[ "python", "wx" ]
Can't get wx.BufferedDC to draw anything
2,173,821
<p>I've got a problem with DCs. I'm trying to make an application that will draw many lines on the screens and needs to update really fast, and since I don't want flickering, I decided to give buffered dcs a shot. But when I run this code, it doesn't draw anything. What am I doing wrong?</p> <pre><code>import wx clas...
1
2010-01-31T23:17:47Z
2,174,076
<p>I've used AutoBufferedPaintDC, but I've found doing my own double-buffering with a MemoryDC to be more flexible. Here's a template for you.</p> <pre><code>import wx class Frame(wx.Frame): def __init__(self): super(Frame, self).__init__(None, -1, 'CursorTracker') self.mdc = None # memory dc to ...
2
2010-02-01T00:48:41Z
[ "python", "wx" ]
pinax ImportError cannot import name UserOpenidAssociation
2,173,829
<p>i have these errors ImportError at / cannot import name UserOpenidAssociation i could make any sense out of the traceback </p> <p>equest Method: GET Request URL: <a href="http://127.0.0.1:8000/" rel="nofollow">http://127.0.0.1:8000/</a> Django Version: 1.1.1 Python Version: 2.6.1 Installed Applications: ['inventory...
0
2010-01-31T23:20:19Z
2,174,822
<p><code>sudo pip install django_openid</code></p>
0
2010-02-01T05:27:24Z
[ "python", "django", "pinax" ]
Why is this genexp performing worse than a list comprehension?
2,173,845
<p>I was trying to find the quickest way to count the number of items in a list matching a specific filter. In this case, finding how many odd numbers there are in a list.</p> <p>While doing this, I was surprised by the results of comparing a list comprehension vs the equivalent generator expression:</p> <pre><code>p...
6
2010-01-31T23:23:57Z
2,173,869
<p>When essentially unlimited memory is available (which will invariably be the case in tiny benchmarks, although often not in real-world problems!-), lists will tend to outperform generators because they can get allocated just once, in one "big bunch" (no memory fragmentation, etc), while generators require (internall...
14
2010-01-31T23:29:29Z
[ "python", "list-comprehension", "generator-expression" ]
Why is this genexp performing worse than a list comprehension?
2,173,845
<p>I was trying to find the quickest way to count the number of items in a list matching a specific filter. In this case, finding how many odd numbers there are in a list.</p> <p>While doing this, I was surprised by the results of comparing a list comprehension vs the equivalent generator expression:</p> <pre><code>p...
6
2010-01-31T23:23:57Z
2,173,878
<p>From what I remember, a generator frame have to be activated for each result, whereas the list comprehension uses the one activation frame. The incremental cost in the list compression is the added cost of the memory -- references to int in your case. The relation may well reverse if each item is a new instance an...
3
2010-01-31T23:31:59Z
[ "python", "list-comprehension", "generator-expression" ]
How do I get virtualenvwrapper and cygwin to co-operate?
2,173,963
<p>I am trying to get <code>virtualenv[wrapper]</code> to work on my Windows machine through Cygwin. The install is successful, together with <code>easy_install</code>, based on these directions: <a href="http://www.doughellmann.com/docs/virtualenvwrapper/" rel="nofollow">http://www.doughellmann.com/docs/virtualenvwr...
8
2010-02-01T00:06:48Z
4,321,352
<p>This post looks promising <a href="http://atbrox.com/2009/09/21/how-to-get-pipvirtualenvfabric-working-on-cygwin/" rel="nofollow">http://atbrox.com/2009/09/21/how-to-get-pipvirtualenvfabric-working-on-cygwin/</a></p> <p>-- Quentin</p>
1
2010-12-01T05:02:47Z
[ "python", "cygwin", "virtualenv" ]
How do I get virtualenvwrapper and cygwin to co-operate?
2,173,963
<p>I am trying to get <code>virtualenv[wrapper]</code> to work on my Windows machine through Cygwin. The install is successful, together with <code>easy_install</code>, based on these directions: <a href="http://www.doughellmann.com/docs/virtualenvwrapper/" rel="nofollow">http://www.doughellmann.com/docs/virtualenvwr...
8
2010-02-01T00:06:48Z
4,456,295
<p>I don't know virtualenv, but I'm seeing what looks like a classic mixed path syntax issue from cygwin:</p> <p>Your string is: </p> <pre><code>D:\.virtualenvs/testenv/bin/predeactivate </code></pre> <p>but Cygwin is interpreting the backslash as an escape for the "." character, producing:</p> <pre><code>D:.virtua...
0
2010-12-16T00:11:00Z
[ "python", "cygwin", "virtualenv" ]
How do I get virtualenvwrapper and cygwin to co-operate?
2,173,963
<p>I am trying to get <code>virtualenv[wrapper]</code> to work on my Windows machine through Cygwin. The install is successful, together with <code>easy_install</code>, based on these directions: <a href="http://www.doughellmann.com/docs/virtualenvwrapper/" rel="nofollow">http://www.doughellmann.com/docs/virtualenvwr...
8
2010-02-01T00:06:48Z
4,834,813
<p>I'm not experienced with virtualenvwrapper, but do use virtualenv regularly. I don't think the activate.bat is intended to be run under cygwin, it works when run in the regular windows shell. I think if you are using cygwin, you might want to use something more like bin/activate(the version for unix-like OS's).</p...
3
2011-01-29T02:49:21Z
[ "python", "cygwin", "virtualenv" ]
How do I get virtualenvwrapper and cygwin to co-operate?
2,173,963
<p>I am trying to get <code>virtualenv[wrapper]</code> to work on my Windows machine through Cygwin. The install is successful, together with <code>easy_install</code>, based on these directions: <a href="http://www.doughellmann.com/docs/virtualenvwrapper/" rel="nofollow">http://www.doughellmann.com/docs/virtualenvwr...
8
2010-02-01T00:06:48Z
12,439,971
<p>This did it for me:</p> <p><a href="https://bitbucket.org/cliffxuan/virtualenvwrapper-for-cygwin-windows-python" rel="nofollow">https://bitbucket.org/cliffxuan/virtualenvwrapper-for-cygwin-windows-python</a></p> <p>The vanilla <code>virtualenvwrapper</code> does not seem to support the Cygwin environment.</p> <p>...
1
2012-09-15T18:28:37Z
[ "python", "cygwin", "virtualenv" ]
How to install NumPy on Windows 64?
2,173,985
<p>NumPy installer can't find python path in the registry.</p> <blockquote> <hr> <h2>Cannot install</h2> <h2>Python version 2.5 required, which was not found in the registry.</h2> <h2>OK</h2> </blockquote> <p>I have to modify the registry? I already modified %PATH% to point to the Python25 installati...
4
2010-02-01T00:15:58Z
2,174,055
<p>can I check what installer you're using for this? I don't think there is an official 64bit Numpy binary, but there is an unofficial one you can try <a href="http://www.lfd.uci.edu/~gohlke/pythonlibs/">here</a>. Of course, if you've already tried this installer then let me know.</p>
5
2010-02-01T00:39:56Z
[ "python", "windows-7", "numpy", "windows-7-x64" ]
How to install NumPy on Windows 64?
2,173,985
<p>NumPy installer can't find python path in the registry.</p> <blockquote> <hr> <h2>Cannot install</h2> <h2>Python version 2.5 required, which was not found in the registry.</h2> <h2>OK</h2> </blockquote> <p>I have to modify the registry? I already modified %PATH% to point to the Python25 installati...
4
2010-02-01T00:15:58Z
2,182,498
<p>Numpy is not supported on python 2.5 for Windows 64 bits, you need at least python 2.6, and even in that case, you need to build it by yourself, or use something like EPD or the installer given in link given by thor.</p> <p>NumPy cannot be used in Google App Engine, so I am not sure to understand the argument there...
2
2010-02-02T07:38:20Z
[ "python", "windows-7", "numpy", "windows-7-x64" ]
How to install NumPy on Windows 64?
2,173,985
<p>NumPy installer can't find python path in the registry.</p> <blockquote> <hr> <h2>Cannot install</h2> <h2>Python version 2.5 required, which was not found in the registry.</h2> <h2>OK</h2> </blockquote> <p>I have to modify the registry? I already modified %PATH% to point to the Python25 installati...
4
2010-02-01T00:15:58Z
12,253,865
<p>Something is strange with the official superpack...</p> <p><a href="http://scipy.org/Download" rel="nofollow">http://scipy.org/Download</a></p> <blockquote> <p>Windows 64 bit unofficial releases Christoph Gohlke has put together an impressive collection of Windows binary installers of recent versions of scie...
2
2012-09-03T20:49:05Z
[ "python", "windows-7", "numpy", "windows-7-x64" ]
recursive nested expression in Python
2,174,015
<p>I am using Python 2.6.4.</p> <p>I have a series of select statements in a text file and I need to extract the field names from each select query. This would be easy if some of the fields didn't use nested functions like to_char() etc. </p> <p>Given select statement fields that could have several nested parenthese...
3
2010-02-01T00:27:04Z
2,174,029
<p>Regular expressions are not suitable for parsing "nested" structures. Try, instead, a full-fledged parsing kit such as <a href="http://pyparsing.wikispaces.com/" rel="nofollow">pyparsing</a> -- examples of using pyparsing specifically to parse SQL can be found <a href="http://michelhollands.net/blog/2007/10/24/usin...
11
2010-02-01T00:31:35Z
[ "python", "regex", "nested", "expression" ]
recursive nested expression in Python
2,174,015
<p>I am using Python 2.6.4.</p> <p>I have a series of select statements in a text file and I need to extract the field names from each select query. This would be easy if some of the fields didn't use nested functions like to_char() etc. </p> <p>Given select statement fields that could have several nested parenthese...
3
2010-02-01T00:27:04Z
2,174,050
<pre><code>&gt;&gt;&gt; import re &gt;&gt;&gt; string = 'ltrim(rtrim(to_char(base_field_name, format))) renamed_field_name' &gt;&gt;&gt; rx = re.compile('^(.*?\()*(.+?)(,.*?)*(,|\).*?)*$') &gt;&gt;&gt; rx.search(string).group(2) 'base_field_name' &gt;&gt;&gt; rx.search('base_field_name').group(2) 'base_field_name' </co...
2
2010-02-01T00:38:34Z
[ "python", "regex", "nested", "expression" ]
recursive nested expression in Python
2,174,015
<p>I am using Python 2.6.4.</p> <p>I have a series of select statements in a text file and I need to extract the field names from each select query. This would be easy if some of the fields didn't use nested functions like to_char() etc. </p> <p>Given select statement fields that could have several nested parenthese...
3
2010-02-01T00:27:04Z
2,174,057
<p>Either a table-driven parser as Alex Martelli suggests or a hand-written recursive descent parser. They're not hard and quite rewarding to write.</p>
2
2010-02-01T00:40:17Z
[ "python", "regex", "nested", "expression" ]
recursive nested expression in Python
2,174,015
<p>I am using Python 2.6.4.</p> <p>I have a series of select statements in a text file and I need to extract the field names from each select query. This would be easy if some of the fields didn't use nested functions like to_char() etc. </p> <p>Given select statement fields that could have several nested parenthese...
3
2010-02-01T00:27:04Z
2,174,064
<p>This may be good enough:</p> <pre><code>import re print re.match(r".*\(([^\)]+)\)", "ltrim(to_char(field_name, format)))").group(1) </code></pre> <p>You would need to do further processing. For example pick up the function name as well and pull the field name according to function signature.</p> <pre><code>.*(\w+...
1
2010-02-01T00:44:10Z
[ "python", "regex", "nested", "expression" ]
recursive nested expression in Python
2,174,015
<p>I am using Python 2.6.4.</p> <p>I have a series of select statements in a text file and I need to extract the field names from each select query. This would be easy if some of the fields didn't use nested functions like to_char() etc. </p> <p>Given select statement fields that could have several nested parenthese...
3
2010-02-01T00:27:04Z
2,174,177
<p>Do you really need regular expressions? To get the one you've got up there I'd use</p> <pre><code> s[s.rfind('(')+1:s.find(')')].split(',')[0] </code></pre> <p>with 's' containing the original string.</p> <p>Of course, it's not a general solution, but...</p>
0
2010-02-01T01:25:32Z
[ "python", "regex", "nested", "expression" ]
recursive nested expression in Python
2,174,015
<p>I am using Python 2.6.4.</p> <p>I have a series of select statements in a text file and I need to extract the field names from each select query. This would be easy if some of the fields didn't use nested functions like to_char() etc. </p> <p>Given select statement fields that could have several nested parenthese...
3
2010-02-01T00:27:04Z
2,174,438
<p>Here's a really hacky parser that does what you want.</p> <p>It works by calling 'eval' on the text to be parsed, mapping all identifiers to a function which returns its first argument (which I'm guessing is what you want given your example). </p> <pre><code>class FakeFunction(object): def __init__(self, name)...
1
2010-02-01T03:07:42Z
[ "python", "regex", "nested", "expression" ]
How do you get a responsive GUI if your codebehind is running an infinte loop? PyQT
2,174,039
<p>If you have a function consistently running an infinite loop in the background, how will your GUI ever be responsive? It is waiting for the loop to finish and this renders the interface useless. How is this solved in PyQT?</p>
5
2010-02-01T00:35:42Z
2,174,047
<p>Use threads.</p> <p>In Qt, they use something called <a href="http://doc.trolltech.com/4.6/signalsandslots.html" rel="nofollow">Signals and Slots</a>. I haven't used Qt since college, but there are plenty of good resources here:</p> <p>PyQt Wiki: <a href="https://wiki.python.org/moin/PyQt/Threading,_Signals_and_Sl...
4
2010-02-01T00:37:47Z
[ "python", "multithreading", "user-interface", "pyqt" ]
How do you get a responsive GUI if your codebehind is running an infinte loop? PyQT
2,174,039
<p>If you have a function consistently running an infinite loop in the background, how will your GUI ever be responsive? It is waiting for the loop to finish and this renders the interface useless. How is this solved in PyQT?</p>
5
2010-02-01T00:35:42Z
2,174,053
<p>You would run the non-GUI code in a QThread. Then your GUI will remain responsive.</p> <p>For a tutorial on threading in QT, see this link:</p> <p><a href="http://doc.trolltech.com/4.4/threads.html" rel="nofollow">http://doc.trolltech.com/4.4/threads.html</a></p> <p>The documentation for Qt's threading class (QTh...
0
2010-02-01T00:39:29Z
[ "python", "multithreading", "user-interface", "pyqt" ]
how to use /dev/ptmx for create a virtual serial port?
2,174,071
<p>I have a program, using pyserial, and I want to test it without using a real serial port device.</p> <p>In windows, I use com0com, and in linux, I know there is a method to create virtual serial port pair without using additional program.</p> <p>so I look up the manual, and found pts, /dev/ptmx, but I don't know h...
5
2010-02-01T00:46:39Z
2,174,086
<p>Per <a href="http://linux.die.net/man/4/ptmx" rel="nofollow">the docs</a>, you need <a href="http://linux.die.net/man/3/ptsname" rel="nofollow">ptsname</a> to get the name of the slave-side of the pseudo-terminal, and also, quoting the docs,</p> <blockquote> <p>Before opening the pseudo-terminal slave, you must...
2
2010-02-01T00:53:38Z
[ "python", "linux", "serial-port" ]
how to use /dev/ptmx for create a virtual serial port?
2,174,071
<p>I have a program, using pyserial, and I want to test it without using a real serial port device.</p> <p>In windows, I use com0com, and in linux, I know there is a method to create virtual serial port pair without using additional program.</p> <p>so I look up the manual, and found pts, /dev/ptmx, but I don't know h...
5
2010-02-01T00:46:39Z
2,174,110
<p>I don't know python but I can point you in the right direction: look <a href="http://www.developerweb.net/forum/showthread.php?t=5623" rel="nofollow">here</a> at a C code sample. Here's the <a href="http://linux.die.net/man/4/ptmx" rel="nofollow">man</a> page for the /dev/ptmx. Make sure the permissions and owner is...
0
2010-02-01T01:00:34Z
[ "python", "linux", "serial-port" ]
how to use /dev/ptmx for create a virtual serial port?
2,174,071
<p>I have a program, using pyserial, and I want to test it without using a real serial port device.</p> <p>In windows, I use com0com, and in linux, I know there is a method to create virtual serial port pair without using additional program.</p> <p>so I look up the manual, and found pts, /dev/ptmx, but I don't know h...
5
2010-02-01T00:46:39Z
2,174,206
<p>You should consider using the <code>pty</code> module instead, which should take care of this for you. (it opens /dev/ptmx or calls <code>openpty</code> or opens another appropriate device, depending on the platform.)</p>
0
2010-02-01T01:38:54Z
[ "python", "linux", "serial-port" ]
how to use /dev/ptmx for create a virtual serial port?
2,174,071
<p>I have a program, using pyserial, and I want to test it without using a real serial port device.</p> <p>In windows, I use com0com, and in linux, I know there is a method to create virtual serial port pair without using additional program.</p> <p>so I look up the manual, and found pts, /dev/ptmx, but I don't know h...
5
2010-02-01T00:46:39Z
2,174,219
<p>You could build a dummy object that implements the same interface as the <code>pySerial</code> classes you use, but do something completely different and easily replicable like reading from and writing to files/terminal/etc.</p> <p>For example:</p> <pre><code>class DummySerial(): #you should consider subclassing...
0
2010-02-01T01:42:53Z
[ "python", "linux", "serial-port" ]
how to use /dev/ptmx for create a virtual serial port?
2,174,071
<p>I have a program, using pyserial, and I want to test it without using a real serial port device.</p> <p>In windows, I use com0com, and in linux, I know there is a method to create virtual serial port pair without using additional program.</p> <p>so I look up the manual, and found pts, /dev/ptmx, but I don't know h...
5
2010-02-01T00:46:39Z
15,095,316
<p>I was trying to make an application that made use of virtual serial ports in order to communicate with some remote devices using TCP/Serial conversion... and I came across to a problem similar to yours. My solution worked out as follows:</p> <pre><code>import os, pty, serial master, slave = pty.openpty() s_name = ...
3
2013-02-26T17:20:54Z
[ "python", "linux", "serial-port" ]
Python rounding issue
2,174,081
<p>I have come across a very strange issue in python. (Using python 2.4.x)</p> <p>In windows:</p> <pre><code>&gt;&gt;&gt; a = 2292.5 &gt;&gt;&gt; print '%.0f' % a 2293 </code></pre> <p>But in Solaris:</p> <pre><code>&gt;&gt;&gt; a = 2292.5 &gt;&gt;&gt; print '%.0f' % a 2292 </code></pre> <p>But this is the same in...
9
2010-02-01T00:51:23Z
2,174,090
<p>I is plataform dependent. You can find the documentation <a href="http://docs.python.org/tutorial/floatingpoint.html" rel="nofollow">here</a>.</p> <p>It is good to user <a href="http://docs.python.org/library/math.html#math.ceil" rel="nofollow">ceil</a> or <a href="http://docs.python.org/library/math.html#math.floo...
0
2010-02-01T00:54:57Z
[ "python" ]
Python rounding issue
2,174,081
<p>I have come across a very strange issue in python. (Using python 2.4.x)</p> <p>In windows:</p> <pre><code>&gt;&gt;&gt; a = 2292.5 &gt;&gt;&gt; print '%.0f' % a 2293 </code></pre> <p>But in Solaris:</p> <pre><code>&gt;&gt;&gt; a = 2292.5 &gt;&gt;&gt; print '%.0f' % a 2292 </code></pre> <p>But this is the same in...
9
2010-02-01T00:51:23Z
2,174,120
<p>The function ultimately in charge of performing that formatting is <code>PyOS_snprintf</code> (see <a href="http://svn.python.org/projects/python/trunk/Python/mysnprintf.c" rel="nofollow">the sources</a>). As you surmise, that's unfortunately system-dependent, i.e., it relies on <code>vsprintf</code>, <code>vsnpri...
9
2010-02-01T01:06:28Z
[ "python" ]
Python rounding issue
2,174,081
<p>I have come across a very strange issue in python. (Using python 2.4.x)</p> <p>In windows:</p> <pre><code>&gt;&gt;&gt; a = 2292.5 &gt;&gt;&gt; print '%.0f' % a 2293 </code></pre> <p>But in Solaris:</p> <pre><code>&gt;&gt;&gt; a = 2292.5 &gt;&gt;&gt; print '%.0f' % a 2292 </code></pre> <p>But this is the same in...
9
2010-02-01T00:51:23Z
2,463,062
<p>round() rounds toward the nearest even integer<br> "%n.nf" works the same way as round()<br> int() truncates towards zero</p> <p>"rounding a positive number to the nearest integer<br> can be implemented by adding 0.5 and truncating"<br> -- <a href="http://en.wikipedia.org/wiki/Rounding" rel="nofollow">http://en.wik...
2
2010-03-17T14:33:21Z
[ "python" ]
Detect most likely words from text without spaces / combined words
2,174,093
<p>Is there a good library can detect and split words from a combined string?</p> <p>Example:</p> <pre><code>"cdimage" -&gt; ["cd", "image"] "filesaveas" -&gt; ["file", "save", "as"] </code></pre>
10
2010-02-01T00:55:56Z
2,174,152
<p>I don't know of any library for it, but it shouldn't be hard to implement basic functionality.</p> <ol> <li>Get a words list, like UNIX's <code>words</code>.</li> <li>Stuff the contents of your word list into a trie.</li> <li>Take the string you want to split and follow its path in the trie. Each time you reach a v...
6
2010-02-01T01:17:11Z
[ "python", "split", "word" ]
Detect most likely words from text without spaces / combined words
2,174,093
<p>Is there a good library can detect and split words from a combined string?</p> <p>Example:</p> <pre><code>"cdimage" -&gt; ["cd", "image"] "filesaveas" -&gt; ["file", "save", "as"] </code></pre>
10
2010-02-01T00:55:56Z
2,174,156
<p>I don't know a library that does this, but it's not too hard to write if you have a list of words:</p> <pre><code>wordList = file('words.txt','r').read().split() words = set( s.lower() for s in wordList ) def splitString(s): found = [] def rec(stringLeft, wordsSoFar): if not stringLeft: ...
1
2010-02-01T01:17:38Z
[ "python", "split", "word" ]
Detect most likely words from text without spaces / combined words
2,174,093
<p>Is there a good library can detect and split words from a combined string?</p> <p>Example:</p> <pre><code>"cdimage" -&gt; ["cd", "image"] "filesaveas" -&gt; ["file", "save", "as"] </code></pre>
10
2010-02-01T00:55:56Z
2,174,196
<p>if you are not doing this for fun, but is actually doing something for work etc, my advice is to tackle this at the source. Why do you have these strings combined like that? Where did you get those strings? If its possible, insert spaces at the source of where those strings come from.</p>
0
2010-02-01T01:34:12Z
[ "python", "split", "word" ]
Detect most likely words from text without spaces / combined words
2,174,093
<p>Is there a good library can detect and split words from a combined string?</p> <p>Example:</p> <pre><code>"cdimage" -&gt; ["cd", "image"] "filesaveas" -&gt; ["file", "save", "as"] </code></pre>
10
2010-02-01T00:55:56Z
2,174,226
<p>Get people to solve them as a captcha on your website :)</p>
2
2010-02-01T01:45:27Z
[ "python", "split", "word" ]
Detect most likely words from text without spaces / combined words
2,174,093
<p>Is there a good library can detect and split words from a combined string?</p> <p>Example:</p> <pre><code>"cdimage" -&gt; ["cd", "image"] "filesaveas" -&gt; ["file", "save", "as"] </code></pre>
10
2010-02-01T00:55:56Z
2,176,059
<p>Here's a dynamic programming solution (implemented as a memoized function). Given a dictionary of words with their frequencies, it splits the input text at the positions that give the overall most likely phrase. You'll have to find a real wordlist, but I included some made-up frequencies for a simple test.</p> <pre...
9
2010-02-01T10:45:51Z
[ "python", "split", "word" ]
Why do we need tuples in Python (or any immutable data type)?
2,174,124
<p>I've read several python tutorials (Dive Into Python, for one), and the language reference on Python.org - I don't see why the language needs tuples.</p> <p>Tuples have no methods compared to a list or set, and if I must convert a tuple to a set or list to be able to sort them, what's the point of using a tuple in ...
102
2010-02-01T01:08:15Z
2,174,151
<p>Sometimes we like to use objects as dictionary keys</p> <p>For what it's worth, tuples recently (2.6+) grew <code>index()</code> and <code>count()</code> methods</p>
13
2010-02-01T01:16:52Z
[ "python", "tuples" ]