title
stringlengths
10
172
question_id
int64
469
40.1M
question_body
stringlengths
22
48.2k
question_score
int64
-44
5.52k
question_date
stringlengths
20
20
answer_id
int64
497
40.1M
answer_body
stringlengths
18
33.9k
answer_score
int64
-38
8.38k
answer_date
stringlengths
20
20
tags
list
What is the best interface from Python 3.1.1 to R?
2,573,132
<p>I am using Python 3.1.1 on Mac OS X 10.6.2 and need an interface to R. When browsing the internet I found out about RPy. Is this the right choice? </p> <p>Currently, a program in Python computes a distance matrix and, stores it in a file. I invoke R separately in an interactive way and read in the matrix for cluste...
12
2010-04-04T00:25:43Z
2,661,971
<p><strong>edit:</strong> Rewrite to summarize the edits that accumulated over time.</p> <p>The current rpy2 release (2.3.x series) has full support for Python 3.3, while no claim is made about Python 3.0, 3.1, or 3.2. At the time of writing the next rpy2 release (under development, 2.4.x series) is only supporting Py...
20
2010-04-18T10:52:37Z
[ "python", "interface", "python-3.x" ]
What is the best interface from Python 3.1.1 to R?
2,573,132
<p>I am using Python 3.1.1 on Mac OS X 10.6.2 and need an interface to R. When browsing the internet I found out about RPy. Is this the right choice? </p> <p>Currently, a program in Python computes a distance matrix and, stores it in a file. I invoke R separately in an interactive way and read in the matrix for cluste...
12
2010-04-04T00:25:43Z
12,966,019
<p>PypeR it's an option if you're trying to use R with recent versions of Python (like 3.1)</p> <p>More info at:</p> <p><a href="http://rinpy.sourceforge.net/" rel="nofollow">http://rinpy.sourceforge.net/</a></p>
4
2012-10-19T01:09:54Z
[ "python", "interface", "python-3.x" ]
Python progression path - From apprentice to guru
2,573,135
<p>I've been learning, working, and playing with Python for a year and a half now. As a biologist slowly making the turn to bio-informatics, this language has been at the very core of all the major contributions I have made in the lab. I more or less fell in love with the way Python permits me to express beautiful solu...
659
2010-04-04T00:28:33Z
2,573,141
<p>Google just recently released an online Python class ("class" as in "a course of study").</p> <p><a href="http://code.google.com/edu/languages/google-python-class/">http://code.google.com/edu/languages/google-python-class/</a></p> <p>I know this doesn't answer your full question, but I think it's a great place to ...
23
2010-04-04T00:32:10Z
[ "python" ]
Python progression path - From apprentice to guru
2,573,135
<p>I've been learning, working, and playing with Python for a year and a half now. As a biologist slowly making the turn to bio-informatics, this language has been at the very core of all the major contributions I have made in the lab. I more or less fell in love with the way Python permits me to express beautiful solu...
659
2010-04-04T00:28:33Z
2,573,225
<p>Not precisely what you're asking for, but I think it's good advice.</p> <p>Learn another language, doesn't matter too much which. Each language has it's own ideas and conventions that you can learn from. Learn about the differences in the languages and more importantly <code>why</code> they're different. Try a p...
2
2010-04-04T01:13:33Z
[ "python" ]
Python progression path - From apprentice to guru
2,573,135
<p>I've been learning, working, and playing with Python for a year and a half now. As a biologist slowly making the turn to bio-informatics, this language has been at the very core of all the major contributions I have made in the lab. I more or less fell in love with the way Python permits me to express beautiful solu...
659
2010-04-04T00:28:33Z
2,573,229
<p>One good way to further your Python knowledge is to <strong>dig into the source code of the libraries, platforms, and frameworks you use already.</strong></p> <p>For example if you're building a site on <a href="http://www.djangoproject.com/">Django</a>, many questions that might stump you can be answered by lookin...
108
2010-04-04T01:16:40Z
[ "python" ]
Python progression path - From apprentice to guru
2,573,135
<p>I've been learning, working, and playing with Python for a year and a half now. As a biologist slowly making the turn to bio-informatics, this language has been at the very core of all the major contributions I have made in the lab. I more or less fell in love with the way Python permits me to express beautiful solu...
659
2010-04-04T00:28:33Z
2,573,269
<p>Download <a href="http://twistedmatrix.com/trac/wiki/Downloads">Twisted</a> and look at the source code. They employ some pretty advanced techniques.</p>
20
2010-04-04T01:38:56Z
[ "python" ]
Python progression path - From apprentice to guru
2,573,135
<p>I've been learning, working, and playing with Python for a year and a half now. As a biologist slowly making the turn to bio-informatics, this language has been at the very core of all the major contributions I have made in the lab. I more or less fell in love with the way Python permits me to express beautiful solu...
659
2010-04-04T00:28:33Z
2,573,362
<p>I learned python first by myself over a summer just by doing the tutorial on the python site (sadly, I don't seem to be able to find that anymore, so I can't post a link). </p> <p>Later, python was taught to me in one of my first year courses at university. In the summer that followed, I practiced with <a href="htt...
10
2010-04-04T02:32:21Z
[ "python" ]
Python progression path - From apprentice to guru
2,573,135
<p>I've been learning, working, and playing with Python for a year and a half now. As a biologist slowly making the turn to bio-informatics, this language has been at the very core of all the major contributions I have made in the lab. I more or less fell in love with the way Python permits me to express beautiful solu...
659
2010-04-04T00:28:33Z
2,573,526
<p><strong>Understand Introspection</strong></p> <ul> <li>write a <code>dir()</code> equivalent</li> <li>write a <code>type()</code> equivalent</li> <li>figure out how to <a href="http://en.wikipedia.org/wiki/Monkey_patch">"monkey-patch"</a></li> <li>use the <code>dis</code> module to see how various language construc...
59
2010-04-04T04:06:11Z
[ "python" ]
Python progression path - From apprentice to guru
2,573,135
<p>I've been learning, working, and playing with Python for a year and a half now. As a biologist slowly making the turn to bio-informatics, this language has been at the very core of all the major contributions I have made in the lab. I more or less fell in love with the way Python permits me to express beautiful solu...
659
2010-04-04T00:28:33Z
2,573,531
<p><strong>Thoroughly Understand All Data Types and Structures</strong></p> <p>For every type and structure, write a series of demo programs that exercise every aspect of the type or data structure. If you do this, it might be worthwhile to blog notes on each one... it might be useful to lots of people!</p>
12
2010-04-04T04:08:54Z
[ "python" ]
Python progression path - From apprentice to guru
2,573,135
<p>I've been learning, working, and playing with Python for a year and a half now. As a biologist slowly making the turn to bio-informatics, this language has been at the very core of all the major contributions I have made in the lab. I more or less fell in love with the way Python permits me to express beautiful solu...
659
2010-04-04T00:28:33Z
2,573,761
<p>Have you seen the book "<a href="http://oreilly.com/catalog/9780596154516/">Bioinformatics Programming using Python</a>"? Looks like you're an exact member of its focus group.</p>
7
2010-04-04T06:39:57Z
[ "python" ]
Python progression path - From apprentice to guru
2,573,135
<p>I've been learning, working, and playing with Python for a year and a half now. As a biologist slowly making the turn to bio-informatics, this language has been at the very core of all the major contributions I have made in the lab. I more or less fell in love with the way Python permits me to express beautiful solu...
659
2010-04-04T00:28:33Z
2,573,965
<p><strong>Understand (more deeply) Python's data types and their roles with regards to memory mgmt</strong></p> <p>As some of you in the community are aware, <a href="http://cyberwebconsulting.com">I teach Python courses</a>, the most popular ones being the comprehensive Intro+Intermediate course as well as an "advan...
92
2010-04-04T08:58:31Z
[ "python" ]
Python progression path - From apprentice to guru
2,573,135
<p>I've been learning, working, and playing with Python for a year and a half now. As a biologist slowly making the turn to bio-informatics, this language has been at the very core of all the major contributions I have made in the lab. I more or less fell in love with the way Python permits me to express beautiful solu...
659
2010-04-04T00:28:33Z
2,575,917
<p>Check out Peter Norvig's essay on becoming a master programmer in 10 years: <a href="http://norvig.com/21-days.html">http://norvig.com/21-days.html</a>. I'd wager it holds true for any language. </p>
67
2010-04-04T21:14:21Z
[ "python" ]
Python progression path - From apprentice to guru
2,573,135
<p>I've been learning, working, and playing with Python for a year and a half now. As a biologist slowly making the turn to bio-informatics, this language has been at the very core of all the major contributions I have made in the lab. I more or less fell in love with the way Python permits me to express beautiful solu...
659
2010-04-04T00:28:33Z
2,576,226
<p>I'll give you the simplest and most effective piece of advice I think anybody could give you: <strong>code</strong>.</p> <p>You can only be better at using a language (which implies understanding it) by <em>coding</em>. You have to actively enjoy coding, be inspired, ask questions, and find answers by yourself.</p>...
41
2010-04-04T23:14:34Z
[ "python" ]
Python progression path - From apprentice to guru
2,573,135
<p>I've been learning, working, and playing with Python for a year and a half now. As a biologist slowly making the turn to bio-informatics, this language has been at the very core of all the major contributions I have made in the lab. I more or less fell in love with the way Python permits me to express beautiful solu...
659
2010-04-04T00:28:33Z
2,576,240
<p>I thought the process of Python mastery went something like:</p> <ol> <li>Discover <a href="http://en.wikipedia.org/wiki/List_comprehension#Python">list comprehensions</a></li> <li>Discover <a href="http://en.wikipedia.org/wiki/Python_syntax_and_semantics#Generators">generators</a></li> <li>Incorporate <a href="htt...
471
2010-04-04T23:19:53Z
[ "python" ]
Python progression path - From apprentice to guru
2,573,135
<p>I've been learning, working, and playing with Python for a year and a half now. As a biologist slowly making the turn to bio-informatics, this language has been at the very core of all the major contributions I have made in the lab. I more or less fell in love with the way Python permits me to express beautiful solu...
659
2010-04-04T00:28:33Z
2,611,783
<p>You already have a lot of reading material, but if you can handle more, I recommend you learn about the evolution of python by reading the Python Enhancement Proposals, especially the "Finished" PEPs and the "Deferred, Abandoned, Withdrawn, and Rejected" PEPs.</p> <p>By seeing how the language has changed, the dec...
6
2010-04-10T00:40:41Z
[ "python" ]
Python progression path - From apprentice to guru
2,573,135
<p>I've been learning, working, and playing with Python for a year and a half now. As a biologist slowly making the turn to bio-informatics, this language has been at the very core of all the major contributions I have made in the lab. I more or less fell in love with the way Python permits me to express beautiful solu...
659
2010-04-04T00:28:33Z
4,147,303
<p>I recommend starting with something that forces you to explore the expressive power of the syntax. Python allows many different ways of writing the same functionality, but there is often a single most elegant and fastest approach. If you're used to the idioms of other languages, you might never otherwise find or acc...
2
2010-11-10T17:38:16Z
[ "python" ]
Python progression path - From apprentice to guru
2,573,135
<p>I've been learning, working, and playing with Python for a year and a half now. As a biologist slowly making the turn to bio-informatics, this language has been at the very core of all the major contributions I have made in the lab. I more or less fell in love with the way Python permits me to express beautiful solu...
659
2010-04-04T00:28:33Z
4,147,969
<p>If you're in and using python for science (which it seems you are) part of that will be learning and understanding scientific libraries, for me these would be </p> <ul> <li>numpy</li> <li>scipy</li> <li>matplotlib</li> <li>mayavi/mlab</li> <li>chaco</li> <li>Cython</li> </ul> <p>knowing how to use the right libra...
24
2010-11-10T18:56:11Z
[ "python" ]
Python progression path - From apprentice to guru
2,573,135
<p>I've been learning, working, and playing with Python for a year and a half now. As a biologist slowly making the turn to bio-informatics, this language has been at the very core of all the major contributions I have made in the lab. I more or less fell in love with the way Python permits me to express beautiful solu...
659
2010-04-04T00:28:33Z
4,162,150
<pre><code>def apprentice(): read(diveintopython) experiment(interpreter) read(python_tutorial) experiment(interpreter, modules/files) watch(pycon) def master(): refer(python-essential-reference) refer(PEPs/language reference) experiment() read(good_python_code) # Eg. twisted, other libraries write...
48
2010-11-12T06:22:54Z
[ "python" ]
Python progression path - From apprentice to guru
2,573,135
<p>I've been learning, working, and playing with Python for a year and a half now. As a biologist slowly making the turn to bio-informatics, this language has been at the very core of all the major contributions I have made in the lab. I more or less fell in love with the way Python permits me to express beautiful solu...
659
2010-04-04T00:28:33Z
4,169,614
<p>Teaching to someone else who is starting to learn Python is always a great way to get your ideas clear and sometimes, I usually get a lot of neat questions from students that have me to re-think conceptual things about Python.</p>
3
2010-11-12T22:25:39Z
[ "python" ]
Python progression path - From apprentice to guru
2,573,135
<p>I've been learning, working, and playing with Python for a year and a half now. As a biologist slowly making the turn to bio-informatics, this language has been at the very core of all the major contributions I have made in the lab. I more or less fell in love with the way Python permits me to express beautiful solu...
659
2010-04-04T00:28:33Z
6,043,780
<h2>Learning algorithms/maths/file IO/Pythonic optimisation</h2> <p>This won't get you guru-hood but to start out, try working through the <a href="http://projecteuler.net/">Project Euler problems</a> The first 50 or so shouldn't tax you if you have decent high-school mathematics and know how to Google. When you solv...
10
2011-05-18T11:15:08Z
[ "python" ]
Python progression path - From apprentice to guru
2,573,135
<p>I've been learning, working, and playing with Python for a year and a half now. As a biologist slowly making the turn to bio-informatics, this language has been at the very core of all the major contributions I have made in the lab. I more or less fell in love with the way Python permits me to express beautiful solu...
659
2010-04-04T00:28:33Z
8,375,074
<p>Attempt <a href="http://challenge.greplin.com/">http://challenge.greplin.com/</a> using Python </p>
5
2011-12-04T11:50:55Z
[ "python" ]
Django1.1 model field value preprocessing before returning
2,573,446
<p>I have a model class like this:</p> <pre><code>class Note(models.Model): author = models.ForeignKey(User, related_name='notes') content = NoteContentField(max_length=256) </code></pre> <p><strong>NoteContentField</strong> is a custom sub-class of <strong>CharField</strong> that override the <strong>to_pyth...
1
2010-04-04T03:19:46Z
2,574,269
<p>I think you should provide the reverse function to <strong>to_python</strong>. </p> <p>Take a look at Django doc here : <a href="http://docs.djangoproject.com/en/dev/howto/custom-model-fields/#converting-python-objects-to-query-values" rel="nofollow">Converting Python objects to query value</a></p>
1
2010-04-04T11:40:07Z
[ "python", "django", "django-models" ]
Django1.1 model field value preprocessing before returning
2,573,446
<p>I have a model class like this:</p> <pre><code>class Note(models.Model): author = models.ForeignKey(User, related_name='notes') content = NoteContentField(max_length=256) </code></pre> <p><strong>NoteContentField</strong> is a custom sub-class of <strong>CharField</strong> that override the <strong>to_pyth...
1
2010-04-04T03:19:46Z
2,574,309
<p>You seem to have only read half the docs. As Pierre-Jean noted above, and even linked you to the correct part of the document, you need to define the reverse function, which is <code>get_db_prep_value</code>.</p>
1
2010-04-04T12:05:31Z
[ "python", "django", "django-models" ]
Django: A Result Specific Numeration for Pagination
2,573,504
<p>Simply put I want what <a href="http://www.reddit.com/" rel="nofollow">http://www.reddit.com/</a> and <a href="http://news.ycombinator.com/" rel="nofollow">http://news.ycombinator.com/</a> have to the left of every link. A numerated link starting with 1 and continuing to the next page by means of pagination.</p> <...
0
2010-04-04T03:57:51Z
2,573,546
<p>As far as I understand, this number for each item on page is computable from 'first_on_page' and number of current item on the page. Maybe you can get number of current item on the page from cycle data, but if not — you can somewhat easily write an incrementing template tag, possibly with using 'first_on_page' ins...
2
2010-04-04T04:18:44Z
[ "python", "django", "pagination" ]
Python: unable to inherit from a C extension
2,573,519
<p>I am trying to add a few extra methods to a matrix type from the pysparse library. Apart from that I want the new class to behave exactly like the original, so I chose to implement the changes using inheritance. However, when I try</p> <pre><code>from pysparse import spmatrix class ll_mat(spmatrix.ll_mat): pas...
6
2010-04-04T04:02:30Z
2,573,536
<p><code>ll_mat</code> is documented to be a <a href="http://pysparse.sourceforge.net/spmatrix.html#spmatrix-module-functions">function</a> -- not the type itself. The idiom is known as "factory function" -- it allows a "creator callable" to return different actual underlying types depending on its arguments.</p> <p>...
8
2010-04-04T04:13:55Z
[ "python", "inheritance" ]
Boost.python building
2,573,667
<p>really can't understand, how to build correctly project that uses boost.python. I've included boost_(python/thread/system)-mt. Here is simple module file:</p> <pre><code>#include &lt;boost/python.hpp&gt; #include "script.hpp" #include "boost/python/detail/wrap_python.hpp" BOOST_PYTHON_MODULE(temp) { namespace ...
1
2010-04-04T05:29:58Z
2,573,681
<p>You seem to be missing the headers from python itself.</p> <p>The symbols such as <code>PySequence_GetSlice</code> and <code>PyExc_ValueError</code> are from the Python headers, not the boost::python headers.</p> <p>That's all I can say, sorry. I don't really know boost::python. I'm surprised you don't have any er...
1
2010-04-04T05:39:53Z
[ "python", "boost", "building" ]
Boost.python building
2,573,667
<p>really can't understand, how to build correctly project that uses boost.python. I've included boost_(python/thread/system)-mt. Here is simple module file:</p> <pre><code>#include &lt;boost/python.hpp&gt; #include "script.hpp" #include "boost/python/detail/wrap_python.hpp" BOOST_PYTHON_MODULE(temp) { namespace ...
1
2010-04-04T05:29:58Z
2,575,224
<p>That looks like a missing library in link phase. All those undefined references are included in the Python library. You probably just need to add something like "-lpython2.5" to your last gcc command.</p>
2
2010-04-04T17:23:59Z
[ "python", "boost", "building" ]
Download whole directories in Python SimpleHTTPServer
2,573,670
<p>I really like how I can easily share files on a network using the SimpleHTTPServer, but I wish there was an option like "download entire directory". Is there an easy (one liner) way to implement this?</p> <p>Thanks</p>
3
2010-04-04T05:30:24Z
2,573,685
<p>There is no one liner which would do it, also what do you mean by "download whole dir" as tar or zip?</p> <p>Anyway you can follow these steps</p> <ol> <li>Derive a class from SimpleHTTPRequestHandler or may be just copy its code </li> <li>Change list_directory method to return a link to "download whole folder"</l...
3
2010-04-04T05:41:23Z
[ "python", "simplehttpserver" ]
Download whole directories in Python SimpleHTTPServer
2,573,670
<p>I really like how I can easily share files on a network using the SimpleHTTPServer, but I wish there was an option like "download entire directory". Is there an easy (one liner) way to implement this?</p> <p>Thanks</p>
3
2010-04-04T05:30:24Z
2,573,689
<p>Look at the sources, e.g. online <a href="http://svn.python.org/view/python/trunk/Lib/SimpleHTTPServer.py?annotate=64762" rel="nofollow">here</a>. Right now, if you call the server with a URL that's a directory, its <code>index.html</code> file is served, or, missing that, the <code>list_directory</code> method is ...
4
2010-04-04T05:41:47Z
[ "python", "simplehttpserver" ]
Download whole directories in Python SimpleHTTPServer
2,573,670
<p>I really like how I can easily share files on a network using the SimpleHTTPServer, but I wish there was an option like "download entire directory". Is there an easy (one liner) way to implement this?</p> <p>Thanks</p>
3
2010-04-04T05:30:24Z
14,732,657
<p>I did that modification for you, I don't know if there'are better ways to do that but:</p> <p>Just save the file (Ex.: ThreadedHTTPServer.py) and access as:</p> <p><code>$ python -m /path/to/ThreadedHTTPServer PORT</code></p> <p><a href="http://bpaste.net/raw/i1D2CWevHxBP1buJrfho/" rel="nofollow">BPaste Raw Versi...
1
2013-02-06T15:28:57Z
[ "python", "simplehttpserver" ]
How to extract a couple marked strings from a line (python)
2,573,698
<p>My Friends,</p> <p>I spent quite some time on this one... but cannot yet figure out a better way to do it. I am coding in python, by the way.</p> <p>So, here is a line of text in a file I am working with, for example:</p> <p>">ref|ZP_01631227.1| 3-dehydroquinate synthase [Nodularia spumigena CCY9414]..."</p> <p>...
0
2010-04-04T05:47:50Z
2,573,711
<pre><code>&gt;&gt;&gt; for line in open("file"): ... if "|" in line: ... whatiwant_1=line.split("|")[1] ... if "[" in line: ... whatiwant_2=line.split("[")[1].split("]")[0] ... &gt;&gt;&gt; print whatiwant_1 , whatiwant_2 ZP_01631227.1 Nodularia spumigena CCY9414 </code></pre>
1
2010-04-04T05:55:58Z
[ "python", "string", "extract", "line" ]
How to extract a couple marked strings from a line (python)
2,573,698
<p>My Friends,</p> <p>I spent quite some time on this one... but cannot yet figure out a better way to do it. I am coding in python, by the way.</p> <p>So, here is a line of text in a file I am working with, for example:</p> <p>">ref|ZP_01631227.1| 3-dehydroquinate synthase [Nodularia spumigena CCY9414]..."</p> <p>...
0
2010-04-04T05:47:50Z
2,573,719
<p>One concise alternative is a regular expression (for some reason they have a bad rep in the Python community, but they do provide conciseness and power for simple text handling):</p> <pre><code>import re s = "&gt;ref|ZP_01631227.1| 3-dehydroquinate synthase [Nodularia spumigena CCY9414]..." mo = re.search(r'\|(.*?)...
4
2010-04-04T06:02:48Z
[ "python", "string", "extract", "line" ]
Monitor and Terminate Python script based on system resource use
2,573,736
<p>What is the "right" or "best" way to monitor the system resources a python script is using and terminate it if the resource use exceeds some predetermined values. In my case memory usage is of concern. I am not asking how to measure the system resource use although I am open to suggestions.</p> <p>As a simple examp...
1
2010-04-04T06:12:46Z
2,573,741
<p>On Unix-like system, a useful "external" way to monitor any process is the <a href="http://linux.die.net/man/1/ulimit" rel="nofollow">ulimit</a> command (you don't clarify whether you want instead to run in Windows, where <code>ulimit</code> doesn't exist and other approaches may, but I don't know them;-).</p> <p>I...
2
2010-04-04T06:19:11Z
[ "python", "resources", "monitoring", "terminate" ]
Monitor and Terminate Python script based on system resource use
2,573,736
<p>What is the "right" or "best" way to monitor the system resources a python script is using and terminate it if the resource use exceeds some predetermined values. In my case memory usage is of concern. I am not asking how to measure the system resource use although I am open to suggestions.</p> <p>As a simple examp...
1
2010-04-04T06:12:46Z
2,574,594
<p><a href="http://docs.python.org/library/resource.html#resource.getrusage" rel="nofollow"><code>resource.getrusage()</code></a> (in particular <code>ru_idrss</code>) can give you the resource usage of the current <code>python</code> interpreter, which you can use as a sentinel to stop processing.</p>
2
2010-04-04T13:57:44Z
[ "python", "resources", "monitoring", "terminate" ]
Django - urls.py - Filenames with a hash/pound (#) sign?
2,573,803
<p>I'm using django and realized that when the filename that the user wants to access (let's say a photo) has the pound sign, the entry in the url.py does not match.</p> <p>Any ideas?</p> <pre><code> url(r'^static/(?P&lt;path&gt;.*)$', 'django.views.static.serve', {'document_root': MEDIA_ROOT}, </code></pre> ...
2
2010-04-04T07:04:51Z
2,573,814
<p>This isn't really Django's fault - the pound (#) sign in a URL means to load the specified anchor on the page. You need to encode the pound sign in your URL to get the browser to request the full image path:</p> <pre><code>/home/user/project/static/upload/images/hello%23world.jpg </code></pre> <p>In a Django templ...
8
2010-04-04T07:15:17Z
[ "python", "regex", "django" ]
Creating Signed URLs for Amazon CloudFront
2,573,919
<p>Short version: How do I make signed URLs "on-demand" to mimic Nginx's X-Accel-Redirect behavior (i.e. protecting downloads) with Amazon CloudFront/S3 using Python.</p> <p>I've got a Django server up and running with an Nginx front-end. I've been getting hammered with requests to it and recently had to install it as...
18
2010-04-04T08:31:37Z
2,628,984
<p>You can use the boto python module to generate them for you:</p> <pre><code>&gt;&gt;&gt; import boto &gt;&gt;&gt; s3conn = boto.connect_s3('KEY', 'SECRET') &gt;&gt;&gt; bucket = s3conn.get_bucket('mybucket', validate=False) &gt;&gt;&gt; key = bucket.new_key('/some/key') &gt;&gt;&gt; key.generate_url(expires_in=10) ...
-4
2010-04-13T11:12:22Z
[ "python", "cdn", "amazon-cloudfront" ]
Creating Signed URLs for Amazon CloudFront
2,573,919
<p>Short version: How do I make signed URLs "on-demand" to mimic Nginx's X-Accel-Redirect behavior (i.e. protecting downloads) with Amazon CloudFront/S3 using Python.</p> <p>I've got a Django server up and running with an Nginx front-end. I've been getting hammered with requests to it and recently had to install it as...
18
2010-04-04T08:31:37Z
6,624,431
<p><a href="http://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/private-content-signed-urls-overview.html">Amazon CloudFront Signed URLs</a> work differently than Amazon S3 signed URLs. CloudFront uses RSA signatures based on a separate CloudFront keypair which you have to set up in your Amazon Account C...
31
2011-07-08T12:30:39Z
[ "python", "cdn", "amazon-cloudfront" ]
Creating Signed URLs for Amazon CloudFront
2,573,919
<p>Short version: How do I make signed URLs "on-demand" to mimic Nginx's X-Accel-Redirect behavior (i.e. protecting downloads) with Amazon CloudFront/S3 using Python.</p> <p>I've got a Django server up and running with an Nginx front-end. I've been getting hammered with requests to it and recently had to install it as...
18
2010-04-04T08:31:37Z
16,145,598
<p>As many have commented already, the <a href="http://stackoverflow.com/a/2628984/45773">initially accepted answer</a> doesn't apply to <a href="http://aws.amazon.com/cloudfront/">Amazon CloudFront</a> in fact, insofar <a href="http://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/PrivateContent.html">Serv...
11
2013-04-22T11:04:55Z
[ "python", "cdn", "amazon-cloudfront" ]
Creating Signed URLs for Amazon CloudFront
2,573,919
<p>Short version: How do I make signed URLs "on-demand" to mimic Nginx's X-Accel-Redirect behavior (i.e. protecting downloads) with Amazon CloudFront/S3 using Python.</p> <p>I've got a Django server up and running with an Nginx front-end. I've been getting hammered with requests to it and recently had to install it as...
18
2010-04-04T08:31:37Z
17,140,595
<p>secretmike's answer works, but it is better to use <a href="https://pypi.python.org/pypi/rsa" rel="nofollow"><code>rsa</code></a> instead of <code>M2Crypto</code>.</p> <p>I used <a href="http://boto.readthedocs.org/en/latest/getting_started.html#installing-boto" rel="nofollow"><code>boto</code></a> which uses <code...
0
2013-06-17T04:50:07Z
[ "python", "cdn", "amazon-cloudfront" ]
Creating Signed URLs for Amazon CloudFront
2,573,919
<p>Short version: How do I make signed URLs "on-demand" to mimic Nginx's X-Accel-Redirect behavior (i.e. protecting downloads) with Amazon CloudFront/S3 using Python.</p> <p>I've got a Django server up and running with an Nginx front-end. I've been getting hammered with requests to it and recently had to install it as...
18
2010-04-04T08:31:37Z
23,049,812
<p>This is what I use for create a policy so that I can give access to multiple files with the same "signature":</p> <pre><code>import json import rsa import time ...
0
2014-04-13T23:42:22Z
[ "python", "cdn", "amazon-cloudfront" ]
Creating Signed URLs for Amazon CloudFront
2,573,919
<p>Short version: How do I make signed URLs "on-demand" to mimic Nginx's X-Accel-Redirect behavior (i.e. protecting downloads) with Amazon CloudFront/S3 using Python.</p> <p>I've got a Django server up and running with an Nginx front-end. I've been getting hammered with requests to it and recently had to install it as...
18
2010-04-04T08:31:37Z
34,322,915
<p>This feature is now <a href="https://github.com/boto/botocore/pull/735/files" rel="nofollow">already supported in Botocore</a>, which is the underlying library of <a href="https://github.com/boto/boto3" rel="nofollow">Boto3, the latest official AWS SDK for Python</a>.</p> <p>The usage looks like this:</p> <pre><co...
4
2015-12-16T22:01:30Z
[ "python", "cdn", "amazon-cloudfront" ]
nonzeros in csr_matrix in scipy.sparse matrices
2,574,057
<p>There is a nonzero() method for the csr_matrix of scipy library, however trying to use that function for csr matrices result in an error, according to the manual that should return a tuple with row and colum arrays. Any ideas on this problem?</p> <p>Best regards, Umut</p>
1
2010-04-04T09:42:39Z
2,575,778
<p>Umut, could you provide a code snippet? The following works for me:</p> <pre><code>import scipy.sparse as sparse x = sparse.csr_matrix([[1,0,1],[0,1,0]]) x.nonzero() </code></pre> <p>and yields</p> <pre><code>(array([0, 0, 1], dtype=int32), array([0, 2, 1], dtype=int32)) </code></pre> <p>This is for the latest ...
1
2010-04-04T20:27:25Z
[ "python", "scipy" ]
Sorting a list of dot sparated numbers, like software versions
2,574,080
<p>I have a list containing version strings, such as things:</p> <pre><code>versions_list = ["1.1.2", "1.0.0", "1.3.3", "1.0.12", "1.0.2"] </code></pre> <p>I would like to sort it, so the result would be something like this:</p> <pre><code>versions_list = ["1.0.0", "1.0.2", "1.0.12", "1.1.2", "1.3.3"] </code></pre> ...
30
2010-04-04T09:51:57Z
2,574,090
<p>Split each version string to compare it as a list of integers:</p> <pre><code>versions_list.sort(key=lambda s: map(int, s.split('.'))) </code></pre> <p>Gives, for your list:</p> <pre><code>['1.0.0', '1.0.2', '1.0.12', '1.1.2', '1.3.3'] </code></pre> <p>In Python3 <code>map</code> no longer returns a <code>list</...
44
2010-04-04T09:56:31Z
[ "python" ]
Sorting a list of dot sparated numbers, like software versions
2,574,080
<p>I have a list containing version strings, such as things:</p> <pre><code>versions_list = ["1.1.2", "1.0.0", "1.3.3", "1.0.12", "1.0.2"] </code></pre> <p>I would like to sort it, so the result would be something like this:</p> <pre><code>versions_list = ["1.0.0", "1.0.2", "1.0.12", "1.1.2", "1.3.3"] </code></pre> ...
30
2010-04-04T09:51:57Z
2,574,230
<p>You can also use <code>distutils.version</code> module of standard library:</p> <pre><code>from distutils.version import StrictVersion versions = ["1.1.2", "1.0.0", "1.3.3", "1.0.12", "1.0.2"] versions.sort(key=StrictVersion) </code></pre> <p>Gives you:</p> <pre><code>['1.0.0', '1.0.2', '1.0.12', '1.1.2', '1.3.3'...
65
2010-04-04T11:16:22Z
[ "python" ]
Sorting a list of dot sparated numbers, like software versions
2,574,080
<p>I have a list containing version strings, such as things:</p> <pre><code>versions_list = ["1.1.2", "1.0.0", "1.3.3", "1.0.12", "1.0.2"] </code></pre> <p>I would like to sort it, so the result would be something like this:</p> <pre><code>versions_list = ["1.0.0", "1.0.2", "1.0.12", "1.1.2", "1.3.3"] </code></pre> ...
30
2010-04-04T09:51:57Z
31,425,911
<p><a href="https://pypi.python.org/pypi/natsort" rel="nofollow">natsort</a> proposes "natural sorting"; wich works very intuitively (in Python 3)</p> <pre><code>from natsort import natsort versions = ["1.1.2", "1.0.0", "1.3.3", "1.0.12", "1.0.2"] natsort(versions) </code></pre> <p>gives</p> <pre><code>['1.0.0', '1....
3
2015-07-15T09:00:56Z
[ "python" ]
sqlalchemy dynamic mapping
2,574,105
<p>I have the following problem:</p> <p>I have the class:</p> <pre><code> class Word(object): def __init__(self): self.id = None self.columns = {} def __str__(self): return "(%s, %s)" % (str(self.id), str(self.columns)) </code></pre> <p>self.columns is a dict which will hold (colum...
10
2010-04-04T10:03:19Z
2,575,016
<p>It seems that you can just use the attributes directly instead of using the <code>columns</code> <code>dict</code>.</p> <p>Consider the following setup:</p> <pre><code>from sqlalchemy import Table, Column, Integer, Unicode, MetaData, create_engine from sqlalchemy.orm import mapper, create_session class Word(objec...
24
2010-04-04T16:07:08Z
[ "python", "sqlalchemy" ]
sqlalchemy dynamic mapping
2,574,105
<p>I have the following problem:</p> <p>I have the class:</p> <pre><code> class Word(object): def __init__(self): self.id = None self.columns = {} def __str__(self): return "(%s, %s)" % (str(self.id), str(self.columns)) </code></pre> <p>self.columns is a dict which will hold (colum...
10
2010-04-04T10:03:19Z
9,156,742
<p>I used nosklo's solution (thanks!) but I already had a primary key (passed in as pk_col) within the column line (first line of csv). So I thought I'd share my modification. I used a ternary. </p> <pre><code>table = Table(tablename, metadata, *((Column(pk_col, Integer, primary_key=True)) if rowname == pk_col els...
3
2012-02-06T07:12:51Z
[ "python", "sqlalchemy" ]
How can I load an MP3 or similar music file for display and analysis in wxWidgets?
2,574,183
<p>I'm developing a GUI in wxPython which allows a user to generate sequences of colours for some toys I'm building. Part of the program needs to load an MP3 (and potentially other formats further down the line) and display it to the user. That should be sufficient to get started but later I'd like to add features like...
2
2010-04-04T10:46:44Z
2,574,532
<p>It looks like <a href="http://www.speech.kth.se/snack/" rel="nofollow">Snack</a> could be a good start. I've not used it.</p> <p><strong>edit</strong>: It's Tk based, but perhaps there are parts or ideas to be taken.</p>
1
2010-04-04T13:37:45Z
[ "c++", "python", "mp3", "wxwidgets", "analysis" ]
How can I load an MP3 or similar music file for display and analysis in wxWidgets?
2,574,183
<p>I'm developing a GUI in wxPython which allows a user to generate sequences of colours for some toys I'm building. Part of the program needs to load an MP3 (and potentially other formats further down the line) and display it to the user. That should be sufficient to get started but later I'd like to add features like...
2
2010-04-04T10:46:44Z
2,581,497
<p>After a little more googling, I think <a href="http://sourceforge.net/projects/pymedia/files/pymedia/" rel="nofollow">PyMedia</a> might well be a good place to start at least as far as a Python implementation goes.</p>
1
2010-04-05T22:12:56Z
[ "c++", "python", "mp3", "wxwidgets", "analysis" ]
how to create multiple selections in text edit box in qt4?
2,574,195
<p>Qt3.3 used to allow for multiple selections in the <strong>QTextEdit</strong> widget by calling the <strong>setSelection()</strong> function and specifying a different selection id (<strong>selNum</strong>) as the last argument in that function. </p> <p>In Qt4, to create a selection, I do it by creating a <strong>Q...
1
2010-04-04T10:55:44Z
2,574,214
<p>How about creating multiple cursors (<code>QTextCursor</code>), each selection a different portion of the text. Would that work for you?</p>
0
2010-04-04T11:07:41Z
[ "python", "qt", "qt4", "pyqt" ]
how to create multiple selections in text edit box in qt4?
2,574,195
<p>Qt3.3 used to allow for multiple selections in the <strong>QTextEdit</strong> widget by calling the <strong>setSelection()</strong> function and specifying a different selection id (<strong>selNum</strong>) as the last argument in that function. </p> <p>In Qt4, to create a selection, I do it by creating a <strong>Q...
1
2010-04-04T10:55:44Z
2,574,559
<p>The solution, i realise now is actually quite simple. </p> <p>To graphically visualise all the various selections (separate <strong>QTextCursor</strong> objects), <em>instead</em> of calling the <strong>setTextCursor()</strong> method for the <strong>QTextEdit</strong> widget for each of the selections, i change th...
1
2010-04-04T13:46:09Z
[ "python", "qt", "qt4", "pyqt" ]
Django manage.py can't find an INSTALLED_APP even though the module is in the path
2,574,451
<p>When I run python manage.py shell I get an error about the last app I've added to INSTALLED_APPS, namely django-evolution, saying it's an undefined module. This is despite the fact that I've added the path to django-evolution to the system path. In fact right after this error I can run python and do an import on dja...
0
2010-04-04T13:04:31Z
2,574,461
<p>You need to add it to your INSTALLED_APPS section of settings.py.</p>
0
2010-04-04T13:10:29Z
[ "python", "django", "django-evolution" ]
Django manage.py can't find an INSTALLED_APP even though the module is in the path
2,574,451
<p>When I run python manage.py shell I get an error about the last app I've added to INSTALLED_APPS, namely django-evolution, saying it's an undefined module. This is despite the fact that I've added the path to django-evolution to the system path. In fact right after this error I can run python and do an import on dja...
0
2010-04-04T13:04:31Z
2,575,989
<p>Does your <code>django_evolution</code> have a <strong>init</strong>.py file in it? Also any folder containing <code>django_evolution</code> needs one.</p>
1
2010-04-04T21:37:47Z
[ "python", "django", "django-evolution" ]
Django manage.py can't find an INSTALLED_APP even though the module is in the path
2,574,451
<p>When I run python manage.py shell I get an error about the last app I've added to INSTALLED_APPS, namely django-evolution, saying it's an undefined module. This is despite the fact that I've added the path to django-evolution to the system path. In fact right after this error I can run python and do an import on dja...
0
2010-04-04T13:04:31Z
8,602,397
<p>If you are using virtualenv and ipython is installed at the system level but your app at the env level, it will lead to this. The way out of it is to remove ipython from the system and to install it into your env.</p>
0
2011-12-22T10:15:10Z
[ "python", "django", "django-evolution" ]
How to use Django's filesizeformat
2,574,540
<p>I have a small app I'm working on where I'm trying to use Django's built in filesizeformat. Currently, the format looks like this: <code>{{ value|filesizeformat }}</code>. I understand I need to define this in my view.py file but, I can't seem to figure out how to do that. I've tried to use the syntax below:</p> ...
3
2010-04-04T13:40:59Z
2,574,550
<p><code>filesizeformat</code> is a <strong>built-in</strong> filter, you do not need to implement it yourself. You should provide the value into the template, for example:</p> <pre><code>{% for page in pages %} &lt;li&gt;page.name {{page.size|filesizeformat}}&lt;/li&gt; {% endfor %} </code></pre> <p>Now when yo...
7
2010-04-04T13:43:41Z
[ "python", "django" ]
Getting a default value on index out of range in Python
2,574,636
<pre><code>a=['123','2',4] b=a[4] or 'sss' print b </code></pre> <p>I want to get a default value when the list index is out of range (here: <code>'sss'</code>).</p> <p>How can I do this?</p>
41
2010-04-04T14:10:17Z
2,574,650
<p>In the Python spirit of "ask for forgiveness, not permission", here's one way:</p> <pre><code>try: b = a[4] except IndexError: b = 'sss' </code></pre>
48
2010-04-04T14:13:56Z
[ "python", "list", "syntax", "default-value" ]
Getting a default value on index out of range in Python
2,574,636
<pre><code>a=['123','2',4] b=a[4] or 'sss' print b </code></pre> <p>I want to get a default value when the list index is out of range (here: <code>'sss'</code>).</p> <p>How can I do this?</p>
41
2010-04-04T14:10:17Z
2,574,655
<pre><code>try: b = a[4] except IndexError: b = 'sss' </code></pre> <p>A cleaner way (only works if you're using a dict):</p> <pre><code>b = a.get(4,"sss") # exact same thing as above </code></pre> <p>Here's another way you might like (again, only for dicts):</p> <pre><code>b = a.setdefault(4,"sss") # if a[...
4
2010-04-04T14:14:48Z
[ "python", "list", "syntax", "default-value" ]
Getting a default value on index out of range in Python
2,574,636
<pre><code>a=['123','2',4] b=a[4] or 'sss' print b </code></pre> <p>I want to get a default value when the list index is out of range (here: <code>'sss'</code>).</p> <p>How can I do this?</p>
41
2010-04-04T14:10:17Z
2,574,656
<p>Using try/catch?</p> <pre><code>try: b=a[4] except IndexError: b='sss' </code></pre>
0
2010-04-04T14:14:55Z
[ "python", "list", "syntax", "default-value" ]
Getting a default value on index out of range in Python
2,574,636
<pre><code>a=['123','2',4] b=a[4] or 'sss' print b </code></pre> <p>I want to get a default value when the list index is out of range (here: <code>'sss'</code>).</p> <p>How can I do this?</p>
41
2010-04-04T14:10:17Z
2,574,659
<p>In the non-Python spirit of "ask for permission, not forgiveness", here's another way:</p> <pre><code>b = a[4] if len(a) &gt; 4 else 'sss' </code></pre>
37
2010-04-04T14:15:45Z
[ "python", "list", "syntax", "default-value" ]
Getting a default value on index out of range in Python
2,574,636
<pre><code>a=['123','2',4] b=a[4] or 'sss' print b </code></pre> <p>I want to get a default value when the list index is out of range (here: <code>'sss'</code>).</p> <p>How can I do this?</p>
41
2010-04-04T14:10:17Z
2,574,669
<p>You could also define a little helper function for these cases:</p> <pre><code>def default(x, e, y): try: return x() except e: return y </code></pre> <p>It returns the return value of the function <code>x</code>, unless it raised an exception of type <code>e</code>; in that case, it returns...
6
2010-04-04T14:19:13Z
[ "python", "list", "syntax", "default-value" ]
Getting a default value on index out of range in Python
2,574,636
<pre><code>a=['123','2',4] b=a[4] or 'sss' print b </code></pre> <p>I want to get a default value when the list index is out of range (here: <code>'sss'</code>).</p> <p>How can I do this?</p>
41
2010-04-04T14:10:17Z
2,574,702
<p>I’m all for asking permission (i.e. I don’t like the <code>try</code>…<code>except</code> method). However, the code gets a lot cleaner when it’s encapsulated in a method:</p> <pre><code>def get_at(array, index, default): if index &lt; 0: index += len(array) if index &lt; 0: raise IndexError('list i...
2
2010-04-04T14:27:12Z
[ "python", "list", "syntax", "default-value" ]
Getting a default value on index out of range in Python
2,574,636
<pre><code>a=['123','2',4] b=a[4] or 'sss' print b </code></pre> <p>I want to get a default value when the list index is out of range (here: <code>'sss'</code>).</p> <p>How can I do this?</p>
41
2010-04-04T14:10:17Z
14,906,256
<p>Since this is a top google hit, it's probably also worth mentioning that the standard "collections" package has a "defaultdict" which provides a more flexible solution to this problem.</p> <p>You can do neat things, for example:</p> <pre><code>twodee = collections.defaultdict(dict) twodee["the horizontal"]["the ve...
1
2013-02-16T02:21:56Z
[ "python", "list", "syntax", "default-value" ]
Getting a default value on index out of range in Python
2,574,636
<pre><code>a=['123','2',4] b=a[4] or 'sss' print b </code></pre> <p>I want to get a default value when the list index is out of range (here: <code>'sss'</code>).</p> <p>How can I do this?</p>
41
2010-04-04T14:10:17Z
15,138,904
<p>You could create your own list-class:</p> <pre><code>class MyList(list): def get(self, index, default=None): return self[index] if len(self) &gt; index else default </code></pre> <p>You can use it like this:</p> <pre><code>&gt;&gt;&gt; l = MyList(['a', 'b', 'c']) &gt;&gt;&gt; l.get(1) 'b' &gt;&gt;&gt;...
8
2013-02-28T15:08:26Z
[ "python", "list", "syntax", "default-value" ]
Getting a default value on index out of range in Python
2,574,636
<pre><code>a=['123','2',4] b=a[4] or 'sss' print b </code></pre> <p>I want to get a default value when the list index is out of range (here: <code>'sss'</code>).</p> <p>How can I do this?</p>
41
2010-04-04T14:10:17Z
22,669,147
<p>For a common case where you want the first element, you can do</p> <pre><code>next(iter([1, 2, 3]), None) </code></pre> <p>I use this to "unwrap" a list, possibly after filtering it.</p> <pre><code>next((x for x in [1, 3, 5] if x % 2 == 0), None) </code></pre> <p>or </p> <pre><code>cur.execute("SELECT field FRO...
1
2014-03-26T17:49:57Z
[ "python", "list", "syntax", "default-value" ]
Getting a default value on index out of range in Python
2,574,636
<pre><code>a=['123','2',4] b=a[4] or 'sss' print b </code></pre> <p>I want to get a default value when the list index is out of range (here: <code>'sss'</code>).</p> <p>How can I do this?</p>
41
2010-04-04T14:10:17Z
22,685,248
<p>In the Python spirit of beautiful is better than ugly</p> <p>Code golf method, using slice and unpacking (not sure if this was valid 4 years ago, but it is in python 2.7 + 3.3)</p> <pre><code>b,=a[4:] or 'sss', </code></pre> <p>Nicer than a wrapper function or try-catch IMHO, but intimidating for beginners. Perso...
7
2014-03-27T10:47:00Z
[ "python", "list", "syntax", "default-value" ]
Getting a default value on index out of range in Python
2,574,636
<pre><code>a=['123','2',4] b=a[4] or 'sss' print b </code></pre> <p>I want to get a default value when the list index is out of range (here: <code>'sss'</code>).</p> <p>How can I do this?</p>
41
2010-04-04T14:10:17Z
28,584,046
<p>another way:</p> <pre><code>b = (a[4:]+['sss'])[0] </code></pre>
5
2015-02-18T12:46:11Z
[ "python", "list", "syntax", "default-value" ]
Getting a default value on index out of range in Python
2,574,636
<pre><code>a=['123','2',4] b=a[4] or 'sss' print b </code></pre> <p>I want to get a default value when the list index is out of range (here: <code>'sss'</code>).</p> <p>How can I do this?</p>
41
2010-04-04T14:10:17Z
34,902,172
<p>If you are looking for a maintainable way of getting default values on the index operator I found the following useful:</p> <p>If you override <code>operator.getitem</code> from the operator module to add an optional default parameter you get identical behaviour to the original while maintaining backwards compatib...
0
2016-01-20T14:03:40Z
[ "python", "list", "syntax", "default-value" ]
MySql: How to know if an entry is compressed or not
2,574,687
<p>I'm working with python and mysql and I want to verify that a certain entry is compressed in the db. Ie:</p> <pre><code>cur = db.getCursor() cur.execute('''select compressed_column from table where id=12345''') res = cur.fetchall() </code></pre> <p>at this point I would like to verify that the entry is compressed ...
0
2010-04-04T14:22:35Z
2,574,717
<p><code>COMPRESS()</code> on MySQL uses zlib, therefore you can try the following to see if the string is compressed:</p> <pre><code>try: out = s.decode('zlib') except zlib.error: out = s </code></pre>
4
2010-04-04T14:33:04Z
[ "python", "mysql" ]
wxWidgets/wxPython: Do two identical events cause two handlings?
2,574,830
<p>When there are two identical events in the event loop, will wxPython handle both of them, or will it call the handler only once for them both?</p> <p>I mean, in my widget I want to have an event like <code>EVT_NEED_TO_RECALCULATE_X</code>. I want this event to be posted in all kinds of different circumstances that ...
0
2010-04-04T15:03:41Z
2,574,897
<p>you're talking about three things</p> <ul> <li>the event</li> <li>the source of the event</li> <li>the event handling</li> </ul> <p>The event is a single one (X needs to be recalculated). It has multiple sources. But it has only a single handler.</p> <p>So it should just work. You make it a single event, add a si...
0
2010-04-04T15:22:25Z
[ "python", "events", "wxpython", "wxwidgets" ]
wxWidgets/wxPython: Do two identical events cause two handlings?
2,574,830
<p>When there are two identical events in the event loop, will wxPython handle both of them, or will it call the handler only once for them both?</p> <p>I mean, in my widget I want to have an event like <code>EVT_NEED_TO_RECALCULATE_X</code>. I want this event to be posted in all kinds of different circumstances that ...
0
2010-04-04T15:03:41Z
2,576,927
<p>If you will post a event 1000 times you will receive it 1000 times, why would any event system group them, that would be a bug.</p> <p>If you do not want to deal with all 1000 of them ignore them, also only you can decide how they should be grouped, if user changes something rapidly do you want to group those chang...
0
2010-04-05T04:28:31Z
[ "python", "events", "wxpython", "wxwidgets" ]
python sax error "junk after document element"
2,574,894
<p>I use python sax to parse xml file. The xml file is actually a combination of multiple xml files. It looks like as follows:</p> <pre><code>&lt;row name="abc" age="40" body="blalalala..." creationdate="03/10/10" /&gt; &lt;row name="bcd" age="50" body="blalalala..." creationdate="03/10/09" /&gt; </code></pre> <p>My...
6
2010-04-04T15:22:07Z
2,574,913
<pre><code>xmldata = ''' &lt;row name="abc" age="40" body="blalalala..." creationdate="03/10/10" /&gt; &lt;row name="bcd" age="50" body="blalalala..." creationdate="03/10/09" /&gt; ''' </code></pre> <p>Add a wrapper tag around the data. I've used ElementTree since it's so simpler, but you'd be able to do the same on a...
11
2010-04-04T15:28:25Z
[ "python", "sax" ]
python sax error "junk after document element"
2,574,894
<p>I use python sax to parse xml file. The xml file is actually a combination of multiple xml files. It looks like as follows:</p> <pre><code>&lt;row name="abc" age="40" body="blalalala..." creationdate="03/10/10" /&gt; &lt;row name="bcd" age="50" body="blalalala..." creationdate="03/10/09" /&gt; </code></pre> <p>My...
6
2010-04-04T15:22:07Z
2,574,926
<p>Seems that you do not have root element in your XML file. Wrap your row elements into single rows element.</p>
4
2010-04-04T15:32:15Z
[ "python", "sax" ]
AppEngine: how do cursors work?
2,575,068
<p>i have the following code</p> <pre><code>def get(self): date = datetime.date.today() loc_query = Location.all() last_cursor = memcache.get('location_cursor') if last_cursor: loc_query.with_cursor(last_cursor) loc_result = loc_query.fetch(1) for loc in loc_result: self.record(loc, d...
0
2010-04-04T16:30:38Z
2,575,105
<p>You're misusing <code>memcache.add</code>, which is documented <a href="http://code.google.com/appengine/docs/python/memcache/functions.html" rel="nofollow">here</a> as:</p> <blockquote> <p>Sets a key's value, if and only if the item is not already in memcache.</p> </blockquote> <p>So you're never storing any ...
5
2010-04-04T16:43:26Z
[ "python" ]
How do I delete a curse window in python and restore background window?
2,575,409
<p>Hell-o guys, I'm working on python curses and I have my initial window with initscr() and I create several new windows to overlap it, I want to know if I can delete these windows and restore the standard screen without having to refill it. Is there a way? I can also ask if someone can tell me the difference between ...
1
2010-04-04T18:15:13Z
2,576,084
<p>This, e.g, should work:</p> <pre><code>import curses def fillwin(w, c): y, x = w.getmaxyx() s = c * (x - 1) for l in range(y): w.addstr(l, 0, s) def main(stdscr): fillwin(stdscr, 'S') stdscr.refresh() stdscr.getch() newwin=curses.newwin(10,20,5,5) fillwin(newwin, 'w') ...
5
2010-04-04T22:20:19Z
[ "python", "window", "curses" ]
Not-quite-JSON string deserialization in Python
2,575,449
<p>I get the following text as a string from an XML-based REST API</p> <pre><code>'d':4 'ca':5 'sen':1 'diann':2,6,8 'feinstein':3,7,9 </code></pre> <p>that I'm looking to deserialize into a pretty little Python dictionary:</p> <pre><code>{ 'd': [4], 'ca': [5], 'sen': [1], 'diann': [2, 6, 8], 'fe...
1
2010-04-04T18:27:56Z
2,575,517
<p>I would rewrite it as this (the only difference is explicitely naming <code>m[0]</code> and <code>m[1]</code>):</p> <pre><code>members = {} for m in elem.text.split(' '): key, value = m.split(':') members[key.replace("'", '')] = map(int, value.split(',')) return members </code></pre> <p>Otherwise this ...
2
2010-04-04T18:53:20Z
[ "python", "regex", "string", "serialization" ]
Not-quite-JSON string deserialization in Python
2,575,449
<p>I get the following text as a string from an XML-based REST API</p> <pre><code>'d':4 'ca':5 'sen':1 'diann':2,6,8 'feinstein':3,7,9 </code></pre> <p>that I'm looking to deserialize into a pretty little Python dictionary:</p> <pre><code>{ 'd': [4], 'ca': [5], 'sen': [1], 'diann': [2, 6, 8], 'fe...
1
2010-04-04T18:27:56Z
2,575,624
<p>I actually like ChristopheD's answer, but in the interest of exploring other possibilities, there's:</p> <pre><code>eval("{" + s.replace(":", ":[").replace(" ", "], ") + "]}") </code></pre> <p>This does some simple replacements to turn the string into legal Python, then uses <code>eval</code> to turn it into a dic...
2
2010-04-04T19:34:38Z
[ "python", "regex", "string", "serialization" ]
Python Tkinter Tix: How to use ScrolledWindow with grid in Tix NoteBook
2,575,451
<p>I'm adding several widgets to a Frame which is located in a <code>tix.NoteBook</code>. When there are too much widgets to fit in the window, I want to use a scrollbar, so I put <code>tix.ScrolledWindow</code> inside that Frame and add my widgets to this ScrolledWindow instead.</p> <p>The problem is that when using ...
0
2010-04-04T18:28:12Z
2,602,374
<p>I solved it without using ´tix.scrolledWindow´. Instead, I went for the autoscrollbar suggested by Fred Lundh <a href="http://effbot.org/zone/tkinter-autoscrollbar.htm" rel="nofollow">here</a>. The main problem was the adaption to the NoteBook widget. First, I tried to put the scrollbar to the root, so that they w...
1
2010-04-08T18:15:25Z
[ "python", "grid", "scrolledwindow", "tix" ]
Simulating Key Press event using Python for Linux
2,575,528
<p>I am writing a script to automate running a particular model. When the model fails, it waits for a user input (Enter key). I can detect when the model has failed, but I am not able to use python (on linux) to simulate a key press event. Windows has the SendKeys library to do this but I was wondering if there is a si...
11
2010-04-04T18:57:49Z
2,575,549
<p><a href="http://people.csail.mit.edu/adonovan/hacks/xsendkey.html" rel="nofollow">http://people.csail.mit.edu/adonovan/hacks/xsendkey.html</a></p>
1
2010-04-04T19:07:01Z
[ "python", "linux", "key", "keypress", "simulate" ]
Simulating Key Press event using Python for Linux
2,575,528
<p>I am writing a script to automate running a particular model. When the model fails, it waits for a user input (Enter key). I can detect when the model has failed, but I am not able to use python (on linux) to simulate a key press event. Windows has the SendKeys library to do this but I was wondering if there is a si...
11
2010-04-04T18:57:49Z
2,576,118
<p>If the "model" is running graphically (with the X window system), the already-suggested <a href="http://people.csail.mit.edu/adonovan/hacks/xsendkey.html">xsendkey</a> is a possibility, or <a href="http://linux.die.net/man/8/xsendkeycode">xsendkeycode</a>. If it's running textually (in a terminal window), then <a h...
5
2010-04-04T22:31:39Z
[ "python", "linux", "key", "keypress", "simulate" ]
Simulating Key Press event using Python for Linux
2,575,528
<p>I am writing a script to automate running a particular model. When the model fails, it waits for a user input (Enter key). I can detect when the model has failed, but I am not able to use python (on linux) to simulate a key press event. Windows has the SendKeys library to do this but I was wondering if there is a si...
11
2010-04-04T18:57:49Z
11,884,904
<p>A more low-level approach would be to create an <code>uinput</code> device from which you would then inject input events into the linux input subsystem. Consider the following libraries:</p> <ul> <li><a href="http://tjjr.fi/sw/python-uinput/" rel="nofollow">python-uinput</a></li> <li><a href="https://github.com/gva...
4
2012-08-09T13:47:03Z
[ "python", "linux", "key", "keypress", "simulate" ]
Simulating Key Press event using Python for Linux
2,575,528
<p>I am writing a script to automate running a particular model. When the model fails, it waits for a user input (Enter key). I can detect when the model has failed, but I am not able to use python (on linux) to simulate a key press event. Windows has the SendKeys library to do this but I was wondering if there is a si...
11
2010-04-04T18:57:49Z
19,457,610
<p>Have a look at this <a href="https://github.com/SavinaRoja/PyUserInput">https://github.com/SavinaRoja/PyUserInput</a> its cross-platform control for mouse and keyboard in python</p> <p>Keyboard control works on X11(linux) and Windows systems. But no mac support(when i wrote this answer).</p> <pre><code>from pykeyb...
8
2013-10-18T19:27:00Z
[ "python", "linux", "key", "keypress", "simulate" ]
Simulating Key Press event using Python for Linux
2,575,528
<p>I am writing a script to automate running a particular model. When the model fails, it waits for a user input (Enter key). I can detect when the model has failed, but I am not able to use python (on linux) to simulate a key press event. Windows has the SendKeys library to do this but I was wondering if there is a si...
11
2010-04-04T18:57:49Z
32,964,361
<p>I recommend <a href="https://pypi.python.org/pypi/PyAutoGUI" rel="nofollow">PyAutoGui</a>. It's ridiculously simple to use, it's cross-platform and it's for Python 3 and 2.</p> <p>In the linked page are listed the dependences and some code examples.</p>
1
2015-10-06T07:42:06Z
[ "python", "linux", "key", "keypress", "simulate" ]
What does printing an empty line do?
2,575,584
<p>I know this question may well be the silliest question you've heard today, but to me it is a big question at this stage of my programming learning.</p> <p>Why is the second empty line needed in this Python code? What does that line do?</p> <pre><code>print 'Content-Type: text/plain' print '' print 'Hello, world!' ...
5
2010-04-04T19:22:44Z
2,575,593
<p>It prints an empty line, just as you have said. It will leave a blank line in the output. The print statement prints its arguments, and then a newline, so this prints just a newline.</p> <p>You could accomplish the same thing with just:</p> <pre><code>print </code></pre>
10
2010-04-04T19:24:59Z
[ "python" ]
What does printing an empty line do?
2,575,584
<p>I know this question may well be the silliest question you've heard today, but to me it is a big question at this stage of my programming learning.</p> <p>Why is the second empty line needed in this Python code? What does that line do?</p> <pre><code>print 'Content-Type: text/plain' print '' print 'Hello, world!' ...
5
2010-04-04T19:22:44Z
2,575,596
<p>Did you even tried to telnet web-server? It needs \n. So, it's what it does, you can write it in one line if needed.</p> <pre><code>print 'Content-Type: text/plain\n\nHello World' </code></pre>
2
2010-04-04T19:25:31Z
[ "python" ]
What does printing an empty line do?
2,575,584
<p>I know this question may well be the silliest question you've heard today, but to me it is a big question at this stage of my programming learning.</p> <p>Why is the second empty line needed in this Python code? What does that line do?</p> <pre><code>print 'Content-Type: text/plain' print '' print 'Hello, world!' ...
5
2010-04-04T19:22:44Z
2,575,612
<p>A blank line is required between the headers and the body in an HTTP response, so a CGI script will print a blank line at just that spot. There's no need for the quotes though, since an unadorned <code>print</code> will output a blank line.</p>
4
2010-04-04T19:32:34Z
[ "python" ]
Why Python language does not have a writeln() method?
2,575,619
<p>If we need to write a new line to a file we have to code:</p> <pre><code>file_output.write('Fooo line \n') </code></pre> <p>Are there any reasons why Python does not have a <code>writeln()</code> method?</p>
11
2010-04-04T19:33:58Z
2,575,629
<p>Probably no real reason, just that it's really easy to write a newline when you need it, so why clutter up the file interface with an extra method just to do that?</p>
0
2010-04-04T19:35:50Z
[ "python", "syntax", "history", "language-design" ]
Why Python language does not have a writeln() method?
2,575,619
<p>If we need to write a new line to a file we have to code:</p> <pre><code>file_output.write('Fooo line \n') </code></pre> <p>Are there any reasons why Python does not have a <code>writeln()</code> method?</p>
11
2010-04-04T19:33:58Z
2,575,631
<p>In Python 2, use:</p> <pre><code>print &gt;&gt;file_output, 'Fooo line ' </code></pre> <p>In Python 3, use:</p> <pre><code>print('Fooo line ', file=file_output) </code></pre>
17
2010-04-04T19:36:29Z
[ "python", "syntax", "history", "language-design" ]
Why Python language does not have a writeln() method?
2,575,619
<p>If we need to write a new line to a file we have to code:</p> <pre><code>file_output.write('Fooo line \n') </code></pre> <p>Are there any reasons why Python does not have a <code>writeln()</code> method?</p>
11
2010-04-04T19:33:58Z
2,575,708
<p>It was omitted to provide a symmetric interface of the <code>file</code> methods and because a <code>writeln()</code> would make no sense:</p> <ul> <li><code>read()</code> matches <code>write()</code>: they both operate on raw data</li> <li><code>readlines()</code> matches <code>writelines()</code>: they both opera...
7
2010-04-04T20:02:33Z
[ "python", "syntax", "history", "language-design" ]
Why Python language does not have a writeln() method?
2,575,619
<p>If we need to write a new line to a file we have to code:</p> <pre><code>file_output.write('Fooo line \n') </code></pre> <p>Are there any reasons why Python does not have a <code>writeln()</code> method?</p>
11
2010-04-04T19:33:58Z
2,859,055
<p><code>print()</code> is the function you are looking for. Like much of the core polymorphism in python, printing is provided by a built-in function instead of using methods (just like <code>len()</code>, <code>next()</code>, <code>repr()</code> etc!).</p> <p>The <code>print()</code> function being the universal int...
2
2010-05-18T16:16:11Z
[ "python", "syntax", "history", "language-design" ]
Why Python language does not have a writeln() method?
2,575,619
<p>If we need to write a new line to a file we have to code:</p> <pre><code>file_output.write('Fooo line \n') </code></pre> <p>Are there any reasons why Python does not have a <code>writeln()</code> method?</p>
11
2010-04-04T19:33:58Z
14,567,103
<p>I feel that it should. Nearest thing you can use is:</p> <pre><code>file_output.writelines([foo_msg, '\n']) </code></pre>
2
2013-01-28T16:57:06Z
[ "python", "syntax", "history", "language-design" ]
What's an easy and fast way to put returned XML data into a dict?
2,575,672
<p>I'm trying to take the data returned from:</p> <pre><code>http://ipinfodb.com/ip_query.php?ip=74.125.45.100&amp;timezone=true </code></pre> <p>Into a dict in a fast and easy way. What's the best way to do this? </p> <p>Thanks.</p>
2
2010-04-04T19:48:51Z
2,575,710
<p><code>xml.etree</code> from standard library starting from python2.5. look also at <code>lxml</code> which has the same interface. I don't "dived in" to much but i think that <a href="http://www.diveintopython3.org/xml.html" rel="nofollow">this is also applicable to python >= 2.5 too</a>.</p> <p><strong>Edit:</stro...
0
2010-04-04T20:02:49Z
[ "python", "xml", "dictionary", "xml-parsing" ]
What's an easy and fast way to put returned XML data into a dict?
2,575,672
<p>I'm trying to take the data returned from:</p> <pre><code>http://ipinfodb.com/ip_query.php?ip=74.125.45.100&amp;timezone=true </code></pre> <p>Into a dict in a fast and easy way. What's the best way to do this? </p> <p>Thanks.</p>
2
2010-04-04T19:48:51Z
2,575,786
<p>Using <code>xml</code> from the standard Python library:</p> <pre><code>import xml.etree.ElementTree as xee contents='''\ &lt;?xml version="1.0" encoding="UTF-8"?&gt; &lt;Response&gt; &lt;Ip&gt;74.125.45.100&lt;/Ip&gt; &lt;Status&gt;OK&lt;/Status&gt; &lt;CountryCode&gt;US&lt;/CountryCode&gt; &lt;CountryName...
8
2010-04-04T20:29:56Z
[ "python", "xml", "dictionary", "xml-parsing" ]
What's an easy and fast way to put returned XML data into a dict?
2,575,672
<p>I'm trying to take the data returned from:</p> <pre><code>http://ipinfodb.com/ip_query.php?ip=74.125.45.100&amp;timezone=true </code></pre> <p>Into a dict in a fast and easy way. What's the best way to do this? </p> <p>Thanks.</p>
2
2010-04-04T19:48:51Z
2,575,844
<p>I would use the xml.dom builtin, something like this:</p> <pre><code>import urllib from xml.dom import minidom data = urllib.urlopen('http://ipinfodb.com/ip_query.php?ip=74.125.45.100&amp;timezone=true') xml_data = minidom.parse(data) my_dict ={} for node in xml_data.getElementsByTagName('Response')[0].childNodes:...
2
2010-04-04T20:52:07Z
[ "python", "xml", "dictionary", "xml-parsing" ]
Django url tag multiple parameters
2,575,737
<p>I have two similar codes. The first one works as expected.</p> <pre><code>urlpatterns = patterns('', (r'^(?P&lt;n1&gt;\d)/test/', test), (r'', test2), {% url testapp.views.test n1=5 %} </code></pre> <p>But adding the second parameter makes the result return empty strin...
4
2010-04-04T20:11:46Z
2,575,829
<p>Try</p> <pre><code>{% url testapp.views.test n1=5,n2=2 %} </code></pre> <p>without the space between the arguments</p> <p><strong>Update:</strong> As of <a href="https://docs.djangoproject.com/en/1.10/ref/templates/builtins/#url" rel="nofollow">Django 1.9</a> (and maybe earlier) the correct way is to omit the com...
11
2010-04-04T20:47:44Z
[ "python", "django", "django-urls" ]
Django url tag multiple parameters
2,575,737
<p>I have two similar codes. The first one works as expected.</p> <pre><code>urlpatterns = patterns('', (r'^(?P&lt;n1&gt;\d)/test/', test), (r'', test2), {% url testapp.views.test n1=5 %} </code></pre> <p>But adding the second parameter makes the result return empty strin...
4
2010-04-04T20:11:46Z
38,680,468
<p><a href="https://docs.djangoproject.com/en/1.9/ref/templates/builtins/#url" rel="nofollow">https://docs.djangoproject.com/en/1.9/ref/templates/builtins/#url</a></p> <p>From Django 1.5 Warning Don’t forget to put quotes around the function path or pattern name!</p> <pre><code>{% url 'some-url-name' arg1=v1 arg2=v...
0
2016-07-31T03:25:31Z
[ "python", "django", "django-urls" ]
Python lookup hostname from IP with 1 second timeout
2,575,760
<p>How can I look up a hostname given an IP address? Furthermore, how can I specify a timeout in case no such reverse DNS entry exists? Trying to keep things as fast as possible. Or is there a better way? Thank you!</p>
33
2010-04-04T20:20:27Z
2,575,779
<pre><code>&gt;&gt;&gt; import socket &gt;&gt;&gt; socket.gethostbyaddr("69.59.196.211") ('stackoverflow.com', ['211.196.59.69.in-addr.arpa'], ['69.59.196.211']) </code></pre> <p>For implementing the timeout on the function, <a href="http://stackoverflow.com/questions/492519/timeout-on-a-python-function-call">this sta...
49
2010-04-04T20:28:02Z
[ "python", "dns", "hostname", "nameservers" ]
Python lookup hostname from IP with 1 second timeout
2,575,760
<p>How can I look up a hostname given an IP address? Furthermore, how can I specify a timeout in case no such reverse DNS entry exists? Trying to keep things as fast as possible. Or is there a better way? Thank you!</p>
33
2010-04-04T20:20:27Z
2,575,785
<p>What you're trying to accomplish is called Reverse DNS lookup. </p> <pre><code>socket.gethostbyaddr("IP") # =&gt; (hostname, alias-list, IP) </code></pre> <p><a href="http://docs.python.org/library/socket.html?highlight=gethostbyaddr#socket.gethostbyaddr">http://docs.python.org/library/socket.html?highlight=getho...
9
2010-04-04T20:29:55Z
[ "python", "dns", "hostname", "nameservers" ]
add a custom RFC822 header via IMAP?
2,575,805
<p>Is there an easy way to add a custom RFC822 header to a message on an IMAP server with imaplib?</p> <p>I am writing a python-based program that filters my IMAP mail store. When I did this with Procmail I had the option of adding headers. But there doesn't seem to be a way to do that with the Python imap implementat...
1
2010-04-04T20:37:59Z
2,590,391
<p>I don't think <a href="http://tools.ietf.org/html/rfc2060.html" rel="nofollow">RFC 2060</a> allows the edit of received mail headers. If you want to edit the mail response header this can be done with the <code>email</code> package.</p>
0
2010-04-07T06:19:51Z
[ "python", "imap", "imaplib" ]
add a custom RFC822 header via IMAP?
2,575,805
<p>Is there an easy way to add a custom RFC822 header to a message on an IMAP server with imaplib?</p> <p>I am writing a python-based program that filters my IMAP mail store. When I did this with Procmail I had the option of adding headers. But there doesn't seem to be a way to do that with the Python imap implementat...
1
2010-04-04T20:37:59Z
2,638,115
<p>Better option would be to use <strong>custom server flags</strong> called keywords.</p> <p>A keyword is defined by the server implementation. Keywords do not begin with "\". Servers MAY permit the client to define new keywords in the mailbox.</p> <p>To add myflag to the message you can use </p> <pre><code>STORE ...
1
2010-04-14T14:20:25Z
[ "python", "imap", "imaplib" ]
Comments in string and strings in comments
2,575,810
<p>I am trying to count characters in comments included in C code using Python and Regex, but no success. I can erase strings first to get rid of comments in strings, but this will erase string in comments too and result will be bad ofc. Is there any chance to ask by using regex to not match strings in comments or vice...
0
2010-04-04T20:40:41Z
2,575,828
<p>Regular expressions are not always a replacement for a <a href="http://sourceforge.net/projects/python4c/" rel="nofollow">real parser</a>.</p>
2
2010-04-04T20:47:43Z
[ "python", "regex" ]