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
how to change default dateformat AAAA-MM-DD to dd/mm/yyyy in Django?
1,677,035
<p>My locale dateformat is dd/mm/yyyy and Django is requering AAAA-MM-DD</p> <p>when the user inputs 04/11/2009 Django raises:</p> <pre><code>_('Enter a valid date in YYYY-MM-DD format.')) </code></pre> <p>Im using simple html input field type="text", Not forms.DateField</p> <p>Thanks :)</p>
0
2009-11-04T22:12:40Z
11,440,266
<p>Based on the OP's post and comments, it looks like there is more here than just using input_formats for the date field, though you'll want to do that. The message 'Enter a valid date in YYYY-MM-DD format' is an exception and <strong>NOT</strong> a form validation error. You'll get this exception if you try to save...
1
2012-07-11T19:45:32Z
[ "python", "django", "date-format" ]
Overriding the newline generation behaviour of Python's print statement
1,677,424
<p>I have a bunch of legacy code for encoding raw emails that contains a lot of print statements such as</p> <pre><code>print &gt;&gt;f, "Content-Type: text/plain" </code></pre> <p>This is all well and good for emails, but we're now leveraging the same code for outputting HTTP request. The problem is that the Python ...
7
2009-11-04T23:36:17Z
1,677,477
<p>(Not sure how/if this fits with the wrapper you intend to use, but in case...)</p> <p>In Python 2.6 (and many preceding versions), you can suppress the newline by adding a comma at the end of the print statement, as in:</p> <pre><code>data = 'some msg\r\n' print data, # note the comma </code></pre> <p>The downsi...
8
2009-11-04T23:48:07Z
[ "python", "printing", "cpython" ]
Overriding the newline generation behaviour of Python's print statement
1,677,424
<p>I have a bunch of legacy code for encoding raw emails that contains a lot of print statements such as</p> <pre><code>print &gt;&gt;f, "Content-Type: text/plain" </code></pre> <p>This is all well and good for emails, but we're now leveraging the same code for outputting HTTP request. The problem is that the Python ...
7
2009-11-04T23:36:17Z
1,677,643
<p>I think I would define a new function <code>writeline</code> in an inherited file/stream class and update the code to use <code>writeline</code> instead of <code>print</code>. The file object itself can hold the line ending style as a member. That should give you some flexibility in behavior and also make the code a...
0
2009-11-05T00:37:29Z
[ "python", "printing", "cpython" ]
Overriding the newline generation behaviour of Python's print statement
1,677,424
<p>I have a bunch of legacy code for encoding raw emails that contains a lot of print statements such as</p> <pre><code>print &gt;&gt;f, "Content-Type: text/plain" </code></pre> <p>This is all well and good for emails, but we're now leveraging the same code for outputting HTTP request. The problem is that the Python ...
7
2009-11-04T23:36:17Z
1,677,663
<p>In python2.x, I think you can do:</p> <pre><code>print &gt;&gt;f "some msg\r\n", </code></pre> <p>to supress the trailing new line.</p> <p>In python3.x, it's a lot simpler:</p> <pre><code>print("some msg", end = "\r\n", file = f) </code></pre>
3
2009-11-05T00:45:44Z
[ "python", "printing", "cpython" ]
Overriding the newline generation behaviour of Python's print statement
1,677,424
<p>I have a bunch of legacy code for encoding raw emails that contains a lot of print statements such as</p> <pre><code>print &gt;&gt;f, "Content-Type: text/plain" </code></pre> <p>This is all well and good for emails, but we're now leveraging the same code for outputting HTTP request. The problem is that the Python ...
7
2009-11-04T23:36:17Z
1,677,738
<p>I also prefer your third solution, but no need to use f.write, any user written function/callable would do. Thus the next changes would become easy. If you use an object you may even hide target file inside it thus removing some syntaxic noise like file or kind of newline.</p> <p>Too bad print is a statement in pyt...
0
2009-11-05T01:15:51Z
[ "python", "printing", "cpython" ]
Overriding the newline generation behaviour of Python's print statement
1,677,424
<p>I have a bunch of legacy code for encoding raw emails that contains a lot of print statements such as</p> <pre><code>print &gt;&gt;f, "Content-Type: text/plain" </code></pre> <p>This is all well and good for emails, but we're now leveraging the same code for outputting HTTP request. The problem is that the Python ...
7
2009-11-04T23:36:17Z
1,677,776
<p>You should solve your problem now and for forever by defining a new output function. Were print a function, this would have been much easier.</p> <p>I suggest writing a new output function, mimicing as much of the modern print function signature as possible (because reusing a good interface is good), for example:</...
10
2009-11-05T01:25:38Z
[ "python", "printing", "cpython" ]
Overriding the newline generation behaviour of Python's print statement
1,677,424
<p>I have a bunch of legacy code for encoding raw emails that contains a lot of print statements such as</p> <pre><code>print &gt;&gt;f, "Content-Type: text/plain" </code></pre> <p>This is all well and good for emails, but we're now leveraging the same code for outputting HTTP request. The problem is that the Python ...
7
2009-11-04T23:36:17Z
1,679,663
<p>Python has modules both to handle email and http headers in an easy compliant way. I suggest you use them instead of solving already solved problems again.</p>
0
2009-11-05T10:34:18Z
[ "python", "printing", "cpython" ]
How does a classmethod object work?
1,677,468
<p>I'm having trouble to understand how a classmethod object works in Python, especially in the context of metaclasses and in <code>__new__</code>. In my special case I would like to get the name of a classmethod member, when I iterate through the <code>members</code> that were given to <code>__new__</code>.</p> <p>Fo...
7
2009-11-04T23:46:36Z
1,677,544
<p><a href="http://gnosis.cx/publish/programming/metaclass%5F2.html" rel="nofollow">This</a> looks like it has the goods.</p>
1
2009-11-05T00:06:56Z
[ "python", "metaclass", "class-method" ]
How does a classmethod object work?
1,677,468
<p>I'm having trouble to understand how a classmethod object works in Python, especially in the context of metaclasses and in <code>__new__</code>. In my special case I would like to get the name of a classmethod member, when I iterate through the <code>members</code> that were given to <code>__new__</code>.</p> <p>Fo...
7
2009-11-04T23:46:36Z
1,677,671
<p>A <code>classmethod</code> object is a descriptor. You need to understand how descriptors work.</p> <p>In a nutshell, a descriptor is an object which has a method <code>__get__</code>, which takes three arguments: <code>self</code>, an <code>instance</code>, and an <code>instance type</code>.</p> <p>During normal ...
17
2009-11-05T00:49:11Z
[ "python", "metaclass", "class-method" ]
Multiple figure arrangement using Matplotlib
1,677,571
<p>Can we control where <a href="http://en.wikipedia.org/wiki/Matplotlib" rel="nofollow">Matplotlib</a> places figures on the screen?</p> <p>I want to generate four figures (in four separate windows) that do not overlap.</p>
8
2009-11-05T00:15:39Z
1,677,982
<p>Not using <a href="http://matplotlib.sourceforge.net/faq/howto_faq.html#use-show" rel="nofollow">show()</a> and Matplotlib alone. The simplest solution may be to use <a href="http://matplotlib.org/api/pyplot_api.html#matplotlib.pyplot.savefig" rel="nofollow">savefig(..)</a> and use your favorite OS image viewer. If ...
0
2009-11-05T02:35:52Z
[ "python", "matplotlib" ]
Multiple figure arrangement using Matplotlib
1,677,571
<p>Can we control where <a href="http://en.wikipedia.org/wiki/Matplotlib" rel="nofollow">Matplotlib</a> places figures on the screen?</p> <p>I want to generate four figures (in four separate windows) that do not overlap.</p>
8
2009-11-05T00:15:39Z
1,678,226
<p>The easiest way I know to do this is to make the window for the figure in your preferred GUI application, and then put the matplotlib figure into this window. There are a bunch of examples of how to do this embedding using different GUI frameworks <a href="http://matplotlib.sourceforge.net/examples/user_interfaces/...
0
2009-11-05T03:49:44Z
[ "python", "matplotlib" ]
Multiple figure arrangement using Matplotlib
1,677,571
<p>Can we control where <a href="http://en.wikipedia.org/wiki/Matplotlib" rel="nofollow">Matplotlib</a> places figures on the screen?</p> <p>I want to generate four figures (in four separate windows) that do not overlap.</p>
8
2009-11-05T00:15:39Z
1,685,423
<p>From <a href="http://en.wikipedia.org/wiki/IPython" rel="nofollow">IPython</a> you can do the following:</p> <pre><code>figure() get_current_fig_manager().window.wm_geometry("400x600+20+40") </code></pre> <p>Or equivalently in a Python script:</p> <pre><code>import pylab as pl pl.figure() pl.get_current_fig_manag...
8
2009-11-06T04:28:27Z
[ "python", "matplotlib" ]
Multiple figure arrangement using Matplotlib
1,677,571
<p>Can we control where <a href="http://en.wikipedia.org/wiki/Matplotlib" rel="nofollow">Matplotlib</a> places figures on the screen?</p> <p>I want to generate four figures (in four separate windows) that do not overlap.</p>
8
2009-11-05T00:15:39Z
7,982,805
<p>It is also possible to use the IPython interface with the Qt backend to achieve a similar result:</p> <pre><code>import matplotlib import pylab as pl f1 = pl.figure() f_manager = pl.get_current_fig_manager() f_manager.window.move(600, 600) pl.show() </code></pre> <p>With f_manager you basically have a PyQt4 object...
3
2011-11-02T15:20:40Z
[ "python", "matplotlib" ]
How to sign a document in python with M2Crypto using particular padding technique?
1,677,594
<p>I need to digitally sign some text in python using a private key stored in a .pem file. It seems like M2Crypto is the preferred way to do that these days, so that's what I'm using. I think I get most of it, but I'm confused about how to configure padding. To be specific, I need to verify the signature in an iPhone...
1
2009-11-05T00:23:54Z
1,677,697
<p>AFAIK M2Crypto adds padding where it's required. </p> <p>PKCS1 padding is the default.</p> <p>But, (again only AFAIK), signatures don't have padding, padding is only added to encrypted data to prevent a possible attack.<br> EDIT: user caf, in a comment says that a padding is essnetial to a good signature. I'm stil...
2
2009-11-05T00:58:34Z
[ "python", "cryptography", "digital-signature", "m2crypto" ]
Convert int64 to uint64
1,677,639
<p>I want to convert an int64 numpy array to a uint64 numpy array, adding 2**63 to the values in the process so that they are still within the valid range allowed by the arrays. So for example if I start from</p> <pre><code>a = np.array([-2**63,2**63-1], dtype=np.int64) </code></pre> <p>I want to end up with</p> <pr...
0
2009-11-05T00:35:29Z
1,677,657
<p>I'm not a real numpy expert, but this:</p> <pre><code>&gt;&gt;&gt; a = np.array([-2**63,2**63-1], dtype=np.int64) &gt;&gt;&gt; b = np.array([x+2**63 for x in a], dtype=np.uint64) &gt;&gt;&gt; b array([ 0, 18446744073709551615], dtype=uint64) </code></pre> <p>works for me with Python 2.6 and numpy...
1
2009-11-05T00:42:36Z
[ "python", "numpy" ]
Convert int64 to uint64
1,677,639
<p>I want to convert an int64 numpy array to a uint64 numpy array, adding 2**63 to the values in the process so that they are still within the valid range allowed by the arrays. So for example if I start from</p> <pre><code>a = np.array([-2**63,2**63-1], dtype=np.int64) </code></pre> <p>I want to end up with</p> <pr...
0
2009-11-05T00:35:29Z
1,678,018
<p>Use astype():</p> <pre><code>(a+2**63).astype(uint64) # array([ 0, 18446744073709551615], dtype=uint64) </code></pre>
2
2009-11-05T02:50:53Z
[ "python", "numpy" ]
Building python 2.6 w/ sqlite3 module if sqlite is installed in non-standard location
1,677,666
<p>I am trying to build python2.6 with support for the sqlite3 module.</p> <p>I have successfully built and installed the sqlite-amalgamation to a non standard path: ./configure --prefix=/my/non/standard/install/path/sqlite/3.6.20/ make make install</p> <p>I would like the python2.6 build to use this path &amp; build...
8
2009-11-05T00:46:43Z
1,677,758
<p>Rather than rebuilding <code>python</code>, the simplest way to get the most recent <code>sqlite3</code> is to install the <a href="http://pypi.python.org/pypi/pysqlite/">pysqlite</a> package which is the more up-to-date version of the standard library's <code>sqlite3</code> module. It includes support for more rec...
7
2009-11-05T01:20:32Z
[ "python", "sqlite3" ]
Proper way of having a unique identifier in Python?
1,677,726
<p>Basically, I have a list like: <code>[START, 'foo', 'bar', 'spam', eggs', END]</code> and the START/END identifiers are necessary for later so I can compare later on. Right now, I have it set up like this:</p> <pre><code>START = object() END = object() </code></pre> <p>This works fine, but it suffers from the prob...
6
2009-11-05T01:10:38Z
1,677,756
<p>I think maybe this would be easier to answer if you were more explicit about what you need this for, but my inclination if faced with a problem like this would be something like:</p> <pre><code>&gt;&gt;&gt; START = os.urandom(16).encode('hex') &gt;&gt;&gt; END = os.urandom(16).encode('hex') </code></pre> <p>Pros o...
0
2009-11-05T01:20:10Z
[ "python", "identifier" ]
Proper way of having a unique identifier in Python?
1,677,726
<p>Basically, I have a list like: <code>[START, 'foo', 'bar', 'spam', eggs', END]</code> and the START/END identifiers are necessary for later so I can compare later on. Right now, I have it set up like this:</p> <pre><code>START = object() END = object() </code></pre> <p>This works fine, but it suffers from the prob...
6
2009-11-05T01:10:38Z
1,677,760
<p>If your list didn't have strings, I'd just use "start", "end" as Python makes the comparison O(1) due to interning.</p> <p>If you do need strings, but not tuples, the complete cheapskate method is:</p> <pre><code>[("START",), 'foo', 'bar', 'spam', eggs', ("END",)] </code></pre> <p>PS: I was sure your list was num...
1
2009-11-05T01:21:14Z
[ "python", "identifier" ]
Proper way of having a unique identifier in Python?
1,677,726
<p>Basically, I have a list like: <code>[START, 'foo', 'bar', 'spam', eggs', END]</code> and the START/END identifiers are necessary for later so I can compare later on. Right now, I have it set up like this:</p> <pre><code>START = object() END = object() </code></pre> <p>This works fine, but it suffers from the prob...
6
2009-11-05T01:10:38Z
1,677,770
<p>If you want an object that's guaranteed to be unique <strong>and</strong> can also be guaranteed to get restored to exactly the same identify if pickled and unpickled right back, top-level functions, classes, class instances, and if you care about <code>is</code> rather than <code>==</code> also lists (and other mut...
9
2009-11-05T01:23:09Z
[ "python", "identifier" ]
Proper way of having a unique identifier in Python?
1,677,726
<p>Basically, I have a list like: <code>[START, 'foo', 'bar', 'spam', eggs', END]</code> and the START/END identifiers are necessary for later so I can compare later on. Right now, I have it set up like this:</p> <pre><code>START = object() END = object() </code></pre> <p>This works fine, but it suffers from the prob...
6
2009-11-05T01:10:38Z
1,677,777
<p>Actually, I like your solution.</p> <p>A while back I was hacking on a Python module, and I wanted to have a special magical value that could not appear anywhere else. I spent some time thinking about it and the best I came up with is the same trick you used: declare a class, and use the class object as the specia...
1
2009-11-05T01:25:40Z
[ "python", "identifier" ]
Proper way of having a unique identifier in Python?
1,677,726
<p>Basically, I have a list like: <code>[START, 'foo', 'bar', 'spam', eggs', END]</code> and the START/END identifiers are necessary for later so I can compare later on. Right now, I have it set up like this:</p> <pre><code>START = object() END = object() </code></pre> <p>This works fine, but it suffers from the prob...
6
2009-11-05T01:10:38Z
1,678,952
<p>You can define a <code>Symbol</code> class for handling START and END.</p> <pre><code>class Symbol: def __init__(self, value): self.value = value def __eq__(self, other): return isinstance(other, Symbol) and other.value == self.value def __repr__(self): return "&lt;sym: %r&gt;"...
2
2009-11-05T07:39:41Z
[ "python", "identifier" ]
Python decorators on class members fail when decorator mechanism is a class
1,677,747
<p>When creating decorators for use on class methods, I'm having trouble when the decorator mechanism is a class rather than a function/closure. When the class form is used, my decorator doesn't get treated as a bound method. </p> <p>Generally I prefer to use the function form for decorators but in this case I have to...
7
2009-11-05T01:18:23Z
1,677,774
<p>Your <code>WrapperClass</code> needs to be a descriptor (just like a function is!), i.e., supply appropriate special methods <code>__get__</code> and <code>__set__</code>. <a href="http://users.rcn.com/python/download/Descriptor.htm">This how-to guide</a> teaches all you need to know about that!-)</p>
10
2009-11-05T01:25:28Z
[ "python", "decorator" ]
CherryPy3 and IIS 6.0
1,677,828
<p>I have a small Python web application using the Cherrypy framework. I am by no means an expert in web servers. </p> <p>I got Cherrypy working with Apache using mod_python on our Ubuntu server. This time, however, I have to use Windows 2003 and IIS 6.0 to host my site.</p> <p>The site runs perfectly as a stand alon...
4
2009-11-05T01:38:55Z
1,680,636
<p>I run CherryPy behind my IIS sites. There are several tricks to get it to work.</p> <ol> <li>When running as the IIS Worker Process identity, you won't have the same permissions as you do when you run the site from your user process. Things will break. In particular, anything that wants to write to the file system ...
10
2009-11-05T13:35:51Z
[ "python", "iis-6", "cherrypy", "isapi-wsgi" ]
CherryPy3 and IIS 6.0
1,677,828
<p>I have a small Python web application using the Cherrypy framework. I am by no means an expert in web servers. </p> <p>I got Cherrypy working with Apache using mod_python on our Ubuntu server. This time, however, I have to use Windows 2003 and IIS 6.0 to host my site.</p> <p>The site runs perfectly as a stand alon...
4
2009-11-05T01:38:55Z
1,726,138
<p>OK, I got it working. Thanks to Jason and all his help. I needed to call</p> <pre><code>cherrypy.config.update({ 'tools.sessions.on': True }) return cherrypy.tree.mount(Root(), '/', config=path_to_config) </code></pre> <p>I had this in the config file under [/] but for some reason it did not like that. Now I can...
2
2009-11-12T23:28:07Z
[ "python", "iis-6", "cherrypy", "isapi-wsgi" ]
Selenium RC: how to capture/handle error?
1,678,195
<p>My test uses Selenium to loop through a CSV list of URLs via an HTTP proxy (working script below). As I watch the script run I can see about 10% of the calls produce "Proxy error: 502" ("Bad_Gateway"); however, the errors are not captured by my catch-all "except Exception" clause -- ie: instead of writing 'error' in...
0
2009-11-05T03:40:39Z
1,679,517
<p>I think that the alternative you propose is ok. rather than the get_html_source, You can use the captureNetworkTraffic function to get the HTTP header. That would be safer because the 502 page can change.</p> <p>Be careful, there is a bug in the captureNetworkTraffic of the selenium python wrapper that can be hacke...
1
2009-11-05T09:57:58Z
[ "python", "error-handling", "csv", "selenium", "loops" ]
Convert Python for -loop to PHP
1,678,342
<p><strong>How can you convert the following code to PHP?</strong></p> <pre><code>summat = [sum(arra[i:i+4]) for i in range(0,len(arra),4)] </code></pre> <p>My attempt</p> <pre><code>$summat = array() foreach ( range(0, $arra.length, 4) as $i) { $summat = array ( array_sum( array_slice( $array, $i, $i+5) ) )...
1
2009-11-05T04:25:18Z
1,678,356
<p>To append a value to an array, use:</p> <pre><code>$summat[] = array_sum(...); </code></pre> <p>The PHP way of doing ranges is similar to the C way:</p> <pre><code>for($i = 0; $i &lt; count($arra); $i += 4) { // ... } </code></pre>
1
2009-11-05T04:29:54Z
[ "php", "python" ]
Convert Python for -loop to PHP
1,678,342
<p><strong>How can you convert the following code to PHP?</strong></p> <pre><code>summat = [sum(arra[i:i+4]) for i in range(0,len(arra),4)] </code></pre> <p>My attempt</p> <pre><code>$summat = array() foreach ( range(0, $arra.length, 4) as $i) { $summat = array ( array_sum( array_slice( $array, $i, $i+5) ) )...
1
2009-11-05T04:25:18Z
1,678,404
<pre><code>$sum = array(); foreach(range(0, count($a), 4) as $i) $sum []= array_sum(array_slice($a, $i, 4)); </code></pre> <p>"[]=" is an append-to-array operator</p> <p>slice's second parameter is slice length, not the last index</p> <p>or even simpler</p> <pre><code>$sum = array_map('array_sum', array_chunk($a...
4
2009-11-05T04:45:24Z
[ "php", "python" ]
accessing memcached stats via cmemcache or django returns warning
1,678,848
<p>My Django application uses memcached via cmemcache. An issue sprung up when I was trying to monitor its usage:</p> <p>I tried to access stats memcached provides through both Django and cmemcache:</p> <p>django:</p> <pre><code>from django.core.cache import cache cache._cache.get_stats() [WARN@1257320533.841286] mc...
0
2009-11-05T07:13:02Z
1,678,977
<p>First, you should not run those versions of memcached. They have lots and lots of known bugs and are many years old.</p> <p>Secondly, we add stats to memcached quite frequently, so if these libraries are complaining when they encounter new stats, you should complain to their authors.</p> <p>Also, I don't believe ...
1
2009-11-05T07:49:30Z
[ "python", "django", "memcached" ]
Komodo Python auto complete: type inference by variable metadata?
1,678,953
<p>I'm using Komodo Edit for <a href="http://en.wikipedia.org/wiki/Python%5F%28programming%5Flanguage%29">Python</a> development, and I want to get the best out of the auto complete.</p> <p>If I do this:</p> <pre><code>a = A() a. </code></pre> <p>I can see a list of members of A. </p> <p>But if I do this:</p> <pre...
7
2009-11-05T07:40:06Z
1,681,103
<p>I don't think that you'll have much luck with this. The problem is that it's really quite difficult to statically infer the type of variables in Python except in the simplest of cases. Often the type isn't known until run-time and so auto completion isn't possible.</p> <p>The IDE does some static analysis to work o...
3
2009-11-05T15:01:49Z
[ "python", "autocomplete", "komodo" ]
Komodo Python auto complete: type inference by variable metadata?
1,678,953
<p>I'm using Komodo Edit for <a href="http://en.wikipedia.org/wiki/Python%5F%28programming%5Flanguage%29">Python</a> development, and I want to get the best out of the auto complete.</p> <p>If I do this:</p> <pre><code>a = A() a. </code></pre> <p>I can see a list of members of A. </p> <p>But if I do this:</p> <pre...
7
2009-11-05T07:40:06Z
1,681,587
<p>This doesn't really answer your question, but with <a href="http://en.wikipedia.org/wiki/Wing%5FIDE">Wing IDE</a> you can give hints to the type analyzer with <code>assert isinstance(b, A)</code>. See <a href="http://www.wingware.com/doc/edit/helping-wing-analyze-code">here</a>. I haven't found a way to do it with K...
8
2009-11-05T16:07:11Z
[ "python", "autocomplete", "komodo" ]
How to plot an image with non-linear y-axis with Matplotlib using imshow?
1,679,126
<p>How can I plot an 2D array as an image with <a href="http://en.wikipedia.org/wiki/Matplotlib">Matplotlib</a> having the y scale relative to the power of two of the y value?</p> <p>For instance the first row of my array will have a height in the image of 1, the second row will have a height of 4, etc. (units are irr...
8
2009-11-05T08:32:02Z
1,679,285
<p>You can look at <a href="http://matplotlib.sourceforge.net/examples/pylab%5Fexamples/image%5Fnonuniform.html" rel="nofollow">matplotlib.image.NonUniformImage</a>. But that only assists with having nonuniform axis - I don't think you're going to be able to plot adaptively like you want to (I think each point in the i...
3
2009-11-05T09:12:50Z
[ "python", "matplotlib" ]
How to plot an image with non-linear y-axis with Matplotlib using imshow?
1,679,126
<p>How can I plot an 2D array as an image with <a href="http://en.wikipedia.org/wiki/Matplotlib">Matplotlib</a> having the y scale relative to the power of two of the y value?</p> <p>For instance the first row of my array will have a height in the image of 1, the second row will have a height of 4, etc. (units are irr...
8
2009-11-05T08:32:02Z
1,679,455
<p>Have you tried to transform the axis? For example:</p> <pre><code>ax = subplot(111) ax.yaxis.set_ticks([0, 2, 4, 8]) imshow(data) </code></pre> <p>This means there must be gaps in the data for the non-existent coordinates, unless there is a way to provide a transform function instead of just lists (never tried).</...
8
2009-11-05T09:48:03Z
[ "python", "matplotlib" ]
How to plot an image with non-linear y-axis with Matplotlib using imshow?
1,679,126
<p>How can I plot an 2D array as an image with <a href="http://en.wikipedia.org/wiki/Matplotlib">Matplotlib</a> having the y scale relative to the power of two of the y value?</p> <p>For instance the first row of my array will have a height in the image of 1, the second row will have a height of 4, etc. (units are irr...
8
2009-11-05T08:32:02Z
1,679,765
<p>If you want both to be able to zoom <em>and</em> save memory, you could do the drawing "by hand". Matplotlib allows you to draw rectangles (they would be your "rectangular pixels"):</p> <pre><code>from matplotlib import patches axes = subplot(111) axes.add_patch(patches.Rectangle((0.2, 0.2), 0.5, 0.5)) </code></pr...
2
2009-11-05T10:53:44Z
[ "python", "matplotlib" ]
How to plot an image with non-linear y-axis with Matplotlib using imshow?
1,679,126
<p>How can I plot an 2D array as an image with <a href="http://en.wikipedia.org/wiki/Matplotlib">Matplotlib</a> having the y scale relative to the power of two of the y value?</p> <p>For instance the first row of my array will have a height in the image of 1, the second row will have a height of 4, etc. (units are irr...
8
2009-11-05T08:32:02Z
6,788,842
<p>The best way I've found to make a scalogram using matplotlib is to use <code>imshow</code>, similar to the implementation of <code>specgram</code>. Using rectangles is slow, because you're having to make a separate glyph for each value. Similarly, you don't want to have to bake things into a uniform NumPy array, bec...
3
2011-07-22T10:42:02Z
[ "python", "matplotlib" ]
How do I make Python pick the correct module without manually modifying sys.path?
1,679,673
<p>I have made some changes in a python module in my checked out copy of a repository, and need to test them. However, when I try to run a script that uses the module, it keeps importing the module from the trunk of the repository, which is of no use to me. </p> <p>I tried setting PYTHONPATH, which did nothing at all....
1
2009-11-05T10:35:10Z
1,679,739
<p>You could write a small script, such as the one below, that prefixes sys.path, then set PYTHONSTARTUP to use that script.</p> <pre><code>import sys sys.path.insert(0, 'c:/temp') </code></pre> <p>For example...</p> <pre><code>C:\temp&gt;set PYTHONSTARTUP=c:\temp\tst.py C:\temp&gt;C:\Python26\python Python 2.6.2 (r...
2
2009-11-05T10:47:37Z
[ "python", "import", "path", "module" ]
How do I make Python pick the correct module without manually modifying sys.path?
1,679,673
<p>I have made some changes in a python module in my checked out copy of a repository, and need to test them. However, when I try to run a script that uses the module, it keeps importing the module from the trunk of the repository, which is of no use to me. </p> <p>I tried setting PYTHONPATH, which did nothing at all....
1
2009-11-05T10:35:10Z
1,679,796
<p>It sounds like you need to install <a href="http://pypi.python.org/pypi/virtualenv" rel="nofollow">virtualenv</a> and use it to set up different environments for different purposes. In one environment, you would import modules from the trunk of the repository, but in another environment you would have a mixture of t...
2
2009-11-05T10:59:13Z
[ "python", "import", "path", "module" ]
How do I make Python pick the correct module without manually modifying sys.path?
1,679,673
<p>I have made some changes in a python module in my checked out copy of a repository, and need to test them. However, when I try to run a script that uses the module, it keeps importing the module from the trunk of the repository, which is of no use to me. </p> <p>I tried setting PYTHONPATH, which did nothing at all....
1
2009-11-05T10:35:10Z
1,679,804
<p>You can create a setup script with <a href="http://pypi.python.org/pypi/setuptools" rel="nofollow">setuptools</a> or <a href="http://pypi.python.org/pypi/distribute" rel="nofollow">distribute</a>, then do a <code>python setup.py develop</code>. It will add a link to your working copy in a .pth file, overriding any i...
0
2009-11-05T11:00:12Z
[ "python", "import", "path", "module" ]
How do I make Python pick the correct module without manually modifying sys.path?
1,679,673
<p>I have made some changes in a python module in my checked out copy of a repository, and need to test them. However, when I try to run a script that uses the module, it keeps importing the module from the trunk of the repository, which is of no use to me. </p> <p>I tried setting PYTHONPATH, which did nothing at all....
1
2009-11-05T10:35:10Z
1,679,860
<p>Your current working directory is first in the <code>sys.path</code>. Anything there trumps anything else on the path.</p> <p>Copy the "test version" to some place closer to the front of the list of directories in <code>sys.path</code>, like your current working directory.</p>
1
2009-11-05T11:12:43Z
[ "python", "import", "path", "module" ]
How to open a file with the standard application?
1,679,798
<p>My application prints a PDF to a temporary file. How can I open that file with the default application in Python?</p> <p>I need a solution for</p> <ul> <li>Windows</li> <li>Linux (Ubuntu with Xfce if there's nothing more general.)</li> </ul> <h3>Related</h3> <ul> <li><a href="http://stackoverflow.com/questions/4...
16
2009-11-05T10:59:30Z
1,679,834
<pre><code>if linux: os.system('xdg-open "$file"') #works for urls too else: os.system('start "$file"') #a total guess </code></pre>
3
2009-11-05T11:06:03Z
[ "python", "windows", "linux" ]
How to open a file with the standard application?
1,679,798
<p>My application prints a PDF to a temporary file. How can I open that file with the default application in Python?</p> <p>I need a solution for</p> <ul> <li>Windows</li> <li>Linux (Ubuntu with Xfce if there's nothing more general.)</li> </ul> <h3>Related</h3> <ul> <li><a href="http://stackoverflow.com/questions/4...
16
2009-11-05T10:59:30Z
1,679,887
<p>on windows it works with <code>os.system('start &lt;myFile&gt;')</code>. On Mac (I know you didn't ask...) it's <code>os.system('open &lt;myFile&gt;')</code> </p>
9
2009-11-05T11:18:27Z
[ "python", "windows", "linux" ]
How to open a file with the standard application?
1,679,798
<p>My application prints a PDF to a temporary file. How can I open that file with the default application in Python?</p> <p>I need a solution for</p> <ul> <li>Windows</li> <li>Linux (Ubuntu with Xfce if there's nothing more general.)</li> </ul> <h3>Related</h3> <ul> <li><a href="http://stackoverflow.com/questions/4...
16
2009-11-05T10:59:30Z
1,679,895
<p><a href="http://docs.python.org/library/os.html#os.startfile">os.startfile</a> is only available for windows for now, but <a href="http://portland.freedesktop.org/xdg-utils-1.0/xdg-open.html">xdg-open</a> will be available on any unix client running X.</p> <pre><code>if sys.platform == 'linux2': subprocess.call...
22
2009-11-05T11:19:33Z
[ "python", "windows", "linux" ]
How to open a file with the standard application?
1,679,798
<p>My application prints a PDF to a temporary file. How can I open that file with the default application in Python?</p> <p>I need a solution for</p> <ul> <li>Windows</li> <li>Linux (Ubuntu with Xfce if there's nothing more general.)</li> </ul> <h3>Related</h3> <ul> <li><a href="http://stackoverflow.com/questions/4...
16
2009-11-05T10:59:30Z
1,681,024
<p>Ask your favorite Application Framework for how to do this in Linux.</p> <p>This will work on Windos and Linux as long as you use GTK:</p> <pre><code>import gtk gtk.show_uri(gtk.gdk.screen_get_default(), URI, 0) </code></pre> <p>where <code>URI</code> is the local URL to the file</p>
0
2009-11-05T14:48:09Z
[ "python", "windows", "linux" ]
How to open a file with the standard application?
1,679,798
<p>My application prints a PDF to a temporary file. How can I open that file with the default application in Python?</p> <p>I need a solution for</p> <ul> <li>Windows</li> <li>Linux (Ubuntu with Xfce if there's nothing more general.)</li> </ul> <h3>Related</h3> <ul> <li><a href="http://stackoverflow.com/questions/4...
16
2009-11-05T10:59:30Z
1,684,160
<p>Open file using an application that your browser thinks is an appropriate one:</p> <pre><code>import webbrowser webbrowser.open_new_tab(filename) </code></pre>
1
2009-11-05T22:39:38Z
[ "python", "windows", "linux" ]
How to open a file with the standard application?
1,679,798
<p>My application prints a PDF to a temporary file. How can I open that file with the default application in Python?</p> <p>I need a solution for</p> <ul> <li>Windows</li> <li>Linux (Ubuntu with Xfce if there's nothing more general.)</li> </ul> <h3>Related</h3> <ul> <li><a href="http://stackoverflow.com/questions/4...
16
2009-11-05T10:59:30Z
3,481,877
<p>A small correction is necessary for NicDumZ's solution to work exactly as given. The problem is with the use of 'is' operator. A working solution is:</p> <pre><code>if sys.platform == 'linux2': subprocess.call(["xdg-open", file]) else: os.startfile(file) </code></pre> <p>A good discussion of this topic is...
2
2010-08-14T03:19:03Z
[ "python", "windows", "linux" ]
How insecure is / replacement for tmpnam?
1,679,844
<p>I considered using <code>tmpnam</code> to set the output file name of a <code>QPrinter</code>. But the Python documentation recommends against using it.</p> <blockquote> <h2>os.tmpnam()</h2> <p>Return a unique path name that is reasonable for creating a temporary file. ... Applications are responsible fo...
1
2009-11-05T11:07:26Z
1,679,854
<p>Please read <a href="http://docs.python.org/library/tempfile.html">http://docs.python.org/library/tempfile.html</a></p> <p>Use that instead.</p>
7
2009-11-05T11:10:37Z
[ "python", "security", "qt", "pyqt" ]
How insecure is / replacement for tmpnam?
1,679,844
<p>I considered using <code>tmpnam</code> to set the output file name of a <code>QPrinter</code>. But the Python documentation recommends against using it.</p> <blockquote> <h2>os.tmpnam()</h2> <p>Return a unique path name that is reasonable for creating a temporary file. ... Applications are responsible fo...
1
2009-11-05T11:07:26Z
1,682,414
<p>Depending on how your QPrinter deals with a file that already exists, you could use QTemporaryFile to create a file, then close the file and keep the reference to the QTemporaryFile object around until you are done with it. (This will also clean up the file for you when you destroy the object.)</p>
0
2009-11-05T17:59:30Z
[ "python", "security", "qt", "pyqt" ]
Arched Relationship Infographic In Python
1,679,917
<p>This is a very specific inforgraphic challange altough the fundemental question is how do you build archs between words using matplotlib, cario or an other python libary.</p> <p>Given a the following data structure.</p> <p>me, you, 7 | me, apple, 9 | apple, you, 1 | bike, me, 5 </p> <p>Names would be displayed ho...
4
2009-11-05T11:24:12Z
1,680,725
<p>I don't really see where the difficulty or challenge is. All you need is a graphics library that can draw text and half circles, which is possible in pretty much everything. There is no need for Bezier curves. For example you could simply create an SVG file (then you don't even need any library and can nicely embed ...
0
2009-11-05T13:53:49Z
[ "python", "matplotlib", "graphviz", "graphic" ]
Arched Relationship Infographic In Python
1,679,917
<p>This is a very specific inforgraphic challange altough the fundemental question is how do you build archs between words using matplotlib, cario or an other python libary.</p> <p>Given a the following data structure.</p> <p>me, you, 7 | me, apple, 9 | apple, you, 1 | bike, me, 5 </p> <p>Names would be displayed ho...
4
2009-11-05T11:24:12Z
1,681,936
<p><code>matplotlib</code> isn't the right library here, since it's not a general purpose graphics library. What you need here is either something like <a href="http://www.cairographics.org/pycairo/" rel="nofollow">Cairo</a>, or much simpler, you can do with the graphics capabilities of any GUI toolkit, such as PyQt. ...
4
2009-11-05T16:46:24Z
[ "python", "matplotlib", "graphviz", "graphic" ]
Arched Relationship Infographic In Python
1,679,917
<p>This is a very specific inforgraphic challange altough the fundemental question is how do you build archs between words using matplotlib, cario or an other python libary.</p> <p>Given a the following data structure.</p> <p>me, you, 7 | me, apple, 9 | apple, you, 1 | bike, me, 5 </p> <p>Names would be displayed ho...
4
2009-11-05T11:24:12Z
1,778,834
<p>There are several libraries, at least one of which relies on Matplotlib, that will do what you want. I recommend Networkx (www.networkx.lanl.gov) to build your graph structure, and which you can then use to call the relevant Matplotlib methods to plot. Networkx and Matplotlib work very well together. </p> <pre><co...
1
2009-11-22T14:26:48Z
[ "python", "matplotlib", "graphviz", "graphic" ]
Reverse a word in Vim
1,680,194
<p>How can I reverse a word in Vim? Preferably with a regex or normal-mode commands, but other methods are welcome too:</p> <blockquote> <p>word => drow</p> </blockquote> <p>Thanks for your help! PS: I'm in windows XP</p> <p>Python is built in supported in my vim, but not Perl.</p>
11
2009-11-05T12:17:09Z
1,680,364
<p><em>if</em> your version of VIM supports it you can do <code>vw\is</code> or <code>viw\is</code> (put your cursor at the first letter of the word before typing the command)... but I have had a lot of compatibility issues with that. Not sure what has to be compiled in or turned on but this only works sometimes.</p> ...
2
2009-11-05T12:49:29Z
[ "python", "regex", "vim" ]
Reverse a word in Vim
1,680,194
<p>How can I reverse a word in Vim? Preferably with a regex or normal-mode commands, but other methods are welcome too:</p> <blockquote> <p>word => drow</p> </blockquote> <p>Thanks for your help! PS: I'm in windows XP</p> <p>Python is built in supported in my vim, but not Perl.</p>
11
2009-11-05T12:17:09Z
1,680,368
<p>Assuming you've got perl support built in to vim, you can do this:</p> <pre><code>command! ReverseWord call ReverseWord() function! ReverseWord() perl &lt;&lt; EOF $curword = VIM::Eval('expand("&lt;cword&gt;")'); $reversed = reverse($curword); VIM::Msg("$curword =&gt; $reversed"); VIM::DoCommand("no...
3
2009-11-05T12:50:10Z
[ "python", "regex", "vim" ]
Reverse a word in Vim
1,680,194
<p>How can I reverse a word in Vim? Preferably with a regex or normal-mode commands, but other methods are welcome too:</p> <blockquote> <p>word => drow</p> </blockquote> <p>Thanks for your help! PS: I'm in windows XP</p> <p>Python is built in supported in my vim, but not Perl.</p>
11
2009-11-05T12:17:09Z
1,680,392
<p>If you have some time on your hands, you can bubble your way there by iteratively transposing characters (<code>xp</code>)...</p>
1
2009-11-05T12:55:29Z
[ "python", "regex", "vim" ]
Reverse a word in Vim
1,680,194
<p>How can I reverse a word in Vim? Preferably with a regex or normal-mode commands, but other methods are welcome too:</p> <blockquote> <p>word => drow</p> </blockquote> <p>Thanks for your help! PS: I'm in windows XP</p> <p>Python is built in supported in my vim, but not Perl.</p>
11
2009-11-05T12:17:09Z
1,680,730
<p>This Tip might help: <a href="http://vim.wikia.com/wiki/Reverse%5Fletters" rel="nofollow">http://vim.wikia.com/wiki/Reverse%5Fletters</a></p>
4
2009-11-05T13:54:25Z
[ "python", "regex", "vim" ]
Reverse a word in Vim
1,680,194
<p>How can I reverse a word in Vim? Preferably with a regex or normal-mode commands, but other methods are welcome too:</p> <blockquote> <p>word => drow</p> </blockquote> <p>Thanks for your help! PS: I'm in windows XP</p> <p>Python is built in supported in my vim, but not Perl.</p>
11
2009-11-05T12:17:09Z
1,681,823
<p>I don't have Python supported on my VIM, but it looks like it would be pretty simple to do it with Python. <a href="http://www.builderau.com.au/program/python/soa/Extending-Vim-with-Python/0,2000064084,339283181,00.htm" rel="nofollow">This article</a> seems like a good explanation of how to use Python in VIM and I'm...
3
2009-11-05T16:35:46Z
[ "python", "regex", "vim" ]
Reverse a word in Vim
1,680,194
<p>How can I reverse a word in Vim? Preferably with a regex or normal-mode commands, but other methods are welcome too:</p> <blockquote> <p>word => drow</p> </blockquote> <p>Thanks for your help! PS: I'm in windows XP</p> <p>Python is built in supported in my vim, but not Perl.</p>
11
2009-11-05T12:17:09Z
1,731,622
<p>Here is another (pythonic) solution based on how this works:</p> <pre><code>:echo join(reverse(split('hello', '.\zs')), '') olleh </code></pre> <p>If you want to replace all words in the buffer,</p> <pre><code>:%s/\(\&lt;.\{-}\&gt;\)/\=join(reverse(split(submatch(1), '.\zs')), '')/g </code></pre> <p>This works b...
5
2009-11-13T20:16:23Z
[ "python", "regex", "vim" ]
Reverse a word in Vim
1,680,194
<p>How can I reverse a word in Vim? Preferably with a regex or normal-mode commands, but other methods are welcome too:</p> <blockquote> <p>word => drow</p> </blockquote> <p>Thanks for your help! PS: I'm in windows XP</p> <p>Python is built in supported in my vim, but not Perl.</p>
11
2009-11-05T12:17:09Z
7,171,015
<p>Well you could use python itself to reverse the line through the filter command. Say the text you had written was: </p> <pre><code>Python </code></pre> <p>You could reverse it by issuing.</p> <pre><code>:1 ! python -c "print raw_input()[::-1]" </code></pre> <p>And your text will be replaced to become:</p> <pre>...
1
2011-08-24T05:52:23Z
[ "python", "regex", "vim" ]
How to calculate the scrape URL for a torrent
1,680,209
<p>I've read the Bit-torrent specification and done a number of searches, trying to find out how I can get the seeds/peers/downloaded data from a torrent tracker (using Python). I can calculate the info hash from a Torrent no problem, which matches up with the info hash given by various working torrent applications.</p...
7
2009-11-05T12:21:11Z
1,680,526
<p>You're passing in a hex-character representation of the info_hash. It should be a binary representation. To get unprintable bytes into the URL use URL-encoding:</p> <pre><code>/scrape?info_hash=%A8%C4%82%90%2B%1Cs%5D%E4bG%97%21%B0%11%DC%7B%3D5X </code></pre> <p>(I'd also try to avoid encoding the <code>_</code> in...
5
2009-11-05T13:19:41Z
[ "python", "bittorrent" ]
How to calculate the scrape URL for a torrent
1,680,209
<p>I've read the Bit-torrent specification and done a number of searches, trying to find out how I can get the seeds/peers/downloaded data from a torrent tracker (using Python). I can calculate the info hash from a Torrent no problem, which matches up with the info hash given by various working torrent applications.</p...
7
2009-11-05T12:21:11Z
23,430,892
<p>My solution:</p> <pre><code>import binascii binary_info_hash = binascii.unhexlify('79b193385de5b967175ca86073670fce0e45a324') print binary_info_hash </code></pre> <p>Result:</p> <pre><code>y%B1%938%5D%E5%B9g%17%5C%A8%60sg%0F%CE%0EE%A3%24 </code></pre> <p>More info: <a href="http://docs.python.org/library/binasc...
2
2014-05-02T14:45:01Z
[ "python", "bittorrent" ]
copy files from IIs6.0 server to client machine without showing file dialog window on click of button in ASP.NET 3.5
1,680,233
<p>File.VBS file should be copied from IIS6.0(File.VBS file will be deployed in IIS along the ASP.NET3.5 application) server to Client “TEMP” folder with out opening the file download dialog box.</p> <p>Thanks!</p>
0
2009-11-05T12:24:20Z
1,680,536
<p>As indicated in the comment by Cheeso,</p> <h2> this is not possible!</h2> <p>This would constitute <strong>a very dangerous security hole</strong>!</p> <p>Although brief on this topic, the <a href="http://www.w3.org/Protocols/rfc2616/rfc2616-sec19.html#sec19.5.1" rel="nofollow"><strong>RFC 2616</strong></a> is n...
1
2009-11-05T13:20:48Z
[ "c#", "python", "ruby" ]
GTK+ Startup Notification Icon
1,680,311
<p>In Gnome, whenever an application is started, the mouse cursor changes from normal to an activity indicator (a spinning wheel type thing on Ubuntu). Is there any way to inform Gnome (through some system call) when the application has finished launching so that the mouse cursor returns to normal without waiting for t...
7
2009-11-05T12:39:50Z
1,680,360
<p>This normally happens automatically when calling the <code>gtk.main()</code> function</p>
0
2009-11-05T12:48:37Z
[ "python", "linux", "ubuntu", "gnome" ]
GTK+ Startup Notification Icon
1,680,311
<p>In Gnome, whenever an application is started, the mouse cursor changes from normal to an activity indicator (a spinning wheel type thing on Ubuntu). Is there any way to inform Gnome (through some system call) when the application has finished launching so that the mouse cursor returns to normal without waiting for t...
7
2009-11-05T12:39:50Z
1,680,917
<p>Normally it happens automatically when you open the application's window.</p> <p>It may be that the application's launcher just calls an already running instance, in that case it won't be automatically detected. The call you need then is this:</p> <pre><code>import gtk gtk.gdk.notify_startup_complete() </code></pr...
5
2009-11-05T14:29:40Z
[ "python", "linux", "ubuntu", "gnome" ]
GTK+ Startup Notification Icon
1,680,311
<p>In Gnome, whenever an application is started, the mouse cursor changes from normal to an activity indicator (a spinning wheel type thing on Ubuntu). Is there any way to inform Gnome (through some system call) when the application has finished launching so that the mouse cursor returns to normal without waiting for t...
7
2009-11-05T12:39:50Z
1,681,886
<p>Your application can opt out of startup notification by adding</p> <pre><code>StartupNotify=false </code></pre> <p>to your application's <code>.desktop</code> file.</p> <p>Of course, it is friendlier to leave it enabled and participate in startup notification.</p>
2
2009-11-05T16:41:41Z
[ "python", "linux", "ubuntu", "gnome" ]
GTK+ Startup Notification Icon
1,680,311
<p>In Gnome, whenever an application is started, the mouse cursor changes from normal to an activity indicator (a spinning wheel type thing on Ubuntu). Is there any way to inform Gnome (through some system call) when the application has finished launching so that the mouse cursor returns to normal without waiting for t...
7
2009-11-05T12:39:50Z
10,165,667
<p>I had a similar issue with an application I wrote. I was launching the application through a shell script containing the line</p> <pre><code>python /path/to/application.py </code></pre> <p>This launched the application as I expected, but the startup notification did not stop. It worked correctly once I changed the...
1
2012-04-15T20:14:45Z
[ "python", "linux", "ubuntu", "gnome" ]
Python: How much space does each element of a list take?
1,680,436
<p>I need a very large list, and am trying to figure out how big I can make it so that it still fits in 1-2GB of RAM. I am using the CPython implementation, on 64 bit (x86_64).</p> <p><em>Edit: thanks to bua's answer, I have filled in some of the more concrete answers.</em></p> <p>What is the space (memory) usage of ...
8
2009-11-05T13:04:35Z
1,680,540
<p>point to start: </p> <pre><code>&gt;&gt;&gt; import sys &gt;&gt;&gt; a=list() &gt;&gt;&gt; type(a) &lt;type 'list'&gt; &gt;&gt;&gt; sys.getsizeof(a) 36 &gt;&gt;&gt; b=1 &gt;&gt;&gt; type(b) &lt;type 'int'&gt; &gt;&gt;&gt; sys.getsizeof(b) 12 </code></pre> <p>and from python help:</p> <pre><code>&gt;&gt;&gt; help(...
9
2009-11-05T13:21:18Z
[ "python", "memory", "list", "performance" ]
Python: How much space does each element of a list take?
1,680,436
<p>I need a very large list, and am trying to figure out how big I can make it so that it still fits in 1-2GB of RAM. I am using the CPython implementation, on 64 bit (x86_64).</p> <p><em>Edit: thanks to bua's answer, I have filled in some of the more concrete answers.</em></p> <p>What is the space (memory) usage of ...
8
2009-11-05T13:04:35Z
1,680,691
<p>If you want lists of numerical values, the standard <a href="http://docs.python.org/library/array.html">array</a> module provides optimized arrays (that have an append method).</p> <p>The non-standard, but commonly used <a href="http://www.scipy.org/Tentative%5FNumPy%5FTutorial">NumPy</a> module gives you fixed-siz...
6
2009-11-05T13:46:35Z
[ "python", "memory", "list", "performance" ]
How do I avoid having class data shared among instances?
1,680,528
<p>What I want is this behavior:</p> <pre><code>class a: list=[] y=a() x=a() x.list.append(1) y.list.append(2) x.list.append(3) y.list.append(4) print x.list [1,3] print y.list [2,4] </code></pre> <p>of course, what really happens when I print is:</p> <pre><code>print x.list [1,2,3,4] print y.lis...
61
2009-11-05T13:19:55Z
1,680,545
<p>You declared "list" as a "class level property" and not "instance level property". In order to have properties scoped at the instance level, you need to initialize them through referencing with the "self" parameter in the <code>__init__</code> method (or elsewhere depending on the situation).</p> <p>You don't stri...
10
2009-11-05T13:22:00Z
[ "python", "class" ]
How do I avoid having class data shared among instances?
1,680,528
<p>What I want is this behavior:</p> <pre><code>class a: list=[] y=a() x=a() x.list.append(1) y.list.append(2) x.list.append(3) y.list.append(4) print x.list [1,3] print y.list [2,4] </code></pre> <p>of course, what really happens when I print is:</p> <pre><code>print x.list [1,2,3,4] print y.lis...
61
2009-11-05T13:19:55Z
1,680,555
<p>You want this:</p> <pre><code>class a: def __init__(self): self.list = [] </code></pre> <p>Declaring the variables inside the class declaration makes them "class" members and not instance members. Declaring them inside the <code>__init__</code> method makes sure that a new instance of the members is cr...
70
2009-11-05T13:23:13Z
[ "python", "class" ]
How do I avoid having class data shared among instances?
1,680,528
<p>What I want is this behavior:</p> <pre><code>class a: list=[] y=a() x=a() x.list.append(1) y.list.append(2) x.list.append(3) y.list.append(4) print x.list [1,3] print y.list [2,4] </code></pre> <p>of course, what really happens when I print is:</p> <pre><code>print x.list [1,2,3,4] print y.lis...
61
2009-11-05T13:19:55Z
1,680,581
<p>Yes you must declare in the "constructor" if you want that the list becomes an object property and not a class property.</p>
3
2009-11-05T13:27:04Z
[ "python", "class" ]
How do I avoid having class data shared among instances?
1,680,528
<p>What I want is this behavior:</p> <pre><code>class a: list=[] y=a() x=a() x.list.append(1) y.list.append(2) x.list.append(3) y.list.append(4) print x.list [1,3] print y.list [2,4] </code></pre> <p>of course, what really happens when I print is:</p> <pre><code>print x.list [1,2,3,4] print y.lis...
61
2009-11-05T13:19:55Z
12,320,191
<p>I think the answers provided are misleading. A property defined inside a class becomes an instance property when the object is instantiated, <strong>regardless of how you define it</strong>. So copies of <code>a.list</code> are made, and <code>x.list</code> and <code>y.list</code> are different copies. The reason th...
-3
2012-09-07T14:34:46Z
[ "python", "class" ]
How do I avoid having class data shared among instances?
1,680,528
<p>What I want is this behavior:</p> <pre><code>class a: list=[] y=a() x=a() x.list.append(1) y.list.append(2) x.list.append(3) y.list.append(4) print x.list [1,3] print y.list [2,4] </code></pre> <p>of course, what really happens when I print is:</p> <pre><code>print x.list [1,2,3,4] print y.lis...
61
2009-11-05T13:19:55Z
15,590,354
<p>The accepted answer works but a little more explanation does not hurt. </p> <p>Class attributes do not become instance attributes when an instance is created. They become instance attributes when a value is assigned to them.</p> <p>In the original code no value is assigned to <code>list</code> attribute after inst...
6
2013-03-23T18:12:40Z
[ "python", "class" ]
How do I avoid having class data shared among instances?
1,680,528
<p>What I want is this behavior:</p> <pre><code>class a: list=[] y=a() x=a() x.list.append(1) y.list.append(2) x.list.append(3) y.list.append(4) print x.list [1,3] print y.list [2,4] </code></pre> <p>of course, what really happens when I print is:</p> <pre><code>print x.list [1,2,3,4] print y.lis...
61
2009-11-05T13:19:55Z
21,492,237
<p>So nearly every response here seems to miss a particular point. Class variables <strong>never</strong> become instance variables as demonstrated by the code below. By utilizing a metaclass to intercept variable assignment at the class level, we can see that when a.myattr is reassigned, the field assignment magic m...
2
2014-01-31T23:52:55Z
[ "python", "class" ]
Google Apps Engine mail fetch
1,680,856
<p>How can I fetch mails from gmail account in Google Apps Engine Django application?</p>
0
2009-11-05T14:18:33Z
1,681,002
<p>Just use the Python's standard <a href="http://docs.python.org/library/poplib.html" rel="nofollow">POP</a> or <a href="http://docs.python.org/library/imaplib.html" rel="nofollow">IMAP</a> client. Google does not provide a GMail API.</p>
-1
2009-11-05T14:45:41Z
[ "python", "google-app-engine", "gmail" ]
Google Apps Engine mail fetch
1,680,856
<p>How can I fetch mails from gmail account in Google Apps Engine Django application?</p>
0
2009-11-05T14:18:33Z
1,681,270
<p>You could cronjob rss feed to gmail messages?</p> <p><a href="http://www.forevergeek.com/2004/10/gmail%5Frss%5Ffeed/" rel="nofollow">gmail rss</a></p> <p><a href="http://code.google.com/appengine/docs/python/config/cron.html" rel="nofollow">python cron</a></p>
0
2009-11-05T15:26:36Z
[ "python", "google-app-engine", "gmail" ]
Google Apps Engine mail fetch
1,680,856
<p>How can I fetch mails from gmail account in Google Apps Engine Django application?</p>
0
2009-11-05T14:18:33Z
1,681,651
<p>I would use <a href="http://libgmail.sourceforge.net/" rel="nofollow">libgmail</a> -- seems to be the most popular pure-Python way to do it. However for app engine use I believe it would have to be ported to use urlfetch and I don't think anybody's done that yet (I'd happily receive news to the contrary!-).</p>
0
2009-11-05T16:13:06Z
[ "python", "google-app-engine", "gmail" ]
Google Apps Engine mail fetch
1,680,856
<p>How can I fetch mails from gmail account in Google Apps Engine Django application?</p>
0
2009-11-05T14:18:33Z
1,683,130
<p><a href="http://code.google.com/appengine/docs/python/mail/receivingmail.html" rel="nofollow">Configure your app to receive email</a>, then, if it really has to be a gmail address, set up the gmail address to forward everything to your appspot address.</p>
2
2009-11-05T19:56:39Z
[ "python", "google-app-engine", "gmail" ]
Detailed explanation about Python's "freeze"
1,681,021
<p>Is there anywhere a detailed explanation about Python's "freeze" thing? I saw the PyPi page, but I don't think it's comprehensive enough.</p>
7
2009-11-05T14:47:48Z
1,681,531
<p>There is documentation about <a href="http://wiki.python.org/moin/Freeze" rel="nofollow">freeze</a> on the wiki and the <a href="http://svn.python.org/projects/python/trunk/Tools/freeze/freeze.py" rel="nofollow">source docstring</a> is pretty good.. There is an alternative, <a href="http://cx-freeze.sourceforge.net/...
6
2009-11-05T16:01:10Z
[ "python", "freeze" ]
Custom exception handling in Python
1,681,036
<p>I have two modules, main and notmain. I declared my custom exception in main module and want to catch it. This exception is raised in notmain module. The problem is I can't catch my exception raised in notmain module.</p> <p>main.py:</p> <pre><code>class MyException(Exception): pass m = __import__('notmain') ...
3
2009-11-05T14:49:49Z
1,681,086
<p>Your module <code>main</code> is imported twice (as <code>main</code> and <code>__main__</code>), each having its own class <code>MyException</code>. You should consider redesigning your application to avoid circular imports.</p>
8
2009-11-05T14:59:04Z
[ "python", "exception", "exception-handling" ]
Custom exception handling in Python
1,681,036
<p>I have two modules, main and notmain. I declared my custom exception in main module and want to catch it. This exception is raised in notmain module. The problem is I can't catch my exception raised in notmain module.</p> <p>main.py:</p> <pre><code>class MyException(Exception): pass m = __import__('notmain') ...
3
2009-11-05T14:49:49Z
1,681,092
<p>The <code><code>__main__</code></code> name, with underscores, is an automatic namespace for the program being called. A workaround would be to declare the exception in a third file (or have a third file that is the user-called program, and just a single method in your "real" program).</p> <p>Also, the way you imp...
1
2009-11-05T14:59:40Z
[ "python", "exception", "exception-handling" ]
how to get tz_info object corresponding to current timezone?
1,681,143
<p>Is there a cross-platform function in <code>python</code> (or <code>pytz</code>) that returns a <code>tzinfo</code> object corresponding to the timezone currently set on the computer?</p> <p>environment variables cannot be counted on as they are not cross-platform</p>
10
2009-11-05T15:08:46Z
1,681,189
<p><a href="http://docs.python.org/library/time.html#time.timezone" rel="nofollow"><code>time.timezone</code></a> returns current timezone offset. there is also a <a href="http://docs.python.org/library/datetime.html#datetime.tzinfo" rel="nofollow"><code>datetime.tzinfo</code></a>, if you need more complicated structur...
2
2009-11-05T15:15:33Z
[ "python", "datetime", "time", "timezone", "pytz" ]
how to get tz_info object corresponding to current timezone?
1,681,143
<p>Is there a cross-platform function in <code>python</code> (or <code>pytz</code>) that returns a <code>tzinfo</code> object corresponding to the timezone currently set on the computer?</p> <p>environment variables cannot be counted on as they are not cross-platform</p>
10
2009-11-05T15:08:46Z
1,681,526
<p>I have not used it myself, but dateutil.tz.tzlocal() should do the trick.</p> <p><a href="http://labix.org/python-dateutil#head-50221b5226c3ccb97daa06ea7d9abf0533ec0310" rel="nofollow">http://labix.org/python-dateutil#head-50221b5226c3ccb97daa06ea7d9abf0533ec0310</a></p>
0
2009-11-05T16:00:48Z
[ "python", "datetime", "time", "timezone", "pytz" ]
how to get tz_info object corresponding to current timezone?
1,681,143
<p>Is there a cross-platform function in <code>python</code> (or <code>pytz</code>) that returns a <code>tzinfo</code> object corresponding to the timezone currently set on the computer?</p> <p>environment variables cannot be counted on as they are not cross-platform</p>
10
2009-11-05T15:08:46Z
1,681,600
<pre><code>&gt;&gt;&gt; import datetime &gt;&gt;&gt; today = datetime.datetime.now() &gt;&gt;&gt; insummer = datetime.datetime(2009,8,15,10,0,0) &gt;&gt;&gt; from pytz import reference &gt;&gt;&gt; localtime = reference.LocalTimezone() &gt;&gt;&gt; localtime.tzname(today) 'PST' &gt;&gt;&gt; localtime.tzname(insummer) '...
6
2009-11-05T16:07:59Z
[ "python", "datetime", "time", "timezone", "pytz" ]
how to get tz_info object corresponding to current timezone?
1,681,143
<p>Is there a cross-platform function in <code>python</code> (or <code>pytz</code>) that returns a <code>tzinfo</code> object corresponding to the timezone currently set on the computer?</p> <p>environment variables cannot be counted on as they are not cross-platform</p>
10
2009-11-05T15:08:46Z
18,385,592
<p>Maybe try:</p> <p><code>import time</code></p> <p><code>print time.tzname</code> #or <code>time.tzname[time.daylight]</code></p>
-1
2013-08-22T16:04:00Z
[ "python", "datetime", "time", "timezone", "pytz" ]
how to get tz_info object corresponding to current timezone?
1,681,143
<p>Is there a cross-platform function in <code>python</code> (or <code>pytz</code>) that returns a <code>tzinfo</code> object corresponding to the timezone currently set on the computer?</p> <p>environment variables cannot be counted on as they are not cross-platform</p>
10
2009-11-05T15:08:46Z
18,569,497
<p><a href="https://github.com/regebro/tzlocal" rel="nofollow"><code>tzlocal</code> module</a> that returns <code>pytz</code> timezones works on *nix and win32:</p> <pre><code>from datetime import datetime from tzlocal import get_localzone # $ pip install tzlocal # get local timezone local_tz = get_localzone() ...
4
2013-09-02T09:12:36Z
[ "python", "datetime", "time", "timezone", "pytz" ]
how to get tz_info object corresponding to current timezone?
1,681,143
<p>Is there a cross-platform function in <code>python</code> (or <code>pytz</code>) that returns a <code>tzinfo</code> object corresponding to the timezone currently set on the computer?</p> <p>environment variables cannot be counted on as they are not cross-platform</p>
10
2009-11-05T15:08:46Z
20,474,043
<p>I was asking the same to myself, and I found the answer in [1]:</p> <p>Take a look at section 8.1.7: the format "%z" (lowercase, the Z uppercase returns also the time zone, but not in the 4-digit format, but in the form of timezone abbreviations, like in [3]) of strftime returns the form "+/- 4DIGIT" that is standa...
-1
2013-12-09T15:16:30Z
[ "python", "datetime", "time", "timezone", "pytz" ]
how to get tz_info object corresponding to current timezone?
1,681,143
<p>Is there a cross-platform function in <code>python</code> (or <code>pytz</code>) that returns a <code>tzinfo</code> object corresponding to the timezone currently set on the computer?</p> <p>environment variables cannot be counted on as they are not cross-platform</p>
10
2009-11-05T15:08:46Z
30,308,165
<p>This following code snippet returns time in a different timezone irrespective of the timezone configured on the server.</p> <pre><code># pip install pytz tzlocal from tzlocal import get_localzone from datetime import datetime from pytz import timezone local_tz = get_localzone() local_datetime = datetime.now(local...
3
2015-05-18T16:14:35Z
[ "python", "datetime", "time", "timezone", "pytz" ]
Python ClientForm Error
1,681,150
<pre><code>import ClientForm from urllib2 import urlopen page = urlopen('http://garciainteractive.com/blog/topic_view/topics/content/') form = ClientForm.ParseResponse(page, backwards_compat=False) print form[0] </code></pre> <p>The problem is that ClientForm parses the first html form the following way:</p> <pre><c...
0
2009-11-05T15:09:24Z
1,684,730
<p>The problem is likely that the HTML itself is invalid - for example it re-uses the id="comment_form" over and over again, while there is only supposed to be one id of a given name per document.</p> <p>Your best solution would probably be to use BeautifulSoup to parse your urlopen page result first, then pretty-prin...
1
2009-11-06T00:56:50Z
[ "python", "clientform" ]
Python ClientForm Error
1,681,150
<pre><code>import ClientForm from urllib2 import urlopen page = urlopen('http://garciainteractive.com/blog/topic_view/topics/content/') form = ClientForm.ParseResponse(page, backwards_compat=False) print form[0] </code></pre> <p>The problem is that ClientForm parses the first html form the following way:</p> <pre><c...
0
2009-11-05T15:09:24Z
1,686,465
<p>As Richard suggested use BeautifulSoup.</p> <pre><code>from BeautifulSoup import BeautifulSoup, SoupStrainer from StringIO import StringIO from urllib2 import urlopen import ClientForm url='http://garciainteractive.com/blog/topic_view/topics/content/' html=urlopen(url).read() forms_filter=SoupStrainer(...
1
2009-11-06T09:31:12Z
[ "python", "clientform" ]
Python: Platform independent way to modify PATH environment variable
1,681,208
<p>Is there a way to modify the PATH environment variable in a platform independent way using python?</p> <p>Something similar to os.path.join()?</p>
43
2009-11-05T15:17:39Z
1,681,244
<p>You should be able to modify <code>os.environ</code>.</p> <p>Since <code>os.pathsep</code> is the character to separate different paths, you should use this to append each new path:</p> <pre><code>os.environ["PATH"] += os.pathsep + path </code></pre> <p>or, if there are several paths to add in a list:</p> <pre><...
78
2009-11-05T15:21:57Z
[ "python", "path", "cross-platform", "environment-variables" ]
Python: Platform independent way to modify PATH environment variable
1,681,208
<p>Is there a way to modify the PATH environment variable in a platform independent way using python?</p> <p>Something similar to os.path.join()?</p>
43
2009-11-05T15:17:39Z
1,681,256
<p>The caveat to be aware of with modifying environment variables in Python, is that there is no equivalent of the "export" shell command. There is no way of injecting changes into the current process, only child processes.</p>
5
2009-11-05T15:24:26Z
[ "python", "path", "cross-platform", "environment-variables" ]
Python: Platform independent way to modify PATH environment variable
1,681,208
<p>Is there a way to modify the PATH environment variable in a platform independent way using python?</p> <p>Something similar to os.path.join()?</p>
43
2009-11-05T15:17:39Z
3,952,557
<p>(Since comments can't contain formatting, I have to put this in an answer, but I feel like it's an important point to make. This is really a comment on <a href="http://stackoverflow.com/questions/1681208/python-platform-independent-way-to-modify-path-environment-variable/1681256#1681256">the comment about there bei...
12
2010-10-17T08:36:37Z
[ "python", "path", "cross-platform", "environment-variables" ]
how code a function similar to itertools.product in python 2.5
1,681,269
<p>I have a list of tuples, e.g: </p> <pre><code>A=[(1,2,3), (3,5,7,9), (7)] </code></pre> <p>and want to generate all permutations with one item from each tuple.</p> <pre><code>1,3,7 1,5,7 1,7,7 ... 3,9,7 </code></pre> <p>I can have any number of tuples and a tuple can have any number of elements. And I can't use ...
5
2009-11-05T15:26:28Z
1,681,286
<p>docs of <a href="http://docs.python.org/library/itertools.html#itertools.product"><code>itertools.product</code></a> have an example of how to implement it in py2.5:</p> <pre><code>def product(*args, **kwds): # product('ABCD', 'xy') --&gt; Ax Ay Bx By Cx Cy Dx Dy # product(range(2), repeat=3) --&gt; 000 001...
12
2009-11-05T15:28:41Z
[ "python" ]
how code a function similar to itertools.product in python 2.5
1,681,269
<p>I have a list of tuples, e.g: </p> <pre><code>A=[(1,2,3), (3,5,7,9), (7)] </code></pre> <p>and want to generate all permutations with one item from each tuple.</p> <pre><code>1,3,7 1,5,7 1,7,7 ... 3,9,7 </code></pre> <p>I can have any number of tuples and a tuple can have any number of elements. And I can't use ...
5
2009-11-05T15:26:28Z
1,681,294
<p>The itertools documentation contains full code showing what each function is equivalent to. The <code>product</code> implementation is <a href="http://docs.python.org/library/itertools.html#itertools.product" rel="nofollow">here</a>.</p>
4
2009-11-05T15:29:33Z
[ "python" ]
how code a function similar to itertools.product in python 2.5
1,681,269
<p>I have a list of tuples, e.g: </p> <pre><code>A=[(1,2,3), (3,5,7,9), (7)] </code></pre> <p>and want to generate all permutations with one item from each tuple.</p> <pre><code>1,3,7 1,5,7 1,7,7 ... 3,9,7 </code></pre> <p>I can have any number of tuples and a tuple can have any number of elements. And I can't use ...
5
2009-11-05T15:26:28Z
7,450,757
<pre><code>def product(*iterables): """ Equivalent of itertools.product for versions &lt; 2.6, which does NOT build intermediate results. Omitted 'repeat' option. product('ABCD', 'xy') --&gt; Ax Ay Bx By Cx Cy Dx Dy """ nIters = len(iterables) lstLenths = [] lstRemaining = [1...
5
2011-09-16T21:52:33Z
[ "python" ]
how code a function similar to itertools.product in python 2.5
1,681,269
<p>I have a list of tuples, e.g: </p> <pre><code>A=[(1,2,3), (3,5,7,9), (7)] </code></pre> <p>and want to generate all permutations with one item from each tuple.</p> <pre><code>1,3,7 1,5,7 1,7,7 ... 3,9,7 </code></pre> <p>I can have any number of tuples and a tuple can have any number of elements. And I can't use ...
5
2009-11-05T15:26:28Z
12,605,800
<p>When playing around with generators, I too found a version of <code>itertools.product</code>, and it is almost as fast as the (native) library version, while being 100% compatible with it, and it does not build intermediate results:</p> <pre><code>def product(*args, **kwds): "Alternative fast implementation of ...
2
2012-09-26T15:59:52Z
[ "python" ]
Nested Python C Extensions/Modules?
1,681,281
<p>How do I compile a C-Python module such that it is local to another? E.g. if I have a module named "bar" and another module named "mymodule", how do I compile "bar" so that it imported via "import mymodule.bar"?</p> <p>(Sorry if this is poorly phrased, I wasn't sure what the proper term for it was.)</p> <p>I tried...
5
2009-11-05T15:27:52Z
1,681,492
<p>The instructions are <a href="http://docs.python.org/distutils/setupscript.html#extension-names-and-packages" rel="nofollow">here</a>:</p> <blockquote> <p>Extension('foo', ['src/foo1.c', 'src/foo2.c'])</p> <p>describes an extension that lives in the root package, while</p> <p>Extension('pkg.foo', ['...
3
2009-11-05T15:57:28Z
[ "python", "distutils", "python-c-api" ]
How do I find out where an icon was clicked (relative to itself) using python?
1,681,339
<p>Essentially, what I want to do is have an icon that has different symbols for various programs at the bottom of it (for example, a python file might have a symbol for command prompt, a text editor, and a debugger, all little squares at the bottom of the icon), and when the user double clicks on one of these, that pr...
-2
2009-11-05T15:36:51Z
1,681,382
<p>You use some GUI system, like GTK+ or wxPython or something.</p>
1
2009-11-05T15:43:22Z
[ "python", "icons" ]
How do I find out where an icon was clicked (relative to itself) using python?
1,681,339
<p>Essentially, what I want to do is have an icon that has different symbols for various programs at the bottom of it (for example, a python file might have a symbol for command prompt, a text editor, and a debugger, all little squares at the bottom of the icon), and when the user double clicks on one of these, that pr...
-2
2009-11-05T15:36:51Z
1,681,623
<p>Sounds like you want to write an extension to windows explorer. This would be a significant project and I'm not sure Python would be the best language (you'd be accessing the win32 api a lot).</p>
1
2009-11-05T16:10:14Z
[ "python", "icons" ]
Google App Engine proxy
1,681,806
<p>What would be the simplest implementation of a proxy written for GAE, which relays every URL (including POST, and header data) to a remote HTTP host, and return with it's result (with special consideration to error codes)? Please apply KISS principles!</p>
3
2009-11-05T16:32:27Z
1,682,413
<p>How about <a href="http://www.google.com/codesearch/p?#SKzQ5XqR4js/trunk/README&amp;q=appengine%20http%20proxy%20" rel="nofollow">this one</a> ?</p>
1
2009-11-05T17:59:14Z
[ "python", "google-app-engine", "proxy" ]
Google App Engine proxy
1,681,806
<p>What would be the simplest implementation of a proxy written for GAE, which relays every URL (including POST, and header data) to a remote HTTP host, and return with it's result (with special consideration to error codes)? Please apply KISS principles!</p>
3
2009-11-05T16:32:27Z
1,682,455
<p>I've found <a href="http://code.google.com/p/downy/source/browse/#hg/proxy" rel="nofollow">this proxy app</a> from the <a href="http://code.google.com/p/downy/" rel="nofollow">Downy</a> project works very well.</p>
2
2009-11-05T18:07:33Z
[ "python", "google-app-engine", "proxy" ]