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 |
|---|---|---|---|---|---|---|---|---|---|
SQLAlchemy DateTime timezone | 414,952 | <p>SQLAlchemy's <code>DateTime</code> type allows for a <code>timezone=True</code> argument to save a non-naive datetime object to the datbase, and to return it as such. Is there any way to modify the timezone of the <code>tzinfo</code> that SQLAlchemy passes in so it could be, for instance, UTC? I realize that I could... | 24 | 2009-01-05T23:46:02Z | 462,028 | <p><a href="http://www.postgresql.org/docs/8.3/interactive/datatype-datetime.html#DATATYPE-TIMEZONES">http://www.postgresql.org/docs/8.3/interactive/datatype-datetime.html#DATATYPE-TIMEZONES</a></p>
<blockquote>
<p>All timezone-aware dates and times are stored internally in UTC. They are converted to local time in t... | 14 | 2009-01-20T16:24:22Z | [
"python",
"datetime",
"timezone",
"sqlalchemy"
] |
SQLAlchemy DateTime timezone | 414,952 | <p>SQLAlchemy's <code>DateTime</code> type allows for a <code>timezone=True</code> argument to save a non-naive datetime object to the datbase, and to return it as such. Is there any way to modify the timezone of the <code>tzinfo</code> that SQLAlchemy passes in so it could be, for instance, UTC? I realize that I could... | 24 | 2009-01-05T23:46:02Z | 12,695,076 | <p>a solution is given in <a href="http://stackoverflow.com/questions/2528189/can-sqlalchemy-datetime-objects-only-be-naive">this questionâs</a> answer:</p>
<p>you can circumvent that by storing all (date)time objects in your database in UTC, and converting the resulting naïve datetime objects to aware ones on retr... | 3 | 2012-10-02T17:16:57Z | [
"python",
"datetime",
"timezone",
"sqlalchemy"
] |
can cherrypy receive multipart/mixed POSTs out of the box? | 415,019 | <p>We're receiving some POST data of xml + arbitrary binary files (like images and audio) from a device that only gives us multipart/mixed encoding.</p>
<p>I've setup a cherrypy upload/POST handler for our receiver end. I've managed to allow it to do arbitrary number of parameters using multipart/form-data. However ... | 5 | 2009-01-06T00:16:30Z | 422,957 | <p>My bad. Whenever the Content-Type is of type "multipart/*", then CP tries to stick the contents into request.params (if any other Content-Type, it goes into request.body).</p>
<p>Unfortunately, CP has assumed that any multipart message is form-data, and made no provision for other subtypes. I've just fixed this in ... | 5 | 2009-01-08T01:55:49Z | [
"python",
"cherrypy"
] |
Why does gethostbyaddr(gethostname()) return my IPv6 IP? | 415,407 | <p>I'm working on making a simple server application with python, and I'm trying to get the IP to bind the listening socket to. An example I looked at uses this: </p>
<pre><code>HOST = gethostbyaddr(gethostname())
</code></pre>
<p>With a little more processing after this, it should give me just the host IP as a strin... | 3 | 2009-01-06T04:01:41Z | 415,417 | <p>Getting your IP address is harder than you might think.</p>
<p>Check <a href="http://stackoverflow.com/questions/270745/how-do-i-determine-all-of-my-ip-addresses-when-i-have-multiple-nics#274644">this answer</a> I gave for the one reliable way I've found.</p>
<p>Here's what the answer says in case you don't like c... | 11 | 2009-01-06T04:07:16Z | [
"python",
"sockets",
"ip-address",
"ipv6",
"ipv4"
] |
Why does gethostbyaddr(gethostname()) return my IPv6 IP? | 415,407 | <p>I'm working on making a simple server application with python, and I'm trying to get the IP to bind the listening socket to. An example I looked at uses this: </p>
<pre><code>HOST = gethostbyaddr(gethostname())
</code></pre>
<p>With a little more processing after this, it should give me just the host IP as a strin... | 3 | 2009-01-06T04:01:41Z | 415,430 | <p><a href="http://docs.python.org/library/socket.html#socket.gethostbyaddr" rel="nofollow"><code>gethostbyaddr()</code></a> takes an IP address as a parameter, not a hostname, so I'm surprised it's working at all without throwing an exception. If instead you meant <a href="http://docs.python.org/library/socket.html#s... | 0 | 2009-01-06T04:10:55Z | [
"python",
"sockets",
"ip-address",
"ipv6",
"ipv4"
] |
Why does gethostbyaddr(gethostname()) return my IPv6 IP? | 415,407 | <p>I'm working on making a simple server application with python, and I'm trying to get the IP to bind the listening socket to. An example I looked at uses this: </p>
<pre><code>HOST = gethostbyaddr(gethostname())
</code></pre>
<p>With a little more processing after this, it should give me just the host IP as a strin... | 3 | 2009-01-06T04:01:41Z | 2,211,983 | <p>IPv6 is taking precedence over IPv4 as it's the newer family, it's generally what you want if your hostname is associated with multiple families. You should be using <a href="http://docs.python.org/library/socket.html#socket.getaddrinfo">getaddrinfo</a> for family independent resolution, here is an example,</p>
<p... | 5 | 2010-02-06T04:02:29Z | [
"python",
"sockets",
"ip-address",
"ipv6",
"ipv4"
] |
How to get current time in Python | 415,511 | <p>What is the module/method used to get current time?</p>
| 1,153 | 2009-01-06T04:54:23Z | 415,519 | <pre><code>>>> import datetime
>>> datetime.datetime.now()
datetime(2009, 1, 6, 15, 8, 24, 78915)
</code></pre>
<p>And just the time:</p>
<pre><code>>>> datetime.datetime.time(datetime.datetime.now())
datetime.time(15, 8, 24, 78915)
</code></pre>
<p>The same but slightly more compact:</p>
... | 1,151 | 2009-01-06T04:57:05Z | [
"python",
"datetime",
"time"
] |
How to get current time in Python | 415,511 | <p>What is the module/method used to get current time?</p>
| 1,153 | 2009-01-06T04:54:23Z | 415,525 | <p>You can use <a href="http://docs.python.org/3.3/library/time.html?highlight=time.strftime#time.strftime"><code>time.strftime()</code></a>: </p>
<pre><code>>>> from time import gmtime, strftime
>>> strftime("%Y-%m-%d %H:%M:%S", gmtime())
'2009-01-05 22:14:39'
</code></pre>
| 475 | 2009-01-06T04:59:52Z | [
"python",
"datetime",
"time"
] |
How to get current time in Python | 415,511 | <p>What is the module/method used to get current time?</p>
| 1,153 | 2009-01-06T04:54:23Z | 415,527 | <pre><code>>>> from time import gmtime, strftime
>>> strftime("%a, %d %b %Y %X +0000", gmtime())
'Tue, 06 Jan 2009 04:54:56 +0000'
</code></pre>
<p>That outputs the current GMT in the specified format. There is also a localtime() method. </p>
<p>This <a href="http://docs.python.org/library/time.html... | 66 | 2009-01-06T05:02:43Z | [
"python",
"datetime",
"time"
] |
How to get current time in Python | 415,511 | <p>What is the module/method used to get current time?</p>
| 1,153 | 2009-01-06T04:54:23Z | 416,605 | <p>Do</p>
<pre><code>from time import time
t = time()
</code></pre>
<ul>
<li><code>t</code> - float number, good for time interval measurement.</li>
</ul>
<p>There is some difference for Unix and Windows platforms.</p>
| 74 | 2009-01-06T13:55:23Z | [
"python",
"datetime",
"time"
] |
How to get current time in Python | 415,511 | <p>What is the module/method used to get current time?</p>
| 1,153 | 2009-01-06T04:54:23Z | 4,538,034 | <p>If you need current time as a <code>time</code> object:</p>
<pre><code>>>> import datetime
>>> now = datetime.datetime.now()
>>> datetime.time(now.hour, now.minute, now.second)
datetime.time(11, 23, 44)
</code></pre>
| 26 | 2010-12-27T10:24:12Z | [
"python",
"datetime",
"time"
] |
How to get current time in Python | 415,511 | <p>What is the module/method used to get current time?</p>
| 1,153 | 2009-01-06T04:54:23Z | 5,877,368 | <p>Similar to <a href="http://stackoverflow.com/questions/415511/how-to-get-current-time-in-python/415519#415519">Harley's answer</a>, but use the <code>str()</code> function for a quick-n-dirty, slightly more human readable format:</p>
<pre><code>>>> from datetime import datetime
>>> str(datetime.no... | 222 | 2011-05-04T00:56:29Z | [
"python",
"datetime",
"time"
] |
How to get current time in Python | 415,511 | <p>What is the module/method used to get current time?</p>
| 1,153 | 2009-01-06T04:54:23Z | 14,229,023 | <pre><code>>>> from datetime import datetime
>>> datetime.now().strftime('%Y-%m-%d %H:%M:%S')
</code></pre>
<p>For this example, the output will be like this: <code>'2013-09-18 11:16:32'</code></p>
<p>The format for <code>strftime</code> is at:<br>
<a href="https://docs.python.org/2/library/time.htm... | 175 | 2013-01-09T05:50:34Z | [
"python",
"datetime",
"time"
] |
How to get current time in Python | 415,511 | <p>What is the module/method used to get current time?</p>
| 1,153 | 2009-01-06T04:54:23Z | 17,287,377 | <p>I'll contribute to this because <code>.isoformat()</code> is in the documentation but not yet here
(this is mighty similar to @Ray Vega's answer):</p>
<pre><code>>>>import datetime
>>> datetime.datetime.now().isoformat()
'2013-06-24T20:35:55.982000'
</code></pre>
| 16 | 2013-06-25T00:38:25Z | [
"python",
"datetime",
"time"
] |
How to get current time in Python | 415,511 | <p>What is the module/method used to get current time?</p>
| 1,153 | 2009-01-06T04:54:23Z | 18,980,227 | <p>Quickest way is</p>
<pre><code>>>> import time
>>> time.strftime("%Y%m%d")
'20130924'
</code></pre>
| 13 | 2013-09-24T11:21:10Z | [
"python",
"datetime",
"time"
] |
How to get current time in Python | 415,511 | <p>What is the module/method used to get current time?</p>
| 1,153 | 2009-01-06T04:54:23Z | 19,710,846 | <p>All good suggestions, but I find it easiest to use <code>ctime()</code> myself:</p>
<pre><code>In [2]: from time import ctime
In [3]: ctime()
Out[3]: 'Thu Oct 31 11:40:53 2013'
</code></pre>
<p>This gives a nicely formatted string representation of current local time.</p>
| 27 | 2013-10-31T15:39:39Z | [
"python",
"datetime",
"time"
] |
How to get current time in Python | 415,511 | <p>What is the module/method used to get current time?</p>
| 1,153 | 2009-01-06T04:54:23Z | 23,753,208 | <pre><code>>>> import datetime, time
>>> time = strftime("%H:%M:%S:%MS", time.localtime())
>>> print time
'00:20:58:20S'
</code></pre>
| 5 | 2014-05-20T07:13:36Z | [
"python",
"datetime",
"time"
] |
How to get current time in Python | 415,511 | <p>What is the module/method used to get current time?</p>
| 1,153 | 2009-01-06T04:54:23Z | 27,611,645 | <p><code>datetime.now()</code> returns the current time as a naive datetime object that represents time in the local timezone. That value may be ambiguous e.g., during DST transitions ("fall back"). To avoid ambiguity either UTC timezone should be used:</p>
<pre><code>from datetime import datetime
utc_time = datetime... | 8 | 2014-12-22T22:52:47Z | [
"python",
"datetime",
"time"
] |
How to get current time in Python | 415,511 | <p>What is the module/method used to get current time?</p>
| 1,153 | 2009-01-06T04:54:23Z | 27,866,830 | <p>This is what I ended up going with: </p>
<pre><code>>>>from time import strftime
>>>strftime("%m/%d/%Y %H:%M")
01/09/2015 13:11
</code></pre>
<p>Also, this table is a necessary reference for choosing the appropriate format codes to get the date formatted just the way you want it (from Python "dat... | 11 | 2015-01-09T18:24:49Z | [
"python",
"datetime",
"time"
] |
How to get current time in Python | 415,511 | <p>What is the module/method used to get current time?</p>
| 1,153 | 2009-01-06T04:54:23Z | 28,371,709 | <p>You can use the time module.</p>
<pre><code>import time
print time.strftime("%d/%m/%Y")
>>> 06/02/2015
</code></pre>
<p>The use of the captial <code>Y</code> gives the full year, using <code>y</code> would give <code>06/02/15</code></p>
<p>You could also use to give a more lengthy time.</p>
<pre><code>... | 6 | 2015-02-06T17:46:46Z | [
"python",
"datetime",
"time"
] |
How to get current time in Python | 415,511 | <p>What is the module/method used to get current time?</p>
| 1,153 | 2009-01-06T04:54:23Z | 28,576,383 | <blockquote>
<h1>How do I get the current time in Python?</h1>
</blockquote>
<h2>The <code>time</code> module</h2>
<p>The <code>time</code> module provides functions that tells us the time in "seconds since the epoch" as well as other utilities.</p>
<pre><code>import time
</code></pre>
<h3>Unix Epoch Time</h3>
<... | 38 | 2015-02-18T05:08:34Z | [
"python",
"datetime",
"time"
] |
How to get current time in Python | 415,511 | <p>What is the module/method used to get current time?</p>
| 1,153 | 2009-01-06T04:54:23Z | 29,980,465 | <p>This is what i use to get the time without having to format , some people dont like the split method but it is useful here :</p>
<pre><code>from time import ctime
print ctime().split()[3]
</code></pre>
<p>Will print in HH:MM:SS format</p>
| 2 | 2015-05-01T01:39:08Z | [
"python",
"datetime",
"time"
] |
How to get current time in Python | 415,511 | <p>What is the module/method used to get current time?</p>
| 1,153 | 2009-01-06T04:54:23Z | 33,704,374 | <p>Try the arrow module from <a href="http://crsmithdev.com/arrow/">http://crsmithdev.com/arrow/</a></p>
<pre><code>import arrow
arrow.now()
</code></pre>
<p>or the utc version</p>
<pre><code>arrow.utcnow()
</code></pre>
<p>to change it's output add .format()</p>
<pre><code>arrow.utcnow().format('YYYY-MM-DD HH:mm:... | 6 | 2015-11-14T02:02:45Z | [
"python",
"datetime",
"time"
] |
How to get current time in Python | 415,511 | <p>What is the module/method used to get current time?</p>
| 1,153 | 2009-01-06T04:54:23Z | 38,366,394 | <pre><code>import datetime
date_time = str(datetime.datetime.now())
date = date_time.split()[0]
time = date_time.split()[1]
</code></pre>
<p>date will print date and time will print time.</p>
| 0 | 2016-07-14T05:50:20Z | [
"python",
"datetime",
"time"
] |
How to get current time in Python | 415,511 | <p>What is the module/method used to get current time?</p>
| 1,153 | 2009-01-06T04:54:23Z | 38,433,505 | <p>I am a simple man and i want time with milliseconds. Simple way to get them:</p>
<pre><code>import time, datetime
print(datetime.datetime.now().time()) # 11:20:08.272239
# or in a more complicated way
print(datetime.datetime.now().time().isoformat()) # 11:20:08.272239
print(date... | 0 | 2016-07-18T09:45:50Z | [
"python",
"datetime",
"time"
] |
How to get current time in Python | 415,511 | <p>What is the module/method used to get current time?</p>
| 1,153 | 2009-01-06T04:54:23Z | 38,615,092 | <p>why not just keep things simple. </p>
<pre><code>>>> from datetime import datetime
>>> datetime.now().strftime("%Y-%m-%d %H:%M:%S")
'2016-07-27 15:56:59'
>>>
</code></pre>
| 5 | 2016-07-27T13:58:36Z | [
"python",
"datetime",
"time"
] |
How to get current time in Python | 415,511 | <p>What is the module/method used to get current time?</p>
| 1,153 | 2009-01-06T04:54:23Z | 39,046,637 | <p>Why not ask the <a href="http://tycho.usno.navy.mil/cgi-bin/timer.pl">U.S. Naval Observatory</a>, the official timekeeper of the United States Navy?</p>
<pre><code>import requests
from lxml import html
page = requests.get('http://tycho.usno.navy.mil/cgi-bin/timer.pl')
tree = html.fromstring(page.content)
print(tre... | 5 | 2016-08-19T19:45:08Z | [
"python",
"datetime",
"time"
] |
URLs: Binary Blob, Unicode or Encoded Unicode String? | 416,315 | <p>I wish to store URLs in a database (MySQL in this case) and process it in Python. Though the database and programming language are probably not this relevant to my question.</p>
<p>In my setup I receive unicode strings when querying a text field in the database. But is a URL actually text? Is encoding from and dec... | 2 | 2009-01-06T12:22:10Z | 416,339 | <p>On the question: "But is a URL actually text?"</p>
<p>It depends on the context, in some languages or libraries (for example java, I'm not sure about python), a URL may be represented internally as an object. However, a URL always has a well defined text representation. So storing the text-representation is much ... | 1 | 2009-01-06T12:30:39Z | [
"python",
"mysql",
"database",
"url"
] |
URLs: Binary Blob, Unicode or Encoded Unicode String? | 416,315 | <p>I wish to store URLs in a database (MySQL in this case) and process it in Python. Though the database and programming language are probably not this relevant to my question.</p>
<p>In my setup I receive unicode strings when querying a text field in the database. But is a URL actually text? Is encoding from and dec... | 2 | 2009-01-06T12:22:10Z | 416,423 | <p>The relevant answer is found in <a href="http://www.ietf.org/rfc/rfc2396.txt" rel="nofollow">RFC 2396</a>, section
2.1 <em>URI and non-ASCII characters</em></p>
<p><hr /></p>
<p>The relationship between URI and characters has been a source of
confusion for characters that are not part of US-ASCII. To describe
the... | 3 | 2009-01-06T13:01:10Z | [
"python",
"mysql",
"database",
"url"
] |
URLs: Binary Blob, Unicode or Encoded Unicode String? | 416,315 | <p>I wish to store URLs in a database (MySQL in this case) and process it in Python. Though the database and programming language are probably not this relevant to my question.</p>
<p>In my setup I receive unicode strings when querying a text field in the database. But is a URL actually text? Is encoding from and dec... | 2 | 2009-01-06T12:22:10Z | 416,994 | <p>Do note there is also a standard for Unicode Web addresses, IRI (Internationalized Resource Identifiers). <a href="http://www.ietf.org/rfc/rfc3987.txt" rel="nofollow">RFC 3987</a></p>
| 1 | 2009-01-06T15:37:53Z | [
"python",
"mysql",
"database",
"url"
] |
Filtering away nearby points from a list | 416,406 | <p>I <a href="http://stackoverflow.com/questions/411837/finding-clusters-of-mass-in-a-matrix-bitmap#411855">half-answered a question about finding clusters of mass in a bitmap</a>. I say half-answered because I left it in a condition where I had all the points in the bitmap sorted by mass and left it to the reader to f... | 0 | 2009-01-06T12:54:57Z | 416,426 | <p>This sounds like color quantization, where you reduce the number of colors in an image. One way would be to plot the colors in space, and combine clusters into the center (or a weighted average) of a cluster.</p>
<p>The exact name of the algorithm that triggered this memory fails me, but I'll edit the answer if it ... | 1 | 2009-01-06T13:02:17Z | [
"python",
"algorithm",
"language-agnostic",
"bitmap",
"filtering"
] |
Filtering away nearby points from a list | 416,406 | <p>I <a href="http://stackoverflow.com/questions/411837/finding-clusters-of-mass-in-a-matrix-bitmap#411855">half-answered a question about finding clusters of mass in a bitmap</a>. I say half-answered because I left it in a condition where I had all the points in the bitmap sorted by mass and left it to the reader to f... | 0 | 2009-01-06T12:54:57Z | 416,428 | <p>Start with the "<a href="http://en.wikipedia.org/wiki/Convex_hull" rel="nofollow">Convex Hull</a>" problem. You're also looking for some "convex hull"-like clusters.</p>
<p>Note that "clusters" is vague. You have an average mass across your field. Some points have above average mass, and some below average. How... | 1 | 2009-01-06T13:03:48Z | [
"python",
"algorithm",
"language-agnostic",
"bitmap",
"filtering"
] |
Filtering away nearby points from a list | 416,406 | <p>I <a href="http://stackoverflow.com/questions/411837/finding-clusters-of-mass-in-a-matrix-bitmap#411855">half-answered a question about finding clusters of mass in a bitmap</a>. I say half-answered because I left it in a condition where I had all the points in the bitmap sorted by mass and left it to the reader to f... | 0 | 2009-01-06T12:54:57Z | 416,489 | <p>Since you are already talking about mass, why not a gravity based solution. A simple particle system would not need to be super accurate, and you would not have to run it for too long before you could make a much better guess at the number of clusters.</p>
<p>If you have a better idea about cluster numbers, k-means... | 1 | 2009-01-06T13:21:28Z | [
"python",
"algorithm",
"language-agnostic",
"bitmap",
"filtering"
] |
Filtering away nearby points from a list | 416,406 | <p>I <a href="http://stackoverflow.com/questions/411837/finding-clusters-of-mass-in-a-matrix-bitmap#411855">half-answered a question about finding clusters of mass in a bitmap</a>. I say half-answered because I left it in a condition where I had all the points in the bitmap sorted by mass and left it to the reader to f... | 0 | 2009-01-06T12:54:57Z | 416,544 | <p>As I mentioned in the comment to your question, the answer is based on whether or not mass can be considered scalar in this context. If so, color based solutions are probably not going to work as color is often not taken as being scalar.</p>
<p>For example, if I have a given area with 1 point of high mass, is that... | 3 | 2009-01-06T13:42:05Z | [
"python",
"algorithm",
"language-agnostic",
"bitmap",
"filtering"
] |
Filtering away nearby points from a list | 416,406 | <p>I <a href="http://stackoverflow.com/questions/411837/finding-clusters-of-mass-in-a-matrix-bitmap#411855">half-answered a question about finding clusters of mass in a bitmap</a>. I say half-answered because I left it in a condition where I had all the points in the bitmap sorted by mass and left it to the reader to f... | 0 | 2009-01-06T12:54:57Z | 416,609 | <p>It sounds to me like you're looking for the <a href="http://en.wikipedia.org/wiki/K_means" rel="nofollow">K-means</a> algorithm.</p>
| 4 | 2009-01-06T13:56:27Z | [
"python",
"algorithm",
"language-agnostic",
"bitmap",
"filtering"
] |
Filtering away nearby points from a list | 416,406 | <p>I <a href="http://stackoverflow.com/questions/411837/finding-clusters-of-mass-in-a-matrix-bitmap#411855">half-answered a question about finding clusters of mass in a bitmap</a>. I say half-answered because I left it in a condition where I had all the points in the bitmap sorted by mass and left it to the reader to f... | 0 | 2009-01-06T12:54:57Z | 417,034 | <p>Just so you know, you are asking for a solution to an <a href="http://en.wikipedia.org/wiki/Ill-posed" rel="nofollow">ill-posed problem: no definitive solution exists. That's fine...it just makes it more fun. Your problem is ill-posed mostly because you don't know how many clusters you want. Clustering is one of ... | 5 | 2009-01-06T15:46:16Z | [
"python",
"algorithm",
"language-agnostic",
"bitmap",
"filtering"
] |
Java Servlet Filter Equivalent in Ruby [on Rails] and PHP? | 417,158 | <p>Not sure if the terminology is correct, but are there rough equivalents to Java Servlet Filters in Ruby and PHP ? Are they actual concrete <em>classes</em> ?</p>
<p>I assume there is also a number of common web app libraries/frameworks in Python. Is there an equivalent there ?</p>
<p>Thanks.</p>
<p><strong>=== AD... | 1 | 2009-01-06T16:17:01Z | 420,249 | <p>In a typical <strong>Apache/PHP</strong> scenario, the answer is generally: No, there are no custom filters. However, there some solutions for problems solved with Java Servlet Filters:</p>
<ul>
<li>There are multiple collaborating <a href="http://httpd.apache.org/docs/2.2/howto/auth.html" rel="nofollow">access con... | 0 | 2009-01-07T13:07:55Z | [
"java",
"php",
"python",
"ruby-on-rails",
"servlets"
] |
Java Servlet Filter Equivalent in Ruby [on Rails] and PHP? | 417,158 | <p>Not sure if the terminology is correct, but are there rough equivalents to Java Servlet Filters in Ruby and PHP ? Are they actual concrete <em>classes</em> ?</p>
<p>I assume there is also a number of common web app libraries/frameworks in Python. Is there an equivalent there ?</p>
<p>Thanks.</p>
<p><strong>=== AD... | 1 | 2009-01-06T16:17:01Z | 453,350 | <blockquote>
<p>I assume there is also a number of
common web app libraries/frameworks in
Python. Is there an equivalent there ?</p>
</blockquote>
<p><strong>Django</strong> provides a framework of middleware hooks that can be used to alter input/output in request/response processing. See the <a href="http://doc... | 2 | 2009-01-17T14:09:04Z | [
"java",
"php",
"python",
"ruby-on-rails",
"servlets"
] |
Java Servlet Filter Equivalent in Ruby [on Rails] and PHP? | 417,158 | <p>Not sure if the terminology is correct, but are there rough equivalents to Java Servlet Filters in Ruby and PHP ? Are they actual concrete <em>classes</em> ?</p>
<p>I assume there is also a number of common web app libraries/frameworks in Python. Is there an equivalent there ?</p>
<p>Thanks.</p>
<p><strong>=== AD... | 1 | 2009-01-06T16:17:01Z | 550,839 | <p><a href="http://api.rubyonrails.com/classes/ActionController/Filters/ClassMethods.html" rel="nofollow">Ruby on Rails has filters</a> that serve this purpose</p>
<p>A new feature is <a href="http://www.pathf.com/blogs/2009/02/its-only-rack-on-rails-but-i-like-it/" rel="nofollow">Rack Middleware</a>, which is similar... | 0 | 2009-02-15T12:56:39Z | [
"java",
"php",
"python",
"ruby-on-rails",
"servlets"
] |
Java Servlet Filter Equivalent in Ruby [on Rails] and PHP? | 417,158 | <p>Not sure if the terminology is correct, but are there rough equivalents to Java Servlet Filters in Ruby and PHP ? Are they actual concrete <em>classes</em> ?</p>
<p>I assume there is also a number of common web app libraries/frameworks in Python. Is there an equivalent there ?</p>
<p>Thanks.</p>
<p><strong>=== AD... | 1 | 2009-01-06T16:17:01Z | 550,856 | <p>In the PHP world, <a href="http://framework.zend.com/" rel="nofollow">Zend Framework</a> provides a plugin API for its front controller object that allows hooking of plugin objects between the pre-routing and post-dispatching phases. Although I didn't have a chance to work with Java servlets I assume this would matc... | 0 | 2009-02-15T13:20:03Z | [
"java",
"php",
"python",
"ruby-on-rails",
"servlets"
] |
Cross Platform SWF Playback with Python? | 417,159 | <p>I'm looking for different solutions to playing back SWF files on Windows, OSX and Linux using Python. Ideally I'd like to embed the player inside a wxPython frame/window.</p>
<p>One possibility I'm investigating is the Mozilla XPCOM framework since its used by FireFox to load the Flash plugin within the browser.</... | 3 | 2009-01-06T16:17:06Z | 425,445 | <p>Though I don't know how to embed a browser within a wxPython window, the following code might serve in a pinch (and will work cross-platform, assuming you're working in Python 2.5 or above):</p>
<pre><code>import webbrowser
webbrowser.open(your_swf_url)
</code></pre>
<p>It might be best to delegate this task to th... | 2 | 2009-01-08T19:03:16Z | [
"python",
"cross-platform",
"flash",
"wxpython"
] |
Cross Platform SWF Playback with Python? | 417,159 | <p>I'm looking for different solutions to playing back SWF files on Windows, OSX and Linux using Python. Ideally I'd like to embed the player inside a wxPython frame/window.</p>
<p>One possibility I'm investigating is the Mozilla XPCOM framework since its used by FireFox to load the Flash plugin within the browser.</... | 3 | 2009-01-06T16:17:06Z | 426,461 | <p>Have you considered <a href="http://www.onflex.org/ted/2008/02/why-adobe-air.php" rel="nofollow">Adobe AIR</a>? </p>
<p>Bruce Eckel said: <a href="http://www.artima.com/weblogs/viewpost.jsp?thread=208528" rel="nofollow">Try combining the power of Python with the polish of Adobe Flash to create a desktop application... | 3 | 2009-01-08T23:23:16Z | [
"python",
"cross-platform",
"flash",
"wxpython"
] |
What does "|" sign mean in a Django template? | 417,265 | <p>I often see something like that:
<code>something.property|escape</code>
<hr />
<code>something</code> is an object, <code>property</code> is it's string property. <code>escape</code> - i don't know :)
<br />
What does this mean? And what min python version it is used in?</p>
<p><br /></p>
<p>EDIT: The question was... | 1 | 2009-01-06T16:44:18Z | 417,273 | <p>It's a bitwise "or". It means escape if the property doesn't exist/is null.</p>
| -1 | 2009-01-06T16:46:54Z | [
"python",
"django",
"django-templates"
] |
What does "|" sign mean in a Django template? | 417,265 | <p>I often see something like that:
<code>something.property|escape</code>
<hr />
<code>something</code> is an object, <code>property</code> is it's string property. <code>escape</code> - i don't know :)
<br />
What does this mean? And what min python version it is used in?</p>
<p><br /></p>
<p>EDIT: The question was... | 1 | 2009-01-06T16:44:18Z | 417,299 | <p>obj.property|escape is the way to apply the <a href="http://docs.djangoproject.com/en/dev/ref/templates/builtins/#built-in-filter-reference" rel="nofollow">escape filter in a template</a>, which will HTML escape the string representation of that property.</p>
| 8 | 2009-01-06T16:55:04Z | [
"python",
"django",
"django-templates"
] |
What does "|" sign mean in a Django template? | 417,265 | <p>I often see something like that:
<code>something.property|escape</code>
<hr />
<code>something</code> is an object, <code>property</code> is it's string property. <code>escape</code> - i don't know :)
<br />
What does this mean? And what min python version it is used in?</p>
<p><br /></p>
<p>EDIT: The question was... | 1 | 2009-01-06T16:44:18Z | 417,630 | <p>The pipe character indicates that you want to send the results of the left hand side to the filter defined on the right side. The filter will modify the value in some way. </p>
<p>The 'escape' filter is just one of many.</p>
<p>The list of built in filters can be found here:
<a href="http://docs.djangoproject.c... | 6 | 2009-01-06T18:27:44Z | [
"python",
"django",
"django-templates"
] |
What does the â|â sign mean in Python? | 417,396 | <p><a href="http://stackoverflow.com/questions/417265/what-does-sign-mean-in-django">This question</a> originally asked (wrongly) what does "|" mean in Python, when the actual question was about Django. That question had a wonderful answer by Triptych I want to preserve. </p>
| 7 | 2009-01-06T17:18:20Z | 417,402 | <p>Bitwise OR</p>
| 0 | 2009-01-06T17:20:22Z | [
"python",
"syntax-rules"
] |
What does the â|â sign mean in Python? | 417,396 | <p><a href="http://stackoverflow.com/questions/417265/what-does-sign-mean-in-django">This question</a> originally asked (wrongly) what does "|" mean in Python, when the actual question was about Django. That question had a wonderful answer by Triptych I want to preserve. </p>
| 7 | 2009-01-06T17:18:20Z | 417,438 | <p>In Python, the <code>'|'</code> operator is defined by default on integer types and set types. </p>
<p>If the two operands are integers, then it will perform a <a href="http://en.wikipedia.org/wiki/Bitwise_operation#OR">bitwise or</a>, which is a mathematical operation.</p>
<p>If the two operands are <code>set</c... | 16 | 2009-01-06T17:28:40Z | [
"python",
"syntax-rules"
] |
What does the â|â sign mean in Python? | 417,396 | <p><a href="http://stackoverflow.com/questions/417265/what-does-sign-mean-in-django">This question</a> originally asked (wrongly) what does "|" mean in Python, when the actual question was about Django. That question had a wonderful answer by Triptych I want to preserve. </p>
| 7 | 2009-01-06T17:18:20Z | 1,986,034 | <p>It could also be "tricked" into a pipe like in unix shells, see here <a href="http://code.google.com/p/python-pipeline/" rel="nofollow">http://code.google.com/p/python-pipeline/</a></p>
| 0 | 2009-12-31T16:33:02Z | [
"python",
"syntax-rules"
] |
How can I tell if an Expando subclass has a property defined? | 417,584 | <p>I'm creating an app that I want to have an expandable set of properties (each a RatingProperty) I also want to validate that any dynamic properties are of the RatingProperty type. </p>
<p>In the Expando documentation it says:</p>
<blockquote>
<p>Tip: If you want to validate a dynamic property value using a Prope... | 0 | 2009-01-06T18:14:01Z | 418,905 | <p>After a bit more research (damn you lazyweb!) I've found a solution that I think is acceptable: </p>
<p>A dynamic property can't be of a db subclassed property type. Thus, there are two distinct steps that must be taken. First you need to create an instance of your property class and validate your value: </p>
<p... | 1 | 2009-01-07T01:51:44Z | [
"python",
"google-app-engine"
] |
How can I tell if an Expando subclass has a property defined? | 417,584 | <p>I'm creating an app that I want to have an expandable set of properties (each a RatingProperty) I also want to validate that any dynamic properties are of the RatingProperty type. </p>
<p>In the Expando documentation it says:</p>
<blockquote>
<p>Tip: If you want to validate a dynamic property value using a Prope... | 0 | 2009-01-06T18:14:01Z | 420,416 | <p>I may be misunderstanding your question, but if you have a list of properties you expect to find, why not just use a standard db.Model, instead of an Expando? You can add additional properties to a Model class, as long as you either provide a default or don't make them required.</p>
| 0 | 2009-01-07T14:07:47Z | [
"python",
"google-app-engine"
] |
How can I tell if an Expando subclass has a property defined? | 417,584 | <p>I'm creating an app that I want to have an expandable set of properties (each a RatingProperty) I also want to validate that any dynamic properties are of the RatingProperty type. </p>
<p>In the Expando documentation it says:</p>
<blockquote>
<p>Tip: If you want to validate a dynamic property value using a Prope... | 0 | 2009-01-06T18:14:01Z | 4,505,283 | <p>It's actually quite easy!</p>
<p><a href="http://msdn.microsoft.com/en-us/library/system.dynamic.expandoobject.aspx" rel="nofollow">ExpandoObject</a> implements <code>(IDictionary<String, Object>)</code> so you just need to do this :</p>
<pre><code> dynamic person = new ExpandoObject();
person.FirstName = "... | 0 | 2010-12-22T00:45:30Z | [
"python",
"google-app-engine"
] |
How can I tell if an Expando subclass has a property defined? | 417,584 | <p>I'm creating an app that I want to have an expandable set of properties (each a RatingProperty) I also want to validate that any dynamic properties are of the RatingProperty type. </p>
<p>In the Expando documentation it says:</p>
<blockquote>
<p>Tip: If you want to validate a dynamic property value using a Prope... | 0 | 2009-01-06T18:14:01Z | 8,359,602 | <p><a href="http://code.google.com/appengine/docs/python/datastore/modelclass.html#Model_properties" rel="nofollow">http://code.google.com/appengine/docs/python/datastore/modelclass.html#Model_properties</a></p>
<p>db.Model has methods to find out all the properties on an instance.</p>
<p>The class exposes a list of ... | 1 | 2011-12-02T16:41:17Z | [
"python",
"google-app-engine"
] |
How can I use Numerical Python with Python 2.6 | 417,664 | <p>I'm forced to upgrade to Python 2.6 and am having issues using Numerical Python (<a href="http://en.wikipedia.org/wiki/NumPy" rel="nofollow">NumPy</a>) with Python 2.6 in Windows. I'm getting the following error...</p>
<pre><code>Traceback (most recent call last):
File "<pyshell#0>", line 1, in <module&... | 2 | 2009-01-06T18:41:29Z | 417,674 | <p>How did you install it? NumPy doesn't currently have a Python 2.6 binary.</p>
<p>If you have <a href="http://en.wikipedia.org/wiki/LAPACK" rel="nofollow">LAPACK</a>/<a href="http://en.wikipedia.org/wiki/Automatically_Tuned_Linear_Algebra_Software" rel="nofollow">ATLAS</a>/<a href="http://en.wikipedia.org/wiki/Basi... | 9 | 2009-01-06T18:45:16Z | [
"python",
"windows",
"numpy"
] |
How can I use Numerical Python with Python 2.6 | 417,664 | <p>I'm forced to upgrade to Python 2.6 and am having issues using Numerical Python (<a href="http://en.wikipedia.org/wiki/NumPy" rel="nofollow">NumPy</a>) with Python 2.6 in Windows. I'm getting the following error...</p>
<pre><code>Traceback (most recent call last):
File "<pyshell#0>", line 1, in <module&... | 2 | 2009-01-06T18:41:29Z | 823,331 | <p><a href="http://sourceforge.net/project/downloading.php?group%5Fid=1369&filename=numpy-1.3.0-win32-superpack-python2.6.exe&a=35708818" rel="nofollow">NumPy 1.3.0 is available for Python 2.6 now</a>.</p>
| 3 | 2009-05-05T04:23:14Z | [
"python",
"windows",
"numpy"
] |
Python: C++-like stream input | 417,703 | <p>Is there a pythonic way of reading - say - mixed integer and char input without reading the whole input at once and without worrying about linebreaks? For example I have a file with whitespace-separated data of which I only know that there are x integers, then y chars and then z more integers. I don't want to assume... | 2 | 2009-01-06T18:55:14Z | 417,741 | <p>Like this?</p>
<pre><code>>>> data = "1 2 3 4 5 6 abcdefg 9 8 7 6 5 4 3"
</code></pre>
<p>For example, we might get this with <code>data= someFile.read()</code></p>
<pre><code>>>> fields= data.split()
>>> x= map(int,fields[:6])
>>> y= fields[6]
>>> z= map(int,fields[7:... | 2 | 2009-01-06T19:13:09Z | [
"c++",
"input",
"stream",
"python"
] |
Python: C++-like stream input | 417,703 | <p>Is there a pythonic way of reading - say - mixed integer and char input without reading the whole input at once and without worrying about linebreaks? For example I have a file with whitespace-separated data of which I only know that there are x integers, then y chars and then z more integers. I don't want to assume... | 2 | 2009-01-06T18:55:14Z | 417,773 | <p>if you don't want to read in a whole line at a time, you might want to try something like this:</p>
<pre><code>def read_tokens(file):
while True:
token = []
while True:
c = file.read(1)
if c not in ['', ' ', '\t', '\n']:
token.append(c)
elif c ... | 3 | 2009-01-06T19:24:52Z | [
"c++",
"input",
"stream",
"python"
] |
Python: C++-like stream input | 417,703 | <p>Is there a pythonic way of reading - say - mixed integer and char input without reading the whole input at once and without worrying about linebreaks? For example I have a file with whitespace-separated data of which I only know that there are x integers, then y chars and then z more integers. I don't want to assume... | 2 | 2009-01-06T18:55:14Z | 417,893 | <p>How about a small generator function that returns a stream of tokens and behaves like <code>cin</code>:</p>
<pre><code>def read_tokens(f):
for line in f:
for token in line.split():
yield token
x = y = z = 5 # for simplicity: 5 ints, 5 char tokens, 5 ints
f = open('data.txt', 'r')
tokens = rea... | 6 | 2009-01-06T20:02:33Z | [
"c++",
"input",
"stream",
"python"
] |
Python: C++-like stream input | 417,703 | <p>Is there a pythonic way of reading - say - mixed integer and char input without reading the whole input at once and without worrying about linebreaks? For example I have a file with whitespace-separated data of which I only know that there are x integers, then y chars and then z more integers. I don't want to assume... | 2 | 2009-01-06T18:55:14Z | 418,257 | <p>How's this? Building on heikogerlach's excellent <code>read_tokens</code>.</p>
<pre><code>def read_tokens(f):
for line in f:
for token in line.split():
yield token
</code></pre>
<p>We can do things like the following to pick up 6 numbers, 7 characters and 6 numbers.</p>
<pre><code>fi = read_... | 0 | 2009-01-06T21:31:22Z | [
"c++",
"input",
"stream",
"python"
] |
Process size in XP from Python | 417,763 | <p>I have a python script that can approach the 2 GB process limit under Windows XP. On a machine with 2 GB physical memory, that can pretty much lock up the machine, even if the Python script is running at below normal priority.</p>
<p>Is there a way in Python to find out my own process size?</p>
<p>Thanks,
Gerry</... | 5 | 2009-01-06T19:22:11Z | 418,533 | <p>try:</p>
<pre><code>import win32process
print win32process.GetProcessMemoryInfo(win32process.GetCurrentProcess())
</code></pre>
| 2 | 2009-01-06T23:00:19Z | [
"python",
"windows-xp"
] |
Process size in XP from Python | 417,763 | <p>I have a python script that can approach the 2 GB process limit under Windows XP. On a machine with 2 GB physical memory, that can pretty much lock up the machine, even if the Python script is running at below normal priority.</p>
<p>Is there a way in Python to find out my own process size?</p>
<p>Thanks,
Gerry</... | 5 | 2009-01-06T19:22:11Z | 4,229,753 | <p>By using psutil <a href="https://github.com/giampaolo/psutil" rel="nofollow">https://github.com/giampaolo/psutil</a> :</p>
<pre><code>>>> import psutil, os
>>> p = psutil.Process(os.getpid())
>>> p.memory_info()
meminfo(rss=6971392, vms=47755264)
>>> p.memory_percent()
0.16821255... | 1 | 2010-11-19T21:55:33Z | [
"python",
"windows-xp"
] |
Process size in XP from Python | 417,763 | <p>I have a python script that can approach the 2 GB process limit under Windows XP. On a machine with 2 GB physical memory, that can pretty much lock up the machine, even if the Python script is running at below normal priority.</p>
<p>Is there a way in Python to find out my own process size?</p>
<p>Thanks,
Gerry</... | 5 | 2009-01-06T19:22:11Z | 4,229,975 | <p>Rather than worrying about limiting your process size at runtime, it might be better to figure out if all the pieces of data that you're currently storing in memory truly need to be in memory at all times.</p>
<p>You probably have plenty of disk space, and simply by creating some temporary files (see the <a href="h... | 0 | 2010-11-19T22:34:29Z | [
"python",
"windows-xp"
] |
Why does Python's string.printable contains unprintable characters? | 418,176 | <p>I have two String.printable mysteries in the one question.</p>
<p>First, in Python 2.6:</p>
<pre><code>>>> string.printable
'0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ!"#$%&\'()*+,-./:;<=>?@[\\]^_`{|}~ \t\n\r\x0b\x0c'
</code></pre>
<p>Look at the end of the string, and you'l... | 12 | 2009-01-06T21:10:31Z | 418,200 | <p>There is a difference in "printable" for "can be displayed on your screen". Your terminal displays the low ascii printer control codes 0x0B and 0x0C as the male and female symbols because that is what those indices in your font contain. Those characters are more accurately described as the Vertical Tabulator and F... | 25 | 2009-01-06T21:15:36Z | [
"python",
"character-encoding"
] |
Why does Python's string.printable contains unprintable characters? | 418,176 | <p>I have two String.printable mysteries in the one question.</p>
<p>First, in Python 2.6:</p>
<pre><code>>>> string.printable
'0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ!"#$%&\'()*+,-./:;<=>?@[\\]^_`{|}~ \t\n\r\x0b\x0c'
</code></pre>
<p>Look at the end of the string, and you'l... | 12 | 2009-01-06T21:10:31Z | 418,445 | <p>From within cmd.exe:</p>
<pre><code>>>> print '\x0b'
â
>>> print '\x0c'
â
>>> print '\f' # form feed
â
>>> print '\v' # vertical tab
â
>>>
</code></pre>
<p>Inside Emacs:</p>
<pre><code>>>> print '\f\v'
^L^K
</code></pre>
<p>Here's an excerpt from <a h... | 6 | 2009-01-06T22:27:59Z | [
"python",
"character-encoding"
] |
How to check that a path has a sticky bit in python? | 418,204 | <p>How to check with python if a path has the sticky bit set?</p>
| 1 | 2009-01-06T21:16:59Z | 418,240 | <p><a href="http://docs.python.org/library/os.html#os.stat" rel="nofollow">os.stat()</a> will return a tupple of information about the file. The first item will be the mode. You would then be able to use some bit arithmetic to get for the sticky bit. The sticky bit has an octal value of 1000.</p>
| 2 | 2009-01-06T21:25:43Z | [
"python"
] |
How to check that a path has a sticky bit in python? | 418,204 | <p>How to check with python if a path has the sticky bit set?</p>
| 1 | 2009-01-06T21:16:59Z | 418,243 | <pre><code>import os
def is_sticky(path):
return os.stat(path).st_mode & 01000 == 01000
</code></pre>
| 7 | 2009-01-06T21:26:05Z | [
"python"
] |
How to convert XML to objects? | 418,497 | <p>I need to load an XML file and put the contents into an object-oriented structure. I want to take this:</p>
<pre><code><main>
<object1 attr="name">content</object>
</main>
</code></pre>
<p>and turn it into something like this:</p>
<pre><code>main
main.object1 = "content"
main.object1.a... | 19 | 2009-01-06T22:47:14Z | 418,534 | <p>How about this</p>
<p><a href="http://evanjones.ca/software/simplexmlparse.html" rel="nofollow">http://evanjones.ca/software/simplexmlparse.html</a></p>
| 1 | 2009-01-06T23:00:31Z | [
"python",
"xml"
] |
How to convert XML to objects? | 418,497 | <p>I need to load an XML file and put the contents into an object-oriented structure. I want to take this:</p>
<pre><code><main>
<object1 attr="name">content</object>
</main>
</code></pre>
<p>and turn it into something like this:</p>
<pre><code>main
main.object1 = "content"
main.object1.a... | 19 | 2009-01-06T22:47:14Z | 418,587 | <p>If googling around for a code-generator doesn't work, you could write your own that uses XML as input and outputs objects in your language of choice.</p>
<p>It's not terribly difficult, however the three step process of Parse XML, Generate Code, Compile/Execute Script does making debugging a bit harder.</p>
| 0 | 2009-01-06T23:18:48Z | [
"python",
"xml"
] |
How to convert XML to objects? | 418,497 | <p>I need to load an XML file and put the contents into an object-oriented structure. I want to take this:</p>
<pre><code><main>
<object1 attr="name">content</object>
</main>
</code></pre>
<p>and turn it into something like this:</p>
<pre><code>main
main.object1 = "content"
main.object1.a... | 19 | 2009-01-06T22:47:14Z | 418,720 | <p>There are three common XML parsers for python: xml.dom.minidom, elementree, and BeautifulSoup.</p>
<p>IMO, BeautifulSoup is by far the best. </p>
<p><a href="http://www.crummy.com/software/BeautifulSoup/" rel="nofollow">http://www.crummy.com/software/BeautifulSoup/</a></p>
| 0 | 2009-01-07T00:09:03Z | [
"python",
"xml"
] |
How to convert XML to objects? | 418,497 | <p>I need to load an XML file and put the contents into an object-oriented structure. I want to take this:</p>
<pre><code><main>
<object1 attr="name">content</object>
</main>
</code></pre>
<p>and turn it into something like this:</p>
<pre><code>main
main.object1 = "content"
main.object1.a... | 19 | 2009-01-06T22:47:14Z | 418,728 | <p>I've been recommending this more than once today, but try <a href="http://www.crummy.com/software/BeautifulSoup/" rel="nofollow">Beautiful Soup</a> (easy_install BeautifulSoup).</p>
<pre><code>from BeautifulSoup import BeautifulSoup
xml = """
<main>
<object attr="name">content</object>
</m... | 7 | 2009-01-07T00:15:27Z | [
"python",
"xml"
] |
How to convert XML to objects? | 418,497 | <p>I need to load an XML file and put the contents into an object-oriented structure. I want to take this:</p>
<pre><code><main>
<object1 attr="name">content</object>
</main>
</code></pre>
<p>and turn it into something like this:</p>
<pre><code>main
main.object1 = "content"
main.object1.a... | 19 | 2009-01-06T22:47:14Z | 418,823 | <pre><code>#@Stephen:
#"can't hardcode the element names, so I need to collect them
#at parse and use them somehow as the object names."
#I don't think thats possible. Instead you can do this.
#this will help you getting any object with a required name.
import BeautifulSoup
class Coll(object):
"""A class whi... | 0 | 2009-01-07T01:06:09Z | [
"python",
"xml"
] |
How to convert XML to objects? | 418,497 | <p>I need to load an XML file and put the contents into an object-oriented structure. I want to take this:</p>
<pre><code><main>
<object1 attr="name">content</object>
</main>
</code></pre>
<p>and turn it into something like this:</p>
<pre><code>main
main.object1 = "content"
main.object1.a... | 19 | 2009-01-06T22:47:14Z | 418,854 | <p>David Mertz's <a href="http://www.xml.com/pub/a/2003/07/02/py-xml.html" rel="nofollow">gnosis.xml.objectify</a> would seem to do this for you. Documentation's a bit hard to come by, but there are a few IBM articles on it, including <a href="http://www.ibm.com/developerworks/xml/library/x-matters39.html" rel="nofollo... | 3 | 2009-01-07T01:21:22Z | [
"python",
"xml"
] |
How to convert XML to objects? | 418,497 | <p>I need to load an XML file and put the contents into an object-oriented structure. I want to take this:</p>
<pre><code><main>
<object1 attr="name">content</object>
</main>
</code></pre>
<p>and turn it into something like this:</p>
<pre><code>main
main.object1 = "content"
main.object1.a... | 19 | 2009-01-06T22:47:14Z | 419,232 | <p>It's worth to have a look at <a href="http://lxml.de/objectify.html">http://lxml.de/objectify.html</a></p>
<pre><code>>>> xml = """<main>
... <object1 attr="name">content</object1>
... <object1 attr="foo">contenbar</object1>
... <test>me</test>
... </main>"""... | 31 | 2009-01-07T04:51:26Z | [
"python",
"xml"
] |
Are there any graph/plotting/anything-like-that libraries for Python 3.0? | 418,835 | <p>As per the title. I am trying to create a simple scater plot, but haven't found any Python 3.0 libraries that can do it. Note, this isn't for a website, so the web ones are a bit useless.</p>
| 3 | 2009-01-07T01:12:41Z | 418,858 | <p>Have you looked at the Google Chart Wrapper?</p>
<p><a href="http://pypi.python.org/pypi/GChartWrapper/0.7" rel="nofollow">http://pypi.python.org/pypi/GChartWrapper/0.7</a></p>
| 0 | 2009-01-07T01:22:17Z | [
"python",
"python-3.x",
"plot",
"graphing",
"scatter-plot"
] |
Are there any graph/plotting/anything-like-that libraries for Python 3.0? | 418,835 | <p>As per the title. I am trying to create a simple scater plot, but haven't found any Python 3.0 libraries that can do it. Note, this isn't for a website, so the web ones are a bit useless.</p>
| 3 | 2009-01-07T01:12:41Z | 419,538 | <p>I would call <a href="http://gnuplot-py.sourceforge.net" rel="nofollow">Gnuplot</a> from Python. No need to reinvent the wheel in Python, Gnuplot is already there and already has a Python interface.</p>
| 0 | 2009-01-07T08:10:37Z | [
"python",
"python-3.x",
"plot",
"graphing",
"scatter-plot"
] |
Are there any graph/plotting/anything-like-that libraries for Python 3.0? | 418,835 | <p>As per the title. I am trying to create a simple scater plot, but haven't found any Python 3.0 libraries that can do it. Note, this isn't for a website, so the web ones are a bit useless.</p>
| 3 | 2009-01-07T01:12:41Z | 421,947 | <p>Maybe you can use Python Imaging Library (PIL).
Also have a look at PyX, but this library is meant to output to PDF, ...</p>
| 1 | 2009-01-07T20:32:30Z | [
"python",
"python-3.x",
"plot",
"graphing",
"scatter-plot"
] |
Are there any graph/plotting/anything-like-that libraries for Python 3.0? | 418,835 | <p>As per the title. I am trying to create a simple scater plot, but haven't found any Python 3.0 libraries that can do it. Note, this isn't for a website, so the web ones are a bit useless.</p>
| 3 | 2009-01-07T01:12:41Z | 467,124 | <p>The GChartWrapper (<a href="http://pypi.python.org/pypi/GChartWrapper/0.7" rel="nofollow">http://pypi.python.org/pypi/GChartWrapper/0.7</a>) does work for py3k</p>
| 1 | 2009-01-21T21:36:59Z | [
"python",
"python-3.x",
"plot",
"graphing",
"scatter-plot"
] |
Are there any graph/plotting/anything-like-that libraries for Python 3.0? | 418,835 | <p>As per the title. I am trying to create a simple scater plot, but haven't found any Python 3.0 libraries that can do it. Note, this isn't for a website, so the web ones are a bit useless.</p>
| 3 | 2009-01-07T01:12:41Z | 8,732,336 | <p>The current <a href="https://github.com/matplotlib/matplotlib" rel="nofollow">development version of matplotlib</a> should work on Python 3.</p>
| 0 | 2012-01-04T18:56:23Z | [
"python",
"python-3.x",
"plot",
"graphing",
"scatter-plot"
] |
Pythonic equivalent of unshift or redo? | 418,915 | <p>I'm learning Python, and I have a situation where I want to consume items from an iterator. The tricky part is that under certain conditions, I want to "un-iterate." That is, put an item back onto the front of the iterator before I loop.</p>
<p>For example, suppose I'm picking apples from a tree. My fruit basket... | 12 | 2009-01-07T01:59:07Z | 418,946 | <p>Why bother with unshifting when the else clause should always occur?</p>
<pre><code>for apple in tree:
if (apple.weight + basket.weight) > 10:
send(basket)
basket.clear()
basket.add(apple)
</code></pre>
<p>Anyway, I'm fairly certain that Python doesn't have the sort of behavior you're look... | 13 | 2009-01-07T02:12:11Z | [
"python",
"redo"
] |
Pythonic equivalent of unshift or redo? | 418,915 | <p>I'm learning Python, and I have a situation where I want to consume items from an iterator. The tricky part is that under certain conditions, I want to "un-iterate." That is, put an item back onto the front of the iterator before I loop.</p>
<p>For example, suppose I'm picking apples from a tree. My fruit basket... | 12 | 2009-01-07T01:59:07Z | 418,964 | <p>There is no way general way to push a value into an iterator in python. A stack or linked list is better suited to that.</p>
<p>If you're iterating over a list or something, of course you can add the item manually back to the list. But you can also iterate over objects which can't be manipulated in such a way.</p... | -2 | 2009-01-07T02:18:04Z | [
"python",
"redo"
] |
Pythonic equivalent of unshift or redo? | 418,915 | <p>I'm learning Python, and I have a situation where I want to consume items from an iterator. The tricky part is that under certain conditions, I want to "un-iterate." That is, put an item back onto the front of the iterator before I loop.</p>
<p>For example, suppose I'm picking apples from a tree. My fruit basket... | 12 | 2009-01-07T01:59:07Z | 418,987 | <blockquote>
<p>I'm learning Python, and I have a situation where I want to consume items from an iterator. The tricky part is that under certain conditions, I want to "un-iterate." That is, put an item back onto the front of the iterator before I loop.</p>
</blockquote>
<p>Here's a simple solution:</p>
<pre><code>... | 16 | 2009-01-07T02:27:28Z | [
"python",
"redo"
] |
Pythonic equivalent of unshift or redo? | 418,915 | <p>I'm learning Python, and I have a situation where I want to consume items from an iterator. The tricky part is that under certain conditions, I want to "un-iterate." That is, put an item back onto the front of the iterator before I loop.</p>
<p>For example, suppose I'm picking apples from a tree. My fruit basket... | 12 | 2009-01-07T01:59:07Z | 418,996 | <p>While I was writing this @Patrick already suggested the same thing. But since I have written it I will paste the code anyways, with comments in code marking methods from Patrick.</p>
<pre><code>import random
apples=[random.randint(1,3) for j in range(10)]
print 'apples',apples
basket=[]
y=6
baskets=[]
for i in r... | 1 | 2009-01-07T02:36:02Z | [
"python",
"redo"
] |
Pythonic equivalent of unshift or redo? | 418,915 | <p>I'm learning Python, and I have a situation where I want to consume items from an iterator. The tricky part is that under certain conditions, I want to "un-iterate." That is, put an item back onto the front of the iterator before I loop.</p>
<p>For example, suppose I'm picking apples from a tree. My fruit basket... | 12 | 2009-01-07T01:59:07Z | 419,100 | <p>You're looking for a generator, an iterator that can receive modifications to its internal state via the send() method</p>
<p><a href="https://docs.python.org/howto/functional.html#passing-values-into-a-generator" rel="nofollow">https://docs.python.org/howto/functional.html#passing-values-into-a-generator</a></p>
| 3 | 2009-01-07T03:29:59Z | [
"python",
"redo"
] |
Pythonic equivalent of unshift or redo? | 418,915 | <p>I'm learning Python, and I have a situation where I want to consume items from an iterator. The tricky part is that under certain conditions, I want to "un-iterate." That is, put an item back onto the front of the iterator before I loop.</p>
<p>For example, suppose I'm picking apples from a tree. My fruit basket... | 12 | 2009-01-07T01:59:07Z | 419,365 | <p>I'd say that <a href="http://mail.python.org/pipermail/python-list/2004-March/253893.html">the most Pythonic solution is the simplest one</a>. Instead of trying to wrap an iterator in a generator expression that allows you to "backtrack" or something similarly complex, use a while loop, as you have in Perl! <strong>... | 6 | 2009-01-07T06:09:24Z | [
"python",
"redo"
] |
Pythonic equivalent of unshift or redo? | 418,915 | <p>I'm learning Python, and I have a situation where I want to consume items from an iterator. The tricky part is that under certain conditions, I want to "un-iterate." That is, put an item back onto the front of the iterator before I loop.</p>
<p>For example, suppose I'm picking apples from a tree. My fruit basket... | 12 | 2009-01-07T01:59:07Z | 420,173 | <p>If you don't want to follow the other's suggestion of just removing the else clause, you can write your own <code>unshift</code> function that will work in a way similar to perl's with any iterable:</p>
<pre><code>class UnshiftableIterable(object):
def __init__(self, iterable):
self._iter = iter(iterabl... | 4 | 2009-01-07T12:40:38Z | [
"python",
"redo"
] |
Pythonic equivalent of unshift or redo? | 418,915 | <p>I'm learning Python, and I have a situation where I want to consume items from an iterator. The tricky part is that under certain conditions, I want to "un-iterate." That is, put an item back onto the front of the iterator before I loop.</p>
<p>For example, suppose I'm picking apples from a tree. My fruit basket... | 12 | 2009-01-07T01:59:07Z | 5,657,672 | <p>By the way, what you really want is list.insert(0,yourObject)</p>
| 0 | 2011-04-14T01:41:59Z | [
"python",
"redo"
] |
Pythonic equivalent of unshift or redo? | 418,915 | <p>I'm learning Python, and I have a situation where I want to consume items from an iterator. The tricky part is that under certain conditions, I want to "un-iterate." That is, put an item back onto the front of the iterator before I loop.</p>
<p>For example, suppose I'm picking apples from a tree. My fruit basket... | 12 | 2009-01-07T01:59:07Z | 14,739,023 | <p>Back to the original question about impementing unshift, operator.delitem can be used to implement a simple non-OO function:</p>
<pre><code>from operator import delitem
def unshift(l,idx):
retval = l[0]
delitem(l,0)
return retval
x = [2,4,6,8]
firstval = unshift(x,0)
print firstval,x
</code></pre>
... | 0 | 2013-02-06T21:20:56Z | [
"python",
"redo"
] |
How to raise an exception on the version number of a module | 419,010 | <p>How can you raise an exception when you import a module that is less or greater than a given value for its __version__?</p>
<p>There are a lot of different ways you could do it, but I feel like there must be some really simple way that eludes me at the moment. In this case the version number is of the format x.x.x<... | 4 | 2009-01-07T02:39:56Z | 419,035 | <p>Like this?</p>
<pre><code>assert tuple(map(int,module.__version__.split("."))) >= (1,2), "Module not version 1.2.x"
</code></pre>
<p>This is wordy, but works pretty well.</p>
<p>Also, look into <a href="http://pypi.python.org/pypi/pip/" rel="nofollow">pip</a>, which provides more advanced functionality.</p>
| 1 | 2009-01-07T02:51:06Z | [
"python",
"versioning"
] |
How to raise an exception on the version number of a module | 419,010 | <p>How can you raise an exception when you import a module that is less or greater than a given value for its __version__?</p>
<p>There are a lot of different ways you could do it, but I feel like there must be some really simple way that eludes me at the moment. In this case the version number is of the format x.x.x<... | 4 | 2009-01-07T02:39:56Z | 419,038 | <p>Python comes with this inbuilt as part of distutils. The module is called <code>distutils.version</code> and is able to compare several different version number formats.</p>
<pre><code>from distutils.version import StrictVersion
print StrictVersion('1.2.2') > StrictVersion('1.2.1')
</code></pre>
<p>For way mor... | 6 | 2009-01-07T02:52:13Z | [
"python",
"versioning"
] |
How to raise an exception on the version number of a module | 419,010 | <p>How can you raise an exception when you import a module that is less or greater than a given value for its __version__?</p>
<p>There are a lot of different ways you could do it, but I feel like there must be some really simple way that eludes me at the moment. In this case the version number is of the format x.x.x<... | 4 | 2009-01-07T02:39:56Z | 419,089 | <p>If you know the exact formatting of the version string a plain comparison will work:</p>
<pre><code>>>> "1.2.2" > "1.2.1"
True
</code></pre>
<p>This will only work if each part of the version is in the single digits, though:</p>
<pre><code>>>> "1.2.2" > "1.2.10" # Bug!
True
</code></pre>
| -1 | 2009-01-07T03:24:51Z | [
"python",
"versioning"
] |
How to raise an exception on the version number of a module | 419,010 | <p>How can you raise an exception when you import a module that is less or greater than a given value for its __version__?</p>
<p>There are a lot of different ways you could do it, but I feel like there must be some really simple way that eludes me at the moment. In this case the version number is of the format x.x.x<... | 4 | 2009-01-07T02:39:56Z | 419,108 | <p>If you are talking about modules installed with easy_install, this is what you need</p>
<pre><code>import pkg_resources
pkg_resources.require("TurboGears>=1.0.5")
</code></pre>
<p>this will raise an error if the installed module is of a lower version</p>
<pre><code>Traceback (most recent call last):
File "te... | 2 | 2009-01-07T03:34:59Z | [
"python",
"versioning"
] |
How to raise an exception on the version number of a module | 419,010 | <p>How can you raise an exception when you import a module that is less or greater than a given value for its __version__?</p>
<p>There are a lot of different ways you could do it, but I feel like there must be some really simple way that eludes me at the moment. In this case the version number is of the format x.x.x<... | 4 | 2009-01-07T02:39:56Z | 420,029 | <p>You should be using setuptools: </p>
<p>It allows you to lock the dependancies of an application, so even if multiple versions of an egg or package exist on a system only the right one will ever be used. </p>
<p>This is a better way of working: Rather than fail if the wrong version of a dependancy is present it is... | 0 | 2009-01-07T11:51:04Z | [
"python",
"versioning"
] |
Python Threads - Critical Section | 419,145 | <p>What is the "critical section" of a thread (in Python)?</p>
<blockquote>
<p>A thread enters the critical section
by calling the acquire() method, which
can either be blocking or
non-blocking. A thread exits the
critical section, by calling the
release() method.</p>
</blockquote>
<p>- <a href="http://li... | 10 | 2009-01-07T03:58:18Z | 419,155 | <p>A critical section of code is one that can only be executed by one thread at a time. Take a chat server for instance. If you have a thread for each connection (i.e., each end user), one "critical section" is the spooling code (sending an incoming message to all the clients). If more than one thread tries to spool a ... | 14 | 2009-01-07T04:07:50Z | [
"python",
"multithreading",
"language-agnostic"
] |
Python Threads - Critical Section | 419,145 | <p>What is the "critical section" of a thread (in Python)?</p>
<blockquote>
<p>A thread enters the critical section
by calling the acquire() method, which
can either be blocking or
non-blocking. A thread exits the
critical section, by calling the
release() method.</p>
</blockquote>
<p>- <a href="http://li... | 10 | 2009-01-07T03:58:18Z | 419,161 | <p>A <a href="http://en.wikipedia.org/wiki/Critical_section" rel="nofollow">"critical section"</a> is a chunk of code in which, for correctness, it is necessary to ensure that only one thread of control can be in that section at a time. In general, you need a critical section to contain references that <em>write</em> ... | 0 | 2009-01-07T04:09:57Z | [
"python",
"multithreading",
"language-agnostic"
] |
Python Threads - Critical Section | 419,145 | <p>What is the "critical section" of a thread (in Python)?</p>
<blockquote>
<p>A thread enters the critical section
by calling the acquire() method, which
can either be blocking or
non-blocking. A thread exits the
critical section, by calling the
release() method.</p>
</blockquote>
<p>- <a href="http://li... | 10 | 2009-01-07T03:58:18Z | 419,213 | <p>Other people have given very nice definitions. Here's the classic example:</p>
<pre><code>import threading
account_balance = 0 # The "resource" that zenazn mentions.
account_balance_lock = threading.Lock()
def change_account_balance(delta):
global account_balance
with account_balance_lock:
# Critic... | 8 | 2009-01-07T04:42:43Z | [
"python",
"multithreading",
"language-agnostic"
] |
What does `if __name__ == "__main__":` do? | 419,163 | <p>What does the <code>if __name__ == "__main__":</code> do?</p>
<pre><code># Threading example
import time, thread
def myfunction(string, sleeptime, lock, *args):
while 1:
lock.acquire()
time.sleep(sleeptime)
lock.release()
time.sleep(sleeptime)
if __name__ == "__main__":
lock... | 2,184 | 2009-01-07T04:11:00Z | 419,174 | <p><code>if __name__ == "__main__"</code> is the part that runs when the script is run from (say) the command line using a command like <code>python myscript.py</code>.</p>
| 61 | 2009-01-07T04:14:23Z | [
"python",
"module",
"namespaces",
"main",
"idioms"
] |
What does `if __name__ == "__main__":` do? | 419,163 | <p>What does the <code>if __name__ == "__main__":</code> do?</p>
<pre><code># Threading example
import time, thread
def myfunction(string, sleeptime, lock, *args):
while 1:
lock.acquire()
time.sleep(sleeptime)
lock.release()
time.sleep(sleeptime)
if __name__ == "__main__":
lock... | 2,184 | 2009-01-07T04:11:00Z | 419,185 | <p>When the Python interpreter reads a source file, it executes all of the code found in it. </p>
<p>Before executing the code, it will define a few special variables. For example, if the python interpreter is running that module (the source file) as the main program, it sets the special <code>__name__</code> variab... | 2,443 | 2009-01-07T04:26:43Z | [
"python",
"module",
"namespaces",
"main",
"idioms"
] |
What does `if __name__ == "__main__":` do? | 419,163 | <p>What does the <code>if __name__ == "__main__":</code> do?</p>
<pre><code># Threading example
import time, thread
def myfunction(string, sleeptime, lock, *args):
while 1:
lock.acquire()
time.sleep(sleeptime)
lock.release()
time.sleep(sleeptime)
if __name__ == "__main__":
lock... | 2,184 | 2009-01-07T04:11:00Z | 419,189 | <p>When your script is run by passing it as a command to the Python interpreter,</p>
<pre><code>python myscript.py
</code></pre>
<p>all of the code that is at indentation level 0 gets executed. Functions and classes that are defined are, well, defined, but none of their code gets ran. Unlike other languages, there'... | 697 | 2009-01-07T04:28:23Z | [
"python",
"module",
"namespaces",
"main",
"idioms"
] |
What does `if __name__ == "__main__":` do? | 419,163 | <p>What does the <code>if __name__ == "__main__":</code> do?</p>
<pre><code># Threading example
import time, thread
def myfunction(string, sleeptime, lock, *args):
while 1:
lock.acquire()
time.sleep(sleeptime)
lock.release()
time.sleep(sleeptime)
if __name__ == "__main__":
lock... | 2,184 | 2009-01-07T04:11:00Z | 419,986 | <p>The simplest explanation for the <code>__name__</code> variable (imho) is the following:</p>
<p>Create the following files.</p>
<pre><code># a.py
import b
</code></pre>
<p>and</p>
<pre><code># b.py
print "Hello World from %s!" % __name__
if __name__ == '__main__':
print "Hello World again from %s!" % __name... | 337 | 2009-01-07T11:35:17Z | [
"python",
"module",
"namespaces",
"main",
"idioms"
] |
What does `if __name__ == "__main__":` do? | 419,163 | <p>What does the <code>if __name__ == "__main__":</code> do?</p>
<pre><code># Threading example
import time, thread
def myfunction(string, sleeptime, lock, *args):
while 1:
lock.acquire()
time.sleep(sleeptime)
lock.release()
time.sleep(sleeptime)
if __name__ == "__main__":
lock... | 2,184 | 2009-01-07T04:11:00Z | 14,502,904 | <p>It is a special for when a Python file is called from the command line. This is typically used to call a "main()" function or execute other appropriate startup code, like commandline arguments handling for instance.</p>
<p>It could be written in several ways, another is:</p>
<pre><code>def main():
dosomething(... | 6 | 2013-01-24T13:48:38Z | [
"python",
"module",
"namespaces",
"main",
"idioms"
] |
What does `if __name__ == "__main__":` do? | 419,163 | <p>What does the <code>if __name__ == "__main__":</code> do?</p>
<pre><code># Threading example
import time, thread
def myfunction(string, sleeptime, lock, *args):
while 1:
lock.acquire()
time.sleep(sleeptime)
lock.release()
time.sleep(sleeptime)
if __name__ == "__main__":
lock... | 2,184 | 2009-01-07T04:11:00Z | 15,789,709 | <p>When there are certain statements in our module (<code>M.py</code>), we want to be executed when it 'll be running as main (not imported), in that case we can place those statements (test-cases, print statements) under this if block. As by default (when module running as main, not imported) the <code>__name__</code>... | 19 | 2013-04-03T14:09:11Z | [
"python",
"module",
"namespaces",
"main",
"idioms"
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.