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
Automatic font recognition with Python
1,708,858
<p>As you may have heard of, there is an online font recognition service call WhatTheFont</p> <p>I'm curious about the tech behind this tool. I think basically we can seperate this into two parts:</p> <ol> <li><p>Generate images from font files of various format, refer to <a href="http://www.fileinfo.com/filetypes/fo...
3
2009-11-10T15:37:36Z
1,713,168
<p>I can't offer Python code, but here are two possible approaches.</p> <ol> <li><p>"Eigen-characters." In face recognition, given a large training set of normalized facial images, you can use principal component analysis (PCA) to obtain a set of "eigenfaces" which, when the training faces are projected upon this subs...
2
2009-11-11T05:14:16Z
[ "python", "image-processing", "fonts" ]
Class Objects and comparing specific attributes
1,708,878
<p>I have the following code.</p> <pre><code>class person(object): def __init__(self, keys): for item in keys: setattr(self, item, None) def __str__(self): return str(self.__dict__) def __eq__(self, other) : return self.__dict__ == other.__dict__ </code></pre>...
0
2009-11-10T15:40:08Z
1,708,926
<p>You can simplify your comparison from:</p> <pre><code>self_vals = [ getattr(self, i) for i in self.valid_keys ] other_vals = [ getattr(other, i) for i in self.valid_keys ] return self_vals == other_vals </code></pre> <p>to:</p> <pre><code>return all(getattr(self, i) == getattr(other, i) for i in self.valid_keys) ...
1
2009-11-10T15:45:36Z
[ "coding-style", "python" ]
Class Objects and comparing specific attributes
1,708,878
<p>I have the following code.</p> <pre><code>class person(object): def __init__(self, keys): for item in keys: setattr(self, item, None) def __str__(self): return str(self.__dict__) def __eq__(self, other) : return self.__dict__ == other.__dict__ </code></pre>...
0
2009-11-10T15:40:08Z
1,709,480
<p>There are minor enhancements (bug fixes) I'd definitely do.</p> <p>In particular, <code>getattr</code> called with two arguments raises an ArgumentError if the attribute's not present, so you could get that exception if you were comparing two instances with different keys. You could just call it with three args in...
2
2009-11-10T16:56:43Z
[ "coding-style", "python" ]
Does anyone have examples of integrating Haystack/Solr with Django?
1,708,915
<p><strong>Note:</strong> This question originally applied to <strong>Xapian</strong>, but due to cross-platform issues and poor understanding of Xapian I (our team) chose <strong>Solr</strong> instead.</p> <p>I'm looking for snippets, tricks, tips, links, and anything to watch out for (gotchas). My technology stack i...
1
2009-11-10T15:43:47Z
1,712,020
<p>A few notes and resources. My advice is mostly related to Haystack in general since I don't have experience with Xapian as a backend.</p> <ol> <li>Installing Xapian (from the Haystack docs) - note that Haystack doesn't support Xapian on its own: <a href="http://haystacksearch.org/docs/installing%5Fsearch%5Fengines....
4
2009-11-10T23:35:36Z
[ "python", "django", "solr", "django-haystack" ]
What does 'u' mean in a list?
1,709,110
<p>This is the first time I've came across this. Just printed a list and each element seems to have a <code>u</code> in front of it i.e. </p> <pre><code>[u'hello', u'hi', u'hey'] </code></pre> <p><strong>What does it mean and why would a list have this in front of each element?</strong></p> <p>As I don't know...
18
2009-11-10T16:11:41Z
1,709,126
<p>The <code>u</code> just means that the following string is a unicode string (as opposed to a plain ascii string). It has nothing to do with the list that happens to contain the (unicode) strings.</p>
7
2009-11-10T16:13:11Z
[ "python", "string", "unicode" ]
What does 'u' mean in a list?
1,709,110
<p>This is the first time I've came across this. Just printed a list and each element seems to have a <code>u</code> in front of it i.e. </p> <pre><code>[u'hello', u'hi', u'hey'] </code></pre> <p><strong>What does it mean and why would a list have this in front of each element?</strong></p> <p>As I don't know...
18
2009-11-10T16:11:41Z
1,709,128
<p>I believe the u' prefix creates a unicode string instead of regular ascii</p>
3
2009-11-10T16:13:17Z
[ "python", "string", "unicode" ]
What does 'u' mean in a list?
1,709,110
<p>This is the first time I've came across this. Just printed a list and each element seems to have a <code>u</code> in front of it i.e. </p> <pre><code>[u'hello', u'hi', u'hey'] </code></pre> <p><strong>What does it mean and why would a list have this in front of each element?</strong></p> <p>As I don't know...
18
2009-11-10T16:11:41Z
1,709,132
<p>it's an indication of unicode string. similar to <code>r''</code> for raw string.</p> <pre><code>&gt;&gt;&gt; type(u'abc') &lt;type 'unicode'&gt; &gt;&gt;&gt; r'ab\c' 'ab\\c' </code></pre>
41
2009-11-10T16:13:28Z
[ "python", "string", "unicode" ]
What does 'u' mean in a list?
1,709,110
<p>This is the first time I've came across this. Just printed a list and each element seems to have a <code>u</code> in front of it i.e. </p> <pre><code>[u'hello', u'hi', u'hey'] </code></pre> <p><strong>What does it mean and why would a list have this in front of each element?</strong></p> <p>As I don't know...
18
2009-11-10T16:11:41Z
1,709,136
<p><a href="http://docs.python.org/tutorial/introduction.html#unicode-strings">Unicode.</a></p>
11
2009-11-10T16:13:38Z
[ "python", "string", "unicode" ]
getting started with django-cms: error on page_submit_row
1,709,201
<p>I am getting started with django-cms and I am facing an exception when I try to edit a page in the admin inteface.</p> <p>A <code>TemplateSyntaxError</code> exception is raised due to the <code>{% page_submit_row %}</code> templatetag. </p> <pre> TemplateSyntaxError at /admin/cms/page/1/ Caught an exception while...
1
2009-11-10T16:22:36Z
1,709,285
<p>You may need to <code>{% load %}</code> the template tag library at the top of your file.</p>
0
2009-11-10T16:33:00Z
[ "python", "django", "django-cms" ]
getting started with django-cms: error on page_submit_row
1,709,201
<p>I am getting started with django-cms and I am facing an exception when I try to edit a page in the admin inteface.</p> <p>A <code>TemplateSyntaxError</code> exception is raised due to the <code>{% page_submit_row %}</code> templatetag. </p> <pre> TemplateSyntaxError at /admin/cms/page/1/ Caught an exception while...
1
2009-11-10T16:22:36Z
1,709,611
<p>It seems that the problem comes from the django-cms installer. It was with RC2 and RC3 is out now.</p> <p>Moreover, It is recommended to use easy_install for the installation</p> <p>easy_instaling RC3 fixed the problem</p> <p>Best</p>
0
2009-11-10T17:15:17Z
[ "python", "django", "django-cms" ]
How can I sort a coordinate list for a rectangle counterclockwise?
1,709,283
<p>I need to sort a coordinate list for a rectangle counterclockwise, and make the north-east corner the first coordinate. These are geographic coordinates (i.e. Longitude, Latitude) in decimal form.<sup>1</sup></p> <p>For example, here are the 4 corners of a rectangle, starting with the north-west corner and moving c...
4
2009-11-10T16:32:46Z
1,709,306
<p>If you take the cross-product of two vectors from a corner then the sign of the result will tell you if it's clockwise or counterclockwise.</p>
1
2009-11-10T16:36:06Z
[ "python", "algorithm", "sorting", "coordinates", "geospatial" ]
How can I sort a coordinate list for a rectangle counterclockwise?
1,709,283
<p>I need to sort a coordinate list for a rectangle counterclockwise, and make the north-east corner the first coordinate. These are geographic coordinates (i.e. Longitude, Latitude) in decimal form.<sup>1</sup></p> <p>For example, here are the 4 corners of a rectangle, starting with the north-west corner and moving c...
4
2009-11-10T16:32:46Z
1,709,344
<p>So, you have 4 points.</p> <p>You always start with the NW point.</p> <p>You know that the points are sorted, just not in which direction.</p> <p>It's a simple test of the first two points whether the list is clockwise or counter clockwise.</p> <p>if (pt1.y != pt2.y) then direction = clockwise.</p> <p>If you de...
0
2009-11-10T16:40:08Z
[ "python", "algorithm", "sorting", "coordinates", "geospatial" ]
How can I sort a coordinate list for a rectangle counterclockwise?
1,709,283
<p>I need to sort a coordinate list for a rectangle counterclockwise, and make the north-east corner the first coordinate. These are geographic coordinates (i.e. Longitude, Latitude) in decimal form.<sup>1</sup></p> <p>For example, here are the 4 corners of a rectangle, starting with the north-west corner and moving c...
4
2009-11-10T16:32:46Z
1,709,347
<p>Rather than sorting, you can just "rebuild" the rectangle in any order you desire.</p> <p>From the original set, collect the min and max latitude and min and max longitude. Then construct the rectangle in any order you want.</p> <p>Northwest corner is max latitude and min longitude. Southwest corner is min latit...
3
2009-11-10T16:40:18Z
[ "python", "algorithm", "sorting", "coordinates", "geospatial" ]
How can I sort a coordinate list for a rectangle counterclockwise?
1,709,283
<p>I need to sort a coordinate list for a rectangle counterclockwise, and make the north-east corner the first coordinate. These are geographic coordinates (i.e. Longitude, Latitude) in decimal form.<sup>1</sup></p> <p>For example, here are the 4 corners of a rectangle, starting with the north-west corner and moving c...
4
2009-11-10T16:32:46Z
1,709,349
<p>Associate an angle with each point (relative to an interior point), and then moving around is trivial.</p> <p>To calculate the angle, find a point in the middle of the shape, for example, <code>(average_lat, average_lng)</code> will be in the center. Then, <code>atan2(lng - average_lng, lat - average_lat)</code> w...
3
2009-11-10T16:40:24Z
[ "python", "algorithm", "sorting", "coordinates", "geospatial" ]
How can I sort a coordinate list for a rectangle counterclockwise?
1,709,283
<p>I need to sort a coordinate list for a rectangle counterclockwise, and make the north-east corner the first coordinate. These are geographic coordinates (i.e. Longitude, Latitude) in decimal form.<sup>1</sup></p> <p>For example, here are the 4 corners of a rectangle, starting with the north-west corner and moving c...
4
2009-11-10T16:32:46Z
1,709,546
<p>solution seems pretty straightforward:</p> <pre><code>&gt;&gt;&gt; import math &gt;&gt;&gt; mlat = sum(x['lat'] for x in l) / len(l) &gt;&gt;&gt; mlng = sum(x['lng'] for x in l) / len(l) &gt;&gt;&gt; def algo(x): return (math.atan2(x['lat'] - mlat, x['lng'] - mlng) + 2 * math.pi) % (2*math.pi) &gt;&gt;&gt; l.s...
5
2009-11-10T17:06:03Z
[ "python", "algorithm", "sorting", "coordinates", "geospatial" ]
How can I sort a coordinate list for a rectangle counterclockwise?
1,709,283
<p>I need to sort a coordinate list for a rectangle counterclockwise, and make the north-east corner the first coordinate. These are geographic coordinates (i.e. Longitude, Latitude) in decimal form.<sup>1</sup></p> <p>For example, here are the 4 corners of a rectangle, starting with the north-west corner and moving c...
4
2009-11-10T16:32:46Z
1,709,577
<p>Assuming that your "rectangles" are always parallel to the equator and meridians (that's what your example implies, but it's not stated explicitely), i.e. you have just two pairs of different lat and lng values: (lat0, lat1) and (lng0, lng1).</p> <p>You get following 4 corners:</p> <pre><code>NE: (lat = max(lat0, ...
3
2009-11-10T17:10:40Z
[ "python", "algorithm", "sorting", "coordinates", "geospatial" ]
How can I sort a coordinate list for a rectangle counterclockwise?
1,709,283
<p>I need to sort a coordinate list for a rectangle counterclockwise, and make the north-east corner the first coordinate. These are geographic coordinates (i.e. Longitude, Latitude) in decimal form.<sup>1</sup></p> <p>For example, here are the 4 corners of a rectangle, starting with the north-west corner and moving c...
4
2009-11-10T16:32:46Z
1,709,994
<p>It is easy. First, we sort the coordinates so we know in which order we have them, then we simply pick them out:</p> <p>Sort them first by lat then by lng, biggest first. Then we swap the last two:</p> <pre><code>L = [ { "lat": 34.495239, "lng": -118.127747 }, # north-west { "lat": 34.495239, "lng": -117.14721...
1
2009-11-10T18:07:06Z
[ "python", "algorithm", "sorting", "coordinates", "geospatial" ]
Run nosetests with warnings as errors?
1,709,388
<p>When running <code>nosetests</code> from the command line, how do you specify that 'non-ignored' warnings should be treated as errors?</p> <p>By default, warnings are printed, but not counted as failures:</p> <pre><code>[snip]/service/accounts/database.py:151: SADeprecationWarning: Use session.add() self.session...
15
2009-11-10T16:45:00Z
1,709,444
<p>I don't think nose can directly control this: the warnings module doesn't raise an exception when the warning is issued. The <code>warnings</code> module gives you control over which warnings should be raised as exceptions.</p>
0
2009-11-10T16:51:55Z
[ "python", "unit-testing", "warnings", "nose" ]
Run nosetests with warnings as errors?
1,709,388
<p>When running <code>nosetests</code> from the command line, how do you specify that 'non-ignored' warnings should be treated as errors?</p> <p>By default, warnings are printed, but not counted as failures:</p> <pre><code>[snip]/service/accounts/database.py:151: SADeprecationWarning: Use session.add() self.session...
15
2009-11-10T16:45:00Z
20,998,338
<p><code>nosetests</code> is a small Python script. Open it with an editor, and add <code>-W error</code> at the end of the first line. This tells the Python interpreter to convert warnings into exceptions.</p> <p>Even simpler is to use Python environment variable to inject "treat warnings as errors" flag:</p> <pre><...
7
2014-01-08T14:25:54Z
[ "python", "unit-testing", "warnings", "nose" ]
Run nosetests with warnings as errors?
1,709,388
<p>When running <code>nosetests</code> from the command line, how do you specify that 'non-ignored' warnings should be treated as errors?</p> <p>By default, warnings are printed, but not counted as failures:</p> <pre><code>[snip]/service/accounts/database.py:151: SADeprecationWarning: Use session.add() self.session...
15
2009-11-10T16:45:00Z
33,237,448
<p>The answer by @khinsen helps a lot, but makes the execution of nosetests stop, if it issues the following warning during test discovery (which is otherwise not visible to the user): "ImportWarning: Not importing directory 'XXX': missing <code>__init__.py</code></p> <p>Furthermore, warnings raised during the import ...
2
2015-10-20T13:04:23Z
[ "python", "unit-testing", "warnings", "nose" ]
PyQt: translating standard buttons
1,709,528
<p>How can I easily translate standard buttons (Yes, No) from QMessageBox? I can't use self.tr on those arguments, so I would like to achieve it in some other simple way. Do I have to use whole translation system?</p>
3
2009-11-10T17:03:15Z
1,709,930
<p>Are you sure you have to translate them yourself? In other toolkits, standard buttons are automatically translated to the language that the user is using.</p>
3
2009-11-10T17:59:54Z
[ "python", "qt", "pyqt", "translation", "button" ]
PyQt: translating standard buttons
1,709,528
<p>How can I easily translate standard buttons (Yes, No) from QMessageBox? I can't use self.tr on those arguments, so I would like to achieve it in some other simple way. Do I have to use whole translation system?</p>
3
2009-11-10T17:03:15Z
1,763,378
<p>The quickest way is something like this:</p> <pre><code>mymessagebox.button(mymessagebox.Yes).setText("Yes, please!") mymessagebox.button(mymessagebox.No).setText("No, thanks.") </code></pre> <p>See the QMessageBox documentation for all possible <a href="http://doc.trolltech.com/4.5/qmessagebox.html#StandardButton...
2
2009-11-19T13:41:42Z
[ "python", "qt", "pyqt", "translation", "button" ]
PyQt: translating standard buttons
1,709,528
<p>How can I easily translate standard buttons (Yes, No) from QMessageBox? I can't use self.tr on those arguments, so I would like to achieve it in some other simple way. Do I have to use whole translation system?</p>
3
2009-11-10T17:03:15Z
4,627,177
<p>Here is how I did :</p> <p>First you need to copy the <code>qt_LOCALE.qm</code> file to your application directory. Mine was :</p> <pre><code>cp /usr/share/qt4/translations/qt_fr.qm . </code></pre> <p>Secondly, you need to load a translator for your application.</p> <pre><code>application = QApplication(argv) l...
7
2011-01-07T15:33:41Z
[ "python", "qt", "pyqt", "translation", "button" ]
PyQt: translating standard buttons
1,709,528
<p>How can I easily translate standard buttons (Yes, No) from QMessageBox? I can't use self.tr on those arguments, so I would like to achieve it in some other simple way. Do I have to use whole translation system?</p>
3
2009-11-10T17:03:15Z
4,627,449
<p>If you want to have Yes/No translated into the current language, usually setting the system language should be enough. Otherwise try with Natim's suggestion. </p> <p>If you want custom texts: The static methods like question() etc. don't allow custom button texts. That's unfortunate, as "Yes"/"No" dialogs are consi...
0
2011-01-07T16:03:05Z
[ "python", "qt", "pyqt", "translation", "button" ]
Using Python/Selenium/Best Tool For The Job to get URI of image requests generated through JavaScript?
1,709,711
<p>I have some JavaScript from a 3rd party vendor that is initiating an image request. I would like to figure out the URI of this image request.</p> <p>I can load the page in my browser, and then monitor "Live HTTP Headers" or "Tamper Data" in order to figure out the image request URI, but I would prefer to create a c...
1
2009-11-10T17:28:48Z
1,730,260
<p>Why can't you just read <code>suffix</code>, or <code>url</code> for that matter? Is the image loaded in an iframe or in your page?</p> <p>If it is loaded in your page, then this may be a <strong>dirty</strong> hack (substitute document.body for whatever element is considered):</p> <pre><code>var ac = document.bod...
0
2009-11-13T16:19:42Z
[ "python", "selenium", "http-headers", "analytics" ]
Using Python/Selenium/Best Tool For The Job to get URI of image requests generated through JavaScript?
1,709,711
<p>I have some JavaScript from a 3rd party vendor that is initiating an image request. I would like to figure out the URI of this image request.</p> <p>I can load the page in my browser, and then monitor "Live HTTP Headers" or "Tamper Data" in order to figure out the image request URI, but I would prefer to create a c...
1
2009-11-10T17:28:48Z
1,738,442
<p>I would pick any one of the many <a href="http://proxies.xhaus.com/python/" rel="nofollow">http proxy servers</a> written in Python -- probably one of the simplest ones at the very top of the list -- and tweak it to record all URLs requested (as well as proxy-serve them) e.g. appending them to a text file -- without...
3
2009-11-15T18:54:41Z
[ "python", "selenium", "http-headers", "analytics" ]
Using Python/Selenium/Best Tool For The Job to get URI of image requests generated through JavaScript?
1,709,711
<p>I have some JavaScript from a 3rd party vendor that is initiating an image request. I would like to figure out the URI of this image request.</p> <p>I can load the page in my browser, and then monitor "Live HTTP Headers" or "Tamper Data" in order to figure out the image request URI, but I would prefer to create a c...
1
2009-11-10T17:28:48Z
1,743,775
<p>The simplest thing to do might be to use something like HtmlUnit and skip a real browser entirely. By using Rhino, it can evaluate JavaScript and likely be used to extract that URL out.</p> <p>That said, if you can't get that working, try out Selenium RC and use the captureNetworkTraffic command (which requires the...
4
2009-11-16T17:52:00Z
[ "python", "selenium", "http-headers", "analytics" ]
Using Python/Selenium/Best Tool For The Job to get URI of image requests generated through JavaScript?
1,709,711
<p>I have some JavaScript from a 3rd party vendor that is initiating an image request. I would like to figure out the URI of this image request.</p> <p>I can load the page in my browser, and then monitor "Live HTTP Headers" or "Tamper Data" in order to figure out the image request URI, but I would prefer to create a c...
1
2009-11-10T17:28:48Z
1,768,554
<p>Use <a href="http://getfirebug.com/" rel="nofollow">Firebug Firefox plugin</a>. It will show you all requests in real time and you can even debug the JS in your Browser or run it step-by-step.</p>
1
2009-11-20T05:42:07Z
[ "python", "selenium", "http-headers", "analytics" ]
Using Python/Selenium/Best Tool For The Job to get URI of image requests generated through JavaScript?
1,709,711
<p>I have some JavaScript from a 3rd party vendor that is initiating an image request. I would like to figure out the URI of this image request.</p> <p>I can load the page in my browser, and then monitor "Live HTTP Headers" or "Tamper Data" in order to figure out the image request URI, but I would prefer to create a c...
1
2009-11-10T17:28:48Z
1,771,133
<p>Ultimately, I did it in python, using Selenium-RC. This solution requires the python files for selenium-rc, and you need to start the java server ("java -jar selenium-server.jar")</p> <pre><code>from selenium import selenium import unittest import lxml.html class TestMyDomain(unittest.TestCase): def setUp(self...
1
2009-11-20T15:17:50Z
[ "python", "selenium", "http-headers", "analytics" ]
Euclidian Distance Python Implementation
1,709,720
<p>I am playing with the following code from programming collective intelligence, this is a function from the book that calculated eclidian distance between two movie critics.</p> <p>This function sums the difference of the rankings in the dictionary, but euclidean distance in n dimensions also includes the square roo...
6
2009-11-10T17:29:29Z
1,709,742
<p>Just for intercomparisons the square root is not necessary and you would get the squared euclidean distance... which is also a distance (mathematically speaking, see <a href="http://en.wikipedia.org/wiki/Metric%5F%28mathematics%29" rel="nofollow">http://en.wikipedia.org/wiki/Metric%5F%28mathematics%29</a>).</p>
1
2009-11-10T17:32:39Z
[ "python", "euclidean-distance" ]
Euclidian Distance Python Implementation
1,709,720
<p>I am playing with the following code from programming collective intelligence, this is a function from the book that calculated eclidian distance between two movie critics.</p> <p>This function sums the difference of the rankings in the dictionary, but euclidean distance in n dimensions also includes the square roo...
6
2009-11-10T17:29:29Z
1,709,743
<p>That's correct. While the square root is necessary for a quantitatively correct result, if all you care about is distance relative to others for sorting, then taking the square root is superfluous.</p>
3
2009-11-10T17:32:46Z
[ "python", "euclidean-distance" ]
Euclidian Distance Python Implementation
1,709,720
<p>I am playing with the following code from programming collective intelligence, this is a function from the book that calculated eclidian distance between two movie critics.</p> <p>This function sums the difference of the rankings in the dictionary, but euclidean distance in n dimensions also includes the square roo...
6
2009-11-10T17:29:29Z
1,709,751
<p>The reason the square root is not used is because it is computationally expensive; it is monotonic (i.e., it preserves order) with the square function, so if all you're interested in is the order of the distances, the square root is unnecessary (and, as mentioned, very expensive computationally).</p>
12
2009-11-10T17:33:53Z
[ "python", "euclidean-distance" ]
Euclidian Distance Python Implementation
1,709,720
<p>I am playing with the following code from programming collective intelligence, this is a function from the book that calculated eclidian distance between two movie critics.</p> <p>This function sums the difference of the rankings in the dictionary, but euclidean distance in n dimensions also includes the square roo...
6
2009-11-10T17:29:29Z
1,715,869
<p>To compute a Cartesian distance, first you must compute the distance-squared, then you take its square root. But computing a square root is computationally expensive. If all you're really interested in is comparing distances, it works just as well to compare the distance-squared--and it's <em>much</em> faster.</p>...
2
2009-11-11T15:21:04Z
[ "python", "euclidean-distance" ]
How does wrapping an unsafe python method (e.g os.chdir) in a class make it thread/exception safe?
1,709,770
<p>In the question <a href="http://stackoverflow.com/questions/431684/how-do-i-cd-in-python">How do I "cd" in python</a>, the accepted answer recommended wrapping the os.chdir call in a class to make the return to your original dir exception safe. Here was the recommended code:</p> <pre><code>class Chdir: d...
4
2009-11-10T17:35:56Z
1,709,815
<p><code>__del__</code> is called when the instance is about to be destroyed. So when you instantiate this class, the current working directory is saved to an instance attribute and then, well, os.chdir is called. When the instance is destroyed (for whatever reason) the current directory is changed to its old value.</p...
1
2009-11-10T17:42:13Z
[ "python", "exception-handling" ]
How does wrapping an unsafe python method (e.g os.chdir) in a class make it thread/exception safe?
1,709,770
<p>In the question <a href="http://stackoverflow.com/questions/431684/how-do-i-cd-in-python">How do I "cd" in python</a>, the accepted answer recommended wrapping the os.chdir call in a class to make the return to your original dir exception safe. Here was the recommended code:</p> <pre><code>class Chdir: d...
4
2009-11-10T17:35:56Z
1,709,847
<p>This code alone is neither thread-safe nor exception-safe. Actually I'm not really sure what you mean by exception-safe. Following code comes to mind:</p> <pre><code>try: # something thrilling except: pass </code></pre> <p>And this is a terrible idea. Exceptions are not for guarding against. Well written c...
-2
2009-11-10T17:46:55Z
[ "python", "exception-handling" ]
How does wrapping an unsafe python method (e.g os.chdir) in a class make it thread/exception safe?
1,709,770
<p>In the question <a href="http://stackoverflow.com/questions/431684/how-do-i-cd-in-python">How do I "cd" in python</a>, the accepted answer recommended wrapping the os.chdir call in a class to make the return to your original dir exception safe. Here was the recommended code:</p> <pre><code>class Chdir: d...
4
2009-11-10T17:35:56Z
1,709,899
<p>The direct answer to the question is: It doesn't, the posted code is horrible.</p> <p>Something like the following could be reasonable to make it "exception safe" (but much better is to avoid chdir and use full paths instead):</p> <pre><code> saved_path = os.getcwd() try: os.chdir(newPath) do_work() f...
5
2009-11-10T17:56:02Z
[ "python", "exception-handling" ]
How does wrapping an unsafe python method (e.g os.chdir) in a class make it thread/exception safe?
1,709,770
<p>In the question <a href="http://stackoverflow.com/questions/431684/how-do-i-cd-in-python">How do I "cd" in python</a>, the accepted answer recommended wrapping the os.chdir call in a class to make the return to your original dir exception safe. Here was the recommended code:</p> <pre><code>class Chdir: d...
4
2009-11-10T17:35:56Z
1,710,140
<p>Thread safety and exception safety are not really the same thing at all. Wrapping the <code>os.chdir</code> call in a class like this is an attempt to make it exception safe <strong>not thread safe</strong>.</p> <p>Exception safety is something you'll frequently hear C++ developers talk about. It isn't talked about...
7
2009-11-10T18:29:13Z
[ "python", "exception-handling" ]
Python __str__: Magic Console
1,709,845
<p>Suppose one decided (yes, this is horrible) to create handle input in the following manner: A user types in a command on the python console after importing your class, the command is actually a class name, the class name's <code>__str__</code> function is actually a function with side effects (e.g. the command is "n...
0
2009-11-10T17:46:49Z
1,709,863
<p>in console you're getting representation of your object, which <code>__repr__</code> is responsible for. <code>__str__</code> used for printing:</p> <pre><code>&gt;&gt;&gt; class A: def __str__(self): return 'spam' &gt;&gt;&gt; A() &lt;__main__.A object at 0x0107E3D0&gt; &gt;&gt;&gt; print(A()) spam &gt...
1
2009-11-10T17:50:21Z
[ "python" ]
Python __str__: Magic Console
1,709,845
<p>Suppose one decided (yes, this is horrible) to create handle input in the following manner: A user types in a command on the python console after importing your class, the command is actually a class name, the class name's <code>__str__</code> function is actually a function with side effects (e.g. the command is "n...
0
2009-11-10T17:46:49Z
1,709,931
<p>You could use instances of a class rather than classes themselves. Something like</p> <pre><code>class MagicConsole(object): def __init__(self, f): self.__f = f def __repr__(self): return self.__f() north = MagicConsole(some_function_for_north) south = MagicConsole(some_function_for_south...
0
2009-11-10T17:59:56Z
[ "python" ]
Python __str__: Magic Console
1,709,845
<p>Suppose one decided (yes, this is horrible) to create handle input in the following manner: A user types in a command on the python console after importing your class, the command is actually a class name, the class name's <code>__str__</code> function is actually a function with side effects (e.g. the command is "n...
0
2009-11-10T17:46:49Z
1,709,987
<p>What you are looking for is the metaclass</p> <pre><code>class Magic(type): def __str__(self): return 'Something crazy' def __repr__(self): return 'Another craziness' class Foo(object): __metaclass__ = Magic &gt;&gt;&gt; print Foo Something crazy &gt;&gt;&gt; Foo Another craziness </co...
5
2009-11-10T18:06:33Z
[ "python" ]
How do I get the value of a property corresponding to a SQLAlchemy InstrumentedAttribute?
1,709,895
<p>Given a <a href="http://www.sqlalchemy.org" rel="nofollow">SQLAlchemy</a> mapped class <code>Table</code> and an instance of that class <code>t</code>, how do I get the value of <code>t.colname</code> corresponding to the <code>sqlalchemy.org.attributes.InstrumentedAttribute</code> instance <code>Table.colname</code...
4
2009-11-10T17:55:32Z
1,711,998
<p>To get an objects attribute value corresponding to an <code>InstrumentedAttribute</code> it should be enough to just get the key of the attribute from it's <code>ColumnProperty</code> and fetch it from the object:</p> <pre><code>t.colname == getattr(t, Table.colname.property.key) </code></pre> <p>If you have a <co...
5
2009-11-10T23:32:16Z
[ "python", "sqlalchemy" ]
How to read, in a line, all characters from column A to B
1,710,030
<p>is it possible in Python, given a file with 10000 lines, where all of them have this structure:</p> <p>1, 2, xvfrt ert5a fsfs4 df f fdfd56 , 234</p> <p>or similar, to read the whole string, and then to store in another string all characters from column 7 to column 17, including spaces, so the new string woul...
1
2009-11-10T18:13:41Z
1,710,059
<pre><code>for l in open("myfile.txt"): c7_17 = l[6:17] # Not sure what you want to do with c7_17 here, but go for it! </code></pre>
0
2009-11-10T18:16:51Z
[ "python", "text-processing" ]
How to read, in a line, all characters from column A to B
1,710,030
<p>is it possible in Python, given a file with 10000 lines, where all of them have this structure:</p> <p>1, 2, xvfrt ert5a fsfs4 df f fdfd56 , 234</p> <p>or similar, to read the whole string, and then to store in another string all characters from column 7 to column 17, including spaces, so the new string woul...
1
2009-11-10T18:13:41Z
1,710,065
<pre><code>another_list = [] for line in f: another_list.append(line[6:17]) </code></pre> <p>Or as a generator (a memory friendly solution):</p> <pre><code>another_list = (line[6:17] for line in f) </code></pre>
5
2009-11-10T18:17:36Z
[ "python", "text-processing" ]
How to read, in a line, all characters from column A to B
1,710,030
<p>is it possible in Python, given a file with 10000 lines, where all of them have this structure:</p> <p>1, 2, xvfrt ert5a fsfs4 df f fdfd56 , 234</p> <p>or similar, to read the whole string, and then to store in another string all characters from column 7 to column 17, including spaces, so the new string woul...
1
2009-11-10T18:13:41Z
1,710,066
<p>You don't say how you want to store the data from each of the 10,000 lines -- if you want them in a list, you would do something like this:</p> <pre><code>my_list = [] for line in open(filename): my_list.append(line[7:18]) </code></pre>
1
2009-11-10T18:17:44Z
[ "python", "text-processing" ]
How to read, in a line, all characters from column A to B
1,710,030
<p>is it possible in Python, given a file with 10000 lines, where all of them have this structure:</p> <p>1, 2, xvfrt ert5a fsfs4 df f fdfd56 , 234</p> <p>or similar, to read the whole string, and then to store in another string all characters from column 7 to column 17, including spaces, so the new string woul...
1
2009-11-10T18:13:41Z
1,710,076
<pre><code>lst = [line[6:17] for line in open(fname)] </code></pre>
7
2009-11-10T18:18:40Z
[ "python", "text-processing" ]
How to read, in a line, all characters from column A to B
1,710,030
<p>is it possible in Python, given a file with 10000 lines, where all of them have this structure:</p> <p>1, 2, xvfrt ert5a fsfs4 df f fdfd56 , 234</p> <p>or similar, to read the whole string, and then to store in another string all characters from column 7 to column 17, including spaces, so the new string woul...
1
2009-11-10T18:13:41Z
1,710,084
<p>This functionw will compute the string that you want and print it out</p> <pre><code>def readCols(filepath): f = open(filepath, 'r') for line in file: newString = line[6:17] print newString </code></pre>
0
2009-11-10T18:19:29Z
[ "python", "text-processing" ]
How to read, in a line, all characters from column A to B
1,710,030
<p>is it possible in Python, given a file with 10000 lines, where all of them have this structure:</p> <p>1, 2, xvfrt ert5a fsfs4 df f fdfd56 , 234</p> <p>or similar, to read the whole string, and then to store in another string all characters from column 7 to column 17, including spaces, so the new string woul...
1
2009-11-10T18:13:41Z
1,710,734
<p>This technically answers the direct question:</p> <pre><code>lst = [line[6:17] for line in open(fname)] </code></pre> <p>but there is a fatal flaw. It is OK for throwaway code, but that data looks suspiciously like comma separated values, and the third field may even be space delimited chunks of data. Far better t...
1
2009-11-10T19:54:51Z
[ "python", "text-processing" ]
How to read, in a line, all characters from column A to B
1,710,030
<p>is it possible in Python, given a file with 10000 lines, where all of them have this structure:</p> <p>1, 2, xvfrt ert5a fsfs4 df f fdfd56 , 234</p> <p>or similar, to read the whole string, and then to store in another string all characters from column 7 to column 17, including spaces, so the new string woul...
1
2009-11-10T18:13:41Z
1,715,792
<p>I'm going to take Michael Dillon's answer a little further. If by "columns 6 through 17" you mean "the first 11 characters of the third comma-separated field", this is a good opportunity to use the <code>csv</code> module. Also, for Python 2.6 and above it's considered best practice to use the 'with' statement whe...
2
2009-11-11T15:09:54Z
[ "python", "text-processing" ]
[Resolved]Python socket not receiving anything
1,710,070
<p>I'm trying to receive a variable length stream from a camera with python, but get weird behaviour. This is Python 2.6.4 (r264:75706) on linux(Ubuntu 9.10)</p> <p>The message is supposed to come with a static header followed by the size, and rest of the stream. here is the code</p> <pre><code>from socket import * i...
0
2009-11-10T18:18:13Z
1,710,213
<p>You don't really know how many bytes you received, since your code is:</p> <pre><code>data='' while len(data)&lt;10: chunk = tcpCliSock.recv(1024) print 'recv\'d %d bites'%len(data) data=data+chunk </code></pre> <p>i.e., you're receiving bytes in <code>chunk</code>, but what you're printing...
1
2009-11-10T18:39:30Z
[ "python", "sockets", "nonblocking" ]
[Resolved]Python socket not receiving anything
1,710,070
<p>I'm trying to receive a variable length stream from a camera with python, but get weird behaviour. This is Python 2.6.4 (r264:75706) on linux(Ubuntu 9.10)</p> <p>The message is supposed to come with a static header followed by the size, and rest of the stream. here is the code</p> <pre><code>from socket import * i...
0
2009-11-10T18:18:13Z
1,717,693
<p>Problem is resolved, interestingly shutdown(1) was causing the problem, the other side does not like http style shutdowns. There are also obvious typos and missing checks but they are not <em>the</em> problem.</p>
0
2009-11-11T20:01:36Z
[ "python", "sockets", "nonblocking" ]
Using QFrame to display different panes of information?
1,710,274
<p>I'm trying to get a QFrame to serve as a "display area" for a couple different kinds of information, eg: you click on something in a list view and an info pane shows up in the frame to give you information about it, you click on a different item and a different pane shows up.</p> <p>Having trouble swapping the dif...
0
2009-11-10T18:47:53Z
1,710,568
<p>Using <a href="http://doc.trolltech.com/4.5/qstackedwidget.html" rel="nofollow"><code>QStackedWidget</code></a> is probably the most standard solution.</p>
2
2009-11-10T19:30:30Z
[ "python", "qt", "pyqt" ]
A server side component for tracking a large number of RSS & Atom feeds
1,710,718
<p>I am looking for an open source component that can help me track a large number of <a href="http://en.wikipedia.org/wiki/RSS" rel="nofollow">RSS</a> feeds (>> 10K RSS sources).</p> <p>I don't care about the programming language, but it should be something with a simple API where I can add or remove RSS feeds and as...
1
2009-11-10T19:52:46Z
1,731,002
<p>I found this site. Most of these seem to be client apps but some listed APIs. Not sure if there's something here for you. <a href="http://java-source.net/open-source/rss-rdf-tools" rel="nofollow">http://java-source.net/open-source/rss-rdf-tools</a></p>
0
2009-11-13T18:25:06Z
[ "java", "python", "rss", "atom" ]
wxPython : Problem updating background color of controls
1,710,724
<p>[EDIT - Reduced and re-posted code, restated question]</p> <p>I would like to change the background color of a frame (or panel; whichever makes it work). The problem is that the background color of controls on that frame (or panel) don't have their background color updated until I click on the control (the slider c...
1
2009-11-10T19:53:16Z
1,713,033
<p>Try putting a panel in each frame and then putting your controls on the panel. In wxPython, frames don't like to have multiple windows (especially for Windows OS), so it usually helps to have the frame own one panel and the panel to own the other controls.</p> <p>If this doesn't solve the problem, please to to phr...
1
2009-11-11T04:34:04Z
[ "python", "wxpython" ]
wxPython : Problem updating background color of controls
1,710,724
<p>[EDIT - Reduced and re-posted code, restated question]</p> <p>I would like to change the background color of a frame (or panel; whichever makes it work). The problem is that the background color of controls on that frame (or panel) don't have their background color updated until I click on the control (the slider c...
1
2009-11-10T19:53:16Z
1,732,169
<p>Try generating and processing a wx.SysColourChangedEvent.</p> <pre><code> def onDarken(self, event): self.panel_1.SetBackgroundColour(wx.Colour(self.sliderDarken.GetValue(),self.sliderDarken.GetValue(),self.sliderDarken.GetValue())) event = wx.SysColourChangedEvent() self.ProcessEvent(even...
1
2009-11-13T21:56:28Z
[ "python", "wxpython" ]
Creating a PyBuffer from a C struct
1,710,820
<p><em>EDIT: Upon re-reading my original question I realized very quickly that it was very poorly worded, ambiguous, and too confusing to ever get a decent answer. That's what I get for rushing out a question at the end of my lunch break. Hopefully this will be clearer:</em></p> <p>I am trying to expose a simple C str...
1
2009-11-10T20:05:36Z
1,964,886
<p>The set of methods to implement so that your extension type supports the buffer protocol is described here: <a href="http://docs.python.org/3.1/c-api/typeobj.html#buffer-object-structures" rel="nofollow">http://docs.python.org/3.1/c-api/typeobj.html#buffer-object-structures</a></p> <p>I recognize that the documenta...
1
2009-12-27T01:29:55Z
[ "python", "python-3.x", "pybuffer" ]
Custom distutils commands
1,710,839
<p>I have a library called "example" that I'm installing into my global site-packages directory. However, I'd like to be able to install two versions, one for production and one for testing (I have a web application and other things that are versioned this way).</p> <p>Is there a way to specify, say "python setup.py ...
21
2009-11-10T20:08:02Z
1,711,234
<p>If you'd like to use multiple version then <a href="http://pypi.python.org/pypi/virtualenv" rel="nofollow">virtualenv</a> with <a href="http://www.doughellmann.com/projects/virtualenvwrapper/" rel="nofollow">virtualenvwrapper</a> can help.</p>
4
2009-11-10T21:14:38Z
[ "python", "deployment", "distutils" ]
Custom distutils commands
1,710,839
<p>I have a library called "example" that I'm installing into my global site-packages directory. However, I'd like to be able to install two versions, one for production and one for testing (I have a web application and other things that are versioned this way).</p> <p>Is there a way to specify, say "python setup.py ...
21
2009-11-10T20:08:02Z
1,712,268
<p>Sure, you can extend distutils with new commands. In your distutil configuration file, add:</p> <pre><code> [global] command-packages=foo.bar </code></pre> <p>this can be in <code>distutils.cfg</code> in the <code>distutils</code> package itself, <code>..pydistutils.cfg</code> in your home directory (no leading ...
12
2009-11-11T00:41:01Z
[ "python", "deployment", "distutils" ]
Custom distutils commands
1,710,839
<p>I have a library called "example" that I'm installing into my global site-packages directory. However, I'd like to be able to install two versions, one for production and one for testing (I have a web application and other things that are versioned this way).</p> <p>Is there a way to specify, say "python setup.py ...
21
2009-11-10T20:08:02Z
1,712,279
<p>See <a href="http://stackoverflow.com/questions/1710839/custom-distutils-commands/1712268#1712268">Alex's answer</a> if you want a way to do this with distutils, but I find <a href="http://www.blueskyonmars.com/projects/paver/" rel="nofollow">Paver</a> to be better for this kind of thing. It makes it a lot easier t...
3
2009-11-11T00:43:57Z
[ "python", "deployment", "distutils" ]
Custom distutils commands
1,710,839
<p>I have a library called "example" that I'm installing into my global site-packages directory. However, I'd like to be able to install two versions, one for production and one for testing (I have a web application and other things that are versioned this way).</p> <p>Is there a way to specify, say "python setup.py ...
21
2009-11-10T20:08:02Z
1,712,544
<p>This can easily be done with distutils by subclassing <strong>distutils.core.Command</strong> inside of setup.py.</p> <p>For example:</p> <pre><code>from distutils.core import setup, Command import os, sys class CleanCommand(Command): description = "custom clean command that forcefully removes dist/build dire...
47
2009-11-11T02:07:20Z
[ "python", "deployment", "distutils" ]
running a system command in a python script
1,710,967
<p>I have been going through "A byte of Python" to learn the syntax and methods etc...</p> <p>I have just started with a simple backup script (straight from the book): </p> <pre><code>#!/usr/bin/python # Filename: backup_ver1.py import os import time # 1. The files and directories to be backed up are specified in...
4
2009-11-10T20:28:58Z
1,710,996
<p>It would help us if you could format your code as code; select the code parts, and click on the "Code Sample" button in the editor toolbar. The icon looks like "101/010" and if you hold the mouse pointer over it, the yellow "tool tip" box says "Code Sample &lt;pre>&lt;/pre> Ctrl+K"</p> <p>I just tried it, and if y...
0
2009-11-10T20:33:39Z
[ "python" ]
running a system command in a python script
1,710,967
<p>I have been going through "A byte of Python" to learn the syntax and methods etc...</p> <p>I have just started with a simple backup script (straight from the book): </p> <pre><code>#!/usr/bin/python # Filename: backup_ver1.py import os import time # 1. The files and directories to be backed up are specified in...
4
2009-11-10T20:28:58Z
1,711,030
<p>Are you sure that the Python script is seeing the same environment you have access to when you enter the command manually in the shell? It could be that zip isn't on the path when Python launches the command.</p>
1
2009-11-10T20:39:18Z
[ "python" ]
running a system command in a python script
1,710,967
<p>I have been going through "A byte of Python" to learn the syntax and methods etc...</p> <p>I have just started with a simple backup script (straight from the book): </p> <pre><code>#!/usr/bin/python # Filename: backup_ver1.py import os import time # 1. The files and directories to be backed up are specified in...
4
2009-11-10T20:28:58Z
1,711,236
<p>The next step I recommend is to modify your script to print the command string, and just look at the string and see if it seems correct.</p> <p>Another thing you can try is to make a batch file that prints out the environment variables, and have Python run that, and see what the environment looks like. Especially ...
0
2009-11-10T21:14:43Z
[ "python" ]
running a system command in a python script
1,710,967
<p>I have been going through "A byte of Python" to learn the syntax and methods etc...</p> <p>I have just started with a simple backup script (straight from the book): </p> <pre><code>#!/usr/bin/python # Filename: backup_ver1.py import os import time # 1. The files and directories to be backed up are specified in...
4
2009-11-10T20:28:58Z
2,033,414
<p>zip command only work in linux not for windows.. thats why it make an error..</p>
0
2010-01-09T12:54:14Z
[ "python" ]
Komodo - watch variables and execute code while on pause in the program
1,711,193
<p>With c# in the Visual Studio IDE I can pause at anytime a program and watch its variables, inspect whatever I want. I noticed that with the Komodo IDE when something crashes and it stops the flow of the program, I can do exactly the same. But for some reason, it seems that when I try to do the same when I manually p...
2
2009-11-10T21:07:41Z
1,711,462
<p>If you put </p> <pre><code>import code code.interact(local=locals()) </code></pre> <p>in your program, then you will be dumped to a python interpreter. (See <a href="http://stackoverflow.com/questions/1637198/method-to-peek-at-a-running-python-program/1637277#1637277">http://stackoverflow.com/questions/1637198/met...
3
2009-11-10T21:47:34Z
[ "python", "komodo", "komodoedit" ]
Python 2.6 on Debian Lenny. Where should the executable go?
1,711,200
<p>I am building python2.6 from source on Debian Lenny. </p> <p>( ./configure make make altinstall )</p> <p>I don't want it to conflict with anything existing, but I want it to be in the default search path for bash. </p> <p>Suggestions?</p> <p>(ps, I'm using a vm, so I can trash it and rebuild.)</p>
0
2009-11-10T21:08:13Z
1,711,218
<p>I would recommend to fetch the source package from testing or unstable and to rebuild it locally so that you get a .deb instead. Doesn't backports.org have it?</p> <p><em>Edit:</em> Debian has python2.6 only in experimental, see <a href="http://packages.debian.org/search?keywords=python2.6" rel="nofollow">here</a>...
2
2009-11-10T21:11:25Z
[ "python", "linux", "debian" ]
Python 2.6 on Debian Lenny. Where should the executable go?
1,711,200
<p>I am building python2.6 from source on Debian Lenny. </p> <p>( ./configure make make altinstall )</p> <p>I don't want it to conflict with anything existing, but I want it to be in the default search path for bash. </p> <p>Suggestions?</p> <p>(ps, I'm using a vm, so I can trash it and rebuild.)</p>
0
2009-11-10T21:08:13Z
1,711,244
<p>That's the purpose of <code>/usr/local</code> according to the <a href="http://www.pathname.com/fhs/" rel="nofollow">FHS</a>.</p> <blockquote> <p>The /usr/local hierarchy is for use by the system administrator when installing software locally.</p> </blockquote> <p>I think configure typically defaults to /usr/loc...
9
2009-11-10T21:16:06Z
[ "python", "linux", "debian" ]
Python 2.6 on Debian Lenny. Where should the executable go?
1,711,200
<p>I am building python2.6 from source on Debian Lenny. </p> <p>( ./configure make make altinstall )</p> <p>I don't want it to conflict with anything existing, but I want it to be in the default search path for bash. </p> <p>Suggestions?</p> <p>(ps, I'm using a vm, so I can trash it and rebuild.)</p>
0
2009-11-10T21:08:13Z
1,711,264
<p>I strongly recommend you do one of these two options.</p> <ul> <li><p>Build a .deb package, and then install the .deb package; the installed then go in the usual places (/usr/bin/python26 for the main interpreter).</p></li> <li><p>Build from source, and install from source into /usr/local/bin.</p></li> </ul> <p>I ...
3
2009-11-10T21:18:31Z
[ "python", "linux", "debian" ]
Python 2.6 on Debian Lenny. Where should the executable go?
1,711,200
<p>I am building python2.6 from source on Debian Lenny. </p> <p>( ./configure make make altinstall )</p> <p>I don't want it to conflict with anything existing, but I want it to be in the default search path for bash. </p> <p>Suggestions?</p> <p>(ps, I'm using a vm, so I can trash it and rebuild.)</p>
0
2009-11-10T21:08:13Z
1,711,271
<p>Your safest bet is to put Python 2.6 in <code>/opt</code> (<code>./configure --prefix=/opt</code>), and modify <code>/etc/profile</code> so that <code>/opt/bin</code> is searched first. </p>
0
2009-11-10T21:19:53Z
[ "python", "linux", "debian" ]
Python 2.6 on Debian Lenny. Where should the executable go?
1,711,200
<p>I am building python2.6 from source on Debian Lenny. </p> <p>( ./configure make make altinstall )</p> <p>I don't want it to conflict with anything existing, but I want it to be in the default search path for bash. </p> <p>Suggestions?</p> <p>(ps, I'm using a vm, so I can trash it and rebuild.)</p>
0
2009-11-10T21:08:13Z
1,711,502
<p>It has already been mentioned, but I'll run through it anyway...</p> <p>Add experimental to the bottom of your /etc/apt/sources.list</p> <p><code>apt-get update</code></p> <p><code>aptitude -t experimental install python2.6 python2.6-dev</code></p> <p>It will pull the requisite updates from experimental into sta...
-1
2009-11-10T21:53:56Z
[ "python", "linux", "debian" ]
Help installing cx_Oracle
1,711,408
<p>I'm trying to install the cx_Oracle for Python 2.6, but it is failing. I don't know enough about C or MS Vis. Studio's compiler to even approach fixing it myself.</p> <p>This is what is output on the command line:</p> <pre class="lang-none prettyprint-override"><code>C:\pydev\cx_Oracle-5.0.1&gt;C:\python26\python...
18
2009-11-10T21:38:03Z
1,711,468
<p>Why don't you use a binary package like <a href="http://prdownloads.sourceforge.net/cx-oracle/cx%5FOracle-5.0.2-10g.win32-py2.6.msi?download">Windows Installer (Oracle 10g, Python 2.6)</a>?</p> <p>See <a href="http://cx-oracle.sourceforge.net/">http://cx-oracle.sourceforge.net/</a> for other binary packages</p> <p...
17
2009-11-10T21:48:05Z
[ "python", "cx-oracle" ]
Help installing cx_Oracle
1,711,408
<p>I'm trying to install the cx_Oracle for Python 2.6, but it is failing. I don't know enough about C or MS Vis. Studio's compiler to even approach fixing it myself.</p> <p>This is what is output on the command line:</p> <pre class="lang-none prettyprint-override"><code>C:\pydev\cx_Oracle-5.0.1&gt;C:\python26\python...
18
2009-11-10T21:38:03Z
1,711,623
<p>You also need some type of Oracle client installed on your machine, since cx_Oracle is just a bridge between Python and the Oracle Client. Valid Oracle Clients include a full Oracle installation (like Standard or XE) or the <a href="http://www.oracle.com/technology/tech/oci/instantclient/index.html">Instant Client<...
8
2009-11-10T22:15:10Z
[ "python", "cx-oracle" ]
Help installing cx_Oracle
1,711,408
<p>I'm trying to install the cx_Oracle for Python 2.6, but it is failing. I don't know enough about C or MS Vis. Studio's compiler to even approach fixing it myself.</p> <p>This is what is output on the command line:</p> <pre class="lang-none prettyprint-override"><code>C:\pydev\cx_Oracle-5.0.1&gt;C:\python26\python...
18
2009-11-10T21:38:03Z
33,067,976
<p>If you use Anaconda Python x64, things are <a href="https://anaconda.org/anaconda/cx_oracle" rel="nofollow">easier</a>:</p> <pre><code>conda install -c https://conda.anaconda.org/anaconda cx_oracle </code></pre> <p>(It will install the right Oracle client)</p> <hr> <p>If you get the following error:</p> <pre><c...
3
2015-10-11T17:30:14Z
[ "python", "cx-oracle" ]
Python web hosting: Why are server restarts necessary?
1,711,483
<p>We currently run a small shared hosting service for a couple of hundred small PHP sites on our servers. We'd like to offer Python support too, but from our initial research at least, a server restart seems to be required after each source code change.</p> <p>Is this really the case? If so, we're just not going to...
6
2009-11-10T21:50:06Z
1,711,578
<p>Depends on how you deploy the Python application. If it is as a pure Python CGI script, no restarts are necessary (not advised at all though, because it will be super slow). If you are using modwsgi in Apache, there are valid ways of <a href="http://code.google.com/p/modwsgi/wiki/ReloadingSourceCode" rel="nofollow">...
4
2009-11-10T22:06:45Z
[ "python", "web-hosting" ]
Python web hosting: Why are server restarts necessary?
1,711,483
<p>We currently run a small shared hosting service for a couple of hundred small PHP sites on our servers. We'd like to offer Python support too, but from our initial research at least, a server restart seems to be required after each source code change.</p> <p>Is this really the case? If so, we're just not going to...
6
2009-11-10T21:50:06Z
1,711,705
<p>Python is a compiled language; the compiled byte code is cached by the Python process for later use, to improve performance. PHP, by default, is interpreted. It's a tradeoff between usability and speed.</p> <p>If you're using a standard WSGI module, such as Apache's <code>mod_wsgi</code>, then you don't have to res...
7
2009-11-10T22:30:35Z
[ "python", "web-hosting" ]
Python web hosting: Why are server restarts necessary?
1,711,483
<p>We currently run a small shared hosting service for a couple of hundred small PHP sites on our servers. We'd like to offer Python support too, but from our initial research at least, a server restart seems to be required after each source code change.</p> <p>Is this really the case? If so, we're just not going to...
6
2009-11-10T21:50:06Z
1,711,851
<blockquote> <p>Is this really the case?</p> </blockquote> <p>It Depends. Code reloading is highly specific to the hosting solution. Most servers provide some way to automatically reload the WSGI script itself, but there's no standardisation; indeed, the question of how a WSGI Application object is connected to a we...
3
2009-11-10T22:58:47Z
[ "python", "web-hosting" ]
Python: "Indentation Error: unindent does not match any outer indentation level"
1,711,756
<p>I just can't figure out what's wrong with this...</p> <pre><code>#!/usr/bin/env python # # Bugs.py # from __future__ import division # No Module! if __name__ != '__main__': print "Bugs.py is not meant to be a module" exit() # App import pygame, sys, random, math pygame.init() # Configurati...
13
2009-11-10T22:38:02Z
1,711,766
<p>It's possible that you have mixed tabs and spaces in your file. You can have python help check for such errors with</p> <pre><code>python -m tabnanny &lt;name of python file&gt; </code></pre>
38
2009-11-10T22:40:47Z
[ "python", "indentation" ]
Python: "Indentation Error: unindent does not match any outer indentation level"
1,711,756
<p>I just can't figure out what's wrong with this...</p> <pre><code>#!/usr/bin/env python # # Bugs.py # from __future__ import division # No Module! if __name__ != '__main__': print "Bugs.py is not meant to be a module" exit() # App import pygame, sys, random, math pygame.init() # Configurati...
13
2009-11-10T22:38:02Z
1,711,768
<p>You probably have a mixture of spaces and tabs in your original source file. Replace all the tabs with four spaces (or vice versa) and you should see the problem straight away.</p> <p>Your code as pasted into your question doesn't have this problem, but I guess your editor (or your web browser, or Stack Overflow i...
5
2009-11-10T22:41:05Z
[ "python", "indentation" ]
Python: "Indentation Error: unindent does not match any outer indentation level"
1,711,756
<p>I just can't figure out what's wrong with this...</p> <pre><code>#!/usr/bin/env python # # Bugs.py # from __future__ import division # No Module! if __name__ != '__main__': print "Bugs.py is not meant to be a module" exit() # App import pygame, sys, random, math pygame.init() # Configurati...
13
2009-11-10T22:38:02Z
1,711,790
<p>Maybe it's this part:</p> <pre><code>if speed &gt; self.buginfo["maxspeed"]: self.buginfo["maxspeed"] = speed if generation &gt; self.buginfo["maxgen"] : self.buginfo["maxgen"] = generation </code></pre> <p>Try to remove the extra space to make it look aligned.</p> <p>Edit: from <a href="http://www.python...
0
2009-11-10T22:46:23Z
[ "python", "indentation" ]
Python: "Indentation Error: unindent does not match any outer indentation level"
1,711,756
<p>I just can't figure out what's wrong with this...</p> <pre><code>#!/usr/bin/env python # # Bugs.py # from __future__ import division # No Module! if __name__ != '__main__': print "Bugs.py is not meant to be a module" exit() # App import pygame, sys, random, math pygame.init() # Configurati...
13
2009-11-10T22:38:02Z
1,711,800
<p>I would recommend checking your indentation levels all the way through. Make sure that you are using either tabs all the way or spaces all the way, with no mixture. I have had odd indentation problems in the past which have been caused by a mixture.</p>
0
2009-11-10T22:48:08Z
[ "python", "indentation" ]
Python: "Indentation Error: unindent does not match any outer indentation level"
1,711,756
<p>I just can't figure out what's wrong with this...</p> <pre><code>#!/usr/bin/env python # # Bugs.py # from __future__ import division # No Module! if __name__ != '__main__': print "Bugs.py is not meant to be a module" exit() # App import pygame, sys, random, math pygame.init() # Configurati...
13
2009-11-10T22:38:02Z
3,218,613
<p>Don't forget the use of """ comments. These need precise indentation too (a 1/2 hr job for me resolving this damn error too!)</p>
2
2010-07-10T09:15:41Z
[ "python", "indentation" ]
Python: "Indentation Error: unindent does not match any outer indentation level"
1,711,756
<p>I just can't figure out what's wrong with this...</p> <pre><code>#!/usr/bin/env python # # Bugs.py # from __future__ import division # No Module! if __name__ != '__main__': print "Bugs.py is not meant to be a module" exit() # App import pygame, sys, random, math pygame.init() # Configurati...
13
2009-11-10T22:38:02Z
4,106,986
<p>Sorry I can't add comments as my reputation is not high enough :-/, so this will have to be an answer.</p> <p>As several have commented, the code you have posted contains several (5) syntax errors (twice = instead of == and three ':' missing).</p> <p>Once the syntax errors corrected I do not have any issue, be it ...
0
2010-11-05T14:48:39Z
[ "python", "indentation" ]
Python: "Indentation Error: unindent does not match any outer indentation level"
1,711,756
<p>I just can't figure out what's wrong with this...</p> <pre><code>#!/usr/bin/env python # # Bugs.py # from __future__ import division # No Module! if __name__ != '__main__': print "Bugs.py is not meant to be a module" exit() # App import pygame, sys, random, math pygame.init() # Configurati...
13
2009-11-10T22:38:02Z
7,908,280
<p>I am using gedit basic version that comes with Ubuntu 11.10. I had the same error. This is mainly caused when you mix spaces with tabs.</p> <p>A good way to differentiate as to which lines have problem would be to go to: 1. edit 2. preferences 3. editor 4. check "automatic indentation" 5. increase the indentation t...
2
2011-10-26T20:10:24Z
[ "python", "indentation" ]
Python: "Indentation Error: unindent does not match any outer indentation level"
1,711,756
<p>I just can't figure out what's wrong with this...</p> <pre><code>#!/usr/bin/env python # # Bugs.py # from __future__ import division # No Module! if __name__ != '__main__': print "Bugs.py is not meant to be a module" exit() # App import pygame, sys, random, math pygame.init() # Configurati...
13
2009-11-10T22:38:02Z
15,199,127
<p>Geany has an option in its menus that says 'Apply Default Intendation' which replaces tabs by the number of spaces if specified in Geany's settings</p>
0
2013-03-04T10:13:26Z
[ "python", "indentation" ]
Python: "Indentation Error: unindent does not match any outer indentation level"
1,711,756
<p>I just can't figure out what's wrong with this...</p> <pre><code>#!/usr/bin/env python # # Bugs.py # from __future__ import division # No Module! if __name__ != '__main__': print "Bugs.py is not meant to be a module" exit() # App import pygame, sys, random, math pygame.init() # Configurati...
13
2009-11-10T22:38:02Z
36,783,689
<p><b>IDLE TO VISUAL STUDIO USERS:</b> I ran into this problem as well when moving code directly from IDLE to Visual Studio. When you press tab IDLE adds 4 spaces instead of a tab. In IDLE, hit Ctl+A to select all of the code and go to Format>Tabify Region. Now move the code to visual studio and most errors should be f...
0
2016-04-22T02:22:50Z
[ "python", "indentation" ]
Python: "Indentation Error: unindent does not match any outer indentation level"
1,711,756
<p>I just can't figure out what's wrong with this...</p> <pre><code>#!/usr/bin/env python # # Bugs.py # from __future__ import division # No Module! if __name__ != '__main__': print "Bugs.py is not meant to be a module" exit() # App import pygame, sys, random, math pygame.init() # Configurati...
13
2009-11-10T22:38:02Z
39,218,976
<p>I had a similar problem with IndentationError in PyCharm.</p> <p>I could not find any tabs in my code, but once I deleted code AFTER the line with the IndentationError, all was well.</p> <p>I suspect that you had a tab in the following line: <code> sex = sex if not sex == 2 else random.randint(0,1) <...
0
2016-08-30T04:52:52Z
[ "python", "indentation" ]
Python: "Indentation Error: unindent does not match any outer indentation level"
1,711,756
<p>I just can't figure out what's wrong with this...</p> <pre><code>#!/usr/bin/env python # # Bugs.py # from __future__ import division # No Module! if __name__ != '__main__': print "Bugs.py is not meant to be a module" exit() # App import pygame, sys, random, math pygame.init() # Configurati...
13
2009-11-10T22:38:02Z
39,419,027
<p>I had this same problem and it had nothing to do with tabs. This was my problem code:</p> <pre><code>def genericFunction(variable): for line in variable: line = variable if variable != None: return variable </code></pre> <p>Note the above <code>for</code> is indented with more spaces than t...
0
2016-09-09T20:07:34Z
[ "python", "indentation" ]
Accessing a matrix element by matrix[(a, b), c] instead of matrix[a, b, c]
1,711,865
<p>I want to achieve the following:</p> <ol> <li>Have a AxBxC matrix (where A,B,C are integers).</li> <li>Access that matrix not as matrix[a, b, c] but as matrix[(a, b), c], this is, I have two variables, var1 = (x, y) and var2 = z and want access my matrix as matrix[var1, var2].</li> </ol> <p>How can this be done? I...
0
2009-11-10T23:01:50Z
1,711,950
<p>If <code>var1 = (x,y)</code>, and <code>var2 = z</code>, you can use</p> <pre><code>matrix[var1][var2] </code></pre>
3
2009-11-10T23:18:35Z
[ "python", "numpy" ]
Accessing a matrix element by matrix[(a, b), c] instead of matrix[a, b, c]
1,711,865
<p>I want to achieve the following:</p> <ol> <li>Have a AxBxC matrix (where A,B,C are integers).</li> <li>Access that matrix not as matrix[a, b, c] but as matrix[(a, b), c], this is, I have two variables, var1 = (x, y) and var2 = z and want access my matrix as matrix[var1, var2].</li> </ol> <p>How can this be done? I...
0
2009-11-10T23:01:50Z
1,712,006
<p>I think you can simply subclass the NumPy matrix type, with a new class of your own; and overload the <code>__getitem__()</code> nethod to accept a tuple. Something like this:</p> <pre><code>class SpecialMatrix(np.matrix): def __getitem__(self, arg1, arg2, arg3=None): try: i, j = arg1 ...
1
2009-11-10T23:33:23Z
[ "python", "numpy" ]
JavaScript equivalent of Python's __setitem__
1,712,074
<pre><code>var obj = {} obj.__setitem__ = function(key, value){ this[key] = value * value } obj.x = 2 // 4 obj.y = 3 // 9 </code></pre> <p>JavaScript doesn't have __setitem__ and this example obviously doesn't work.</p> <p>In python <a href="http://docs.python.org/reference/datamodel.html#object.__setitem__">__se...
7
2009-11-10T23:48:15Z
1,712,126
<blockquote> <p>Is it possible to implement __setitem__ behavior in JavaScript? </p> </blockquote> <p>No. There is no getter/setter for arbitrary properties in JavaScript.</p> <p>In Firefox you can use JavaScript 1.5+'s getters and setters to define <code>x</code> and <code>y</code> properties that square their val...
10
2009-11-11T00:03:16Z
[ "javascript", "python", "syntactic-sugar" ]
JavaScript equivalent of Python's __setitem__
1,712,074
<pre><code>var obj = {} obj.__setitem__ = function(key, value){ this[key] = value * value } obj.x = 2 // 4 obj.y = 3 // 9 </code></pre> <p>JavaScript doesn't have __setitem__ and this example obviously doesn't work.</p> <p>In python <a href="http://docs.python.org/reference/datamodel.html#object.__setitem__">__se...
7
2009-11-10T23:48:15Z
1,712,135
<p>I don't think you can override the [] operator in the current version of Javascript. In current Javascript, objects are largely just associative arrays, so the [] operator just adds a key/value pair to array that is the object.</p> <p>You could write methods that set specific values or even squared a number and ad...
1
2009-11-11T00:04:38Z
[ "javascript", "python", "syntactic-sugar" ]
JavaScript equivalent of Python's __setitem__
1,712,074
<pre><code>var obj = {} obj.__setitem__ = function(key, value){ this[key] = value * value } obj.x = 2 // 4 obj.y = 3 // 9 </code></pre> <p>JavaScript doesn't have __setitem__ and this example obviously doesn't work.</p> <p>In python <a href="http://docs.python.org/reference/datamodel.html#object.__setitem__">__se...
7
2009-11-10T23:48:15Z
1,712,139
<p>you can do this (as objects in javascript are also associative arrays):</p> <pre><code>var obj = {}; obj._ = function(key, value){ this[key] = value * value; } obj._('x', 2); // 4 obj._('y', 3); // 9 alert(obj.x + "," + obj.y); //--&gt; 4,9 </code></pre>
5
2009-11-11T00:05:31Z
[ "javascript", "python", "syntactic-sugar" ]
JavaScript equivalent of Python's __setitem__
1,712,074
<pre><code>var obj = {} obj.__setitem__ = function(key, value){ this[key] = value * value } obj.x = 2 // 4 obj.y = 3 // 9 </code></pre> <p>JavaScript doesn't have __setitem__ and this example obviously doesn't work.</p> <p>In python <a href="http://docs.python.org/reference/datamodel.html#object.__setitem__">__se...
7
2009-11-10T23:48:15Z
1,712,152
<p>No, but there are plans for supporting a similar feature in JavaScript 2. The following object literal syntax has been suggested on <a href="https://bugzilla.mozilla.org/show%5Fbug.cgi?id=312116">Mozilla bug 312116</a> and it seems that it might be how it will be done for object literals:</p> <pre><code>({ get * ...
7
2009-11-11T00:07:43Z
[ "javascript", "python", "syntactic-sugar" ]
JavaScript equivalent of Python's __setitem__
1,712,074
<pre><code>var obj = {} obj.__setitem__ = function(key, value){ this[key] = value * value } obj.x = 2 // 4 obj.y = 3 // 9 </code></pre> <p>JavaScript doesn't have __setitem__ and this example obviously doesn't work.</p> <p>In python <a href="http://docs.python.org/reference/datamodel.html#object.__setitem__">__se...
7
2009-11-10T23:48:15Z
1,749,537
<p>There are no true setters and getters in the commonly implemented Javascript versions, so if you want to emulate the effect you have to use some different syntax. For a property <code>obj.x</code>, using <code>obj.x()</code> to access the value of the property and <code>obj.x(123)</code> to set the value seems like ...
5
2009-11-17T15:13:03Z
[ "javascript", "python", "syntactic-sugar" ]
Formatting "yesterday's" date in python
1,712,116
<p>I need to find "yesterday's" date in this format <code>MMDDYY</code> in Python.</p> <p>So for instance, today's date would be represented like this: 111009</p> <p>I can easily do this for today but I have trouble doing it automatically for "yesterday".</p>
85
2009-11-11T00:01:16Z
1,712,127
<pre><code>&gt;&gt;&gt; from datetime import date, timedelta &gt;&gt;&gt; yesterday = date.today() - timedelta(1) &gt;&gt;&gt; print yesterday.strftime('%m%d%y') '110909' </code></pre>
139
2009-11-11T00:03:31Z
[ "python", "datetime", "date" ]
Formatting "yesterday's" date in python
1,712,116
<p>I need to find "yesterday's" date in this format <code>MMDDYY</code> in Python.</p> <p>So for instance, today's date would be represented like this: 111009</p> <p>I can easily do this for today but I have trouble doing it automatically for "yesterday".</p>
85
2009-11-11T00:01:16Z
1,712,128
<p>This should do what you want:</p> <pre><code>import datetime yesterday = datetime.datetime.now() - datetime.timedelta(days = 1) print yesterday.strftime("%m%d%y") </code></pre>
7
2009-11-11T00:03:40Z
[ "python", "datetime", "date" ]
Formatting "yesterday's" date in python
1,712,116
<p>I need to find "yesterday's" date in this format <code>MMDDYY</code> in Python.</p> <p>So for instance, today's date would be represented like this: 111009</p> <p>I can easily do this for today but I have trouble doing it automatically for "yesterday".</p>
85
2009-11-11T00:01:16Z
1,712,129
<pre><code>import datetime now = datetime.datetime.now() now -= datetime.timedelta(days=1) print now.strftime("%m%d%y") </code></pre>
5
2009-11-11T00:03:53Z
[ "python", "datetime", "date" ]
Formatting "yesterday's" date in python
1,712,116
<p>I need to find "yesterday's" date in this format <code>MMDDYY</code> in Python.</p> <p>So for instance, today's date would be represented like this: 111009</p> <p>I can easily do this for today but I have trouble doing it automatically for "yesterday".</p>
85
2009-11-11T00:01:16Z
1,712,130
<p>You can find all the string format codes here: <a href="http://au2.php.net/strftime" rel="nofollow">http://au2.php.net/strftime</a></p> <pre><code>In [1]: import datetime In [2]: today=datetime.date.today() In [3]: yesterday=today-datetime.timedelta(1) In [4]: yesterday.strftime('%m%d%y') Out[4]: '110909' </code...
1
2009-11-11T00:04:02Z
[ "python", "datetime", "date" ]
Formatting "yesterday's" date in python
1,712,116
<p>I need to find "yesterday's" date in this format <code>MMDDYY</code> in Python.</p> <p>So for instance, today's date would be represented like this: 111009</p> <p>I can easily do this for today but I have trouble doing it automatically for "yesterday".</p>
85
2009-11-11T00:01:16Z
1,712,131
<pre><code>from datetime import datetime, timedelta yesterday = datetime.now() - timedelta(days=1) yesterday.strftime('%m%d%y') </code></pre>
103
2009-11-11T00:04:20Z
[ "python", "datetime", "date" ]
Formatting "yesterday's" date in python
1,712,116
<p>I need to find "yesterday's" date in this format <code>MMDDYY</code> in Python.</p> <p>So for instance, today's date would be represented like this: 111009</p> <p>I can easily do this for today but I have trouble doing it automatically for "yesterday".</p>
85
2009-11-11T00:01:16Z
1,712,133
<p>This should do the trick. Stolen from the <a href="http://mail.python.org/pipermail/python-list/2006-May/023647.html" rel="nofollow">python mailing list</a>.</p> <pre><code>from datetime import datetime, timedelta today = datetime.today() yesterday = today - timedelta(1) </code></pre>
3
2009-11-11T00:04:31Z
[ "python", "datetime", "date" ]
Formatting "yesterday's" date in python
1,712,116
<p>I need to find "yesterday's" date in this format <code>MMDDYY</code> in Python.</p> <p>So for instance, today's date would be represented like this: 111009</p> <p>I can easily do this for today but I have trouble doing it automatically for "yesterday".</p>
85
2009-11-11T00:01:16Z
7,917,292
<p>if you want a one-liner...</p> <pre><code>from datetime import datetime, timedelta yesterday = (date.today() - timedelta(days=1)).strftime('%m%d%y') </code></pre>
-3
2011-10-27T14:20:06Z
[ "python", "datetime", "date" ]