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
Python: List Sorting with Multiple Attributes and Mixed Order
1,516,249
<p>I have to sort a python list, with multiple attributes. I can do that in ascending order for ALL attributes easily with</p> <pre><code>L.sort(key=operator.attrgetter(attribute)).... </code></pre> <p>but the problem is, that I have use mixed configurations for ascending/descending... I have to "imitate" a bit the S...
12
2009-10-04T12:10:07Z
1,516,449
<p>If your attributes are numeric, you have this.</p> <pre><code>def mixed_order( a ): return ( a.attribute1, -a.attribute2 ) someList.sort( key=mixed_order ) </code></pre> <p>If your attributes includes strings or other more complex objects, you have some choices.</p> <p>The <code>.sort()</code> method is stab...
22
2009-10-04T13:48:13Z
[ "python", "list", "sorting" ]
How to remove "similar" but not identical content in a MySQL database
1,516,263
<p>Suppose I have this table:</p> <pre><code>ID | description ------------------- 5 | The bird flew over the tree. 2 | The birds, flew over the tree </code></pre> <p>These two rows have "similar" content. How would I remove #2? </p> <ol> <li>What algorithm should I use for "similar" text?</li> <li>How would I do ...
3
2009-10-04T12:16:49Z
1,516,291
<p>Typically, for each value, you'd create a 'simplified' value (remove whatever wasn't essential ... in your example, the punctuation and pluralization), and then compare the simplified values for equality.</p>
3
2009-10-04T12:28:06Z
[ "python", "mysql", "algorithm", "string" ]
How to remove "similar" but not identical content in a MySQL database
1,516,263
<p>Suppose I have this table:</p> <pre><code>ID | description ------------------- 5 | The bird flew over the tree. 2 | The birds, flew over the tree </code></pre> <p>These two rows have "similar" content. How would I remove #2? </p> <ol> <li>What algorithm should I use for "similar" text?</li> <li>How would I do ...
3
2009-10-04T12:16:49Z
1,516,499
<p>You could use the <a href="http://dev.mysql.com/doc/refman/5.0/en/string-comparison-functions.html#operator%5Flike" rel="nofollow">LIKE operator</a>.</p> <pre><code>DELETE FROM myTable WHERE description LIKE 'The bird%flew over the tree%'; </code></pre>
0
2009-10-04T14:08:46Z
[ "python", "mysql", "algorithm", "string" ]
How to remove "similar" but not identical content in a MySQL database
1,516,263
<p>Suppose I have this table:</p> <pre><code>ID | description ------------------- 5 | The bird flew over the tree. 2 | The birds, flew over the tree </code></pre> <p>These two rows have "similar" content. How would I remove #2? </p> <ol> <li>What algorithm should I use for "similar" text?</li> <li>How would I do ...
3
2009-10-04T12:16:49Z
1,516,516
<p>What you could try is stripping necessary punctuation and running each sentence through a <a href="http://en.wikipedia.org/wiki/Stemming" rel="nofollow">stemmer</a> (e.g. a <a href="http://tartarus.org/~martin/PorterStemmer/" rel="nofollow">Porter Stemmer</a>). </p> <p>Once you have a stemmed version of the sentenc...
5
2009-10-04T14:17:25Z
[ "python", "mysql", "algorithm", "string" ]
How to remove "similar" but not identical content in a MySQL database
1,516,263
<p>Suppose I have this table:</p> <pre><code>ID | description ------------------- 5 | The bird flew over the tree. 2 | The birds, flew over the tree </code></pre> <p>These two rows have "similar" content. How would I remove #2? </p> <ol> <li>What algorithm should I use for "similar" text?</li> <li>How would I do ...
3
2009-10-04T12:16:49Z
10,457,601
<p>You can define the difference between two strings to be the edit distance, which is the number of operations needed to change one string to another. The set of operations can be anything you want, but if the two strings are of different size in the comparison, you must have an insertion and deletion operation.</p> ...
0
2012-05-05T00:02:59Z
[ "python", "mysql", "algorithm", "string" ]
python varargs before function name?
1,516,467
<p>I'm doing some Python coding in a clients code base and I stumbled on a line of code that looks something like this (the variable names have been changed to protect the innocent):</p> <pre><code>reply = function1(a=foo, **function2(bar, b=baz)) </code></pre> <p>Normally ** in the argument list collects remaining k...
2
2009-10-04T13:56:21Z
1,516,477
<p>I'd say that this is just calling a function that returns a dict-like object and therefor the asterisks just convert the returned dict into the keyword arguments for function1, just as usual.</p>
11
2009-10-04T13:59:53Z
[ "python", "varargs" ]
sqlite3 in Python
1,516,508
<p>How do I check if the database file already exists or not? And, if the it exists, how do I check if it already has a specific table or not? </p>
6
2009-10-04T14:13:24Z
1,516,527
<p>To see if a database exists, you can <a href="http://docs.python.org/library/sqlite3.html#sqlite3.connect"><code>sqlite3.connect</code></a> to the file that you think contains the database, and try running a query on it. If it is <em>not</em> a database, you will get this error:</p> <pre><code>&gt;&gt;&gt; c.execu...
9
2009-10-04T14:22:18Z
[ "python", "sqlite3" ]
Displaying integers in a wxpython listctrl
1,516,742
<p>I have a wxPython ListCtrl with five columns. Four of these hold strings, the last one has integer values. I have been storing these as strings (i.e. '4', '17', etc.). However, now that I have added a ColumnSorterMixin to let me sort specific columns in the list, I'm finding, of course, that the integer column is be...
2
2009-10-04T15:58:18Z
1,516,874
<p>I think that the most robust way of doing custom sort is to use <a href="http://docs.wxwidgets.org/stable/wx%5Fwxlistctrl.html#wxlistctrlsortitems" rel="nofollow">SortItems()</a> function in wx.ListCtrl. Note that you have to provide item data for each item (using <code>SetItemData()</code>) </p> <p>Just provide yo...
2
2009-10-04T17:01:12Z
[ "python", "wxpython", "listctrl" ]
In Django, how do I filter based on all entities in a many-to-many relation instead of any?
1,516,795
<p>I have a model like this:</p> <pre><code>class Task(models.model): TASK_STATUS_CHOICES = ( (u"P", u'Pending'), (u"A", u'Assigned'), (u"C", u'Complete'), (u"F", u'Failed') ) status = models.CharField(max_length=2, choices=TASK_STATUS_CHOICES) prerequisites = models.Man...
4
2009-10-04T16:27:27Z
1,517,516
<p>For your first question -- 'all tasks whose prerequisites are all complete':</p> <pre><code>&gt;&gt;&gt; Task.objects.exclude(prerequisites__status__in=['A','P','F']) </code></pre> <p>This will also include tasks with no prerequisites (as they have no incomplete prerequisites). As a doctest (using your model defi...
4
2009-10-04T22:10:01Z
[ "python", "django", "orm" ]
Python insert not getting desired results?
1,516,889
<p>#!/usr/bin/python</p> <pre><code>numbers = [1, 2, 3, 5, 6, 7] clean = numbers.insert(3, 'four') print clean # desire results [1, 2, 3, 'four', 5, 6, 7] </code></pre> <p>I am getting "None". What am I doing wrong?</p>
3
2009-10-04T17:07:30Z
1,516,896
<p>Mutating-methods on lists tend to return <code>None</code>, <strong>not</strong> the modified list as you expect -- such metods perform their effect by altering the list in-place, not by building and returning a new one. So, <code>print numbers</code> instead of <code>print clean</code> will show you the altered li...
12
2009-10-04T17:11:18Z
[ "python" ]
Python insert not getting desired results?
1,516,889
<p>#!/usr/bin/python</p> <pre><code>numbers = [1, 2, 3, 5, 6, 7] clean = numbers.insert(3, 'four') print clean # desire results [1, 2, 3, 'four', 5, 6, 7] </code></pre> <p>I am getting "None". What am I doing wrong?</p>
3
2009-10-04T17:07:30Z
1,516,899
<p>The insert method modifies the list in place and does not return a new reference. Try:</p> <pre><code>&gt;&gt;&gt; numbers = [1, 2, 3, 5, 6, 7] &gt;&gt;&gt; numbers.insert(3, 'four') &gt;&gt;&gt; print numbers [1, 2, 3, 'four', 5, 6, 7] </code></pre>
6
2009-10-04T17:11:33Z
[ "python" ]
Python insert not getting desired results?
1,516,889
<p>#!/usr/bin/python</p> <pre><code>numbers = [1, 2, 3, 5, 6, 7] clean = numbers.insert(3, 'four') print clean # desire results [1, 2, 3, 'four', 5, 6, 7] </code></pre> <p>I am getting "None". What am I doing wrong?</p>
3
2009-10-04T17:07:30Z
1,516,902
<p>insert will insert the item into the given list. Print numbers instead and you'll see your results. insert does not return the new list.</p>
1
2009-10-04T17:12:05Z
[ "python" ]
Python insert not getting desired results?
1,516,889
<p>#!/usr/bin/python</p> <pre><code>numbers = [1, 2, 3, 5, 6, 7] clean = numbers.insert(3, 'four') print clean # desire results [1, 2, 3, 'four', 5, 6, 7] </code></pre> <p>I am getting "None". What am I doing wrong?</p>
3
2009-10-04T17:07:30Z
1,516,903
<p>The list.insert() operator doesn't return anything, what you probably want is:</p> <pre><code>print numbers </code></pre>
1
2009-10-04T17:12:09Z
[ "python" ]
monitor service for "failure"
1,516,943
<p>I'm developing a script which monitors a service for failure and launches another a different action depending on if failure is present or not. </p> <p>I require a python script to monitor the output from a python program "monitor-services" and parsing the output search for an occurance of the word "failure". If pr...
0
2009-10-04T17:33:49Z
1,517,148
<pre><code>#!/usr/bin/python from subprocess import Popen, PIPE import sys data = Popen(["monitor-services"], stdout=PIPE).communicate()[0] sys.exit("failure" in data) </code></pre> <p>This does everything you want, except for the 30s wait (which I don't understand). Notice that it returns 0 if failure is not found,...
1
2009-10-04T19:09:08Z
[ "python", "scripting" ]
python refresh/reload
1,517,038
<p>This is a very basic question - but I haven't been able to find an answer by searching online.</p> <p>I am using python to control ArcGIS, and I have a simple python script, that calls some pre-written code.</p> <p>However, when I make a change to the pre-written code, it does not appear to result in any change. I...
21
2009-10-04T18:23:26Z
1,517,072
<p>One way to do this is to call <a href="http://docs.python.org/library/functions.html#reload"><code>reload</code></a>.</p> <p>Example: Here is the contents of <code>foo.py</code>:</p> <pre><code>def bar(): return 1 </code></pre> <p>In an interactive session, I can do:</p> <pre><code>&gt;&gt;&gt; import foo &...
17
2009-10-04T18:40:08Z
[ "python", "refresh", "reload" ]
python refresh/reload
1,517,038
<p>This is a very basic question - but I haven't been able to find an answer by searching online.</p> <p>I am using python to control ArcGIS, and I have a simple python script, that calls some pre-written code.</p> <p>However, when I make a change to the pre-written code, it does not appear to result in any change. I...
21
2009-10-04T18:23:26Z
1,517,073
<p>I'm not really sure that is what you mean, so don't hesitate to correct me. You are importing a module - let's call it mymodule.py - in your program, but when you change its contents, you don't see the difference?</p> <p>Python will not look for changes in mymodule.py each time it is used, it will load it a first t...
1
2009-10-04T18:40:27Z
[ "python", "refresh", "reload" ]
python refresh/reload
1,517,038
<p>This is a very basic question - but I haven't been able to find an answer by searching online.</p> <p>I am using python to control ArcGIS, and I have a simple python script, that calls some pre-written code.</p> <p>However, when I make a change to the pre-written code, it does not appear to result in any change. I...
21
2009-10-04T18:23:26Z
1,517,087
<p>It's unclear what you mean with "refresh", but the normal behavior of Python is that you need to restart the software for it to take a new look on a Python module and reread it.</p> <p>If your changes isn't taken care of even after restart, then this is due to one of two errors:</p> <ol> <li>The timestamp on the p...
24
2009-10-04T18:46:24Z
[ "python", "refresh", "reload" ]
python refresh/reload
1,517,038
<p>This is a very basic question - but I haven't been able to find an answer by searching online.</p> <p>I am using python to control ArcGIS, and I have a simple python script, that calls some pre-written code.</p> <p>However, when I make a change to the pre-written code, it does not appear to result in any change. I...
21
2009-10-04T18:23:26Z
7,479,862
<p>I used the following when importing all objects from within a module to ensure web2py was using my current code:</p> <pre><code>import buttons import table reload(buttons) reload(table) from buttons import * from table import * </code></pre>
0
2011-09-20T03:39:59Z
[ "python", "refresh", "reload" ]
python refresh/reload
1,517,038
<p>This is a very basic question - but I haven't been able to find an answer by searching online.</p> <p>I am using python to control ArcGIS, and I have a simple python script, that calls some pre-written code.</p> <p>However, when I make a change to the pre-written code, it does not appear to result in any change. I...
21
2009-10-04T18:23:26Z
27,299,101
<p>I had the exact same issue creating a geoprocessing script for ArcGIS 10.2. I had a python toolbox script, a tool script and then a common script. I have a parameter for Dev/Test/Prod in the tool that would control which version of the code was run. Dev would run the code in the dev folder, test from test folder and...
0
2014-12-04T16:31:15Z
[ "python", "refresh", "reload" ]
python refresh/reload
1,517,038
<p>This is a very basic question - but I haven't been able to find an answer by searching online.</p> <p>I am using python to control ArcGIS, and I have a simple python script, that calls some pre-written code.</p> <p>However, when I make a change to the pre-written code, it does not appear to result in any change. I...
21
2009-10-04T18:23:26Z
35,972,411
<p>I found a bypass online. Magic commands exist. It works like a charm for me. The Reload option didn't work for me. Got it from <a href="https://support.enthought.com/hc/en-us/articles/204469240-Jupyter-IPython-After-editing-a-module-changes-are-not-effective-without-kernel-restart?page=1#comment_203342093" rel="nofo...
0
2016-03-13T15:57:10Z
[ "python", "refresh", "reload" ]
How do I install SciPy on 64 bit Windows?
1,517,129
<p>How do I install SciPy on my system?</p> <p>For the NumPy part (that SciPy depends on) there is actually an installer for 64 bit Windows: <a href="http://dfn.dl.sourceforge.net/project/numpy/NumPy/1.3.0/numpy-1.3.0.win-amd64-py2.6.msi">numpy-1.3.0.win-amd64-py2.6.msi</a> (is direct download URL, 2310144 bytes).</p>...
54
2009-10-04T19:01:43Z
1,517,139
<p>Try to install Python 2.6.3 over your 2.6.2 (this should also add correct Registry entry), or to register your existing installation <a href="http://effbot.org/zone/python-register.htm" rel="nofollow">using this script</a>. Installer should work after that.</p> <p>Building SciPy requires a Fortran compiler and libr...
1
2009-10-04T19:05:48Z
[ "python", "windows", "64bit", "numpy", "scipy" ]
How do I install SciPy on 64 bit Windows?
1,517,129
<p>How do I install SciPy on my system?</p> <p>For the NumPy part (that SciPy depends on) there is actually an installer for 64 bit Windows: <a href="http://dfn.dl.sourceforge.net/project/numpy/NumPy/1.3.0/numpy-1.3.0.win-amd64-py2.6.msi">numpy-1.3.0.win-amd64-py2.6.msi</a> (is direct download URL, 2310144 bytes).</p>...
54
2009-10-04T19:01:43Z
1,517,333
<p>As the transcript for SciPy told you, SciPy isn't really supposed to work on Win64:</p> <pre><code>Warning: Windows 64 bits support is experimental, and only available for testing. You are advised not to use it for production. </code></pre> <p>So I would suggest to install the 32-bit version of Python, and stop at...
5
2009-10-04T20:44:04Z
[ "python", "windows", "64bit", "numpy", "scipy" ]
How do I install SciPy on 64 bit Windows?
1,517,129
<p>How do I install SciPy on my system?</p> <p>For the NumPy part (that SciPy depends on) there is actually an installer for 64 bit Windows: <a href="http://dfn.dl.sourceforge.net/project/numpy/NumPy/1.3.0/numpy-1.3.0.win-amd64-py2.6.msi">numpy-1.3.0.win-amd64-py2.6.msi</a> (is direct download URL, 2310144 bytes).</p>...
54
2009-10-04T19:01:43Z
1,517,680
<p>I haven't tried it, but you may want to download <a href="http://www.portablepython.com/wiki/PortablePython1.1Py2.5.4" rel="nofollow">this version</a> of <a href="http://www.portablepython.com/" rel="nofollow">Portable Python</a>. It comes with Scipy-0.7.0b1 running on Python 2.5.4. </p>
3
2009-10-04T23:13:37Z
[ "python", "windows", "64bit", "numpy", "scipy" ]
How do I install SciPy on 64 bit Windows?
1,517,129
<p>How do I install SciPy on my system?</p> <p>For the NumPy part (that SciPy depends on) there is actually an installer for 64 bit Windows: <a href="http://dfn.dl.sourceforge.net/project/numpy/NumPy/1.3.0/numpy-1.3.0.win-amd64-py2.6.msi">numpy-1.3.0.win-amd64-py2.6.msi</a> (is direct download URL, 2310144 bytes).</p>...
54
2009-10-04T19:01:43Z
1,523,358
<p>Short answer: windows 64 support is still work in progress at this time. The superpack will certainly not work on a 64 bits python (but it should work fine on a 32 bits python, even on windows 64).</p> <p>The main issue with windows 64 is that building with mingw-w64 is not stable at this point: it may be our's (nu...
29
2009-10-06T02:47:52Z
[ "python", "windows", "64bit", "numpy", "scipy" ]
How do I install SciPy on 64 bit Windows?
1,517,129
<p>How do I install SciPy on my system?</p> <p>For the NumPy part (that SciPy depends on) there is actually an installer for 64 bit Windows: <a href="http://dfn.dl.sourceforge.net/project/numpy/NumPy/1.3.0/numpy-1.3.0.win-amd64-py2.6.msi">numpy-1.3.0.win-amd64-py2.6.msi</a> (is direct download URL, 2310144 bytes).</p>...
54
2009-10-04T19:01:43Z
2,114,531
<p>Unofficial 64-bit installers for <a href="http://en.wikipedia.org/wiki/NumPy">NumPy</a> and <a href="http://en.wikipedia.org/wiki/SciPy">SciPy</a> are available at <a href="http://www.lfd.uci.edu/~gohlke/pythonlibs/">http://www.lfd.uci.edu/~gohlke/pythonlibs/</a></p>
52
2010-01-22T02:18:23Z
[ "python", "windows", "64bit", "numpy", "scipy" ]
How do I install SciPy on 64 bit Windows?
1,517,129
<p>How do I install SciPy on my system?</p> <p>For the NumPy part (that SciPy depends on) there is actually an installer for 64 bit Windows: <a href="http://dfn.dl.sourceforge.net/project/numpy/NumPy/1.3.0/numpy-1.3.0.win-amd64-py2.6.msi">numpy-1.3.0.win-amd64-py2.6.msi</a> (is direct download URL, 2310144 bytes).</p>...
54
2009-10-04T19:01:43Z
2,114,577
<p>For completeness: <a href="http://www.enthought.com/" rel="nofollow">Enthought</a> has a Python distribution which includes SciPy; however, it's not free. Caveat: I've never used it.</p>
2
2010-01-22T02:30:32Z
[ "python", "windows", "64bit", "numpy", "scipy" ]
How do I install SciPy on 64 bit Windows?
1,517,129
<p>How do I install SciPy on my system?</p> <p>For the NumPy part (that SciPy depends on) there is actually an installer for 64 bit Windows: <a href="http://dfn.dl.sourceforge.net/project/numpy/NumPy/1.3.0/numpy-1.3.0.win-amd64-py2.6.msi">numpy-1.3.0.win-amd64-py2.6.msi</a> (is direct download URL, 2310144 bytes).</p>...
54
2009-10-04T19:01:43Z
2,459,784
<p>Another alternative: <a href="http://www.pythonxy.com/" rel="nofollow">http://www.pythonxy.com/</a></p> <p>Free and includes lots of stuff meant to work together smoothly.</p> <p><a href="http://permalink.gmane.org/gmane.comp.python.xy.devel/109" rel="nofollow">This person</a> says </p> <blockquote> <p>Did you ...
2
2010-03-17T03:45:20Z
[ "python", "windows", "64bit", "numpy", "scipy" ]
How do I install SciPy on 64 bit Windows?
1,517,129
<p>How do I install SciPy on my system?</p> <p>For the NumPy part (that SciPy depends on) there is actually an installer for 64 bit Windows: <a href="http://dfn.dl.sourceforge.net/project/numpy/NumPy/1.3.0/numpy-1.3.0.win-amd64-py2.6.msi">numpy-1.3.0.win-amd64-py2.6.msi</a> (is direct download URL, 2310144 bytes).</p>...
54
2009-10-04T19:01:43Z
2,760,359
<p>I was getting this same error on a 32-bit machine. I fixed it by registering my Python installation, using the script at:</p> <p><a href="http://effbot.org/zone/python-register.htm" rel="nofollow">http://effbot.org/zone/python-register.htm</a> </p> <p>It's possible that the script would also make the 64-bit super...
0
2010-05-03T18:41:43Z
[ "python", "windows", "64bit", "numpy", "scipy" ]
How do I install SciPy on 64 bit Windows?
1,517,129
<p>How do I install SciPy on my system?</p> <p>For the NumPy part (that SciPy depends on) there is actually an installer for 64 bit Windows: <a href="http://dfn.dl.sourceforge.net/project/numpy/NumPy/1.3.0/numpy-1.3.0.win-amd64-py2.6.msi">numpy-1.3.0.win-amd64-py2.6.msi</a> (is direct download URL, 2310144 bytes).</p>...
54
2009-10-04T19:01:43Z
16,299,104
<p>Install Python distribution <a href="http://www.python.org/download/" rel="nofollow">http://www.python.org/download/</a>.</p> <p>Download and Install Anaconda Python Distribution.</p> <p>Make Anaconda Python distribution link to py3.3, if you want Numpy, Scipy or Matplotlib to work in py3.3 or just use it like tha...
0
2013-04-30T11:45:40Z
[ "python", "windows", "64bit", "numpy", "scipy" ]
How do I install SciPy on 64 bit Windows?
1,517,129
<p>How do I install SciPy on my system?</p> <p>For the NumPy part (that SciPy depends on) there is actually an installer for 64 bit Windows: <a href="http://dfn.dl.sourceforge.net/project/numpy/NumPy/1.3.0/numpy-1.3.0.win-amd64-py2.6.msi">numpy-1.3.0.win-amd64-py2.6.msi</a> (is direct download URL, 2310144 bytes).</p>...
54
2009-10-04T19:01:43Z
16,300,038
<p><a href="http://code.google.com/p/winpython/" rel="nofollow">WinPython</a> is an open-source distribution that has 64-bit numpy and scipy.</p>
4
2013-04-30T12:34:15Z
[ "python", "windows", "64bit", "numpy", "scipy" ]
How do I install SciPy on 64 bit Windows?
1,517,129
<p>How do I install SciPy on my system?</p> <p>For the NumPy part (that SciPy depends on) there is actually an installer for 64 bit Windows: <a href="http://dfn.dl.sourceforge.net/project/numpy/NumPy/1.3.0/numpy-1.3.0.win-amd64-py2.6.msi">numpy-1.3.0.win-amd64-py2.6.msi</a> (is direct download URL, 2310144 bytes).</p>...
54
2009-10-04T19:01:43Z
36,177,359
<p>It is terrible to install such Python data science packages independently on Windows. Try <a href="https://www.continuum.io/downloads#_windows" rel="nofollow">Anaconda</a> (one installer, 400 more Python packages, py2 &amp; py3 support). Anaconda really helps me a lot!</p>
1
2016-03-23T11:47:57Z
[ "python", "windows", "64bit", "numpy", "scipy" ]
What's a good library to do computational geometry (like CGAL) in a garbage-collected language?
1,517,192
<p>I need a library to handle computational geometry in a project, especially boolean operations, but just about every feature is useful. The best library I can find for this is <a href="http://www.cgal.org/">CGAL</a>, but this is the sort of project I would hesitate to make without garbage collection.</p> <p>What la...
7
2009-10-04T19:33:16Z
1,517,213
<p>I would still recommend to proceed with Python and the existing Python binding. When you find it's incomplete, you'll also find that it is fairly easy to extend - Python's C API is designed so that integrating with external libraries is fairly easy (for experienced C programmers).</p>
4
2009-10-04T19:45:51Z
[ "python", "binding", "garbage-collection", "computational-geometry", "cgal" ]
What's a good library to do computational geometry (like CGAL) in a garbage-collected language?
1,517,192
<p>I need a library to handle computational geometry in a project, especially boolean operations, but just about every feature is useful. The best library I can find for this is <a href="http://www.cgal.org/">CGAL</a>, but this is the sort of project I would hesitate to make without garbage collection.</p> <p>What la...
7
2009-10-04T19:33:16Z
2,227,063
<p>Perhaps you can look at Shapely for python</p> <p><a href="http://pypi.python.org/pypi/Shapely/" rel="nofollow">http://pypi.python.org/pypi/Shapely/</a></p> <p>For Java I would use JTS</p> <p>For .NET I would use SharpMap or .NETTopologySuite</p>
3
2010-02-09T05:50:09Z
[ "python", "binding", "garbage-collection", "computational-geometry", "cgal" ]
What's a good library to do computational geometry (like CGAL) in a garbage-collected language?
1,517,192
<p>I need a library to handle computational geometry in a project, especially boolean operations, but just about every feature is useful. The best library I can find for this is <a href="http://www.cgal.org/">CGAL</a>, but this is the sort of project I would hesitate to make without garbage collection.</p> <p>What la...
7
2009-10-04T19:33:16Z
2,489,751
<p>JTS is also available in .NET via IKVM.</p>
0
2010-03-22T02:46:28Z
[ "python", "binding", "garbage-collection", "computational-geometry", "cgal" ]
What's a good library to do computational geometry (like CGAL) in a garbage-collected language?
1,517,192
<p>I need a library to handle computational geometry in a project, especially boolean operations, but just about every feature is useful. The best library I can find for this is <a href="http://www.cgal.org/">CGAL</a>, but this is the sort of project I would hesitate to make without garbage collection.</p> <p>What la...
7
2009-10-04T19:33:16Z
16,423,563
<p>I've just found this and it seems very promising even if it seems a young project: <a href="https://pyrr.readthedocs.org/en/latest/index.html#" rel="nofollow">https://pyrr.readthedocs.org/en/latest/index.html#</a></p> <blockquote> <p>Pyrr is a Python mathematical library.</p> </blockquote> <p>and it is based on ...
0
2013-05-07T16:00:32Z
[ "python", "binding", "garbage-collection", "computational-geometry", "cgal" ]
What's a good library to do computational geometry (like CGAL) in a garbage-collected language?
1,517,192
<p>I need a library to handle computational geometry in a project, especially boolean operations, but just about every feature is useful. The best library I can find for this is <a href="http://www.cgal.org/">CGAL</a>, but this is the sort of project I would hesitate to make without garbage collection.</p> <p>What la...
7
2009-10-04T19:33:16Z
20,856,338
<p>The <a href="http://code.google.com/p/cgal-bindings/" rel="nofollow">CGAL-bindings</a> project provides bindings for CGAL using SWIG. The targeted languages, so far, are Java and Python. The CGAL-bindings project is open source, and supported/founded by two french companies.</p>
1
2013-12-31T11:05:09Z
[ "python", "binding", "garbage-collection", "computational-geometry", "cgal" ]
Cutting text from IPython shell using Ctrl-X is broken
1,517,259
<p>I use IPython very frequently and happily. Somehow, cutting text from the shell using the keyboard shortcut, <kbd>Ctrl</kbd> + <kbd>X</kbd>, is broken. Actually, I have a few different installations of IPython. In some of the installations, the shortcut works; in the others, it doesn't work.</p> <p>What might be th...
0
2009-10-04T20:08:08Z
1,517,291
<p>You say you have multiple instances installed -- are these all on different machines? What operating system(s) are they running? If you access them remotely, what operating system are <em>you</em> running?</p> <p>Do you get to them using ssh? Do you run something like screen, either locally or remotely, or both? Th...
2
2009-10-04T20:26:22Z
[ "python", "keyboard-shortcuts", "ipython" ]
Basic cocoa application using dock in Python, but not Xcode and all that extras
1,517,342
<p>It seems that if I want to create a very basic Cocoa application with a dock icon and the like, I would <a href="http://developer.apple.com/cocoa/pyobjc.html" rel="nofollow">have to use</a> Xcode and the GUI builder (w/ <strong>PyObjC</strong>).</p> <p>The application I am intending to write is largely concerned wi...
2
2009-10-04T20:46:22Z
1,517,377
<p><a href="http://pyobjc.sourceforge.net/" rel="nofollow">PyObjC</a>, which is included with Mac OS X 10.5 and 10.6, is pretty close to what you're looking for.</p>
2
2009-10-04T21:01:12Z
[ "python", "cocoa", "pyobjc", "dock" ]
Basic cocoa application using dock in Python, but not Xcode and all that extras
1,517,342
<p>It seems that if I want to create a very basic Cocoa application with a dock icon and the like, I would <a href="http://developer.apple.com/cocoa/pyobjc.html" rel="nofollow">have to use</a> Xcode and the GUI builder (w/ <strong>PyObjC</strong>).</p> <p>The application I am intending to write is largely concerned wi...
2
2009-10-04T20:46:22Z
1,517,639
<p>Chuck is correct about PyObjC.</p> <p>You should then read about this NSApplication method to change your icon. </p> <p><a href="http://developer.apple.com/mac/library/documentation/Cocoa/Reference/ApplicationKit/Classes/NSApplication%5FClass/Reference/Reference.html#//apple%5Fref/occ/instm/NSApplication/setApplic...
0
2009-10-04T23:01:10Z
[ "python", "cocoa", "pyobjc", "dock" ]
Basic cocoa application using dock in Python, but not Xcode and all that extras
1,517,342
<p>It seems that if I want to create a very basic Cocoa application with a dock icon and the like, I would <a href="http://developer.apple.com/cocoa/pyobjc.html" rel="nofollow">have to use</a> Xcode and the GUI builder (w/ <strong>PyObjC</strong>).</p> <p>The application I am intending to write is largely concerned wi...
2
2009-10-04T20:46:22Z
1,517,691
<p>Install the latest <a href="http://svn.pythonmac.org/py2app/py2app/trunk/doc/index.html">py2app</a>, then make a new directory -- cd to it -- in it make a <code>HelloWorld.py</code> file such as:</p> <pre><code># generic Python imports import datetime import os import sched import sys import tempfile import threadi...
8
2009-10-04T23:18:09Z
[ "python", "cocoa", "pyobjc", "dock" ]
About Python's built in sort() method
1,517,347
<p>What algorithm is the built in <code>sort()</code> method in Python using? Is it possible to have a look at the code for that method?</p>
43
2009-10-04T20:48:00Z
1,517,357
<p>In early python-versions, the sort function implemented a modified version of quicksort. However, it was deemed unstable and as of 2.3 they switched to using an adaptive mergesort algorithm.</p>
6
2009-10-04T20:52:09Z
[ "python", "algorithm", "sorting", "python-internals" ]
About Python's built in sort() method
1,517,347
<p>What algorithm is the built in <code>sort()</code> method in Python using? Is it possible to have a look at the code for that method?</p>
43
2009-10-04T20:48:00Z
1,517,363
<p>Sure! The code's <a href="http://svn.python.org/view/python/trunk/Objects/listobject.c?revision=69227&amp;view=markup">here</a>, starting with function <code>islt</code> and proceeding for QUITE a while;-). As Chris's comment suggests, it's C code. You'll also want to read <a href="http://svn.python.org/view/pytho...
60
2009-10-04T20:53:10Z
[ "python", "algorithm", "sorting", "python-internals" ]
About Python's built in sort() method
1,517,347
<p>What algorithm is the built in <code>sort()</code> method in Python using? Is it possible to have a look at the code for that method?</p>
43
2009-10-04T20:48:00Z
1,517,648
<p>I just wanted to supply a very helpful link that I missed in Alex's otherwise comprehensive answer: <a href="http://corte.si/posts/code/timsort/index.html">A high-level explanation of Python's timsort</a> (with graph visualizations!).</p> <p>(Yes, the algorithm is basically known as <a href="http://en.wikipedia.org...
19
2009-10-04T23:03:41Z
[ "python", "algorithm", "sorting", "python-internals" ]
How can I interact with the android scripting environment from an android app?
1,517,372
<p>I'd like to use python scripts as plugins for an app I'm developing. This seems to be possible by interacting with android-scripting-environment (ASE), as is done by Locale, but I haven't found any documentation about this. How you execute ASE scripts from your own app?</p>
2
2009-10-04T20:59:23Z
1,519,428
<p>It looks like the Locale "plugin" is just recieving a broadcasted <code>Intent</code> to <code>com.twofortyfouram.locale.intent.action.FIRE_SETTING</code> which includs the script as an <code>Extra</code> with the name <code>com.google.ase.extra.SCRIPT_NAME</code>.</p> <p>The relevant bits are in <a href="http://co...
0
2009-10-05T11:03:43Z
[ "python", "android", "ase", "android-scripting" ]
Closing sockets in python
1,517,418
<p>I'm modifying Python code that have this form:</p> <pre><code>def foo(self): try: connect socket except Exception, e: some error reporting stuff return an error use the socket do some other stuff if some condition: return do some more stuff socket.close...
3
2009-10-04T21:24:44Z
1,517,433
<p>You seem to be wanting the finally block added to try/except in 2.5</p> <p><a href="http://docs.python.org/whatsnew/2.5.html#pep-341-unified-try-except-finally" rel="nofollow">http://docs.python.org/whatsnew/2.5.html#pep-341-unified-try-except-finally</a></p> <p>You are correct that relying on the autoclose when g...
1
2009-10-04T21:31:22Z
[ "python", "sockets", "try-catch" ]
Closing sockets in python
1,517,418
<p>I'm modifying Python code that have this form:</p> <pre><code>def foo(self): try: connect socket except Exception, e: some error reporting stuff return an error use the socket do some other stuff if some condition: return do some more stuff socket.close...
3
2009-10-04T21:24:44Z
1,517,457
<p>You can use a <code>try-finally</code> block, which was added in Python 2.5:</p> <pre><code>try: open socket do stuff with socket finally: close socket </code></pre> <p>Or you can use the <code>with</code> statement, which was added in Python 2.6 (and can be used in 2.5 with a <code>from __future__ imp...
11
2009-10-04T21:44:33Z
[ "python", "sockets", "try-catch" ]
Closing sockets in python
1,517,418
<p>I'm modifying Python code that have this form:</p> <pre><code>def foo(self): try: connect socket except Exception, e: some error reporting stuff return an error use the socket do some other stuff if some condition: return do some more stuff socket.close...
3
2009-10-04T21:24:44Z
1,517,522
<p>In addition to the try/finally block, consider setting a socket default timeout that will automatically close the socket(s) after your specified time. </p> <p><a href="http://docs.python.org/library/socket.html?highlight=setdefaulttimeout#socket.setdefaulttimeout" rel="nofollow">http://docs.python.org/library/socke...
0
2009-10-04T22:12:05Z
[ "python", "sockets", "try-catch" ]
How to space a write file
1,517,456
<p>Hello everyone I'm currently new to python, and I'm trying to write a program where the user can input a message and the output will show the numeric code of the message, but at the same time I need to write the numeric code to an additional file.</p> <p>So for example the user inputs the word "Hello" The user will...
0
2009-10-04T21:44:12Z
1,517,463
<p>just manually add a space:</p> <pre><code>outfile.write(str(ascii) + " ") </code></pre>
2
2009-10-04T21:45:43Z
[ "python", "file", "spacing" ]
How to space a write file
1,517,456
<p>Hello everyone I'm currently new to python, and I'm trying to write a program where the user can input a message and the output will show the numeric code of the message, but at the same time I need to write the numeric code to an additional file.</p> <p>So for example the user inputs the word "Hello" The user will...
0
2009-10-04T21:44:12Z
1,517,478
<p>Bear in mind that cobbal's answer will add an extra space to the end of the file. You can strip it off using:</p> <pre><code>s.rstrip(str(ascii)) </code></pre>
0
2009-10-04T21:53:45Z
[ "python", "file", "spacing" ]
How to space a write file
1,517,456
<p>Hello everyone I'm currently new to python, and I'm trying to write a program where the user can input a message and the output will show the numeric code of the message, but at the same time I need to write the numeric code to an additional file.</p> <p>So for example the user inputs the word "Hello" The user will...
0
2009-10-04T21:44:12Z
1,517,519
<p>You can do this without the loop using Python list comprehension and the join method to add the spaces between the ascii values.</p> <pre><code>" ".join([str(ord(c)) for c in message]) </code></pre> <p>This will evaluate to a string of ascii values separated by spaces.</p>
5
2009-10-04T22:10:23Z
[ "python", "file", "spacing" ]
Linux packaging abstraction layer written in Python?
1,517,495
<p>I'm looking for a way to generate .deb and .rpm packages from my build scripts, containing the resulting products. Since everything is written in Python, I'm wondering if anyone knows of an abstraction layer that would allow me to drive both RPM and Deb construction from the same code?</p>
2
2009-10-04T22:01:41Z
1,517,593
<p>Distutils in python's standard library has a <a href="http://docs.python.org/distutils/builtdist.html#creating-rpm-packages" rel="nofollow">bdist_rpm</a> command to build rpms and the third-paty <a href="http://github.com/astraw/stdeb" rel="nofollow">stdeb</a> module adds a command for producing debs.</p>
2
2009-10-04T22:40:38Z
[ "python", "packaging", "rpm", "deb" ]
Stream large binary files with urllib2 to file
1,517,616
<p>I use the following code to stream large files from the Internet into a local file:</p> <pre><code>fp = open(file, 'wb') req = urllib2.urlopen(url) for line in req: fp.write(line) fp.close() </code></pre> <p>This works but it downloads quite slowly. Is there a faster way? (The files are large so I don't want t...
44
2009-10-04T22:50:47Z
1,517,659
<p>I used to use <code>mechanize</code> module and its Browser.retrieve() method. In the past it took 100% CPU and downloaded things very slowly, but some recent release fixed this bug and works very quickly.</p> <p>Example:</p> <pre><code>import mechanize browser = mechanize.Browser() browser.retrieve('http://www.ke...
6
2009-10-04T23:07:49Z
[ "python", "file", "streaming", "urllib2" ]
Stream large binary files with urllib2 to file
1,517,616
<p>I use the following code to stream large files from the Internet into a local file:</p> <pre><code>fp = open(file, 'wb') req = urllib2.urlopen(url) for line in req: fp.write(line) fp.close() </code></pre> <p>This works but it downloads quite slowly. Is there a faster way? (The files are large so I don't want t...
44
2009-10-04T22:50:47Z
1,517,728
<p>No reason to work line by line (small chunks AND requires Python to find the line ends for you!-), just chunk it up in bigger chunks, e.g.:</p> <pre><code>from urllib2 import urlopen # Python 2 # from urllib.request import urlopen # Python 3 response = urlopen(url) CHUNK = 16 * 1024 with open(file, 'wb') as f: ...
79
2009-10-04T23:42:58Z
[ "python", "file", "streaming", "urllib2" ]
Stream large binary files with urllib2 to file
1,517,616
<p>I use the following code to stream large files from the Internet into a local file:</p> <pre><code>fp = open(file, 'wb') req = urllib2.urlopen(url) for line in req: fp.write(line) fp.close() </code></pre> <p>This works but it downloads quite slowly. Is there a faster way? (The files are large so I don't want t...
44
2009-10-04T22:50:47Z
5,397,438
<p>You can also use <a href="http://docs.python.org/library/shutil.html" rel="nofollow">shutil</a>:</p> <pre><code>import shutil from urllib2 import urlopen # Python 2 # from urllib.request import urlopen # Python 3 req = urlopen(url) with open(file, 'wb') as fp: shutil.copyfileobj(req, fp) </code></pre>
56
2011-03-22T20:28:18Z
[ "python", "file", "streaming", "urllib2" ]
Stream large binary files with urllib2 to file
1,517,616
<p>I use the following code to stream large files from the Internet into a local file:</p> <pre><code>fp = open(file, 'wb') req = urllib2.urlopen(url) for line in req: fp.write(line) fp.close() </code></pre> <p>This works but it downloads quite slowly. Is there a faster way? (The files are large so I don't want t...
44
2009-10-04T22:50:47Z
25,532,537
<p>You can use urllib.retrieve() to download files:</p> <p>Example:</p> <pre><code>from urllib import urlretrieve # Python 2 # from urllib.request import urlretrieve # Python 3 url = "http://www.examplesite.com/myfile" urlretreive(url,"./local_file") </code></pre>
2
2014-08-27T16:34:35Z
[ "python", "file", "streaming", "urllib2" ]
Django: How to modify a text field before showing it in admin
1,517,626
<p>I have a Django Model with a text field. I would like to modify the content of the text field before it's presented to the user in Django Admin.</p> <p>I was expecting to see signal equivalent of <strong>post_load</strong> but it doesn't seem to exist.</p> <p><strong>To be more specific:</strong></p> <p>I have a ...
1
2009-10-04T22:56:21Z
1,517,707
<p>Have a look into <a href="http://docs.djangoproject.com/en/dev/ref/contrib/admin/#django.contrib.admin.ModelAdmin.form" rel="nofollow">Providing your own form</a> for the admin pages. </p> <p>Once you have your own form, you can use the default param in the form to provide the initial value you want. See the docs o...
2
2009-10-04T23:26:04Z
[ "python", "django", "django-models", "django-signals" ]
Django: How to modify a text field before showing it in admin
1,517,626
<p>I have a Django Model with a text field. I would like to modify the content of the text field before it's presented to the user in Django Admin.</p> <p>I was expecting to see signal equivalent of <strong>post_load</strong> but it doesn't seem to exist.</p> <p><strong>To be more specific:</strong></p> <p>I have a ...
1
2009-10-04T22:56:21Z
1,518,289
<p>There is no post_load because there is no load function.</p> <p>Loading of the instance is done in <strong>init</strong> function, therefore the right answer is to use post_init signal.</p>
1
2009-10-05T04:43:52Z
[ "python", "django", "django-models", "django-signals" ]
Is it possible to save a list of values into a SQLite column?
1,517,771
<p>I want 3 columns to have 9 different values, like a list in Python. Is it possible? If not in SQLite, then on another database engine?</p>
4
2009-10-05T00:26:26Z
1,517,795
<p>Generally, you do this by stringifying the list (with repr()), and then saving the string. On reading the string from the database, use eval() to re-create the list. Be careful, though that you are certain no user-generated data can get into the column, or the eval() is a security risk.</p>
5
2009-10-05T00:40:24Z
[ "python", "sqlite" ]
Is it possible to save a list of values into a SQLite column?
1,517,771
<p>I want 3 columns to have 9 different values, like a list in Python. Is it possible? If not in SQLite, then on another database engine?</p>
4
2009-10-05T00:26:26Z
1,518,067
<p>You must serialize the list (or other Python object) into a string of bytes, aka "BLOB";-), through your favorite means (<code>marshal</code> is good for lists of elementary values such as numbers or strings &amp;c, <code>cPickle</code> if you want a very general solution, etc), and deserialize it when you fetch it ...
8
2009-10-05T02:45:13Z
[ "python", "sqlite" ]
Is it possible to save a list of values into a SQLite column?
1,517,771
<p>I want 3 columns to have 9 different values, like a list in Python. Is it possible? If not in SQLite, then on another database engine?</p>
4
2009-10-05T00:26:26Z
1,518,649
<p>Your question is difficult to understand. Here it is again:</p> <p>I want 3 columns to have 9 different values, like a list in Python. Is it possible? If not in SQLite, then on another database engine?</p> <p>Here is what I believe you are asking: is it possible to take a Python list of 9 different values, and sa...
3
2009-10-05T07:19:11Z
[ "python", "sqlite" ]
Python Image Library ellipse with wide outline
1,517,778
<p>When creating an ellipse with PIL, is it possible to have a thicker/wider outline? Currently, I'm trying to do <code>canvas.ellipse(box, outline=colour, fill=None)</code>, but would like to be able to give the <code>outline</code> parameter a width.</p>
2
2009-10-05T00:29:11Z
1,518,075
<p>You could use the <a href="http://effbot.org/zone/aggdraw-index.htm" rel="nofollow">aggdraw</a> advanced-graphics add-on module to PIL -- with it, the method to draw an ellipse, like others, takes a <code>pen</code> object which you can make with your favorite width (as well as color and opacity).</p>
1
2009-10-05T02:48:59Z
[ "python", "image", "python-imaging-library" ]
Using lookahead with generators
1,517,862
<p>I have implemented a generator-based scanner in Python that tokenizes a string into tuples of the form <em>(token type, token value)</em>:</p> <pre><code>for token in scan("a(b)"): print token </code></pre> <p>would print</p> <pre><code>("literal", "a") ("l_paren", "(") ... </code></pre> <p>The next task imp...
16
2009-10-05T01:10:55Z
1,517,887
<p>It's not pretty, but this may do what you want:</p> <pre><code>def paired_iter(it): token = it.next() for lookahead in it: yield (token, lookahead) token = lookahead yield (token, None) def scan(s): for c in s: yield c for this_token, next_token in paired_iter(scan("ABCDEF"...
6
2009-10-05T01:23:56Z
[ "python", "generator", "lookahead" ]
Using lookahead with generators
1,517,862
<p>I have implemented a generator-based scanner in Python that tokenizes a string into tuples of the form <em>(token type, token value)</em>:</p> <pre><code>for token in scan("a(b)"): print token </code></pre> <p>would print</p> <pre><code>("literal", "a") ("l_paren", "(") ... </code></pre> <p>The next task imp...
16
2009-10-05T01:10:55Z
1,517,965
<p>You can write a wrapper that buffers some number of items from the generator, and provides a lookahead() function to peek at those buffered items:</p> <pre><code>class Lookahead: def __init__(self, iter): self.iter = iter self.buffer = [] def __iter__(self): return self def nex...
13
2009-10-05T02:03:46Z
[ "python", "generator", "lookahead" ]
Using lookahead with generators
1,517,862
<p>I have implemented a generator-based scanner in Python that tokenizes a string into tuples of the form <em>(token type, token value)</em>:</p> <pre><code>for token in scan("a(b)"): print token </code></pre> <p>would print</p> <pre><code>("literal", "a") ("l_paren", "(") ... </code></pre> <p>The next task imp...
16
2009-10-05T01:10:55Z
1,517,967
<p>Paul's is a good answer. A class based approach with arbitrary lookahead might look something like:</p> <pre><code>class lookahead(object): def __init__(self, generator, lookahead_count=1): self.gen = iter(generator) self.look_count = lookahead_count def __iter__(self): self.lookahe...
0
2009-10-05T02:04:01Z
[ "python", "generator", "lookahead" ]
Using lookahead with generators
1,517,862
<p>I have implemented a generator-based scanner in Python that tokenizes a string into tuples of the form <em>(token type, token value)</em>:</p> <pre><code>for token in scan("a(b)"): print token </code></pre> <p>would print</p> <pre><code>("literal", "a") ("l_paren", "(") ... </code></pre> <p>The next task imp...
16
2009-10-05T01:10:55Z
1,517,982
<p>Here is an example that allows a single item to be sent back to the generator</p> <pre><code>def gen(): for i in range(100): v=yield i # when you call next(), v will be set to None if v: yield None # this yields None to send() call v=yield v # so this...
2
2009-10-05T02:10:48Z
[ "python", "generator", "lookahead" ]
Using lookahead with generators
1,517,862
<p>I have implemented a generator-based scanner in Python that tokenizes a string into tuples of the form <em>(token type, token value)</em>:</p> <pre><code>for token in scan("a(b)"): print token </code></pre> <p>would print</p> <pre><code>("literal", "a") ("l_paren", "(") ... </code></pre> <p>The next task imp...
16
2009-10-05T01:10:55Z
1,518,097
<p>Pretty good answers there, but my favorite approach would be to use <code>itertools.tee</code> -- given an iterator, it returns two (or more if requested) that can be advanced independently. It buffers in memory just as much as needed (i.e., not much, if the iterators don't get very "out of step" from each other). ...
18
2009-10-05T03:00:18Z
[ "python", "generator", "lookahead" ]
Using lookahead with generators
1,517,862
<p>I have implemented a generator-based scanner in Python that tokenizes a string into tuples of the form <em>(token type, token value)</em>:</p> <pre><code>for token in scan("a(b)"): print token </code></pre> <p>would print</p> <pre><code>("literal", "a") ("l_paren", "(") ... </code></pre> <p>The next task imp...
16
2009-10-05T01:10:55Z
1,518,260
<p>Since you say you are tokenizing a string and not a general iterable, I suggest the simplest solution of just expanding your tokenizer to return a 3-tuple: <code>(token_type, token_value, token_index)</code>, where <code>token_index</code> is the index of the token in the string. Then you can look forward, backward...
1
2009-10-05T04:25:33Z
[ "python", "generator", "lookahead" ]
Using lookahead with generators
1,517,862
<p>I have implemented a generator-based scanner in Python that tokenizes a string into tuples of the form <em>(token type, token value)</em>:</p> <pre><code>for token in scan("a(b)"): print token </code></pre> <p>would print</p> <pre><code>("literal", "a") ("l_paren", "(") ... </code></pre> <p>The next task imp...
16
2009-10-05T01:10:55Z
6,449,237
<p>How I would write it concisely, if I just needed 1 element's worth of lookahead:</p> <pre><code>SEQUENCE_END = object() def lookahead(iterable): iter = iter(iterable) current = next(iter) for ahead in iter: yield current,ahead current = ahead yield current,SEQUENCE_END </code></pre>...
0
2011-06-23T04:10:21Z
[ "python", "generator", "lookahead" ]
Using lookahead with generators
1,517,862
<p>I have implemented a generator-based scanner in Python that tokenizes a string into tuples of the form <em>(token type, token value)</em>:</p> <pre><code>for token in scan("a(b)"): print token </code></pre> <p>would print</p> <pre><code>("literal", "a") ("l_paren", "(") ... </code></pre> <p>The next task imp...
16
2009-10-05T01:10:55Z
15,726,344
<p>Construct a simple lookahead wrapper using <a href="http://docs.python.org/2.7/library/itertools.html#itertools.tee" rel="nofollow"><em>itertools.tee</em></a>:</p> <pre><code>from itertools import tee, islice class LookAhead: 'Wrap an iterator with lookahead indexing' def __init__(self, iterator): ...
2
2013-03-31T04:28:58Z
[ "python", "generator", "lookahead" ]
What's the best way to read python documentation for all installed packages?
1,517,885
<p>I use python.org a lot for reading python documentation. I also use ipython help function, but I would prefer a GUI app that I could run on my machine that would show documentation for all installed packages.</p> <p>Do you know if anything like this exists?</p> <p>Do you have any suggestions?</p>
5
2009-10-05T01:20:07Z
1,517,890
<p>The <code>pydoc</code> command has a built-in HTTP server, which you can start with:</p> <pre><code>pydoc -p 8080 </code></pre> <p>Then head to <a href="http://localhost:8080/">http://localhost:8080/</a> in your browser. It will have documentation for all modules installed on its search path, which includes anythi...
9
2009-10-05T01:25:04Z
[ "python", "documentation" ]
Python Image Uploading with AjaxUpload
1,517,959
<p>I'm trying to use AjaxUpload with Python: <a href="http://valums.com/ajax-upload/" rel="nofollow">http://valums.com/ajax-upload/</a></p> <p>I would like to know how to access the uploaded file with Python. On the web site, it says:</p> <pre><code>* PHP: $_FILES['userfile'] * Rails: params[:userfile] </code></pre...
4
2009-10-05T02:00:14Z
1,518,170
<p>in django, you can use:</p> <pre><code>request.FILES['file'] </code></pre> <p>instead of:</p> <pre><code>request.POST['file'] </code></pre> <p>i did not know how to do in pylons...maybe it is the same concept..</p>
0
2009-10-05T03:37:07Z
[ "python", "pylons", "python-imaging-library", "image-uploading", "ajax-upload" ]
Python Image Uploading with AjaxUpload
1,517,959
<p>I'm trying to use AjaxUpload with Python: <a href="http://valums.com/ajax-upload/" rel="nofollow">http://valums.com/ajax-upload/</a></p> <p>I would like to know how to access the uploaded file with Python. On the web site, it says:</p> <pre><code>* PHP: $_FILES['userfile'] * Rails: params[:userfile] </code></pre...
4
2009-10-05T02:00:14Z
1,698,974
<pre><code>import cgi #This will give you the data of the file, # but won't give you the filename, unfortunately. # For that you have to do some other trick. file_data = cgi.FieldStorage.getfirst('file') #&lt;IGNORE if you're not using mod_python&gt; #(If you're using mod_python you can also get the Request object #...
1
2009-11-09T03:39:50Z
[ "python", "pylons", "python-imaging-library", "image-uploading", "ajax-upload" ]
Python Image Uploading with AjaxUpload
1,517,959
<p>I'm trying to use AjaxUpload with Python: <a href="http://valums.com/ajax-upload/" rel="nofollow">http://valums.com/ajax-upload/</a></p> <p>I would like to know how to access the uploaded file with Python. On the web site, it says:</p> <pre><code>* PHP: $_FILES['userfile'] * Rails: params[:userfile] </code></pre...
4
2009-10-05T02:00:14Z
4,769,662
<p>I'm working with Pyramid, and I was trying to do the same thing. After some time I came up with this solution.</p> <pre><code>from cStringIO import StringIO from cgi import FieldStorage fs = FieldStorage(fp=request['wsgi.input'], environ=request) f = StringIO(fs.value) im = Image.open(f) </code></pre> <p>I'm not...
1
2011-01-22T18:22:49Z
[ "python", "pylons", "python-imaging-library", "image-uploading", "ajax-upload" ]
banshee: How would I set the rating for a specific track on Banshee through DBus?
1,517,984
<p>I'd like to set the 'rating' of a specific track (i.e. not only the one currently playing) on Banshee through the DBus interface?</p>
1
2009-10-05T02:11:39Z
1,560,744
<p>Banshee does not expose rating functions via DBus.</p> <p>You can quickly view all functions that it exposes, using applications like d-feet[1]. Make sure that an instance of the application you are interested in (like Banshee in this case) is running.</p> <p>There is a bug report already requesting to add rating ...
2
2009-10-13T14:54:18Z
[ "python", "linux", "dbus", "banshee" ]
banshee: How would I set the rating for a specific track on Banshee through DBus?
1,517,984
<p>I'd like to set the 'rating' of a specific track (i.e. not only the one currently playing) on Banshee through the DBus interface?</p>
1
2009-10-05T02:11:39Z
7,144,007
<p>Banshee does support rating via commandline since last year.</p> <pre><code>banshee --set-rating={1;2;3;4;5} </code></pre> <p>See the bug report for more options: <a href="https://bugzilla.gnome.org/show_bug.cgi?id=579754" rel="nofollow">Add item rating to DBus interface</a></p>
2
2011-08-22T06:52:13Z
[ "python", "linux", "dbus", "banshee" ]
banshee: How would I set the rating for a specific track on Banshee through DBus?
1,517,984
<p>I'd like to set the 'rating' of a specific track (i.e. not only the one currently playing) on Banshee through the DBus interface?</p>
1
2009-10-05T02:11:39Z
11,862,540
<p>Sadly the developer have not implemented a GET method, so there is no common way to execute "rate current track 1 star up/down"-command, much less than a specific track. Does anyone has written a script which provide this feature? Yet, I haven't found any solution to modify the D-Bus Property via command line. Final...
1
2012-08-08T10:26:46Z
[ "python", "linux", "dbus", "banshee" ]
How to keep query parameters during pagination with webhelpers.paginate
1,518,068
<p>I look an example of paginating from <a href="http://rapidprototype.ch/bg2docs/tg2pagination.html" rel="nofollow">http://rapidprototype.ch/bg2docs/tg2pagination.html</a> for my Turbogears 2 project and it works great but, I have a problem regarding my query parameters when I change the page I'm looking.</p> <p>This...
2
2009-10-05T02:45:19Z
1,518,293
<p>After experimenting on the shell for a while I think I found a solution.</p> <p>There's a kwargs dictionary defined in currentPage (after being assigned from paginate.Page), so I made some experiments sending parameters and it worked. This is how.</p> <pre><code>currentPage = paginate.Page(products, page, items_p...
1
2009-10-05T04:45:13Z
[ "python", "pagination", "pylons", "genshi", "turbogears2" ]
How to keep query parameters during pagination with webhelpers.paginate
1,518,068
<p>I look an example of paginating from <a href="http://rapidprototype.ch/bg2docs/tg2pagination.html" rel="nofollow">http://rapidprototype.ch/bg2docs/tg2pagination.html</a> for my Turbogears 2 project and it works great but, I have a problem regarding my query parameters when I change the page I'm looking.</p> <p>This...
2
2009-10-05T02:45:19Z
1,587,593
<p>you should use syntax like:</p> <pre><code>currentPage.kwargs['q'] = q currentPage = paginate.Page( products, page, items_per_page=50, q = q ) </code></pre>
1
2009-10-19T08:48:11Z
[ "python", "pagination", "pylons", "genshi", "turbogears2" ]
How to keep query parameters during pagination with webhelpers.paginate
1,518,068
<p>I look an example of paginating from <a href="http://rapidprototype.ch/bg2docs/tg2pagination.html" rel="nofollow">http://rapidprototype.ch/bg2docs/tg2pagination.html</a> for my Turbogears 2 project and it works great but, I have a problem regarding my query parameters when I change the page I'm looking.</p> <p>This...
2
2009-10-05T02:45:19Z
10,733,016
<p>you can update request params, like this snippets.</p> <pre><code>def paginate(self, items, items_per_page=20): """https://bitbucket.org/bbangert/webhelpers/src/acfb17881c1c/webhelpers/paginate.py""" current_page = self.request.GET.get('page') or 1 def page_url(page): params = self.request.par...
0
2012-05-24T07:28:15Z
[ "python", "pagination", "pylons", "genshi", "turbogears2" ]
Django - use reverse url mapping in settings
1,518,286
<p>A few of the options in the django settings file are urls, for example <code>LOGIN_URL</code> and <code>LOGIN_REDIRECT_URL</code>. Is it possible to avoid hardcoding these urls, and instead use reverse url mapping? At the moment this is really the only place where I find myself writing the same urls in multiple...
28
2009-10-05T04:40:49Z
1,519,675
<h1>Django 1.5 and later</h1> <p>As of Django 1.5, <code>LOGIN_URL</code> and <code>LOGIN_REDIRECT_URL</code> accept named URL patterns. That means you don't need to hardcode any urls in your settings.</p> <pre><code>LOGIN_URL = 'login' # name of url pattern </code></pre> <p>For Django 1.5 - 1.9, you can also use th...
39
2009-10-05T12:03:31Z
[ "python", "django", "url", "dry" ]
Django - use reverse url mapping in settings
1,518,286
<p>A few of the options in the django settings file are urls, for example <code>LOGIN_URL</code> and <code>LOGIN_REDIRECT_URL</code>. Is it possible to avoid hardcoding these urls, and instead use reverse url mapping? At the moment this is really the only place where I find myself writing the same urls in multiple...
28
2009-10-05T04:40:49Z
8,790,991
<p>In django development version reverse_lazy() becomes an option: <a href="https://docs.djangoproject.com/en/dev/ref/urlresolvers/#reverse-lazy" rel="nofollow">https://docs.djangoproject.com/en/dev/ref/urlresolvers/#reverse-lazy</a></p>
11
2012-01-09T15:42:51Z
[ "python", "django", "url", "dry" ]
Using Embedded Dictionary for iterative charater replacement
1,518,358
<p>I'm trying to understand an iterative function that that takes a string "12345" and returns all the possible misspellings based upon a dictionary of keys close to each character in the string.</p> <pre><code>outerDic = {} Dict1 = {'1':'2','2':'q'} outerDic['1'] = Dict1 Dict1 = {'1':'1','2':'q','3':'w','4':'3'} oute...
0
2009-10-05T05:14:09Z
1,518,387
<p>I'm not sure what the inner dicts, all with keys '1', '2', etc, signify -- are they basically just stand-ins for lists presenting possible typos? But then some (but not all) would also include the "right" character... a non-typo...?! Sorry, but you're really being extremely confusing in this presentation -- the ex...
1
2009-10-05T05:28:54Z
[ "python", "function", "iteration" ]
Python - Google App Engine
1,518,383
<p>I'm just starting learning google app engine.</p> <p>When I enter the following code below, all I got is "Hello world!" I think the desired result is "Hello, webapp World!"</p> <p>What am I missing? I even try copying the google framework folder to live in the same folder as my app.</p> <p>Thanks.</p> <pre><code...
0
2009-10-05T05:27:43Z
1,518,392
<p>Running exactly this code DOES give me the desired output. I suspect you must be erroneously running some <em>other</em> code, since there's absolutely <strong>no</strong> way this code as given could possibly emit what you observe.</p>
5
2009-10-05T05:30:50Z
[ "python" ]
How to parse Youtube search results?
1,518,481
<p>When a user submits a query, I would like to append this to search results in Youtube and download this "page" on the backend of my code (Python-Django).</p> <p>What is the best way to do this? Do you suggest that I do this manually? And create a custom parser? Scanning each line for a certain pattern...</p> <p>O...
0
2009-10-05T06:13:49Z
1,518,526
<p>The preferred way is probably with the <a href="http://code.google.com/apis/youtube/getting%5Fstarted.html#data%5Fapi" rel="nofollow">YouTube API</a></p>
5
2009-10-05T06:36:59Z
[ "python" ]
Stripping code for production
1,518,484
<p>So I want to physically get rid of debugging code before deploying it to appengine. What I'm doing right now is a simple check:</p> <pre><code>settings.py: DEBUG = os.environ['HTTP_HOST'] == 'localhost' from settings import DEBUG if DEBUG: #ensure I haven't screwed smth up during refactoring </code></pre> <p>...
0
2009-10-05T06:14:55Z
1,518,489
<p>No, there isn't clean way. </p> <p><a href="http://stackoverflow.com/questions/560040/conditional-compilation-in-python">http://stackoverflow.com/questions/560040/conditional-compilation-in-python</a></p> <p>Differrent question, similar goals.</p>
3
2009-10-05T06:18:55Z
[ "python", "google-app-engine" ]
Stripping code for production
1,518,484
<p>So I want to physically get rid of debugging code before deploying it to appengine. What I'm doing right now is a simple check:</p> <pre><code>settings.py: DEBUG = os.environ['HTTP_HOST'] == 'localhost' from settings import DEBUG if DEBUG: #ensure I haven't screwed smth up during refactoring </code></pre> <p>...
0
2009-10-05T06:14:55Z
1,518,512
<p>If you are worried about the code and able to do this, you could use a decorator approach to inject the debugs, and then for production code, redefine the decorator functions to be no-ops. </p> <p>Honestly, I wouldn't worry about it though since the if statement should correspond to a jump statement in assembly, or...
2
2009-10-05T06:32:56Z
[ "python", "google-app-engine" ]
Stripping code for production
1,518,484
<p>So I want to physically get rid of debugging code before deploying it to appengine. What I'm doing right now is a simple check:</p> <pre><code>settings.py: DEBUG = os.environ['HTTP_HOST'] == 'localhost' from settings import DEBUG if DEBUG: #ensure I haven't screwed smth up during refactoring </code></pre> <p>...
0
2009-10-05T06:14:55Z
1,519,061
<p>First, I'd suggest making your check "os.environ['SERVER_SOFTWARE'].startswith('Dev')". This will work even if you access the dev server on another host.</p> <p>Also, your 'DEBUG' statement will only be evaluated the first time the config module is imported on each App server instance. This is fine, since the debug...
2
2009-10-05T09:34:06Z
[ "python", "google-app-engine" ]
Stripping code for production
1,518,484
<p>So I want to physically get rid of debugging code before deploying it to appengine. What I'm doing right now is a simple check:</p> <pre><code>settings.py: DEBUG = os.environ['HTTP_HOST'] == 'localhost' from settings import DEBUG if DEBUG: #ensure I haven't screwed smth up during refactoring </code></pre> <p>...
0
2009-10-05T06:14:55Z
1,519,143
<p>You would most likely benefit from using the <a href="http://docs.python.org/library/logging.html" rel="nofollow">logging module</a> and importance levels.</p> <p>Code wouldn't need to be removed before publishing, you can granularly configure the importance level should you ever need to debug in production and it ...
1
2009-10-05T09:55:19Z
[ "python", "google-app-engine" ]
Python most common element in a list
1,518,522
<p>What is an efficient way to find the most common element in a Python list?</p> <p>My list items may not be hashable so can't use a dictionary. Also in case of draws the item with the lowest index should be returned. Example:</p> <pre><code>&gt;&gt;&gt; most_common(['duck', 'duck', 'goose']) 'duck' &gt;&gt;&gt; mos...
63
2009-10-05T06:35:44Z
1,518,531
<p>If they are not hashable, you can sort them and do a single loop over the result counting the items (identical items will be next to each other). But it might be faster to make them hashable and use a dict.</p> <pre><code>def most_common(lst): cur_length = 0 max_length = 0 cur_i = 0 max_i = 0 cu...
8
2009-10-05T06:39:56Z
[ "python", "list" ]
Python most common element in a list
1,518,522
<p>What is an efficient way to find the most common element in a Python list?</p> <p>My list items may not be hashable so can't use a dictionary. Also in case of draws the item with the lowest index should be returned. Example:</p> <pre><code>&gt;&gt;&gt; most_common(['duck', 'duck', 'goose']) 'duck' &gt;&gt;&gt; mos...
63
2009-10-05T06:35:44Z
1,518,533
<p>Sort a copy of the list and find the longest run. You can decorate the list before sorting it with the index of each element, and then choose the run that starts with the lowest index in the case of a tie.</p>
5
2009-10-05T06:40:21Z
[ "python", "list" ]
Python most common element in a list
1,518,522
<p>What is an efficient way to find the most common element in a Python list?</p> <p>My list items may not be hashable so can't use a dictionary. Also in case of draws the item with the lowest index should be returned. Example:</p> <pre><code>&gt;&gt;&gt; most_common(['duck', 'duck', 'goose']) 'duck' &gt;&gt;&gt; mos...
63
2009-10-05T06:35:44Z
1,518,542
<p>This is the obvious slow solution (O(n^2)) if neither sorting nor hashing is feasible, but equality comparison (<code>==</code>) is available:</p> <pre><code>def most_common(items): if not items: raise ValueError fitems = [] best_idx = 0 for item in items: item_missing = True i = 0 for f...
1
2009-10-05T06:46:53Z
[ "python", "list" ]
Python most common element in a list
1,518,522
<p>What is an efficient way to find the most common element in a Python list?</p> <p>My list items may not be hashable so can't use a dictionary. Also in case of draws the item with the lowest index should be returned. Example:</p> <pre><code>&gt;&gt;&gt; most_common(['duck', 'duck', 'goose']) 'duck' &gt;&gt;&gt; mos...
63
2009-10-05T06:35:44Z
1,518,563
<p>Here:</p> <pre><code>def most_common(l): max = 0 maxitem = None for x in set(l): count = l.count(x) if count &gt; max: max = count maxitem = x return maxitem </code></pre> <p>I have a vague feeling there is a method somewhere in the standard library that wil...
0
2009-10-05T06:56:18Z
[ "python", "list" ]
Python most common element in a list
1,518,522
<p>What is an efficient way to find the most common element in a Python list?</p> <p>My list items may not be hashable so can't use a dictionary. Also in case of draws the item with the lowest index should be returned. Example:</p> <pre><code>&gt;&gt;&gt; most_common(['duck', 'duck', 'goose']) 'duck' &gt;&gt;&gt; mos...
63
2009-10-05T06:35:44Z
1,518,564
<pre><code>&gt;&gt;&gt; li = ['goose', 'duck', 'duck'] &gt;&gt;&gt; def foo(li): st = set(li) mx = -1 for each in st: temp = li.count(each): if mx &lt; temp: mx = temp h = each return h &gt;&gt;&gt; foo(li) 'duck' </cod...
0
2009-10-05T06:56:50Z
[ "python", "list" ]
Python most common element in a list
1,518,522
<p>What is an efficient way to find the most common element in a Python list?</p> <p>My list items may not be hashable so can't use a dictionary. Also in case of draws the item with the lowest index should be returned. Example:</p> <pre><code>&gt;&gt;&gt; most_common(['duck', 'duck', 'goose']) 'duck' &gt;&gt;&gt; mos...
63
2009-10-05T06:35:44Z
1,518,588
<p>A one-liner:</p> <pre><code>def most_common (lst): return max(((item, lst.count(item)) for item in set(lst)), key=lambda a: a[1])[0]</code></pre>
2
2009-10-05T07:04:24Z
[ "python", "list" ]
Python most common element in a list
1,518,522
<p>What is an efficient way to find the most common element in a Python list?</p> <p>My list items may not be hashable so can't use a dictionary. Also in case of draws the item with the lowest index should be returned. Example:</p> <pre><code>&gt;&gt;&gt; most_common(['duck', 'duck', 'goose']) 'duck' &gt;&gt;&gt; mos...
63
2009-10-05T06:35:44Z
1,518,632
<p>A simpler one-liner:</p> <pre><code>def most_common(lst): return max(set(lst), key=lst.count) </code></pre>
253
2009-10-05T07:14:52Z
[ "python", "list" ]
Python most common element in a list
1,518,522
<p>What is an efficient way to find the most common element in a Python list?</p> <p>My list items may not be hashable so can't use a dictionary. Also in case of draws the item with the lowest index should be returned. Example:</p> <pre><code>&gt;&gt;&gt; most_common(['duck', 'duck', 'goose']) 'duck' &gt;&gt;&gt; mos...
63
2009-10-05T06:35:44Z
1,518,754
<pre><code># use Decorate, Sort, Undecorate to solve the problem def most_common(iterable): # Make a list with tuples: (item, index) # The index will be used later to break ties for most common item. lst = [(x, i) for i, x in enumerate(iterable)] lst.sort() # lst_final will also be a list of tuple...
2
2009-10-05T08:02:50Z
[ "python", "list" ]
Python most common element in a list
1,518,522
<p>What is an efficient way to find the most common element in a Python list?</p> <p>My list items may not be hashable so can't use a dictionary. Also in case of draws the item with the lowest index should be returned. Example:</p> <pre><code>&gt;&gt;&gt; most_common(['duck', 'duck', 'goose']) 'duck' &gt;&gt;&gt; mos...
63
2009-10-05T06:35:44Z
1,519,293
<p>This is an O(n) solution.</p> <pre><code>mydict = {} cnt, itm = 0, '' for item in reversed(lst): mydict[item] = mydict.get(item, 0) + 1 if mydict[item] &gt;= cnt : cnt, itm = mydict[item], item print itm </code></pre> <p>(reversed is used to make sure that it returns the lowest index item)</p...
4
2009-10-05T10:29:02Z
[ "python", "list" ]
Python most common element in a list
1,518,522
<p>What is an efficient way to find the most common element in a Python list?</p> <p>My list items may not be hashable so can't use a dictionary. Also in case of draws the item with the lowest index should be returned. Example:</p> <pre><code>&gt;&gt;&gt; most_common(['duck', 'duck', 'goose']) 'duck' &gt;&gt;&gt; mos...
63
2009-10-05T06:35:44Z
1,520,716
<p>With so many solutions proposed, I'm amazed nobody's proposed what I'd consider an obvious one (for non-hashable but comparable elements) -- [<code>itertools.groupby</code>][1]. <code>itertools</code> offers fast, reusable functionality, and lets you delegate some tricky logic to well-tested standard library compon...
49
2009-10-05T15:16:29Z
[ "python", "list" ]
Python most common element in a list
1,518,522
<p>What is an efficient way to find the most common element in a Python list?</p> <p>My list items may not be hashable so can't use a dictionary. Also in case of draws the item with the lowest index should be returned. Example:</p> <pre><code>&gt;&gt;&gt; most_common(['duck', 'duck', 'goose']) 'duck' &gt;&gt;&gt; mos...
63
2009-10-05T06:35:44Z
2,634,155
<p>You probably don't need this anymore, but this is what I did for a similar problem. (It looks longer than it is because of the comments.)</p> <pre><code>itemList = ['hi', 'hi', 'hello', 'bye'] counter = {} maxItemCount = 0 for item in itemList: try: # Referencing this will cause a KeyError exception ...
3
2010-04-14T00:35:16Z
[ "python", "list" ]
Python most common element in a list
1,518,522
<p>What is an efficient way to find the most common element in a Python list?</p> <p>My list items may not be hashable so can't use a dictionary. Also in case of draws the item with the lowest index should be returned. Example:</p> <pre><code>&gt;&gt;&gt; most_common(['duck', 'duck', 'goose']) 'duck' &gt;&gt;&gt; mos...
63
2009-10-05T06:35:44Z
19,600,390
<pre><code>def mostCommon(lst): # Finds the element of highest value &amp; occurrence table = {} # Counts the number of occurences for each number for ele in lst: if ele in table: table[ele] = table[ele] + 1 else: table.update( {ele : 1} ) # Inverts the key...
0
2013-10-25T22:30:07Z
[ "python", "list" ]