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
Is there a way in Sphinx/Pygments to emphasize one or more lines of code in literal includes?
2,473,214
<p>In some sphinx docs I am writing, I am including code samples from an ancillary file like so:</p> <pre><code>.. literalinclude:: mymodule.py :pyobject: MyClass :linenos: </code></pre> <p>This particular doc is a tutorial, where the classes are build up step by step. What I would like to do is include the ent...
8
2010-03-18T20:41:07Z
2,529,616
<p>You could patch sphinx's LiteralInclude directive in sphinx/directives/code.py</p> <ul> <li>There you would need to do something such that when you include code you can specify a start/end line to emphasize in this snippet.</li> <li>The second step would require creating some ways to highlight things differently. T...
2
2010-03-27T14:29:30Z
[ "python", "documentation-generation", "python-sphinx", "pygments" ]
Is there a way in Sphinx/Pygments to emphasize one or more lines of code in literal includes?
2,473,214
<p>In some sphinx docs I am writing, I am including code samples from an ancillary file like so:</p> <pre><code>.. literalinclude:: mymodule.py :pyobject: MyClass :linenos: </code></pre> <p>This particular doc is a tutorial, where the classes are build up step by step. What I would like to do is include the ent...
8
2010-03-18T20:41:07Z
10,198,601
<p>Sphinx now has an <code>emphasize-lines</code> directive for literal includes:</p> <p><a href="http://sphinx-doc.org/markup/code.html#includes" rel="nofollow">http://sphinx-doc.org/markup/code.html#includes</a></p>
5
2012-04-17T20:26:44Z
[ "python", "documentation-generation", "python-sphinx", "pygments" ]
How to get Eclipse + PyDev + App Engine + Unit testing to work?
2,473,467
<p>I want to run my unit tests for a Python Google App Engine project using</p> <blockquote> <p>Run As => Python unit-test</p> </blockquote> <p>But when I try that all my Model tests bail with the error message:</p> <pre><code>BadArgumentError: app must not be empty. </code></pre> <p>Anyone got this to work?</p> ...
4
2010-03-18T21:30:42Z
2,486,747
<p>Pasting the answer I got from the Fabioz (the PyDev creator) himself over at the PyDev forums on SF: <a href="https://sourceforge.net/projects/pydev/forums/forum/293649/topic/3618848" rel="nofollow">https://sourceforge.net/projects/pydev/forums/forum/293649/topic/3618848</a></p> <blockquote> <p>There's no such op...
3
2010-03-21T10:44:51Z
[ "python", "unit-testing", "google-app-engine", "pydev" ]
How do I set a Jabber status with python-xmpp?
2,473,487
<p>How do I set a GChat or jabber status via python? Right now I've got this:</p> <pre><code>import xmpp new_status = "blah blah blah" login = 'email' pwd = 'password' cnx = xmpp.Client('gmail.com') cnx.connect( server=('talk.google.com',5223) ) cnx.auth(login, pwd, 'botty') pres = xmpp.Presence() pres.set...
5
2010-03-18T21:33:23Z
2,473,772
<p>You might want to take a look at this file:</p> <p><a href="http://steliosm.net/projects/picaxejabber/picaxe_xmpp.py" rel="nofollow">http://steliosm.net/projects/picaxejabber/picaxe_xmpp.py</a></p> <p><strong>Edit:</strong> My bad, first answer was out of context, I've misread your code.</p> <pre><code>cnx.sendIn...
1
2010-03-18T22:27:26Z
[ "python", "chat", "xmpp", "status" ]
How do I set a Jabber status with python-xmpp?
2,473,487
<p>How do I set a GChat or jabber status via python? Right now I've got this:</p> <pre><code>import xmpp new_status = "blah blah blah" login = 'email' pwd = 'password' cnx = xmpp.Client('gmail.com') cnx.connect( server=('talk.google.com',5223) ) cnx.auth(login, pwd, 'botty') pres = xmpp.Presence() pres.set...
5
2010-03-18T21:33:23Z
3,563,976
<p>NOTE: wanted to mention this to those who want to do what's mentioned in this thread. If one is not familiar with XMPP protocol and stanzas, one might miss some needed info to set proper status. The xmpppy module docs don't seem to explicitly clarify the steps to set presence.</p> <p>Setting initial presence is eas...
1
2010-08-25T08:10:24Z
[ "python", "chat", "xmpp", "status" ]
PyQt and unittest - how to handle signals and slots
2,473,577
<p>some small application I'm developing uses a module I have written to check certain web services via a REST API. I've been trying to add unit tests to it so I don't break stuff, and I stumbled upon a problem.</p> <p>I use a lot of signal-slot connections to perform operations asynchronously. For example a typical t...
1
2010-03-18T21:52:40Z
2,474,624
<p>You need to avoid exiting the test method until the callback has been called. I believe the call is going to happen in a separate thread, so a <a href="http://docs.python.org/library/threading.html?highlight=threading.event#threading.Event" rel="nofollow">threading.Event</a> seems appropriate:</p> <pre><code>impor...
2
2010-03-19T02:28:55Z
[ "python", "pyqt", "unit-testing" ]
Get the Model context of a Key object in Datastore (App Engine)
2,473,632
<p>I'd like to bypass some frequent queries by storing <code>str(key)</code> in memcache. When I get the <code>encoded_key</code> back from memcached, I can reconstruct the key with <code>Key(encoded=encoded_key)</code>.</p> <p>But how can I query the actual object from the key? A possibility would be to use</p> <pre...
0
2010-03-18T22:01:48Z
2,473,653
<p>Are you just storing the result of <code>str(key)</code> in memcached? If so, when you get it back, you should be able to just do <code>db.get(key)</code> to get the entity to which it points.</p> <p><code>db.get()</code> will take either a <code>db.Key</code> object or the string representation of a <code>db.Key<...
3
2010-03-18T22:06:00Z
[ "python", "google-app-engine", "gae-datastore" ]
How to make a call to an executable from Python script?
2,473,655
<p>I need to execute this script from my Python script.</p> <p>Is it possible? The script generate some outputs with some files being written. How do I access these files? I have tried with subprocess call function but without success.</p> <pre><code>fx@fx-ubuntu:~/Documents/projects/foo$ bin/bar -c somefile.xml -d t...
5
2010-03-18T22:06:07Z
2,473,728
<p>The simplest way is:</p> <pre><code>import os cmd = 'bin/bar --option --otheroption' os.system(cmd) # returns the exit status </code></pre> <p>You access the files in the usual way, by using <code>open()</code>.</p> <p>If you need to do more complicated subprocess management then the <a href="http://docs.python.o...
8
2010-03-18T22:17:18Z
[ "python", "linux", "executable", "system-calls" ]
How to make a call to an executable from Python script?
2,473,655
<p>I need to execute this script from my Python script.</p> <p>Is it possible? The script generate some outputs with some files being written. How do I access these files? I have tried with subprocess call function but without success.</p> <pre><code>fx@fx-ubuntu:~/Documents/projects/foo$ bin/bar -c somefile.xml -d t...
5
2010-03-18T22:06:07Z
2,474,508
<p>For executing the external program, do this:</p> <pre><code>import subprocess args = ("bin/bar", "-c", "somefile.xml", "-d", "text.txt", "-r", "aString", "-f", "anotherString") #Or just: #args = "bin/bar -c somefile.xml -d text.txt -r aString -f anotherString".split() popen = subprocess.Popen(args, stdout=subproces...
19
2010-03-19T01:47:04Z
[ "python", "linux", "executable", "system-calls" ]
Python: speed up removal of every n-th element from list
2,473,710
<p>I'm trying to solve <a href="http://www.spoj.pl/problems/ASSIST/" rel="nofollow">this programming riddle</a> and although the solution (see code below) <strong>works</strong> correctly, it is too slow for succesful submission.</p> <ul> <li>Any pointers as how to make this run faster (removal of every n-th element f...
8
2010-03-18T22:14:01Z
2,473,769
<p>You're better off using an array and zeroing out every Nth item using that strategy; after you do this a few times in a row, the updates start getting tricky so you'd want to re-form the array. This should improve the speed by at least a factor of 10. Do you need vastly better than that?</p>
1
2010-03-18T22:26:55Z
[ "python", "performance", "algorithm" ]
Python: speed up removal of every n-th element from list
2,473,710
<p>I'm trying to solve <a href="http://www.spoj.pl/problems/ASSIST/" rel="nofollow">this programming riddle</a> and although the solution (see code below) <strong>works</strong> correctly, it is too slow for succesful submission.</p> <ul> <li>Any pointers as how to make this run faster (removal of every n-th element f...
8
2010-03-18T22:14:01Z
2,473,913
<p>Try using these two lines for the deletion and filtering, instead of what you have; <code>filter(None, ...)</code> runs considerably faster than the <code>filter(lambda ...)</code>.</p> <pre><code>sieve[::item] = [0]*-(-len(sieve)//item) sieve = filter(None, sieve) </code></pre> <p>Edit: much better to simply use...
4
2010-03-18T22:58:13Z
[ "python", "performance", "algorithm" ]
Python: speed up removal of every n-th element from list
2,473,710
<p>I'm trying to solve <a href="http://www.spoj.pl/problems/ASSIST/" rel="nofollow">this programming riddle</a> and although the solution (see code below) <strong>works</strong> correctly, it is too slow for succesful submission.</p> <ul> <li>Any pointers as how to make this run faster (removal of every n-th element f...
8
2010-03-18T22:14:01Z
2,474,047
<p>An explanation on how to solve this problem can be found <a href="http://www.algorithmist.com/index.php/UVa_10909" rel="nofollow">here</a>. (The problem I linked to asks for more, but the main step in that problem is the same as the one you're trying to solve.) The site I linked to also contains a sample solution in...
2
2010-03-18T23:28:52Z
[ "python", "performance", "algorithm" ]
Python: speed up removal of every n-th element from list
2,473,710
<p>I'm trying to solve <a href="http://www.spoj.pl/problems/ASSIST/" rel="nofollow">this programming riddle</a> and although the solution (see code below) <strong>works</strong> correctly, it is too slow for succesful submission.</p> <ul> <li>Any pointers as how to make this run faster (removal of every n-th element f...
8
2010-03-18T22:14:01Z
2,474,665
<p>Why not just create a new list?</p> <pre><code>L = [x for (i, x) in enumerate(L) if i % n] </code></pre>
0
2010-03-19T02:38:07Z
[ "python", "performance", "algorithm" ]
Python: speed up removal of every n-th element from list
2,473,710
<p>I'm trying to solve <a href="http://www.spoj.pl/problems/ASSIST/" rel="nofollow">this programming riddle</a> and although the solution (see code below) <strong>works</strong> correctly, it is too slow for succesful submission.</p> <ul> <li>Any pointers as how to make this run faster (removal of every n-th element f...
8
2010-03-18T22:14:01Z
2,474,809
<p>This series is called <strong><a href="http://www.research.att.com/~njas/sequences/A003309" rel="nofollow">ludic numbers</a></strong></p> <p><code>__delslice__</code> should be faster than <code>__setslice__</code>+<code>filter</code></p> <pre><code>&gt;&gt;&gt; L=[2,3,4,5,6,7,8,9,10,11,12] &gt;&gt;&gt; lucky=[] &...
7
2010-03-19T03:27:28Z
[ "python", "performance", "algorithm" ]
Python 'datetime.datetime' object is unsubscriptable
2,473,760
<p>First, I am NOT a python developer. I am trying to fix an issue within a python script that is being executed from the command line. This script was written by someone who is no longer around, and no longer willing to help with issues. </p> <p>This is python 2.5, and for the moment it cannot be upgraded. Here are t...
1
2010-03-18T22:25:02Z
2,473,814
<p>Its not the import fault. Its the *start_time[:6] *end_time[:6] that Python doesn't like. Replace it</p>
1
2010-03-18T22:35:34Z
[ "python" ]
Python 'datetime.datetime' object is unsubscriptable
2,473,760
<p>First, I am NOT a python developer. I am trying to fix an issue within a python script that is being executed from the command line. This script was written by someone who is no longer around, and no longer willing to help with issues. </p> <p>This is python 2.5, and for the moment it cannot be upgraded. Here are t...
1
2010-03-18T22:25:02Z
2,473,828
<p>It looks like you just want the time right? The datetime.strptime method returns a 'datetime' object and as such the following attributes contain the time: datetime.day, datetime.hour, datetime.year, etc.</p>
2
2010-03-18T22:39:09Z
[ "python" ]
Python 'datetime.datetime' object is unsubscriptable
2,473,760
<p>First, I am NOT a python developer. I am trying to fix an issue within a python script that is being executed from the command line. This script was written by someone who is no longer around, and no longer willing to help with issues. </p> <p>This is python 2.5, and for the moment it cannot be upgraded. Here are t...
1
2010-03-18T22:25:02Z
2,473,928
<p>The following code doesn't make sense to me:</p> <pre><code>start_time = datetime.strptime(str(paf.Start),"%Y-%m-%d %H:%M:%S") dict_start = datetime(*start_time[:6]) </code></pre> <p>If you need a tuple mapping in dict_start, then use something like this:</p> <pre><code>start_time = datetime.strptime(str(paf.Star...
0
2010-03-18T23:00:36Z
[ "python" ]
Python 'datetime.datetime' object is unsubscriptable
2,473,760
<p>First, I am NOT a python developer. I am trying to fix an issue within a python script that is being executed from the command line. This script was written by someone who is no longer around, and no longer willing to help with issues. </p> <p>This is python 2.5, and for the moment it cannot be upgraded. Here are t...
1
2010-03-18T22:25:02Z
2,473,973
<p>Robert, try replacing</p> <pre><code>dict_start = datetime(*start_time[:6]) </code></pre> <p>with</p> <pre><code>dict_start = start_time </code></pre> <p>and </p> <pre><code>dict_end = datetime(*end_time[:6]) </code></pre> <p>with </p> <pre><code>dict_end = end_time </code></pre> <p>It looks silly, but perha...
1
2010-03-18T23:08:33Z
[ "python" ]
Python 'datetime.datetime' object is unsubscriptable
2,473,760
<p>First, I am NOT a python developer. I am trying to fix an issue within a python script that is being executed from the command line. This script was written by someone who is no longer around, and no longer willing to help with issues. </p> <p>This is python 2.5, and for the moment it cannot be upgraded. Here are t...
1
2010-03-18T22:25:02Z
2,474,603
<p>Looks like the <code>datetime.strptime</code> call was actually meant to be a call to <code>time.strptime</code> (with a separate <code>import time</code> at the start of the module) -- the latter call would indeed return a subscriptable, tuple-like object, and the idiom</p> <pre><code>xx = time.strptime(...) yy = ...
1
2010-03-19T02:20:18Z
[ "python" ]
Python 'datetime.datetime' object is unsubscriptable
2,473,760
<p>First, I am NOT a python developer. I am trying to fix an issue within a python script that is being executed from the command line. This script was written by someone who is no longer around, and no longer willing to help with issues. </p> <p>This is python 2.5, and for the moment it cannot be upgraded. Here are t...
1
2010-03-18T22:25:02Z
2,474,638
<p>Observations:</p> <p>Whoever wrote the code didn't test it; it never could have run properly.</p> <p>Whoever wrote it was confusing datetime.datetime.strptime with time.strptime.</p> <p>Once upon a time (pun intended) datetime.datetime.strptime didn't exist. One had to do something like the following: </p> <pre>...
1
2010-03-19T02:31:47Z
[ "python" ]
Is there a way to circumvent Python list.append() becoming progressively slower in a loop as the list grows?
2,473,783
<p>I have a big file I'm reading from, and convert every few lines to an instance of an Object.</p> <p>Since I'm looping through the file, I stash the instance to a list using list.append(instance), and then continue looping.</p> <p>This is a file that's around ~100MB so it isn't too large, but as the list grows lar...
35
2010-03-18T22:30:08Z
2,473,827
<p>Can you try <strike>http://docs.python.org/release/2.5.2/lib/deque-objects.html</strike> allocating expected number of required elements in your list? ? I would bet that list is a contiguous storage that has to be reallocated and copied every few iterations. (similar to some popular implementations of std::vector in...
1
2010-03-18T22:39:07Z
[ "python", "class", "list", "performance", "append" ]
Is there a way to circumvent Python list.append() becoming progressively slower in a loop as the list grows?
2,473,783
<p>I have a big file I'm reading from, and convert every few lines to an instance of an Object.</p> <p>Since I'm looping through the file, I stash the instance to a list using list.append(instance), and then continue looping.</p> <p>This is a file that's around ~100MB so it isn't too large, but as the list grows lar...
35
2010-03-18T22:30:08Z
2,474,076
<p>There is nothing to circumvent: <strong>appending to a list is O(1) amortized.</strong> </p> <p>A list (in CPython) is an array at least as long as the list and up to twice as long. If the array isn't full, appending to a list is just as simple as assigning one of the array members (O(1)). Every time the array is f...
12
2010-03-18T23:37:09Z
[ "python", "class", "list", "performance", "append" ]
Is there a way to circumvent Python list.append() becoming progressively slower in a loop as the list grows?
2,473,783
<p>I have a big file I'm reading from, and convert every few lines to an instance of an Object.</p> <p>Since I'm looping through the file, I stash the instance to a list using list.append(instance), and then continue looping.</p> <p>This is a file that's around ~100MB so it isn't too large, but as the list grows lar...
35
2010-03-18T22:30:08Z
2,474,124
<p>A lot of these answers are just wild guesses. I like Mike Graham's the best because he's right about how lists are implemented. But I've written some code to reproduce your claim and look into it further. Here are some findings.</p> <p>Here's what I started with.</p> <pre><code>import time x = [] for i in range...
4
2010-03-18T23:50:22Z
[ "python", "class", "list", "performance", "append" ]
Is there a way to circumvent Python list.append() becoming progressively slower in a loop as the list grows?
2,473,783
<p>I have a big file I'm reading from, and convert every few lines to an instance of an Object.</p> <p>Since I'm looping through the file, I stash the instance to a list using list.append(instance), and then continue looping.</p> <p>This is a file that's around ~100MB so it isn't too large, but as the list grows lar...
35
2010-03-18T22:30:08Z
2,480,015
<p><em>The poor performance you observe is caused by a bug in the Python garbage collector. <strong>To resolve this issue, disable garbage collection as you build the list and turn it on after you finish.</strong> You will find that performance approximates the amoritized 0(1) behavior expected of list appending in P...
80
2010-03-19T19:20:21Z
[ "python", "class", "list", "performance", "append" ]
Is there a way to circumvent Python list.append() becoming progressively slower in a loop as the list grows?
2,473,783
<p>I have a big file I'm reading from, and convert every few lines to an instance of an Object.</p> <p>Since I'm looping through the file, I stash the instance to a list using list.append(instance), and then continue looping.</p> <p>This is a file that's around ~100MB so it isn't too large, but as the list grows lar...
35
2010-03-18T22:30:08Z
8,308,736
<p>I encountered this problem while using Numpy arrays, created as follows:</p> <pre><code>import numpy theArray = array([],dtype='int32') </code></pre> <p>Appending to this array within a loop took progressively longer as the array grew, which was a deal-breaker given that I had 14M appends to make.</p> <p>The garb...
1
2011-11-29T09:50:17Z
[ "python", "class", "list", "performance", "append" ]
Is there a way to circumvent Python list.append() becoming progressively slower in a loop as the list grows?
2,473,783
<p>I have a big file I'm reading from, and convert every few lines to an instance of an Object.</p> <p>Since I'm looping through the file, I stash the instance to a list using list.append(instance), and then continue looping.</p> <p>This is a file that's around ~100MB so it isn't too large, but as the list grows lar...
35
2010-03-18T22:30:08Z
38,669,493
<p>Use a set instead then convert it to a list at the end</p> <pre><code>my_set=set() with open(in_file) as f: # do your thing my_set.add(instance) my_list=list(my_set) my_list.sort() # if you want it sorted </code></pre> <p>I had the same problem and this solved the time problem by several orders. </p>
0
2016-07-30T01:20:52Z
[ "python", "class", "list", "performance", "append" ]
Python script web service timeout
2,473,872
<p>We have had a Python script running for many months now that simply scans through a directory of files, and posts each file to our web site via a web service call. The web site is also written in Python.</p> <p>For no apparent reason, this morning this script started throwing the following error:</p> <pre><code>ur...
0
2010-03-18T22:47:32Z
2,473,911
<p>I think if it was working up until this point the suspect is not the code but the site. However, you may want to dig around in the code and write some debugging. The urllib2 module method urlopen throws the object URLError as you can see and has an attribute 'reason'. Beyond that I am not sure what you might do t...
0
2010-03-18T22:57:22Z
[ "python" ]
Python 3 Gui Development?
2,473,949
<p>Are there any good gui libraries for python 3 (NOT 2)? I would love to use tkinter but it's widgets are not native and it is extremely ugly in my opinion. I was wondering if there were any other gui libraries for python 3.</p>
17
2010-03-18T23:03:52Z
2,473,984
<p>in python 3.1, you can use <a href="http://docs.python.org/dev/py3k/library/tkinter.ttk.html">ttk</a> (tk themed widgets)<br> widgets look more native and not as ugly (imo).</p>
5
2010-03-18T23:10:26Z
[ "python", "python-3.x" ]
Python 3 Gui Development?
2,473,949
<p>Are there any good gui libraries for python 3 (NOT 2)? I would love to use tkinter but it's widgets are not native and it is extremely ugly in my opinion. I was wondering if there were any other gui libraries for python 3.</p>
17
2010-03-18T23:03:52Z
2,474,183
<p><a href="http://www.riverbankcomputing.co.uk/" rel="nofollow">That would be PyQt</a> (currently at 4.7.2, supporting Python 3.x since 4.6 if I recall correctly).</p> <p>This is not just any GUI library, this is (in my opinion) <strong>the</strong> most mature Python cross-platform GUI library. (PyQt are the binding...
4
2010-03-19T00:05:27Z
[ "python", "python-3.x" ]
Python 3 Gui Development?
2,473,949
<p>Are there any good gui libraries for python 3 (NOT 2)? I would love to use tkinter but it's widgets are not native and it is extremely ugly in my opinion. I was wondering if there were any other gui libraries for python 3.</p>
17
2010-03-18T23:03:52Z
2,482,691
<p>PyQt has had <a href="http://www.riverbankcomputing.com/news/pyqt-45" rel="nofollow">support for Python 3 since version 4.5</a>.</p> <p>The dual license for PyQt may not be suitable for your purposes. Nokia is keen to have Qt bindings for Python freely available for use, including commercial. Negotiating for PyQt ...
7
2010-03-20T10:45:23Z
[ "python", "python-3.x" ]
Python 3 Gui Development?
2,473,949
<p>Are there any good gui libraries for python 3 (NOT 2)? I would love to use tkinter but it's widgets are not native and it is extremely ugly in my opinion. I was wondering if there were any other gui libraries for python 3.</p>
17
2010-03-18T23:03:52Z
13,523,175
<p>I gave a glance at <em>PyQt4</em> and <em>ttk</em>, as suggested by other answers to this question. I think <em>PyQt4</em> is the best of the two from the technical perspective, but for what I saw it's definitely not <em>pythonic</em>, as it is a direct translation from the C++ API).</p> <p>Searching for another al...
0
2012-11-23T04:37:49Z
[ "python", "python-3.x" ]
Python 3 Gui Development?
2,473,949
<p>Are there any good gui libraries for python 3 (NOT 2)? I would love to use tkinter but it's widgets are not native and it is extremely ugly in my opinion. I was wondering if there were any other gui libraries for python 3.</p>
17
2010-03-18T23:03:52Z
23,186,109
<p>Finally, wxPython is getting ready, too.</p> <p>I just installed a pre-release version (dev76380) of wxPython3.0.1 (Phoenix) for Python 3.4 (64-bit) on my Windows 7 box. According to the mailing list (<a href="https://groups.google.com/forum/#!topic/wxpython-dev/LmGIrQyh7jc" rel="nofollow">https://groups.google.com...
1
2014-04-20T18:27:34Z
[ "python", "python-3.x" ]
Calculate Matrix Rank using scipy
2,473,983
<p>I'd like to calculate the <a href="http://en.wikipedia.org/wiki/Rank_%28linear_algebra%29">mathematical rank</a> of a matrix using scipy. The most obvious function <code>numpy.rank</code> calculates the dimension of an array (ie. scalars have dimension 0, vectors 1, matrices 2, etc...). I am aware that the <code>num...
32
2010-03-18T23:10:19Z
2,474,029
<p>I don't know about Numpy in particular, but that's unlikely to be a built-in operation on a matrix; it involves fairly intensive numerical computations (and associated concerns about floating-point roundoff error and so forth) and threshold selections that may or may not be appropriate in a given context, and algori...
1
2010-03-18T23:22:58Z
[ "python", "matrix", "numpy", "scipy" ]
Calculate Matrix Rank using scipy
2,473,983
<p>I'd like to calculate the <a href="http://en.wikipedia.org/wiki/Rank_%28linear_algebra%29">mathematical rank</a> of a matrix using scipy. The most obvious function <code>numpy.rank</code> calculates the dimension of an array (ie. scalars have dimension 0, vectors 1, matrices 2, etc...). I am aware that the <code>num...
32
2010-03-18T23:10:19Z
2,474,035
<p>The <strong>linear algebra functions are generally grouped in <code>numpy.linalg</code></strong>. (They're also available from <code>scipy.linalg</code>, which has more functionality.) This allows polymorphism: the functions can accept any of the types that SciPy handles.</p> <p>So, yes, <strong>the <code>numpy.lin...
1
2010-03-18T23:25:41Z
[ "python", "matrix", "numpy", "scipy" ]
Calculate Matrix Rank using scipy
2,473,983
<p>I'd like to calculate the <a href="http://en.wikipedia.org/wiki/Rank_%28linear_algebra%29">mathematical rank</a> of a matrix using scipy. The most obvious function <code>numpy.rank</code> calculates the dimension of an array (ie. scalars have dimension 0, vectors 1, matrices 2, etc...). I am aware that the <code>num...
32
2010-03-18T23:10:19Z
2,474,251
<p><strong>This answer is out of date.</strong></p> <p>The answer is no—there is currently no function dedicated to calculating the matrix rank of an array/matrix in scipy. Adding one has been discussed before, but if it's going to happen, I don't believe it has yet.</p>
2
2010-03-19T00:21:28Z
[ "python", "matrix", "numpy", "scipy" ]
Calculate Matrix Rank using scipy
2,473,983
<p>I'd like to calculate the <a href="http://en.wikipedia.org/wiki/Rank_%28linear_algebra%29">mathematical rank</a> of a matrix using scipy. The most obvious function <code>numpy.rank</code> calculates the dimension of an array (ie. scalars have dimension 0, vectors 1, matrices 2, etc...). I am aware that the <code>num...
32
2010-03-18T23:10:19Z
3,356,123
<p>To provide a rough code snippet for people who need to get this done in practice. Feel free to improve.</p> <pre><code>u, s, v = np.linalg.svd(A) rank = np.sum(s &gt; 1e-10) </code></pre>
11
2010-07-28T18:24:14Z
[ "python", "matrix", "numpy", "scipy" ]
Calculate Matrix Rank using scipy
2,473,983
<p>I'd like to calculate the <a href="http://en.wikipedia.org/wiki/Rank_%28linear_algebra%29">mathematical rank</a> of a matrix using scipy. The most obvious function <code>numpy.rank</code> calculates the dimension of an array (ie. scalars have dimension 0, vectors 1, matrices 2, etc...). I am aware that the <code>num...
32
2010-03-18T23:10:19Z
3,356,217
<p>If <code>numpy</code> does not offer a rank facility, why don't you write your own?</p> <p>An efficient way to compute the rank is via the Singular Value Decomposition - the rank of the matrix is equal to the number of non-zero singular values.</p> <pre><code>def rank(A, eps=1e-12): u, s, vh = numpy.linalg.svd...
5
2010-07-28T18:36:57Z
[ "python", "matrix", "numpy", "scipy" ]
Calculate Matrix Rank using scipy
2,473,983
<p>I'd like to calculate the <a href="http://en.wikipedia.org/wiki/Rank_%28linear_algebra%29">mathematical rank</a> of a matrix using scipy. The most obvious function <code>numpy.rank</code> calculates the dimension of an array (ie. scalars have dimension 0, vectors 1, matrices 2, etc...). I am aware that the <code>num...
32
2010-03-18T23:10:19Z
6,900,786
<p>Numpy provides <code>numpy.linalg.matrix_rank()</code>:</p> <pre><code>&gt;&gt;&gt; import numpy &gt;&gt;&gt; numpy.__version__ '1.5.1' &gt;&gt;&gt; A = numpy.matrix([[1,3,7],[2,8,3],[7,8,1]]) &gt;&gt;&gt; numpy.linalg.matrix_rank(A) 3 </code></pre>
45
2011-08-01T15:32:57Z
[ "python", "matrix", "numpy", "scipy" ]
Getting the index of the returned max or min item using max()/min() on a list
2,474,015
<p>I'm using Python's <code>max</code> and <code>min</code> functions on lists for a minimax algorithm, and I need the index of the value returned by <code>max()</code> or <code>min()</code>. In other words, I need to know which move produced the max (at a first player's turn) or min (second player) value.</p> <pre><c...
121
2010-03-18T23:20:35Z
2,474,030
<pre> if isMinLevel: return values.index(min(values)) else: return values.index(max(values)) </pre>
94
2010-03-18T23:23:08Z
[ "python" ]
Getting the index of the returned max or min item using max()/min() on a list
2,474,015
<p>I'm using Python's <code>max</code> and <code>min</code> functions on lists for a minimax algorithm, and I need the index of the value returned by <code>max()</code> or <code>min()</code>. In other words, I need to know which move produced the max (at a first player's turn) or min (second player) value.</p> <pre><c...
121
2010-03-18T23:20:35Z
2,474,238
<p>You can find the min/max index and value at the same time if you enumerate the items in the list, but perform min/max on the original values of the list. Like so:</p> <pre><code>import operator min_index, min_value = min(enumerate(values), key=operator.itemgetter(1)) max_index, max_value = max(enumerate(values), ke...
175
2010-03-19T00:18:32Z
[ "python" ]
Getting the index of the returned max or min item using max()/min() on a list
2,474,015
<p>I'm using Python's <code>max</code> and <code>min</code> functions on lists for a minimax algorithm, and I need the index of the value returned by <code>max()</code> or <code>min()</code>. In other words, I need to know which move produced the max (at a first player's turn) or min (second player) value.</p> <pre><c...
121
2010-03-18T23:20:35Z
5,667,773
<p>I think the answer above solves your problem but I thought I'd share a method that gives you the minimum and all the indices the minimum appears in.</p> <pre><code>minval = min(mylist) ind = [i for i, v in enumerate(mylist) if v == minval] </code></pre> <p>This passes the list twice but is still quite fast. It is ...
1
2011-04-14T18:22:41Z
[ "python" ]
Getting the index of the returned max or min item using max()/min() on a list
2,474,015
<p>I'm using Python's <code>max</code> and <code>min</code> functions on lists for a minimax algorithm, and I need the index of the value returned by <code>max()</code> or <code>min()</code>. In other words, I need to know which move produced the max (at a first player's turn) or min (second player) value.</p> <pre><c...
121
2010-03-18T23:20:35Z
10,046,066
<p>Just a minor addition to what has already been said. <code>values.index(min(values))</code> seems to return the smallest index of min. The following gets the largest index:</p> <pre><code> values.reverse() (values.index(min(values)) + len(values) - 1) % len(values) values.reverse() </code></pre> <p>The ...
1
2012-04-06T16:09:02Z
[ "python" ]
Getting the index of the returned max or min item using max()/min() on a list
2,474,015
<p>I'm using Python's <code>max</code> and <code>min</code> functions on lists for a minimax algorithm, and I need the index of the value returned by <code>max()</code> or <code>min()</code>. In other words, I need to know which move produced the max (at a first player's turn) or min (second player) value.</p> <pre><c...
121
2010-03-18T23:20:35Z
11,825,864
<p>Say that you have a list <code>values = [3,6,1,5]</code>, and need the index of the smallest element, i.e. <code>index_min = 2</code> in this case.</p> <p>Avoid the solution with <code>itemgetter()</code> presented in the other answers, and use instead</p> <pre><code>index_min = min(xrange(len(values)), key=values...
113
2012-08-06T09:43:48Z
[ "python" ]
Getting the index of the returned max or min item using max()/min() on a list
2,474,015
<p>I'm using Python's <code>max</code> and <code>min</code> functions on lists for a minimax algorithm, and I need the index of the value returned by <code>max()</code> or <code>min()</code>. In other words, I need to know which move produced the max (at a first player's turn) or min (second player) value.</p> <pre><c...
121
2010-03-18T23:20:35Z
13,533,657
<p>If you want to find the index of max within a list of numbers (which seems your case), then I suggest you use numpy:</p> <pre><code>import numpy as np ind = np.argmax(mylist) </code></pre>
52
2012-11-23T17:41:42Z
[ "python" ]
Getting the index of the returned max or min item using max()/min() on a list
2,474,015
<p>I'm using Python's <code>max</code> and <code>min</code> functions on lists for a minimax algorithm, and I need the index of the value returned by <code>max()</code> or <code>min()</code>. In other words, I need to know which move produced the max (at a first player's turn) or min (second player) value.</p> <pre><c...
121
2010-03-18T23:20:35Z
13,989,707
<p>Possibly a simpler solution would be to turn the array of values into an array of value,index-pairs, and take the max/min of that. This would give the largest/smallest index that has the max/min (i.e. pairs are compared by first comparing the first element, and then comparing the second element if the first ones are...
19
2012-12-21T11:53:50Z
[ "python" ]
Getting the index of the returned max or min item using max()/min() on a list
2,474,015
<p>I'm using Python's <code>max</code> and <code>min</code> functions on lists for a minimax algorithm, and I need the index of the value returned by <code>max()</code> or <code>min()</code>. In other words, I need to know which move produced the max (at a first player's turn) or min (second player) value.</p> <pre><c...
121
2010-03-18T23:20:35Z
18,678,087
<pre><code>list=[1.1412, 4.3453, 5.8709, 0.1314] list.index(min(list)) </code></pre> <p>Will give you first index of minimum.</p>
11
2013-09-07T21:30:44Z
[ "python" ]
Getting the index of the returned max or min item using max()/min() on a list
2,474,015
<p>I'm using Python's <code>max</code> and <code>min</code> functions on lists for a minimax algorithm, and I need the index of the value returned by <code>max()</code> or <code>min()</code>. In other words, I need to know which move produced the max (at a first player's turn) or min (second player) value.</p> <pre><c...
121
2010-03-18T23:20:35Z
29,100,695
<p>Why bother to add indices first and then reverse them? Enumerate() function is just a special case of zip() function usage. Let's use it in appropiate way:</p> <pre><code>my_indexed_list = zip(my_list, range(len(my_list))) min_value, min_index = min(my_indexed_list) max_value, max_index = max(my_indexed_list) </co...
2
2015-03-17T13:45:16Z
[ "python" ]
Getting the index of the returned max or min item using max()/min() on a list
2,474,015
<p>I'm using Python's <code>max</code> and <code>min</code> functions on lists for a minimax algorithm, and I need the index of the value returned by <code>max()</code> or <code>min()</code>. In other words, I need to know which move produced the max (at a first player's turn) or min (second player) value.</p> <pre><c...
121
2010-03-18T23:20:35Z
29,669,315
<p>Use numpy module's function numpy.where</p> <pre><code>import numpy as n x = n.array((3,3,4,7,4,56,65,1)) </code></pre> <p>For index of minimum value: </p> <pre><code>idx = n.where(x==x.min())[0] </code></pre> <p>For index of maximum value:</p> <pre><code>idx = n.where(x==x.max())[0] </code></pre> <p>In fac...
3
2015-04-16T08:29:14Z
[ "python" ]
Getting the index of the returned max or min item using max()/min() on a list
2,474,015
<p>I'm using Python's <code>max</code> and <code>min</code> functions on lists for a minimax algorithm, and I need the index of the value returned by <code>max()</code> or <code>min()</code>. In other words, I need to know which move produced the max (at a first player's turn) or min (second player) value.</p> <pre><c...
121
2010-03-18T23:20:35Z
32,639,622
<p><a href="https://docs.python.org/3/library/functions.html#max" rel="nofollow">https://docs.python.org/3/library/functions.html#max</a></p> <p>If multiple items are maximal, the function returns the first one encountered. This is consistent with other sort-stability preserving tools such as <code>sorted(iterable, ke...
0
2015-09-17T20:42:25Z
[ "python" ]
Getting the index of the returned max or min item using max()/min() on a list
2,474,015
<p>I'm using Python's <code>max</code> and <code>min</code> functions on lists for a minimax algorithm, and I need the index of the value returned by <code>max()</code> or <code>min()</code>. In other words, I need to know which move produced the max (at a first player's turn) or min (second player) value.</p> <pre><c...
121
2010-03-18T23:20:35Z
38,850,518
<p>A simple way for finding the indexes with minimal value in a list if you don't want to import additional modules:</p> <pre><code>min_value = min(values) indexes_with_min_value = [i for i in range(0,len(values)) if values[i] == min_value] </code></pre> <p>Then choose for example the first one:</p> <pre><code>choos...
0
2016-08-09T12:17:54Z
[ "python" ]
How do I retrieve an automated report and save it to a database?
2,474,062
<p>I've got a web server that will take scripts in Python, PHP or Perl. I don't know much about any of those languages, but of the three, Python seems the least scary. It has a MySql database set up, and I know enough SQL to manage it and write queries for it.</p> <p>I also have a program that I want to add automate...
0
2010-03-18T23:33:36Z
2,474,134
<p>I don't know python so I am showing you php.</p> <p>So assuming your bug sending code posts to <code>file.php?report=report+is+here</code></p> <p>The following will work. </p> <pre><code>&lt;? # code to initialize the database here $rc = mysql_connect(...); if (!$rc) { die ("Could not connect to the datab...
0
2010-03-18T23:51:49Z
[ "python", "error-reporting" ]
How do I retrieve an automated report and save it to a database?
2,474,062
<p>I've got a web server that will take scripts in Python, PHP or Perl. I don't know much about any of those languages, but of the three, Python seems the least scary. It has a MySql database set up, and I know enough SQL to manage it and write queries for it.</p> <p>I also have a program that I want to add automate...
0
2010-03-18T23:33:36Z
2,474,205
<p>With Python, it depends on your web hosting. Some shared web hosts do PHP and then only do Perl/Python (and Ruby etc.) through CGI. With Python, you can build web stuff either using the CGI model or - if you have hosting that supports it - WSGI. If you are going to do Python and CGI, just look in the documentation f...
0
2010-03-19T00:10:00Z
[ "python", "error-reporting" ]
Python to extract data from a file
2,474,216
<p>I am trying to extract the text between that has specific text file: </p> <pre><code>---- data1 data1 data1 extractme ---- data2 data2 data2 ---- data3 data3 extractme ---- </code></pre> <p>and then dump it to text file so that</p> <pre><code>---- data1 data1 data1 extractme --- data3 data3 extractme --- </code>...
1
2010-03-19T00:11:21Z
2,474,258
<p>For Python2</p> <pre><code>#!/usr/bin/env python with open("infile.txt") as infile: with open("outfile.txt","w") as outfile: collector = [] for line in infile: if line.startswith("----"): collector = [] collector.append(line) if line.startswit...
2
2010-03-19T00:22:23Z
[ "python", "file-io" ]
Python to extract data from a file
2,474,216
<p>I am trying to extract the text between that has specific text file: </p> <pre><code>---- data1 data1 data1 extractme ---- data2 data2 data2 ---- data3 data3 extractme ---- </code></pre> <p>and then dump it to text file so that</p> <pre><code>---- data1 data1 data1 extractme --- data3 data3 extractme --- </code>...
1
2010-03-19T00:11:21Z
2,474,453
<p>This works well enough for me. Your sample data is in a file called "data.txt" and the output goes to "result.txt"</p> <pre><code>inFile = open("data.txt") outFile = open("result.txt", "w") buffer = [] keepCurrentSet = True for line in inFile: buffer.append(line) if line.startswith("----"): #---- s...
4
2010-03-19T01:30:07Z
[ "python", "file-io" ]
Python to extract data from a file
2,474,216
<p>I am trying to extract the text between that has specific text file: </p> <pre><code>---- data1 data1 data1 extractme ---- data2 data2 data2 ---- data3 data3 extractme ---- </code></pre> <p>and then dump it to text file so that</p> <pre><code>---- data1 data1 data1 extractme --- data3 data3 extractme --- </code>...
1
2010-03-19T00:11:21Z
2,474,489
<p>I imagine the change in number of dashes (4 in the input, sometimes 4 and sometimes 3 in the output) is an error and not actually desired (since no algorithm is even hinted at, to explain how many dashes are to be output on different occasions).</p> <p>I would structure the task in terms of reading and yielding one...
4
2010-03-19T01:41:46Z
[ "python", "file-io" ]
Python to extract data from a file
2,474,216
<p>I am trying to extract the text between that has specific text file: </p> <pre><code>---- data1 data1 data1 extractme ---- data2 data2 data2 ---- data3 data3 extractme ---- </code></pre> <p>and then dump it to text file so that</p> <pre><code>---- data1 data1 data1 extractme --- data3 data3 extractme --- </code>...
1
2010-03-19T00:11:21Z
2,474,499
<pre><code>data=open("file").read().split("----") print '----'.join([ i for i in data if "extractme" in i ]) </code></pre>
1
2010-03-19T01:44:38Z
[ "python", "file-io" ]
Python for a hobbyist programmer ( a few questions)
2,474,224
<p>I'm a hobbyist programmer (only in TI-Basic before now), and after much, much, much debating with myself, I've decided to learn Python. I don't have a ton of free time to teach myself a hundred languages and all programming I do will be for personal use or for distributing to people who need them, so I decided that ...
9
2010-03-19T00:14:23Z
2,474,240
<blockquote> <p>Is python powerful enough to handle most things?</p> </blockquote> <p>Yes. Period. Study <a href="http://play.eveonline.com/en/home.aspx" rel="nofollow">EveOnline</a> game for more information. Look at <a href="http://www.pygame.org/news.html" rel="nofollow">pygame</a> framework. Free free to u...
14
2010-03-19T00:18:36Z
[ "python", "networking", "programming-languages", "robust" ]
Python for a hobbyist programmer ( a few questions)
2,474,224
<p>I'm a hobbyist programmer (only in TI-Basic before now), and after much, much, much debating with myself, I've decided to learn Python. I don't have a ton of free time to teach myself a hundred languages and all programming I do will be for personal use or for distributing to people who need them, so I decided that ...
9
2010-03-19T00:14:23Z
2,474,246
<p>I think that Python is very powerful to do a lot of things, but just like Java and C++, it often depends on good third-party libraries. I come from a Java background but use Python for a lot of things, and it's been a fun ride. I've done things like statistics, and automation, not sure about the UI though that often...
6
2010-03-19T00:19:58Z
[ "python", "networking", "programming-languages", "robust" ]
Python for a hobbyist programmer ( a few questions)
2,474,224
<p>I'm a hobbyist programmer (only in TI-Basic before now), and after much, much, much debating with myself, I've decided to learn Python. I don't have a ton of free time to teach myself a hundred languages and all programming I do will be for personal use or for distributing to people who need them, so I decided that ...
9
2010-03-19T00:14:23Z
2,474,256
<ol> <li><p>Probably yes. Maybe the stat crunching thing will be kinda slow, and maybe a game depending on what kind of game, but generally the performance is good enough, and you save a lot of time on the actual programming. If you REALLY need performance, you can make a module in C, but usually there is a library wri...
2
2010-03-19T00:22:16Z
[ "python", "networking", "programming-languages", "robust" ]
Python for a hobbyist programmer ( a few questions)
2,474,224
<p>I'm a hobbyist programmer (only in TI-Basic before now), and after much, much, much debating with myself, I've decided to learn Python. I don't have a ton of free time to teach myself a hundred languages and all programming I do will be for personal use or for distributing to people who need them, so I decided that ...
9
2010-03-19T00:14:23Z
2,474,262
<ol> <li>Absolutely.</li> <li>What type of networking? It has socket, http, xml, smtp/pop, telnet, and much more built in.</li> <li>Python obfuscation won't be nearly as good as a compiled language. Usually that isn't a problem.</li> <li>It's the <a href="http://stackoverflow.com/tags">9th most popular tag on stackover...
4
2010-03-19T00:23:37Z
[ "python", "networking", "programming-languages", "robust" ]
Python for a hobbyist programmer ( a few questions)
2,474,224
<p>I'm a hobbyist programmer (only in TI-Basic before now), and after much, much, much debating with myself, I've decided to learn Python. I don't have a ton of free time to teach myself a hundred languages and all programming I do will be for personal use or for distributing to people who need them, so I decided that ...
9
2010-03-19T00:14:23Z
2,474,325
<blockquote> <p>Is python powerful enough to handle most things that a typical programmer might do in his off-time? I have in mind things like complex stat generators based on user input for tabletop games, making small games, automate install processes, and build interactive websites, but probably a hundred things a...
3
2010-03-19T00:41:12Z
[ "python", "networking", "programming-languages", "robust" ]
Python for a hobbyist programmer ( a few questions)
2,474,224
<p>I'm a hobbyist programmer (only in TI-Basic before now), and after much, much, much debating with myself, I've decided to learn Python. I don't have a ton of free time to teach myself a hundred languages and all programming I do will be for personal use or for distributing to people who need them, so I decided that ...
9
2010-03-19T00:14:23Z
2,475,188
<p>Points 1 and 2: HELL YEAH.</p> <p>Point 4: kind of. Python is good at some network stuff. It's not Java or C++. Just use zlib (zip library) and pickle (serialization) for everything, and look at xmlrpclib if you need IPC.</p> <p>Point 3: No. However, you can write C modules (for the performance critical, and hard-...
0
2010-03-19T05:38:56Z
[ "python", "networking", "programming-languages", "robust" ]
Python for a hobbyist programmer ( a few questions)
2,474,224
<p>I'm a hobbyist programmer (only in TI-Basic before now), and after much, much, much debating with myself, I've decided to learn Python. I don't have a ton of free time to teach myself a hundred languages and all programming I do will be for personal use or for distributing to people who need them, so I decided that ...
9
2010-03-19T00:14:23Z
2,475,530
<p>Python is up to the task (and better) for 1, 2 and 4.</p> <p>The best solution for 3 from what you describe would probably be to make your programs really open-source with GPL or BSD like licence. This way people will edit your super-cool sources (but often experienced programmers, not just script kiddies) and buil...
0
2010-03-19T07:06:00Z
[ "python", "networking", "programming-languages", "robust" ]
Make CSRF middleware work in Django's 404 error pages
2,474,310
<p>I put a login box alone with a keyword search box in 404.html in a Django project so in case a 404 error is raised, visitors get more options to jump to other parts.</p> <p>But the CSRF middleware doesn't work in 404 error page with no csrf token rendered. I tried move 'django.middleware.csrf.CsrfViewMiddleware' to...
1
2010-03-19T00:36:08Z
2,476,827
<p>My idea is you should make <a href="http://docs.djangoproject.com/en/dev/topics/http/views/#customizing-error-views" rel="nofollow">your own error handler</a> and generate the token manually with django.middleware.csrf.get_token()</p>
0
2010-03-19T11:33:27Z
[ "python", "django", "csrf", "middleware" ]
Make CSRF middleware work in Django's 404 error pages
2,474,310
<p>I put a login box alone with a keyword search box in 404.html in a Django project so in case a 404 error is raised, visitors get more options to jump to other parts.</p> <p>But the CSRF middleware doesn't work in 404 error page with no csrf token rendered. I tried move 'django.middleware.csrf.CsrfViewMiddleware' to...
1
2010-03-19T00:36:08Z
4,454,123
<p>Looks like they've fixed this in Django <a href="http://code.djangoproject.com/ticket/14565" rel="nofollow">http://code.djangoproject.com/ticket/14565</a></p> <p>That said, it doesn't seem to be in the latest release, so I created a custom error view with the same contents as <code>'django.views.defaults.page_not_f...
1
2010-12-15T19:43:00Z
[ "python", "django", "csrf", "middleware" ]
Precomputed Kernels with LibSVM in Python
2,474,460
<p>I've been searching the net for ~3 hours but I couldn't find a solution yet. I want to give a precomputed kernel to libsvm and classify a dataset, but:</p> <ul> <li><p>How can I generate a precomputed kernel? (for example, what is the basic precomputed kernel for <a href="http://archive.ics.uci.edu/ml/machine-learn...
6
2010-03-19T01:32:12Z
2,476,353
<p><strong>First of all</strong>, some background to kernels and SVMs...</p> <p>If you want to pre-compute a kernel for <code>n</code> vectors (of any dimension), what need to do is calculate the kernel function between each pair of examples. The kernel function takes two vectors and gives a scalar, so you can think o...
12
2010-03-19T10:07:27Z
[ "python", "machine-learning", "libsvm" ]
Precomputed Kernels with LibSVM in Python
2,474,460
<p>I've been searching the net for ~3 hours but I couldn't find a solution yet. I want to give a precomputed kernel to libsvm and classify a dataset, but:</p> <ul> <li><p>How can I generate a precomputed kernel? (for example, what is the basic precomputed kernel for <a href="http://archive.ics.uci.edu/ml/machine-learn...
6
2010-03-19T01:32:12Z
3,691,381
<p>I believe that the <a href="http://scikit-learn.sourceforge.net" rel="nofollow">scikit-learn</a>'s binding of libSVM should answer your needs. See the examples and the documentation at <a href="http://scikit-learn.sourceforge.net/modules/svm.html#kernel-functions" rel="nofollow">http://scikit-learn.sourceforge.net/m...
3
2010-09-11T14:42:23Z
[ "python", "machine-learning", "libsvm" ]
Precomputed Kernels with LibSVM in Python
2,474,460
<p>I've been searching the net for ~3 hours but I couldn't find a solution yet. I want to give a precomputed kernel to libsvm and classify a dataset, but:</p> <ul> <li><p>How can I generate a precomputed kernel? (for example, what is the basic precomputed kernel for <a href="http://archive.ics.uci.edu/ml/machine-learn...
6
2010-03-19T01:32:12Z
3,704,188
<p>Here is a simple two category 3 vector custom kernel input file that works correctly. I will explain the parts (though you should also see StompChicken's answer):</p> <p><code> 1 0:1 1:10 2:12 3:21<br> 2 0:2 1:12 2:19 3:30<br> 1 0:3 1:21 2:30 3:130<br> </code></p> <p>The first number on each line is which categor...
2
2010-09-13T20:35:40Z
[ "python", "machine-learning", "libsvm" ]
Precomputed Kernels with LibSVM in Python
2,474,460
<p>I've been searching the net for ~3 hours but I couldn't find a solution yet. I want to give a precomputed kernel to libsvm and classify a dataset, but:</p> <ul> <li><p>How can I generate a precomputed kernel? (for example, what is the basic precomputed kernel for <a href="http://archive.ics.uci.edu/ml/machine-learn...
6
2010-03-19T01:32:12Z
4,458,811
<p>scikit-learn hides most of the details of libsvm when handling custom kernels. You can either just pass an arbitrary function as your kernel and it will compute the gram matrix for you or pass the precomputed Gram matrix of the kernel.</p> <p>For the first one, the syntax is:</p> <pre><code> &gt;&gt;&gt; from sc...
4
2010-12-16T08:39:28Z
[ "python", "machine-learning", "libsvm" ]
Extending Python and Objective-C
2,474,554
<p>I'm a fan of clean code. I like my languages to be able to express what I'm trying to do, but I like the syntax to mirror that too.</p> <p>For example, I work on a lot of programs in Objective-C for jailbroken iPhones, which patch other code using the <code>method_setImplementation()</code> function of the runtime....
1
2010-03-19T02:01:08Z
2,474,626
<p>If you don't have any experience in compiler or interpreter design my answer is an emphatic NO, it is one of the biggest challenges in computer science.</p> <p>If you do have experience my answer shifts to "that is a really dumb idea."</p> <p>Do you envision this becoming a large mature product that other people w...
2
2010-03-19T02:29:28Z
[ "python", "objective-c", "pyobjc" ]
Extending Python and Objective-C
2,474,554
<p>I'm a fan of clean code. I like my languages to be able to express what I'm trying to do, but I like the syntax to mirror that too.</p> <p>For example, I work on a lot of programs in Objective-C for jailbroken iPhones, which patch other code using the <code>method_setImplementation()</code> function of the runtime....
1
2010-03-19T02:01:08Z
2,475,334
<p><em>There are only two kinds of programming languages:</em>, the truism goes, <em>the ones every one complains about and the ones no one uses.</em> People who want to make programs don't choose a language because it's beautiful or clean; they choose it because it is supported, available, and not so awful that you ju...
1
2010-03-19T06:15:56Z
[ "python", "objective-c", "pyobjc" ]
Explicit disable MySQL query cache in some parts of program
2,474,609
<p>In a Django project, some cronjob programs are mainly used for administrative or analysis purposes, e.g. generating site usage stats, rotating user activities log, etc. </p> <p>We probably do not hope MySQL to cache queries in those programs to save memory usage and improve query cache efficiency. </p> <p>Is it po...
2
2010-03-19T02:23:17Z
2,474,643
<p>Per <a href="http://dev.mysql.com/doc/refman/5.1/en/query-cache-configuration.html" rel="nofollow">http://dev.mysql.com/doc/refman/5.1/en/query-cache-configuration.html</a></p> <blockquote> <p>Individual clients can control cache behavior for their own connection by setting the SESSION query_cache_type value. Fo...
2
2010-03-19T02:32:54Z
[ "python", "mysql", "django", "caching" ]
From escaped html -> to regular html? - Python
2,474,971
<p>I used BeautifulSoup to handle XML files that I have collected through a REST API.</p> <p>The responses contain HTML code, but BeautifulSoup escapes all the HTML tags so it can be displayed nicely.</p> <p>Unfortunately I need the HTML code.</p> <hr> <p>How would I go on about transforming the escaped HTML into p...
3
2010-03-19T04:25:24Z
2,474,992
<p>I think you want <a href="http://docs.python.org/library/xml.sax.utils.html?highlight=xml#xml.sax.saxutils.unescape">xml.sax.saxutils.unescape</a> from the Python standard library.</p> <p>E.g.:</p> <pre><code>&gt;&gt;&gt; from xml.sax import saxutils as su &gt;&gt;&gt; s = '&amp;lt;foo&amp;gt;bar&amp;lt;/foo&amp;g...
10
2010-03-19T04:31:55Z
[ "python", "html", "escaping", "beautifulsoup", "lxml" ]
From escaped html -> to regular html? - Python
2,474,971
<p>I used BeautifulSoup to handle XML files that I have collected through a REST API.</p> <p>The responses contain HTML code, but BeautifulSoup escapes all the HTML tags so it can be displayed nicely.</p> <p>Unfortunately I need the HTML code.</p> <hr> <p>How would I go on about transforming the escaped HTML into p...
3
2010-03-19T04:25:24Z
2,475,000
<p>You could try the <a href="http://docs.python.org/library/urllib.html" rel="nofollow">urllib</a> module?</p> <p>It has a method <code>unquote()</code> that might suit your needs.</p> <p>Edit: on second thought, (and more reading of your question) you might just want to just use <code>string.replace()</code></p> <...
0
2010-03-19T04:33:33Z
[ "python", "html", "escaping", "beautifulsoup", "lxml" ]
construct graph from python set type
2,475,176
<p>The short question, is there an off the self function to make a graph from a collection of python sets? The longer question: I have several python sets. They each overlap or some are sub sets of others. I would like to make a graph (as in nodes and edges) nodes are the elements in the sets. The edges are intersectio...
0
2010-03-19T05:36:29Z
2,475,377
<p>It's not too hard to code yourself:</p> <pre><code>def intersection_graph(sets): adjacency_list = {} for i, s1 in enumerate(sets): for j, s2 in enumerate(sets): if j == i: continue try: lst = adjacency_list[i] except KeyError: ...
1
2010-03-19T06:24:52Z
[ "python", "graph", "set", "nodes", "edges" ]
construct graph from python set type
2,475,176
<p>The short question, is there an off the self function to make a graph from a collection of python sets? The longer question: I have several python sets. They each overlap or some are sub sets of others. I would like to make a graph (as in nodes and edges) nodes are the elements in the sets. The edges are intersectio...
0
2010-03-19T05:36:29Z
2,476,249
<p>&nbsp;</p> <pre><code>def MakeGraphfromSets(sets): egs = [] l = len(sets) for i in range(l): for j in range(i,l): w = sets[i].intersection(sets[j]) egs.append((i,j,len(w))) return egs # (source set index,destination set index,length of intersection) sets = [set([1,2...
1
2010-03-19T09:48:32Z
[ "python", "graph", "set", "nodes", "edges" ]
How do I set prifix to django contrib tables names?
2,475,215
<p>HI</p> <p>One of my requirement is to have prefix on all the tables of the django based project (Because db is hosted on shared server). I have used db_table Meta option to set the prefix for the tables which I have created. </p> <p>Now my query is how do I set the prefix for tables provided by django.contrib.</p>...
0
2010-03-19T05:46:05Z
2,475,858
<p>From reading <a href="http://code.djangoproject.com/ticket/891" rel="nofollow">this ticket</a>, I would say it is not possible without a hack.</p>
1
2010-03-19T08:27:18Z
[ "python", "django", "django-models" ]
Python | How to append elements to a list randomly
2,475,518
<p>Is there a way to append elements to a list randomly, built in function</p> <p>ex:</p> <pre><code>def random_append(): lst = ['a'] lst.append('b') lst.append('c') lst.append('d') lst.append('e') return print lst </code></pre> <p>this will out put <code>['a', 'b', 'c', 'd', 'e']</code...
5
2010-03-19T07:03:46Z
2,475,536
<p>If there is supposed to be exactly one of each item</p> <pre><code>&gt;&gt;&gt; from random import randint &gt;&gt;&gt; a=[] &gt;&gt;&gt; for x in "abcde": ... a.insert(randint(0,len(a)),x) ... &gt;&gt;&gt; a ['b', 'a', 'd', 'c', 'e'] </code></pre> <p>If you are allowing duplicates (as the output indicates)</p> ...
10
2010-03-19T07:08:59Z
[ "python" ]
Python | How to append elements to a list randomly
2,475,518
<p>Is there a way to append elements to a list randomly, built in function</p> <p>ex:</p> <pre><code>def random_append(): lst = ['a'] lst.append('b') lst.append('c') lst.append('d') lst.append('e') return print lst </code></pre> <p>this will out put <code>['a', 'b', 'c', 'd', 'e']</code...
5
2010-03-19T07:03:46Z
2,475,603
<p><code>random.shuffle</code> is probably the best tool for the job. It is simple, obvious, and well-named—it's probably more readable than the other suggestions you will get. Additionally, using it is O(n), but using <code>insert</code> (an O(n) operation) n times is quadratic.</p>
6
2010-03-19T07:25:45Z
[ "python" ]
Python | How to append elements to a list randomly
2,475,518
<p>Is there a way to append elements to a list randomly, built in function</p> <p>ex:</p> <pre><code>def random_append(): lst = ['a'] lst.append('b') lst.append('c') lst.append('d') lst.append('e') return print lst </code></pre> <p>this will out put <code>['a', 'b', 'c', 'd', 'e']</code...
5
2010-03-19T07:03:46Z
2,475,867
<pre><code>from random import choice n=10 seq=['a','b','c','d'] rstr=[choice(seq) for i in range(n)] </code></pre>
0
2010-03-19T08:28:41Z
[ "python" ]
Python | How to append elements to a list randomly
2,475,518
<p>Is there a way to append elements to a list randomly, built in function</p> <p>ex:</p> <pre><code>def random_append(): lst = ['a'] lst.append('b') lst.append('c') lst.append('d') lst.append('e') return print lst </code></pre> <p>this will out put <code>['a', 'b', 'c', 'd', 'e']</code...
5
2010-03-19T07:03:46Z
2,478,217
<p>If you need to perform single insert in a random position then the already given trivial exapmle works:</p> <pre><code>from random import randrange, sample def random_insert(lst, item): lst.insert(randrange(len(lst)+1), item) </code></pre> <p>However if you need to insert k items to a list of length n then us...
4
2010-03-19T14:55:44Z
[ "python" ]
pygtk - dynamically update the widgets taking input from the gtk combo box
2,475,872
<p>On selecting value from 1 to 10 from gtk combox box it should populate the checkbox by taking combo box value as an input. Say for example if i select 5 then 5 checkbox will be generated. It works.. But the issue is after i selected 5 now im selecting next value as 3 from combo box then there 8 checkboxes are displa...
0
2010-03-19T08:29:20Z
2,481,892
<p>Add this to your code right before you add your comboboxes:</p> <pre><code>for widget in myVBox.get_children(): myVBox.remove(widget) </code></pre>
2
2010-03-20T04:15:53Z
[ "python", "gtk", "pygtk", "glade" ]
Python (Twisted) - reading from fifo and sending read data to multiple protocols
2,476,234
<p>Im trying to write some kind of multi protocol bot (jabber/irc) that would read messages from fifo file (one liners mostly) and then send them to irc channel and jabber contacts. So far, I managed to create two factories to connect to jabber and irc, and they seem to be working. </p> <p>However, I've problem with r...
4
2010-03-19T09:45:17Z
2,476,445
<p>The fifo is the problem. Read from a socket instead. This will fit info the Twisted event-driven model much better. Trying to do things outside the control of the reactor is usually the wrong approach.</p> <p>---- update based on feedback that the fifo is an external constraint, not avoidable ----</p> <p>OK, the c...
1
2010-03-19T10:25:19Z
[ "python", "twisted", "xmpp", "irc", "fifo" ]
Python (Twisted) - reading from fifo and sending read data to multiple protocols
2,476,234
<p>Im trying to write some kind of multi protocol bot (jabber/irc) that would read messages from fifo file (one liners mostly) and then send them to irc channel and jabber contacts. So far, I managed to create two factories to connect to jabber and irc, and they seem to be working. </p> <p>However, I've problem with r...
4
2010-03-19T09:45:17Z
2,478,970
<p>You can read/write on a file descriptor without blocking the reactor as you do with sockets, by the way doesn't sockets use file descriptors?</p> <p>In your case create a class that implements <code>twisted.internet.interfaces.IReadDescriptor</code> and add to reactor using <code>twisted.internet.interfaces.IReacto...
3
2010-03-19T16:39:05Z
[ "python", "twisted", "xmpp", "irc", "fifo" ]
What should I learn & use to become a pro in PHP & Python Web development?
2,476,335
<p>I'll just show some code to show how I do web development in PHP.</p> <pre><code>&lt;html&gt; &lt;head&gt; &lt;title&gt;Example #3 TDavid's Very First PHP Script ever!&lt;/title&gt; &lt;/head&gt; &lt;? print(Date("m/j/y")); require_once("somefile.php"); $mysql_db = "DATABASE NAME"; $mysql_user = "YOUR MYSQL USER...
1
2010-03-19T10:04:23Z
2,476,357
<p>PHP was built for making web pages, so a lot of the infrastructure is already set up for you. Python was built more as a general-purpose scripting language so you need a bit of extra infrastructure to handle requests and produce web pages.</p> <p>There are multiple frameworks for Python. <a href="http://www.djangop...
3
2010-03-19T10:07:59Z
[ "php", "python" ]
What should I learn & use to become a pro in PHP & Python Web development?
2,476,335
<p>I'll just show some code to show how I do web development in PHP.</p> <pre><code>&lt;html&gt; &lt;head&gt; &lt;title&gt;Example #3 TDavid's Very First PHP Script ever!&lt;/title&gt; &lt;/head&gt; &lt;? print(Date("m/j/y")); require_once("somefile.php"); $mysql_db = "DATABASE NAME"; $mysql_user = "YOUR MYSQL USER...
1
2010-03-19T10:04:23Z
2,476,363
<p>My recommendation and the book im actually reading <a href="http://books.google.com/books?id=uaZQAAAAMAAJ&amp;q=advanced+php+programming&amp;dq=advanced+php+programming&amp;hl=es&amp;ei=Nk2jS8H_EZHx4gb196n4CQ&amp;sa=X&amp;oi=book_result&amp;ct=result&amp;resnum=1&amp;ved=0CC4Q6AEwAA" rel="nofollow">http://books.goog...
0
2010-03-19T10:09:17Z
[ "php", "python" ]
What should I learn & use to become a pro in PHP & Python Web development?
2,476,335
<p>I'll just show some code to show how I do web development in PHP.</p> <pre><code>&lt;html&gt; &lt;head&gt; &lt;title&gt;Example #3 TDavid's Very First PHP Script ever!&lt;/title&gt; &lt;/head&gt; &lt;? print(Date("m/j/y")); require_once("somefile.php"); $mysql_db = "DATABASE NAME"; $mysql_user = "YOUR MYSQL USER...
1
2010-03-19T10:04:23Z
2,476,364
<p>There are many PHP frameworks resembling Django. I suggest you try one of them. Like Zend or CodeIgniter.</p>
0
2010-03-19T10:09:32Z
[ "php", "python" ]
What should I learn & use to become a pro in PHP & Python Web development?
2,476,335
<p>I'll just show some code to show how I do web development in PHP.</p> <pre><code>&lt;html&gt; &lt;head&gt; &lt;title&gt;Example #3 TDavid's Very First PHP Script ever!&lt;/title&gt; &lt;/head&gt; &lt;? print(Date("m/j/y")); require_once("somefile.php"); $mysql_db = "DATABASE NAME"; $mysql_user = "YOUR MYSQL USER...
1
2010-03-19T10:04:23Z
2,476,493
<p>One thing you could improve in your code sample: <strong>don't repeat yourself</strong>.</p> <p>You say you do every file like the above? If so, then you have your database password in every file, and the code to create a connection is repeated over and over. That's clutter, and if your database password ever chang...
1
2010-03-19T10:35:19Z
[ "php", "python" ]
What should I learn & use to become a pro in PHP & Python Web development?
2,476,335
<p>I'll just show some code to show how I do web development in PHP.</p> <pre><code>&lt;html&gt; &lt;head&gt; &lt;title&gt;Example #3 TDavid's Very First PHP Script ever!&lt;/title&gt; &lt;/head&gt; &lt;? print(Date("m/j/y")); require_once("somefile.php"); $mysql_db = "DATABASE NAME"; $mysql_user = "YOUR MYSQL USER...
1
2010-03-19T10:04:23Z
2,476,616
<blockquote> <p>But, can any one give me some idea about how web development in Python works?</p> <blockquote> <p>user (client) request for page ---> webserver(->embedded PHP interpreter) ----> Server side(PHP) Script ---> MySQL Server.</p> </blockquote> <p>Now, is it that instead of PHP interpr...
2
2010-03-19T10:56:00Z
[ "php", "python" ]
writing 'bits' to c++ file streams
2,476,748
<p>How can i write 'one bit' into a file stream or file structure each time? is it possible to write to a queue and then flush it ? is it possible with c# or java? this was needed when i try to implement an instance of Huffman codding. i can't write bits into files. so write them to a bitset and then (when compression ...
10
2010-03-19T11:18:23Z
2,476,806
<p>Buffering the individual bits until you've accumulated a whole byte seems like a good idea:</p> <pre><code>byte b; int s; void WriteBit(bool x) { b |= (x ? 1 : 0) &lt;&lt; s; s++; if (s == 8) { WriteByte(b); b = 0; s = 0; } } </code></pre> <p>You just have to deal with...
13
2010-03-19T11:29:24Z
[ "c#", "java", "c++", "python", "bit-fiddling" ]
writing 'bits' to c++ file streams
2,476,748
<p>How can i write 'one bit' into a file stream or file structure each time? is it possible to write to a queue and then flush it ? is it possible with c# or java? this was needed when i try to implement an instance of Huffman codding. i can't write bits into files. so write them to a bitset and then (when compression ...
10
2010-03-19T11:18:23Z
2,476,942
<p>Which filesystem are you using?</p> <p>Most likely it stores the length of the file in bytes (are there <em>any</em> that don't?), so it's impossible to have a physical file that is not a whole number of bytes.</p> <p>So if you are writing to the file as a stream of bits, you either have to truncate the last few b...
3
2010-03-19T11:53:27Z
[ "c#", "java", "c++", "python", "bit-fiddling" ]
writing 'bits' to c++ file streams
2,476,748
<p>How can i write 'one bit' into a file stream or file structure each time? is it possible to write to a queue and then flush it ? is it possible with c# or java? this was needed when i try to implement an instance of Huffman codding. i can't write bits into files. so write them to a bitset and then (when compression ...
10
2010-03-19T11:18:23Z
2,477,060
<p>You can't really. I'm pretty sure the problem is not with the language or the filesystem, but a hardware issue. Processors are designed to work with bytes. Probably the closest you can do is write your last byte over and over again, right padded with zeros, changing them as you go, one at a time.</p> <p>so to wr...
0
2010-03-19T12:10:09Z
[ "c#", "java", "c++", "python", "bit-fiddling" ]
writing 'bits' to c++ file streams
2,476,748
<p>How can i write 'one bit' into a file stream or file structure each time? is it possible to write to a queue and then flush it ? is it possible with c# or java? this was needed when i try to implement an instance of Huffman codding. i can't write bits into files. so write them to a bitset and then (when compression ...
10
2010-03-19T11:18:23Z
2,477,111
<p>I would recommend allocating a rather large buffer (4096 bytes at least) and flush that off to disk whenever it fills up. Using a one-byte buffer usually causes bad performance.</p>
0
2010-03-19T12:16:47Z
[ "c#", "java", "c++", "python", "bit-fiddling" ]
writing 'bits' to c++ file streams
2,476,748
<p>How can i write 'one bit' into a file stream or file structure each time? is it possible to write to a queue and then flush it ? is it possible with c# or java? this was needed when i try to implement an instance of Huffman codding. i can't write bits into files. so write them to a bitset and then (when compression ...
10
2010-03-19T11:18:23Z
2,477,157
<p>I did this once for huffman decoding and ended up writing the bits as chars and thus handling everything internally as a plain old C string. </p> <p>That way you don't have to worry about the trailing byte and it's human readable as well. Also checking bits is is easier since its just a matter of addressing the cha...
0
2010-03-19T12:23:38Z
[ "c#", "java", "c++", "python", "bit-fiddling" ]
writing 'bits' to c++ file streams
2,476,748
<p>How can i write 'one bit' into a file stream or file structure each time? is it possible to write to a queue and then flush it ? is it possible with c# or java? this was needed when i try to implement an instance of Huffman codding. i can't write bits into files. so write them to a bitset and then (when compression ...
10
2010-03-19T11:18:23Z
2,477,696
<p>You can use <a href="http://www.boost.org/doc/libs/release/libs/dynamic_bitset/dynamic_bitset.html" rel="nofollow"><code>boost::dynamic_bitset</code></a> along with <a href="http://en.cppreference.com/w/cpp/iterator/ostream_iterator" rel="nofollow"><code>std::ostream_iterator</code></a> to achieve the desired result...
8
2010-03-19T13:39:06Z
[ "c#", "java", "c++", "python", "bit-fiddling" ]
writing 'bits' to c++ file streams
2,476,748
<p>How can i write 'one bit' into a file stream or file structure each time? is it possible to write to a queue and then flush it ? is it possible with c# or java? this was needed when i try to implement an instance of Huffman codding. i can't write bits into files. so write them to a bitset and then (when compression ...
10
2010-03-19T11:18:23Z
2,478,818
<p>The issue here is that many platforms do not have direct bit access. They group bits into a minimal package, often times the <em>byte</em> or <em>word</em>. Also, the protocol for stream devices does not facilitate transmission of individual bits. </p> <p>The common method to deal with individual bits is to pack...
0
2010-03-19T16:13:41Z
[ "c#", "java", "c++", "python", "bit-fiddling" ]
python Illegal instruction on AIX5.2
2,476,881
<p>everyone: I run my python script functions like this: read from a text file, and store the data as dict. But when in the loop, an Illegal instruction occurs. why this happens? the code is like this:</p> <pre><code>d={} datafile=open('a.txt') # a big text file for line in datafile: line=line.rstrip('\n') f...
-1
2010-03-19T11:43:22Z
2,476,911
<p>This looks very wrong. <code>token</code> is a string in an array of strings returned by <code>line.split()</code>. So <code>token[0]</code> is the first character of that string. Therefore I don't believe that you'll ever get anything like <code>Parsing line 1065</code> in your output. As Mark wrote, you'd see a <c...
3
2010-03-19T11:49:18Z
[ "python", "aix" ]
Redirect print in Python: val = print(arg) to output mixed iterable to file
2,476,931
<p>So lets say I have an incredibly nested iterable of lists/dictionaries. I would like to print them to a file as easily as possible. Why can't I just redirect print to a file?</p> <p><code>val = print(arg)</code> gets a SyntaxError.</p> <p>Is there a way to access stdinput?</p> <p>And why does print take foreve...
2
2010-03-19T11:51:48Z
2,477,018
<p>Seeing how you're using <code>print</code> as function, <a href="http://docs.python.org/library/functions.html#print" rel="nofollow">docs say that you can redirect to file</a> like this:</p> <pre><code>print(arg, file=open('fname', 'w')) </code></pre>
1
2010-03-19T12:04:59Z
[ "python", "list", "dictionary", "iterable" ]
Redirect print in Python: val = print(arg) to output mixed iterable to file
2,476,931
<p>So lets say I have an incredibly nested iterable of lists/dictionaries. I would like to print them to a file as easily as possible. Why can't I just redirect print to a file?</p> <p><code>val = print(arg)</code> gets a SyntaxError.</p> <p>Is there a way to access stdinput?</p> <p>And why does print take foreve...
2
2010-03-19T11:51:48Z
2,477,061
<p>You could look into the <a href="http://docs.python.org/library/logging.html" rel="nofollow">logging</a> module of Python. Perhaps that's the perfect match in this case.</p>
2
2010-03-19T12:10:25Z
[ "python", "list", "dictionary", "iterable" ]
Redirect print in Python: val = print(arg) to output mixed iterable to file
2,476,931
<p>So lets say I have an incredibly nested iterable of lists/dictionaries. I would like to print them to a file as easily as possible. Why can't I just redirect print to a file?</p> <p><code>val = print(arg)</code> gets a SyntaxError.</p> <p>Is there a way to access stdinput?</p> <p>And why does print take foreve...
2
2010-03-19T11:51:48Z
2,478,056
<p>In Python <code>3.*</code>, to redirect one <code>print</code> call to an open file object <code>destination</code>,</p> <pre><code>print(arg, file=destination) </code></pre> <p>In Python <code>2.*</code>, where <code>print</code> is a statement, the syntax is</p> <pre><code>print&gt;&gt;destination, arg </code><...
1
2010-03-19T14:34:21Z
[ "python", "list", "dictionary", "iterable" ]