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 |
|---|---|---|---|---|---|---|---|---|---|
PHP Frameworks (CodeIgniter, Yii, CakePHP) vs. Django | 2,578,540 | <p>I have to develop a site which has to accomodate around 2000 users a day and speed is a criterion for it. Moreover, the site is a user oriented one where the user will be able to log in and check his profile, register for specific events he/she wants to participate in. The site is to be hosted on a VPS server.Althou... | 20 | 2010-04-05T13:18:44Z | 7,084,868 | <p>I am using CodeIgniter 1.7.2 and for complex websites it's very good and powerfull, but it definitely is missing some kind of code generator which will allow for example to build an IT application in one click.
I had the impression (from watching a tutorial) that Django has it.</p>
| 0 | 2011-08-16T20:52:25Z | [
"python",
"django",
"cakephp",
"web-frameworks",
"yii"
] |
PHP Frameworks (CodeIgniter, Yii, CakePHP) vs. Django | 2,578,540 | <p>I have to develop a site which has to accomodate around 2000 users a day and speed is a criterion for it. Moreover, the site is a user oriented one where the user will be able to log in and check his profile, register for specific events he/she wants to participate in. The site is to be hosted on a VPS server.Althou... | 20 | 2010-04-05T13:18:44Z | 10,847,083 | <p>Codeigniter it's fast and very documented also has a large community to and finaly friendly with the programmer.</p>
| 4 | 2012-06-01T08:43:39Z | [
"python",
"django",
"cakephp",
"web-frameworks",
"yii"
] |
Is there an admin plugin for Python Pylon? | 2,578,641 | <p>Im moving from django to pylons, is there an admin app?</p>
| 3 | 2010-04-05T13:40:11Z | 2,578,772 | <p>Not out of the box, but there are few options you can use. See <a href="http://wiki.pylonshq.com/display/pylonscookbook/Forms" rel="nofollow">Forms - Pylons Cookbook - PythonWeb</a> for the options:</p>
<ul>
<li><a href="http://code.google.com/p/formalchemy/" rel="nofollow">formalchemy</a> - the only one I used per... | 3 | 2010-04-05T14:07:55Z | [
"python",
"pylons"
] |
How can I plot NaN values as a special color with imshow in matplotlib? | 2,578,752 | <p>I am trying to use imshow in matplotlib to plot data as a heatmap, but some of the values are NaNs. I'd like the NaNs to be rendered as a special color not found in the colormap.</p>
<p>example:</p>
<pre><code>import numpy as np
import matplotlib.pyplot as plt
f = plt.figure()
ax = f.add_subplot(111)
a = np.arange... | 45 | 2010-04-05T14:03:56Z | 2,578,873 | <p>Hrm, it appears I can use a masked array to do this:</p>
<pre><code>masked_array = np.ma.array (a, mask=np.isnan(a))
cmap = matplotlib.cm.jet
cmap.set_bad('white',1.)
ax.imshow(masked_array, interpolation='nearest', cmap=cmap)
</code></pre>
<p>This should suffice, though I'm still open to suggestions. :]</p>
| 45 | 2010-04-05T14:30:10Z | [
"python",
"matplotlib",
null
] |
How can I plot NaN values as a special color with imshow in matplotlib? | 2,578,752 | <p>I am trying to use imshow in matplotlib to plot data as a heatmap, but some of the values are NaNs. I'd like the NaNs to be rendered as a special color not found in the colormap.</p>
<p>example:</p>
<pre><code>import numpy as np
import matplotlib.pyplot as plt
f = plt.figure()
ax = f.add_subplot(111)
a = np.arange... | 45 | 2010-04-05T14:03:56Z | 10,481,708 | <p>It did not work for me. I was getting error message, so did workaround:</p>
<pre><code>a[3,:] = -999
masked_array=np.ma.masked_where(a==-999, a)
cmap = matplotlib.cm.jet
cmap.set_bad('w',1.)
ax.imshow(masked_array, interpolation='nearest', cmap=cmap)
</code></pre>
| 2 | 2012-05-07T12:01:36Z | [
"python",
"matplotlib",
null
] |
What is the best way to convert a zope DateTime object into Python datetime object? | 2,578,770 | <p>I need to convert a zope 2 DateTime object into a Python datetime object. What is the best way to do that? Thanks, Erika</p>
| 8 | 2010-04-05T14:07:42Z | 2,578,802 | <p>If you mean <a href="http://wiki.zope.org/zope2/DateTime" rel="nofollow">this</a> one</p>
<pre><code>.strftime('%m/%d/%Y %H:%M') = 04/25/2005 10:19
</code></pre>
<p>then reverse is</p>
<pre><code>>>> time.strptime('04/25/2005 10:19','%m/%d/%Y %H:%M')
time.struct_time(tm_year=2005, tm_mon=4, tm_mday=25, ... | 1 | 2010-04-05T14:13:40Z | [
"python",
"zope"
] |
What is the best way to convert a zope DateTime object into Python datetime object? | 2,578,770 | <p>I need to convert a zope 2 DateTime object into a Python datetime object. What is the best way to do that? Thanks, Erika</p>
| 8 | 2010-04-05T14:07:42Z | 2,578,836 | <pre><code>modernthingy = datetime.datetime.fromtimestamp(zopethingy.timeTime())
</code></pre>
<p>The <code>datetime</code> instance is timezone-naive; if you need to support timezones (as Zope2's <code>DateTime</code> does), I recommend third-party extension package <a href="http://pytz.sourceforge.net/">pytz</a>.</p... | 7 | 2010-04-05T14:20:21Z | [
"python",
"zope"
] |
What is the best way to convert a zope DateTime object into Python datetime object? | 2,578,770 | <p>I need to convert a zope 2 DateTime object into a Python datetime object. What is the best way to do that? Thanks, Erika</p>
| 8 | 2010-04-05T14:07:42Z | 2,579,381 | <p>Newer DateTime implementations (2.11 and up) have a <code>asdatetime</code> method that returns a python datetime.datetime instance:</p>
<pre><code>modernthingy = zopethingy.asdatetime()
</code></pre>
| 10 | 2010-04-05T15:59:40Z | [
"python",
"zope"
] |
Sorting HTML table (with anchor tags and data in cells) in Python | 2,578,971 | <p>I have a necessity to sort a given HTML table of the following structure, in Python.</p>
<pre><code><table>
<tr>
<td><a href="#">ABCD</a></td>
<td>A23BND</td>
<td><a title="ABCD">345345</td>
</tr>
<tr>
... | 0 | 2010-04-05T14:49:08Z | 2,579,000 | <p>The <code>sort</code> method has the valueable <code>key</code> and <code>cmp</code> arguments which you can use for custom sorting. If you augment the <code>data</code> data structure with the extra information you need for sorting, you can use either <code>key</code> or <code>cmp</code> (depending on exact need) i... | 0 | 2010-04-05T14:54:06Z | [
"python",
"html",
"sorting",
"html-table"
] |
Sorting HTML table (with anchor tags and data in cells) in Python | 2,578,971 | <p>I have a necessity to sort a given HTML table of the following structure, in Python.</p>
<pre><code><table>
<tr>
<td><a href="#">ABCD</a></td>
<td>A23BND</td>
<td><a title="ABCD">345345</td>
</tr>
<tr>
... | 0 | 2010-04-05T14:49:08Z | 2,579,036 | <p>It sorts by the text because that's what you're extracting as the key when you do</p>
<pre><code>key = elem.findtext(colName)
</code></pre>
<p>I imagine <code>colName</code> is some tag string, and <code>findtext</code> will just find the text of the first subelement matching that tag. If what you want instead is... | 1 | 2010-04-05T15:00:32Z | [
"python",
"html",
"sorting",
"html-table"
] |
Sorting HTML table (with anchor tags and data in cells) in Python | 2,578,971 | <p>I have a necessity to sort a given HTML table of the following structure, in Python.</p>
<pre><code><table>
<tr>
<td><a href="#">ABCD</a></td>
<td>A23BND</td>
<td><a title="ABCD">345345</td>
</tr>
<tr>
... | 0 | 2010-04-05T14:49:08Z | 2,676,928 | <p>I know this wasn't your question, but best practice for this sort of thing is to use Javascript. You will get a much better user experience on your website (if that's what you're doing).</p>
<p>This js library is excellent and easy to use:
<a href="http://www.kryogenix.org/code/browser/sorttable/" rel="nofollow"... | 0 | 2010-04-20T16:37:15Z | [
"python",
"html",
"sorting",
"html-table"
] |
How to Convert DD to DMS in Python | 2,579,535 | <p>How Do you Convert Decimal Degrees to Degrees Minutes Secands In Python? Is there a Formula already written?</p>
| 8 | 2010-04-05T16:32:40Z | 2,579,617 | <p>Use <code>fmod</code> and rounding to get the degrees and fraction separated. Multiply the fraction by 60 and repeat to get minutes and a remainder. Then multiply that last part by 60 again to get the number of seconds.</p>
| 0 | 2010-04-05T16:51:27Z | [
"python"
] |
How to Convert DD to DMS in Python | 2,579,535 | <p>How Do you Convert Decimal Degrees to Degrees Minutes Secands In Python? Is there a Formula already written?</p>
| 8 | 2010-04-05T16:32:40Z | 2,580,001 | <p>Just a couple of <code>* 60</code> multiplications and a couple of <code>int</code> truncations, i.e.:</p>
<pre><code>>>> decdegrees = 31.125
>>> degrees = int(decdegrees)
>>> temp = 60 * (decdegrees - degrees)
>>> minutes = int(temp)
>>> seconds = 60 * (temp - minutes)
... | 5 | 2010-04-05T17:56:02Z | [
"python"
] |
How to Convert DD to DMS in Python | 2,579,535 | <p>How Do you Convert Decimal Degrees to Degrees Minutes Secands In Python? Is there a Formula already written?</p>
| 8 | 2010-04-05T16:32:40Z | 2,580,236 | <p>This is exactly what <code>divmod</code> was invented for:</p>
<pre><code>>>> def decdeg2dms(dd):
... mnt,sec = divmod(dd*3600,60)
... deg,mnt = divmod(mnt,60)
... return deg,mnt,sec
>>> dd = 45 + 30.0/60 + 1.0/3600
>>> print dd
45.5002777778
>>> decdeg2dms(dd)
(45.0, 30.0... | 10 | 2010-04-05T18:32:02Z | [
"python"
] |
How to Convert DD to DMS in Python | 2,579,535 | <p>How Do you Convert Decimal Degrees to Degrees Minutes Secands In Python? Is there a Formula already written?</p>
| 8 | 2010-04-05T16:32:40Z | 10,286,690 | <p>Here is my updated version based upon Paul McGuire's. This one should handle negatives correctly.</p>
<pre><code>def decdeg2dms(dd):
is_positive = dd >= 0
dd = abs(dd)
minutes,seconds = divmod(dd*3600,60)
degrees,minutes = divmod(minutes,60)
degrees = degrees if is_positive else -degrees
return... | 6 | 2012-04-23T19:07:47Z | [
"python"
] |
How to Convert DD to DMS in Python | 2,579,535 | <p>How Do you Convert Decimal Degrees to Degrees Minutes Secands In Python? Is there a Formula already written?</p>
| 8 | 2010-04-05T16:32:40Z | 12,737,895 | <p>If you want to handle negatives properly, the first non-zero measure is set negative. It is counter to common practice to specify all of degrees, minutes and seconds as negative (<a href="http://en.wikipedia.org/wiki/Geographic_coordinate_conversion">Wikipedia</a> shows 40° 26.7717, -79° 56.93172 as a valid exampl... | 5 | 2012-10-05T00:27:06Z | [
"python"
] |
How to Convert DD to DMS in Python | 2,579,535 | <p>How Do you Convert Decimal Degrees to Degrees Minutes Secands In Python? Is there a Formula already written?</p>
| 8 | 2010-04-05T16:32:40Z | 29,576,278 | <p>This is my Python code:</p>
<pre><code>def DecimaltoDMS(Decimal):
d = int(Decimal)
m = int((Decimal - d) * 60)
s = (Decimal - d - m/60) * 3600.00
z= round(s, 2)
if d >= 0:
print ("N ", abs(d), "º ", abs(m), "' ", abs(z), '" ')
else:
print ("S ", abs(d), "º ", abs(m), "' ", abs(z), '" ')
</code></pre>
| 0 | 2015-04-11T09:31:46Z | [
"python"
] |
How to Convert DD to DMS in Python | 2,579,535 | <p>How Do you Convert Decimal Degrees to Degrees Minutes Secands In Python? Is there a Formula already written?</p>
| 8 | 2010-04-05T16:32:40Z | 30,584,601 | <p>The sign has better be returned separately, so that it can be used to choose from <code>('N', 'S')</code> or <code>('E', 'W')</code>, for example.</p>
<pre><code>import math
def dd_to_dms(degs):
neg = degs < 0
degs = (-1) ** neg * degs
degs, d_int = math.modf(degs)
mins, m_int = math.modf(60 * d... | 0 | 2015-06-01T22:49:30Z | [
"python"
] |
Python 2.5.2: remove what found between two lines that contain two concrete strings | 2,579,609 | <p>is there any way to remove what found between two lines that contain two concrete strings?</p>
<p>I mean: I want to remove anything found between 'heaven' and 'hell' in a text file with this text:</p>
<pre><code>I'm in heaven
foobar
I'm in hell
</code></pre>
<p>After executing the script/function i'm asking the t... | 0 | 2010-04-05T16:49:19Z | 2,579,685 | <p>Use a flag to indicate whether you're writing or not.</p>
<pre><code>from __future__ import with_statement
writing = True
with open('myfile.txt') as f:
with open('output.txt') as out:
for line in f:
if writing:
if "heaven" in line:
writing = False
... | 3 | 2010-04-05T17:01:19Z | [
"python",
"lines"
] |
Python 2.5.2: remove what found between two lines that contain two concrete strings | 2,579,609 | <p>is there any way to remove what found between two lines that contain two concrete strings?</p>
<p>I mean: I want to remove anything found between 'heaven' and 'hell' in a text file with this text:</p>
<pre><code>I'm in heaven
foobar
I'm in hell
</code></pre>
<p>After executing the script/function i'm asking the t... | 0 | 2010-04-05T16:49:19Z | 2,579,894 | <p>I apologize but this sounds like a homework problem. We have a policy on these: <a href="http://meta.stackexchange.com/questions/10811/homework-on-stackoverflow">http://meta.stackexchange.com/questions/10811/homework-on-stackoverflow</a></p>
<p>However, what I can say is that the feature @nosklo wrote about <em>is<... | 0 | 2010-04-05T17:36:09Z | [
"python",
"lines"
] |
Python 2.5.2: remove what found between two lines that contain two concrete strings | 2,579,609 | <p>is there any way to remove what found between two lines that contain two concrete strings?</p>
<p>I mean: I want to remove anything found between 'heaven' and 'hell' in a text file with this text:</p>
<pre><code>I'm in heaven
foobar
I'm in hell
</code></pre>
<p>After executing the script/function i'm asking the t... | 0 | 2010-04-05T16:49:19Z | 2,579,916 | <p>You could do something like the following with regular expressions. There are probably more efficient ways to do it since I'm still learning a lot of python, but this should work. </p>
<pre><code>import re
f = open('hh_remove.txt')
lines = f.readlines()
pattern1 = re.compile("heaven",re.I)
pattern2 = re.comp... | 0 | 2010-04-05T17:38:58Z | [
"python",
"lines"
] |
Python 2.5.2: remove what found between two lines that contain two concrete strings | 2,579,609 | <p>is there any way to remove what found between two lines that contain two concrete strings?</p>
<p>I mean: I want to remove anything found between 'heaven' and 'hell' in a text file with this text:</p>
<pre><code>I'm in heaven
foobar
I'm in hell
</code></pre>
<p>After executing the script/function i'm asking the t... | 0 | 2010-04-05T16:49:19Z | 2,580,037 | <p>Looks like by "remove" you mean "rewrite the input file in-place" (or make it look like you're so doing;-), in which case <a href="http://docs.python.org/library/fileinput.html?highlight=fileinput#fileinput.input" rel="nofollow">fileinput.input</a> helps:</p>
<pre><code>import fileinput
writing = True
for line in f... | 1 | 2010-04-05T18:01:50Z | [
"python",
"lines"
] |
Python 2.5.2: remove what found between two lines that contain two concrete strings | 2,579,609 | <p>is there any way to remove what found between two lines that contain two concrete strings?</p>
<p>I mean: I want to remove anything found between 'heaven' and 'hell' in a text file with this text:</p>
<pre><code>I'm in heaven
foobar
I'm in hell
</code></pre>
<p>After executing the script/function i'm asking the t... | 0 | 2010-04-05T16:49:19Z | 2,580,386 | <p>see below. I dont know if it's ok but It seems is working ok.</p>
<pre><code>import re,fileinput,os
for path, dirs, files in os.walk(path):
for filename in files:
fullpath = os.path.join(path, filename)
f = open(fullpath,'r')
data = f.read()
patter = re.compile('Im in heav... | -1 | 2010-04-05T18:55:48Z | [
"python",
"lines"
] |
Do you use the get/set pattern (in Python)? | 2,579,840 | <p>Using get/set seems to be a common practice in Java (for various reasons), but I hardly see Python code that uses this.</p>
<p>Why do you use or avoid get/set methods in Python?</p>
| 49 | 2010-04-05T17:26:20Z | 2,579,864 | <p>Cool link: <a href="http://dirtsimple.org/2004/12/python-is-not-java.html">Python is not Java</a> :)</p>
<blockquote>
<p>In Java, you have to use getters and setters because using public fields gives you no opportunity to go back and change your mind later to using getters and setters. So in Java, you might as we... | 34 | 2010-04-05T17:31:13Z | [
"python",
"getter-setter"
] |
Do you use the get/set pattern (in Python)? | 2,579,840 | <p>Using get/set seems to be a common practice in Java (for various reasons), but I hardly see Python code that uses this.</p>
<p>Why do you use or avoid get/set methods in Python?</p>
| 49 | 2010-04-05T17:26:20Z | 2,579,867 | <p>No, it's unpythonic. The generally accepted way is to use normal data attribute and replace the ones that need more complex get/set logic with properties.</p>
| 11 | 2010-04-05T17:31:27Z | [
"python",
"getter-setter"
] |
Do you use the get/set pattern (in Python)? | 2,579,840 | <p>Using get/set seems to be a common practice in Java (for various reasons), but I hardly see Python code that uses this.</p>
<p>Why do you use or avoid get/set methods in Python?</p>
| 49 | 2010-04-05T17:26:20Z | 2,579,994 | <p>Here is what Guido van Rossum says about that in <a href="http://rads.stackoverflow.com/amzn/click/0596515170"><em>Masterminds of Programming</em></a></p>
<blockquote>
<p><strong>What do you mean by "fighting the language"?</strong></p>
<p><strong>Guido:</strong> That usually means that they're
trying to c... | 17 | 2010-04-05T17:54:29Z | [
"python",
"getter-setter"
] |
Do you use the get/set pattern (in Python)? | 2,579,840 | <p>Using get/set seems to be a common practice in Java (for various reasons), but I hardly see Python code that uses this.</p>
<p>Why do you use or avoid get/set methods in Python?</p>
| 49 | 2010-04-05T17:26:20Z | 2,580,011 | <p>Your observation is correct. This is not a normal style of Python programming. Attributes are all public, so you just access (get, set, delete) them as you would with attributes of any object that has them (not just classes or instances). It's easy to tell when Java programmers learn Python because their Python code... | 4 | 2010-04-05T17:57:24Z | [
"python",
"getter-setter"
] |
Do you use the get/set pattern (in Python)? | 2,579,840 | <p>Using get/set seems to be a common practice in Java (for various reasons), but I hardly see Python code that uses this.</p>
<p>Why do you use or avoid get/set methods in Python?</p>
| 49 | 2010-04-05T17:26:20Z | 2,580,114 | <p>In python, you can just access the attribute directly because it is public:</p>
<pre><code>class MyClass(object):
def __init__(self):
self.my_attribute = 0
my_object = MyClass()
my_object.my_attribute = 1 # etc.
</code></pre>
<p>If you want to do something on access or mutation of the attribute, yo... | 72 | 2010-04-05T18:16:52Z | [
"python",
"getter-setter"
] |
Do you use the get/set pattern (in Python)? | 2,579,840 | <p>Using get/set seems to be a common practice in Java (for various reasons), but I hardly see Python code that uses this.</p>
<p>Why do you use or avoid get/set methods in Python?</p>
| 49 | 2010-04-05T17:26:20Z | 2,580,290 | <p>The short answer to your question is no, you should use properties when needed. Ryan Tamyoko provides the long answer in his article <a href="http://tomayko.com/writings/getters-setters-fuxors" rel="nofollow">Getters/Setters/Fuxors</a></p>
<blockquote>
<p>The basic value to take away from all this is that you wan... | 4 | 2010-04-05T18:41:18Z | [
"python",
"getter-setter"
] |
Do you use the get/set pattern (in Python)? | 2,579,840 | <p>Using get/set seems to be a common practice in Java (for various reasons), but I hardly see Python code that uses this.</p>
<p>Why do you use or avoid get/set methods in Python?</p>
| 49 | 2010-04-05T17:26:20Z | 30,046,345 | <p>Our teacher showed one example on class explaining when we should use accessor functions. </p>
<pre><code>class Woman(Human):
def getAge(self):
if self.age > 30:
return super().getAge() - 10
else:
return super().getAge()
</code></pre>
| -3 | 2015-05-05T07:09:22Z | [
"python",
"getter-setter"
] |
Using set with values from a table | 2,579,866 | <p>I'm writing a database of all DVDs I have at home.
One of the fields, <code>actors</code>, I would like it to be a set of values from an other table, which is storing actors. So for every film I want to store a list of actors, all of which selected from a list of actors, taken from a different table.</p>
<p>Is it p... | 3 | 2010-04-05T17:31:16Z | 2,579,920 | <p>Make your tables like this:</p>
<pre><code>Movies
MovieID int auto increment/identity PK
MovieTitle
MovieDescription
etc...
Actors
ActorID int auto increment/identity PK
ActorName
DateOfBirth
etc...
MovieActors
MovieID PK and FK
ActorID PK and FK
RoleName
etc...
</code></pre>
<p>Don't store multip... | 2 | 2010-04-05T17:39:27Z | [
"python",
"sql",
"mysql",
"django-models"
] |
Using set with values from a table | 2,579,866 | <p>I'm writing a database of all DVDs I have at home.
One of the fields, <code>actors</code>, I would like it to be a set of values from an other table, which is storing actors. So for every film I want to store a list of actors, all of which selected from a list of actors, taken from a different table.</p>
<p>Is it p... | 3 | 2010-04-05T17:31:16Z | 2,579,922 | <p>The answer is clear too. You will need not a field, but another films_actors table. This table would act as your field, but much more reliable. This is called many-to-many relation.</p>
| 1 | 2010-04-05T17:39:29Z | [
"python",
"sql",
"mysql",
"django-models"
] |
How do "and" and "or" work when combined in one statement? | 2,579,959 | <p>For some reason this function confused me:</p>
<pre><code>def protocol(port):
return port == "443" and "https://" or "http://"
</code></pre>
<p>Can somebody explain the order of what's happening behind the scenes to make this work the way it does.</p>
<p>I understood it as this until I tried it:</p>
<p>Eithe... | 3 | 2010-04-05T17:47:39Z | 2,579,972 | <p><code>and</code> returns the right operand if the left is true. <code>or</code> returns the right operand if the left is false. Otherwise they both return the left operand. They are said to <strong>coalesce</strong>.</p>
| 7 | 2010-04-05T17:50:25Z | [
"python",
"boolean-logic",
"if-statement"
] |
How do "and" and "or" work when combined in one statement? | 2,579,959 | <p>For some reason this function confused me:</p>
<pre><code>def protocol(port):
return port == "443" and "https://" or "http://"
</code></pre>
<p>Can somebody explain the order of what's happening behind the scenes to make this work the way it does.</p>
<p>I understood it as this until I tried it:</p>
<p>Eithe... | 3 | 2010-04-05T17:47:39Z | 2,579,973 | <p>It's an old-ish idiom; inserting parentheses to show priority,</p>
<pre><code>(port == "443" and "https://") or "http://"
</code></pre>
<p><code>x and y</code> returns <code>y</code> if <code>x</code> is truish, <code>x</code> if <code>x</code> is falsish; <code>a or b</code>, vice versa, returns <code>a</code> if... | 20 | 2010-04-05T17:50:41Z | [
"python",
"boolean-logic",
"if-statement"
] |
How do "and" and "or" work when combined in one statement? | 2,579,959 | <p>For some reason this function confused me:</p>
<pre><code>def protocol(port):
return port == "443" and "https://" or "http://"
</code></pre>
<p>Can somebody explain the order of what's happening behind the scenes to make this work the way it does.</p>
<p>I understood it as this until I tried it:</p>
<p>Eithe... | 3 | 2010-04-05T17:47:39Z | 2,579,974 | <p>This is an ugly hack that is not recommended. It works because of the short-circuiting behaviour of <code>and</code> and <code>or</code> and that they return the one of their arguments rather than a boolean value. Using this technique gives a risk of introducing hard-to-find bugs, so don't use it in new code.</p>
<... | 2 | 2010-04-05T17:51:09Z | [
"python",
"boolean-logic",
"if-statement"
] |
How do "and" and "or" work when combined in one statement? | 2,579,959 | <p>For some reason this function confused me:</p>
<pre><code>def protocol(port):
return port == "443" and "https://" or "http://"
</code></pre>
<p>Can somebody explain the order of what's happening behind the scenes to make this work the way it does.</p>
<p>I understood it as this until I tried it:</p>
<p>Eithe... | 3 | 2010-04-05T17:47:39Z | 2,579,984 | <p>You may want to read up on the "and / or trick" of Python in this article <a href="http://diveintopython.net/power_of_introspection/and_or.html" rel="nofollow">The Peculiar Nature of And and Or in Python</a>. It's a bit like the <code>IIF()</code> in VBA or VB, or <code>?:</code> in C-style languages.</p>
| 1 | 2010-04-05T17:52:27Z | [
"python",
"boolean-logic",
"if-statement"
] |
How do "and" and "or" work when combined in one statement? | 2,579,959 | <p>For some reason this function confused me:</p>
<pre><code>def protocol(port):
return port == "443" and "https://" or "http://"
</code></pre>
<p>Can somebody explain the order of what's happening behind the scenes to make this work the way it does.</p>
<p>I understood it as this until I tried it:</p>
<p>Eithe... | 3 | 2010-04-05T17:47:39Z | 2,579,997 | <p>This construction works because it 'unfolds' to the following code:</p>
<p>a and b --></p>
<pre><code>if a:
return b
else:
return a
</code></pre>
<p>a or b --></p>
<pre><code>if a:
return a
else:
return b
</code></pre>
| 0 | 2010-04-05T17:55:03Z | [
"python",
"boolean-logic",
"if-statement"
] |
How do "and" and "or" work when combined in one statement? | 2,579,959 | <p>For some reason this function confused me:</p>
<pre><code>def protocol(port):
return port == "443" and "https://" or "http://"
</code></pre>
<p>Can somebody explain the order of what's happening behind the scenes to make this work the way it does.</p>
<p>I understood it as this until I tried it:</p>
<p>Eithe... | 3 | 2010-04-05T17:47:39Z | 2,580,086 | <p><code>C and X or Y</code> is the long-running early attempt by Python users to proxy for <code>C ? X : Y</code></p>
<p>For the most part it works, <em>except</em> if <code>X</code> is <code>False</code> -- this has led to many bugs in Python code, so in the <a href="http://www.python.org/doc/faq/programming/#is-the... | 5 | 2010-04-05T18:10:29Z | [
"python",
"boolean-logic",
"if-statement"
] |
Not Possible to Reference self in a Method Declaration? | 2,580,022 | <p>I wanted to write a method with an argument that defaults to a member variable like so:</p>
<pre><code>def method(self, arg1=0, arg2=self.member):
</code></pre>
<p>Apparently this is not allowed. Should I write it a different way, or perhaps use a value of <code>arg2</code> to signal when to use the member variab... | 0 | 2010-04-05T17:59:25Z | 2,580,054 | <p>Yep, use a sentinel -- e.g.:</p>
<pre><code>class Foo(object):
_sentinel = object()
def method(self, arg1=0, arg2=_sentinel):
if arg2 is self._sentinel: arg2 = self.member
...
...
</code></pre>
<p>note that you need barename <code>_sentinel</code> in the <code>def</code>, but <code>self... | 5 | 2010-04-05T18:04:29Z | [
"python",
"argument-passing"
] |
Not Possible to Reference self in a Method Declaration? | 2,580,022 | <p>I wanted to write a method with an argument that defaults to a member variable like so:</p>
<pre><code>def method(self, arg1=0, arg2=self.member):
</code></pre>
<p>Apparently this is not allowed. Should I write it a different way, or perhaps use a value of <code>arg2</code> to signal when to use the member variab... | 0 | 2010-04-05T17:59:25Z | 2,580,056 | <pre><code>def method(self, arg1=0, arg2=None):
if arg2 is None:
arg2 = self.member
...
</code></pre>
| 2 | 2010-04-05T18:04:31Z | [
"python",
"argument-passing"
] |
Does Python support short-circuiting? | 2,580,136 | <p>Does Python support short-circuiting in boolean expressions?</p>
| 166 | 2010-04-05T18:19:55Z | 2,580,142 | <p>Yep, both <code>and</code> and <code>or</code> operators short-circuit -- see <a href="http://docs.python.org/library/stdtypes.html?highlight=short%20circuit#boolean-operations-and-or-not">the docs</a>.</p>
| 150 | 2010-04-05T18:20:26Z | [
"python",
"short-circuiting"
] |
Does Python support short-circuiting? | 2,580,136 | <p>Does Python support short-circuiting in boolean expressions?</p>
| 166 | 2010-04-05T18:19:55Z | 14,892,812 | <h3>Short-circuiting behavior in operator <code>and</code>, <code>or</code>:</h3>
<p>One can observe the <a href="http://cis.poly.edu/cs1114/pyLecturettes/short-circuit-eval.html">Python's short-circuiting behavior</a> of <code>and</code>, <code>or</code> operators in my following example: </p>
<pre><code>>>&... | 86 | 2013-02-15T10:34:36Z | [
"python",
"short-circuiting"
] |
Does Python support short-circuiting? | 2,580,136 | <p>Does Python support short-circuiting in boolean expressions?</p>
| 166 | 2010-04-05T18:19:55Z | 17,888,874 | <p>Yes. Try the following in your python interpreter:</p>
<p>and</p>
<pre><code>>>>False and 3/0
False
>>>True and 3/0
ZeroDivisionError: integer division or modulo by zero
</code></pre>
<p>or</p>
<pre><code>>>>True or 3/0
True
>>>False or 3/0
ZeroDivisionError: integer division ... | 30 | 2013-07-26T18:52:32Z | [
"python",
"short-circuiting"
] |
Optimizing Python code with many attribute and dictionary lookups | 2,580,158 | <p>I have written a program in Python which spends a large amount of time looking up attributes of objects and values from dictionary keys. I would like to know if there's any way I can optimize these lookup times, potentially with a C extension, to reduce the time of execution, or if I need to simply re-implement the ... | 3 | 2010-04-05T18:22:38Z | 2,580,460 | <p>Try just directly accessing the dict and catch KeyErrors, it might be faster depending on your hit/miss ratio:</p>
<pre><code># cache this object
ignode = interaction_graph.node
neighbor_z_scores = []
for neighbor in node_neighbors:
try:
neighbor_z_scores.append(ignode[neighbor]['weight'])
except Ke... | 0 | 2010-04-05T19:05:20Z | [
"python",
"optimization",
"dictionary",
"profiling"
] |
Optimizing Python code with many attribute and dictionary lookups | 2,580,158 | <p>I have written a program in Python which spends a large amount of time looking up attributes of objects and values from dictionary keys. I would like to know if there's any way I can optimize these lookup times, potentially with a C extension, to reduce the time of execution, or if I need to simply re-implement the ... | 3 | 2010-04-05T18:22:38Z | 2,581,658 | <p>How about keeping the iteration order of interaction_graph.neighbors_iter(node) sorted (or partially sorted using collections.heapq)? Since you're just trying to find the max value, you can iterate node_neighbors in descending order, the first node that is in selected_node must be the max in selected_node.</p>
<p>S... | 1 | 2010-04-05T22:52:18Z | [
"python",
"optimization",
"dictionary",
"profiling"
] |
Optimizing Python code with many attribute and dictionary lookups | 2,580,158 | <p>I have written a program in Python which spends a large amount of time looking up attributes of objects and values from dictionary keys. I would like to know if there's any way I can optimize these lookup times, potentially with a C extension, to reduce the time of execution, or if I need to simply re-implement the ... | 3 | 2010-04-05T18:22:38Z | 2,581,710 | <p>I don't see why your "weight" lookups have to be in the form of <code>["weight"]</code> (nodes are dictionaries?) instead of <code>.weight</code> (nodes are objects).</p>
<p>If your nodes are objects, and don't have a lot of fields, you can take advantage of <a href="http://docs.python.org/reference/datamodel.html#... | 1 | 2010-04-05T23:08:06Z | [
"python",
"optimization",
"dictionary",
"profiling"
] |
Optimizing Python code with many attribute and dictionary lookups | 2,580,158 | <p>I have written a program in Python which spends a large amount of time looking up attributes of objects and values from dictionary keys. I would like to know if there's any way I can optimize these lookup times, potentially with a C extension, to reduce the time of execution, or if I need to simply re-implement the ... | 3 | 2010-04-05T18:22:38Z | 2,660,732 | <p>Without looking deeply into your code, try adding a little speed with <code>itertools</code>.</p>
<p>Add these at the module level:</p>
<pre><code>import itertools as it, operator as op
GET_WEIGHT= op.attrgetter('weight')
</code></pre>
<p>Change:</p>
<pre><code>neighbors_in_selected_nodes = (neighbor for neighbo... | 0 | 2010-04-18T01:18:57Z | [
"python",
"optimization",
"dictionary",
"profiling"
] |
Python initialization and circular reference counts | 2,580,218 | <p>Can we initialize Python objects with statement like this:</p>
<pre><code>a = b = c = None
</code></pre>
<p>It seems to me when I did <code>a = b = c = list()</code>, it will cause a circular reference count issue.</p>
| 1 | 2010-04-05T18:29:13Z | 2,580,237 | <p>No. That's equivalent to:</p>
<pre>
c = list()
b = c
a = b
</pre>
<p>There is no problem. Why did you think there would be an issue?</p>
| 1 | 2010-04-05T18:32:05Z | [
"python"
] |
Python initialization and circular reference counts | 2,580,218 | <p>Can we initialize Python objects with statement like this:</p>
<pre><code>a = b = c = None
</code></pre>
<p>It seems to me when I did <code>a = b = c = list()</code>, it will cause a circular reference count issue.</p>
| 1 | 2010-04-05T18:29:13Z | 2,580,240 | <p>There are no cycles in your code and even if there were, Python's garbage collector can handle a circular reference fine, so you don't ever need to worry about that.</p>
<p>However your code has another (possible) problem: All three variables will point to the same list. This means that changing, for example, a, wi... | 4 | 2010-04-05T18:32:45Z | [
"python"
] |
Python initialization and circular reference counts | 2,580,218 | <p>Can we initialize Python objects with statement like this:</p>
<pre><code>a = b = c = None
</code></pre>
<p>It seems to me when I did <code>a = b = c = list()</code>, it will cause a circular reference count issue.</p>
| 1 | 2010-04-05T18:29:13Z | 2,580,242 | <p>Yes, you can do that. There is no circular reference in your code and even if there were, it wouldn't cause any problems as Python has a garbage collector that correctly handles cycles.</p>
| 2 | 2010-04-05T18:33:16Z | [
"python"
] |
How to detect if 2 news articles have the same topic? (Python language-comparison) | 2,580,367 | <p>I'm looking for ideas on recommended approach.</p>
<p>I'm trying to scrape some headlines and body text from articles for a few specific sites, similar to what Google does with Google News.</p>
<p>The problem is across different sites, they may have articles on the same exact subject, worded slightly differently.<... | 2 | 2010-04-05T18:52:38Z | 2,580,397 | <p><a href="http://en.wikipedia.org/wiki/Cosine_similarity" rel="nofollow">http://en.wikipedia.org/wiki/Cosine_similarity</a></p>
| 3 | 2010-04-05T18:57:40Z | [
"python",
"comparison",
"language-comparisons"
] |
Syntax highlighting: rich text box control for .NET | 2,580,374 | <p>I'm looking for a free control/component/library something like a rich text box for editing codes of python (or other languages.)<br>
I like to have some features:</p>
<ul>
<li>Highlight codes</li>
<li>Auto Indent</li>
<li>Line numbering</li>
<li>Defining new styles or rules of highlighting (for OpenType keywords)<... | 3 | 2010-04-05T18:53:13Z | 2,580,388 | <p>Have a look at <a href="http://scintillanet.codeplex.com/" rel="nofollow">ScintillaNET</a>.</p>
<blockquote>
<p>ScintillaNET is a powerful text editing control for Windows Forms applications and a managed wrapper around the versatile Scintilla Windows control. Created with the developer in mind, the ScintllaNET A... | 4 | 2010-04-05T18:56:49Z | [
".net",
"python",
"controls",
"ironpython",
"components"
] |
Syntax highlighting: rich text box control for .NET | 2,580,374 | <p>I'm looking for a free control/component/library something like a rich text box for editing codes of python (or other languages.)<br>
I like to have some features:</p>
<ul>
<li>Highlight codes</li>
<li>Auto Indent</li>
<li>Line numbering</li>
<li>Defining new styles or rules of highlighting (for OpenType keywords)<... | 3 | 2010-04-05T18:53:13Z | 2,580,453 | <p>A commercial option is ActiPro Software's <a href="http://www.actiprosoftware.com/Products/DotNet/WPF/SyntaxEditor/Default.aspx" rel="nofollow" title="SyntaxEditor">SyntaxEditor</a>. The link is for a WPF version of the control. They also offer a WinForms version which I've used for XML editing - works very well.</p... | 1 | 2010-04-05T19:04:23Z | [
".net",
"python",
"controls",
"ironpython",
"components"
] |
How to respond to HTTP OPTIONS request on a JSON-RPC server | 2,580,461 | <p>My JSON-RPC client (browser using dojo JSON-RPC) makes a JSON-RPC request (dojo.callRemote) to my JSON-RPC server on <em>myserver.com/12345</em> (Python 2.5, SimpleJSONRPCServer). </p>
<p>The server then gets a HTTP request with header "OPTIONS / HTTP/1.1", which it can't handle by default, so I wrote a custom hand... | 4 | 2010-04-05T19:05:22Z | 3,967,728 | <p>See the <a href="http://www.w3.org/TR/cors/" rel="nofollow">CORS Specification</a>.</p>
<p>(BTW; there's a header registry for HTTP, see <a href="http://www.iana.org/assignments/message-headers/prov-headers.html" rel="nofollow">http://www.iana.org/assignments/message-headers/prov-headers.html</a> and <a href="http:... | 2 | 2010-10-19T11:14:30Z | [
"python",
"http",
"dojo",
"json-rpc"
] |
How to respond to HTTP OPTIONS request on a JSON-RPC server | 2,580,461 | <p>My JSON-RPC client (browser using dojo JSON-RPC) makes a JSON-RPC request (dojo.callRemote) to my JSON-RPC server on <em>myserver.com/12345</em> (Python 2.5, SimpleJSONRPCServer). </p>
<p>The server then gets a HTTP request with header "OPTIONS / HTTP/1.1", which it can't handle by default, so I wrote a custom hand... | 4 | 2010-04-05T19:05:22Z | 4,842,336 | <p>add code and try, it work fine for me:</p>
<pre><code>class CGIHTTPRequestHandler(SimpleHTTPServer.SimpleHTTPRequestHandler):
...
...
def do_OPTIONS(self):
self.send_response(200, "ok")
self.send_header('Access-Control-Allow-Origin', self.headers.dict['origin'])
self.send_header('Access-... | 2 | 2011-01-30T10:18:35Z | [
"python",
"http",
"dojo",
"json-rpc"
] |
How to respond to HTTP OPTIONS request on a JSON-RPC server | 2,580,461 | <p>My JSON-RPC client (browser using dojo JSON-RPC) makes a JSON-RPC request (dojo.callRemote) to my JSON-RPC server on <em>myserver.com/12345</em> (Python 2.5, SimpleJSONRPCServer). </p>
<p>The server then gets a HTTP request with header "OPTIONS / HTTP/1.1", which it can't handle by default, so I wrote a custom hand... | 4 | 2010-04-05T19:05:22Z | 8,480,630 | <p>Check my code. It works for client javascript code running in Chrome browser.</p>
<pre><code>class MyHandler(BaseHTTPRequestHandler):
def do_OPTIONS(self):
self.send_response(200, "ok")
self.send_header('Access-Control-Allow-Origin', '*')
self.send_heade... | 0 | 2011-12-12T20:50:15Z | [
"python",
"http",
"dojo",
"json-rpc"
] |
Database on the fly with scripting languages | 2,580,497 | <p>I have a set of .csv files that I want to process. It would be far easier to process it with SQL queries. I wonder if there is some way to load a .csv file and use SQL language to look into it with a scripting language like python or ruby. Loading it with something similar to ActiveRecord would be awesome. </p>
<p>... | 19 | 2010-04-05T19:10:17Z | 2,580,540 | <p>Use a DB in a library like <a href="http://sqlite.org/" rel="nofollow">SQLite</a>.
There are <a href="http://docs.python.org/library/sqlite3.html" rel="nofollow">Python</a> and <a href="http://sqlite-ruby.rubyforge.org/" rel="nofollow">Ruby</a> versions .</p>
<p>Load your CSV into table, there might be modules/lib... | 4 | 2010-04-05T19:15:51Z | [
"python",
"sql",
"database",
"sqlite3",
"sqlalchemy"
] |
Database on the fly with scripting languages | 2,580,497 | <p>I have a set of .csv files that I want to process. It would be far easier to process it with SQL queries. I wonder if there is some way to load a .csv file and use SQL language to look into it with a scripting language like python or ruby. Loading it with something similar to ActiveRecord would be awesome. </p>
<p>... | 19 | 2010-04-05T19:10:17Z | 2,580,542 | <p>CSV files are not databases--they have no indices--and any SQL simulation you imposed upon them would amount to little more than searching through the entire thing over and over again. </p>
| 4 | 2010-04-05T19:15:55Z | [
"python",
"sql",
"database",
"sqlite3",
"sqlalchemy"
] |
Database on the fly with scripting languages | 2,580,497 | <p>I have a set of .csv files that I want to process. It would be far easier to process it with SQL queries. I wonder if there is some way to load a .csv file and use SQL language to look into it with a scripting language like python or ruby. Loading it with something similar to ActiveRecord would be awesome. </p>
<p>... | 19 | 2010-04-05T19:10:17Z | 2,580,543 | <p>There's <a href="http://docs.python.org/library/sqlite3"><code>sqlite3</code></a>, included into python. With it you can create a database (<strong>on memory</strong>) and add rows to it, and perform SQL queries.</p>
<p>If you want neat ActiveRecord-like functionality you should add an external ORM, like <a href="h... | 55 | 2010-04-05T19:15:58Z | [
"python",
"sql",
"database",
"sqlite3",
"sqlalchemy"
] |
Database on the fly with scripting languages | 2,580,497 | <p>I have a set of .csv files that I want to process. It would be far easier to process it with SQL queries. I wonder if there is some way to load a .csv file and use SQL language to look into it with a scripting language like python or ruby. Loading it with something similar to ActiveRecord would be awesome. </p>
<p>... | 19 | 2010-04-05T19:10:17Z | 2,580,548 | <p>Looked at Perl and and Text::CSV and DBI? There are many modules on CPAN to do exactly this. Here is an example (from <a href="http://perlmeme.org/tutorials/parsing_csv.html">HERE</a>):</p>
<pre><code>#!/usr/bin/perl
use strict;
use warnings;
use DBI;
# Connect to the database, (the directory containing our csv fi... | 4 | 2010-04-05T19:16:54Z | [
"python",
"sql",
"database",
"sqlite3",
"sqlalchemy"
] |
Database on the fly with scripting languages | 2,580,497 | <p>I have a set of .csv files that I want to process. It would be far easier to process it with SQL queries. I wonder if there is some way to load a .csv file and use SQL language to look into it with a scripting language like python or ruby. Loading it with something similar to ActiveRecord would be awesome. </p>
<p>... | 19 | 2010-04-05T19:10:17Z | 2,580,549 | <p>You could use either scripting language to parse the CSV file and store the data into <a href="http://sqlite.org/" rel="nofollow">SQLite</a>, which just uses a single file for storage. From there you have it in a database and can run queries against it.</p>
<p>Alternatively, on windows you can setup an ODBC data so... | 3 | 2010-04-05T19:16:54Z | [
"python",
"sql",
"database",
"sqlite3",
"sqlalchemy"
] |
Database on the fly with scripting languages | 2,580,497 | <p>I have a set of .csv files that I want to process. It would be far easier to process it with SQL queries. I wonder if there is some way to load a .csv file and use SQL language to look into it with a scripting language like python or ruby. Loading it with something similar to ActiveRecord would be awesome. </p>
<p>... | 19 | 2010-04-05T19:10:17Z | 2,580,913 | <p>PHP FlatfileDB available <a href="http://sourceforge.net/projects/flatfiledb/" rel="nofollow">here</a> is a very good option if you are building a web app</p>
| 1 | 2010-04-05T20:14:33Z | [
"python",
"sql",
"database",
"sqlite3",
"sqlalchemy"
] |
Database on the fly with scripting languages | 2,580,497 | <p>I have a set of .csv files that I want to process. It would be far easier to process it with SQL queries. I wonder if there is some way to load a .csv file and use SQL language to look into it with a scripting language like python or ruby. Loading it with something similar to ActiveRecord would be awesome. </p>
<p>... | 19 | 2010-04-05T19:10:17Z | 9,156,660 | <p>I used nosklo's solution (thanks!) but I already had a primary key (passed in as pk_col) within the column line (first line of csv). So I thought I'd share my modification. I used a ternary. </p>
<pre><code>table = Table(tablename, metadata,
*((Column(pk_col, Integer, primary_key=True)) if rowname == pk_col els... | 2 | 2012-02-06T07:03:57Z | [
"python",
"sql",
"database",
"sqlite3",
"sqlalchemy"
] |
Using BeautifulSoup's findAll to search html element's innerText to get same result as searching attributes? | 2,580,507 | <p>For instance if I am searching by an element's attribute like id:</p>
<pre><code>soup.findAll('span',{'id':re.compile("^score_")})
</code></pre>
<p>I get back a list of the whole span element that matches (which I like).</p>
<p>But if I try to search by the innerText of the html element like this:</p>
<pre><code... | 5 | 2010-04-05T19:11:24Z | 2,580,532 | <p>You don't get back the text. You get a <code>NavigableString</code> with the text. That object has methods to go to the parent, etc.</p>
<pre><code>from BeautifulSoup import BeautifulSoup
import re
soup = BeautifulSoup('<html><p>foo</p></html>')
r = soup.findAll('p', text=re.compile('foo')... | 6 | 2010-04-05T19:14:33Z | [
"python",
"beautifulsoup"
] |
Unittest in Django. What is relationship between TestCase class and method | 2,580,519 | <p>I am doing some unit testing stuff in Django. What is the relationship between TestCase class and the actual method in this class? What is the best practice for organizing these stuff?</p>
<p>For example, I have </p>
<pre><code>class Test(TestCase):
def __init__(self):
...
def testTestA(self):
... | 1 | 2010-04-05T19:12:46Z | 2,580,768 | <ol>
<li><p>You rarely write <code>__init__</code> for a <code>TestCase</code>. So strike that from your mental model of unit testing.</p></li>
<li><p>You sometimes write a <code>setUp</code> and <code>tearDown</code>. Django automates much of this, however, and you often merely provide a static <code>fixtures=</code... | 7 | 2010-04-05T19:53:09Z | [
"python",
"django",
"unit-testing"
] |
Unittest in Django. What is relationship between TestCase class and method | 2,580,519 | <p>I am doing some unit testing stuff in Django. What is the relationship between TestCase class and the actual method in this class? What is the best practice for organizing these stuff?</p>
<p>For example, I have </p>
<pre><code>class Test(TestCase):
def __init__(self):
...
def testTestA(self):
... | 1 | 2010-04-05T19:12:46Z | 2,580,793 | <p>It's kind of hard to answer this question regarding the proper organization of cases A and B and test methods 1, 2 and 3...</p>
<p>However splitting the tests to test cases serves two major purposes:
1) Organizing the tests around some logical groups, such as CustomerViewTests, OrdersAggregationTests, etc.</p>
<p>... | 1 | 2010-04-05T19:56:25Z | [
"python",
"django",
"unit-testing"
] |
Unittest in Django. Static variable feeded into the test case | 2,580,648 | <p>I want to generate some dynamic data and feed these data in to test cases. But I found that Django will initial the test class every time to do the test. So the data will get generated every time django test framework calls the function. </p>
<p>Is there anyway to use something like the singleton or static variable... | 2 | 2010-04-05T19:35:50Z | 2,580,813 | <p>This is normal unittest behavior, though you would normally set up the test data in the <code>setUp()</code> method instead of <code>__init__</code> (and destroy it in <code>tearDown()</code> perhaps). </p>
<p>If generating your dynamic test data takes to long to perform for each test case method, then I guess the ... | 3 | 2010-04-05T19:59:24Z | [
"python",
"django",
"unit-testing"
] |
Passing string with (accidental) escape character loses character even though it's a raw string | 2,580,654 | <p>I have a function with a python doctest that fails because one of the test input strings has a backslash that's treated like an escape character even though I've encoded the string as a raw string. </p>
<p>My doctest looks like this:</p>
<pre><code>>>> infile = [ "Todo: fix me", "/** todo: fix", "*... | 1 | 2010-04-05T19:36:38Z | 2,580,707 | <p>Read your original regex carefully:</p>
<pre><code>r"""(?:/{0,2}\**\s?todo):?\s*(?P<todo>.+)"""
</code></pre>
<p>It matches: zero to two slashes, then 0+ stars, then 0 or 1 "whitespace characters" (blanks, tabs etc), then the literal characters <code>'todo'</code> (and so on).</p>
<p>Your rawstring is:</p>
... | 2 | 2010-04-05T19:44:52Z | [
"python",
"regex",
"escaping",
"doctest",
"rawstring"
] |
Passing string with (accidental) escape character loses character even though it's a raw string | 2,580,654 | <p>I have a function with a python doctest that fails because one of the test input strings has a backslash that's treated like an escape character even though I've encoded the string as a raw string. </p>
<p>My doctest looks like this:</p>
<pre><code>>>> infile = [ "Todo: fix me", "/** todo: fix", "*... | 1 | 2010-04-05T19:36:38Z | 2,581,359 | <p>This gets even more strange as I venture down the road of doctests.</p>
<p>Consider this <a href="http://gist.github.com/356930" rel="nofollow">python script</a>.</p>
<p>If you uncomment the lines 22 and 23, the script passes just fine, as the method returns <code>True</code>, which is both asserted and explicitly... | 1 | 2010-04-05T21:41:42Z | [
"python",
"regex",
"escaping",
"doctest",
"rawstring"
] |
Live Updating Widget for 100+ concurrent users | 2,580,669 | <p>what would you use if you had to have a div box on your website that would have to be updated constantly with new HTML content from the server.</p>
<p>simple polling is probably not very resource inefficient - imagine also having 10'000 users and the div has to update.</p>
<p>what is the most efficient or elegant ... | 0 | 2010-04-05T19:38:48Z | 2,581,033 | <p>Consider using <a href="http://memcached.org/" rel="nofollow">memcached</a>. By caching content in memory
you will reduce the number of calls to the (database?) server that generates the content. </p>
<p>To keep the content up to date you should use the <a href="http://code.google.com/intl/sv-SE/appengine/docs/pyth... | 1 | 2010-04-05T20:38:33Z | [
"python",
"comet",
"scaling",
"tornado"
] |
Pythonic mapping of an array (Beginner) | 2,580,802 | <p>I've got a question related to a beginner Python snippet I've written to introduce myself to the language. It's an admittedly trivial early effort, but I'm still wondering how I could have written it more elegantly.</p>
<p>The program outputs NATO phoenetic readable versions of an argument, such "H2O" -> "Hotel 2 O... | 1 | 2010-04-05T19:58:20Z | 2,580,836 | <p>The dict <a href="http://docs.python.org/library/stdtypes.html#dict.get" rel="nofollow">get with default</a> perhaps?</p>
<pre><code>for char in sys.argv[1].lower():
print nato.get(char, char) # try to get nato[char] otherwise return char
</code></pre>
| 5 | 2010-04-05T20:02:49Z | [
"python",
"arrays"
] |
Pythonic mapping of an array (Beginner) | 2,580,802 | <p>I've got a question related to a beginner Python snippet I've written to introduce myself to the language. It's an admittedly trivial early effort, but I'm still wondering how I could have written it more elegantly.</p>
<p>The program outputs NATO phoenetic readable versions of an argument, such "H2O" -> "Hotel 2 O... | 1 | 2010-04-05T19:58:20Z | 2,580,929 | <p>Using the above suggestion and a generator expression to do it all in one line</p>
<pre><code>print ' '.join(nato.get(c,c) for c in sys.argv[1].lower())
</code></pre>
| 3 | 2010-04-05T20:18:21Z | [
"python",
"arrays"
] |
Pythonic mapping of an array (Beginner) | 2,580,802 | <p>I've got a question related to a beginner Python snippet I've written to introduce myself to the language. It's an admittedly trivial early effort, but I'm still wondering how I could have written it more elegantly.</p>
<p>The program outputs NATO phoenetic readable versions of an argument, such "H2O" -> "Hotel 2 O... | 1 | 2010-04-05T19:58:20Z | 2,580,967 | <p>Here's a compact way of building your list:</p>
<pre><code>import sys
import string
NATO = '''Alpha Bravo Charlie Delta Echo Foxtrot Golf Hotel India Juliet
Kilo Lima Mike November Oscar Papa Quebec Romeo Sierra Tango Uniform
Victor Whiskey X-Ray Yankee Zulu'''.split()
nato = dict(zip(string.lowercase,NATO))
if ... | 2 | 2010-04-05T20:26:02Z | [
"python",
"arrays"
] |
Parsing text file in python | 2,580,841 | <p>I have html-file. I have to replace all text between this: [%anytext%]. As I understand, it's very easy to do with BeautifulSoup for parsing hmtl. But what is regular expression and how to remove&write back text data?</p>
<hr>
<p>Okay, here is the sample file:</p>
<pre><code><html>
[t1] [t2] ... [tood... | 2 | 2010-04-05T20:03:01Z | 2,580,927 | <p>Looks like you need to parse a generic textfile, looking for that marker to replace it -- the fact that other text outside the marker is HTML, at least from the way you phrased your task, does not seem to matter.</p>
<p>If so, and what you want is to replace every occurrence of <code>[%anytext%]</code> with <code>l... | 2 | 2010-04-05T20:17:21Z | [
"python",
"html",
"parsing"
] |
Parsing text file in python | 2,580,841 | <p>I have html-file. I have to replace all text between this: [%anytext%]. As I understand, it's very easy to do with BeautifulSoup for parsing hmtl. But what is regular expression and how to remove&write back text data?</p>
<hr>
<p>Okay, here is the sample file:</p>
<pre><code><html>
[t1] [t2] ... [tood... | 2 | 2010-04-05T20:03:01Z | 2,581,032 | <p>Regex does the trick if you are needing to replace any text between "[%" and "%]".</p>
<p>The code would look something like this:</p>
<pre><code>import re
newstring = re.sub("\[%.*?%\]",newtext,oldstring)
</code></pre>
<p>The regex used here is lazy so it would match everything between an occurrence of "[%" an... | 2 | 2010-04-05T20:38:16Z | [
"python",
"html",
"parsing"
] |
How to skip interstitial in a django view if a user hits the back button? | 2,580,905 | <p>I have an application with an interstitial page to hold the user while an intensive operation runs in the background (takes anywhere from 30 secs to 1 minute). Once the operation is done, the user is redirected to the results page.</p>
<p>Once on the result page, typical user behavior is to hit the 'back' button to... | 1 | 2010-04-05T20:12:59Z | 2,582,464 | <p>How do you keep the interstitial page from entering the flow? Eliminate it.</p>
<p>I'm only recently wrapping my head around AJAX, so wish I could give you a more concrete answer, but the general approach is to use something like <a href="http://jquery.com/" rel="nofollow">jQuery</a> to replace the contents of the ... | 2 | 2010-04-06T03:26:11Z | [
"python",
"django",
"caching",
"header",
"interstitial"
] |
Disable autocomplete on textfield in Django? | 2,580,955 | <p>Does anyone know how you can turn off autocompletion on a textfield in Django? </p>
<p>For example, a form that I generate from my model has an input field for a credit card number. It is bad practice to leave autocompletion on. When making the form by hand, I'd add a autocomplete="off" statement, but how do you do... | 11 | 2010-04-05T20:23:48Z | 2,581,040 | <p>In your form, specify the widget you want to use for the field, and add an <code>attrs</code> dictionary on that widget. For example (straight from the <a href="http://docs.djangoproject.com/en/dev/ref/forms/widgets/#django.forms.Widget.attrs">django documentation</a>):</p>
<pre><code>class CommentForm(forms.Form):... | 19 | 2010-04-05T20:39:30Z | [
"python",
"django",
"forms",
"autocomplete"
] |
Disable autocomplete on textfield in Django? | 2,580,955 | <p>Does anyone know how you can turn off autocompletion on a textfield in Django? </p>
<p>For example, a form that I generate from my model has an input field for a credit card number. It is bad practice to leave autocompletion on. When making the form by hand, I'd add a autocomplete="off" statement, but how do you do... | 11 | 2010-04-05T20:23:48Z | 3,672,334 | <p>Add the autocomplete="off" to the form tag, so you don't have to change the django.form instance.</p>
<p><code><form action="." method="post" autocomplete="off">
{{ form }}
</form></code></p>
| 17 | 2010-09-08T22:19:32Z | [
"python",
"django",
"forms",
"autocomplete"
] |
Disable autocomplete on textfield in Django? | 2,580,955 | <p>Does anyone know how you can turn off autocompletion on a textfield in Django? </p>
<p>For example, a form that I generate from my model has an input field for a credit card number. It is bad practice to leave autocompletion on. When making the form by hand, I'd add a autocomplete="off" statement, but how do you do... | 11 | 2010-04-05T20:23:48Z | 36,562,872 | <p>If you are defining your own forms, you can add attributes to your fields in the form.</p>
<pre><code>class CommentForm(forms.Form):
name = forms.CharField(widget=forms.TextInput(attrs={
'autocomplete':'off'
}))
</code></pre>
<p>If you are using modelforms, you won't have the luxury of defining fie... | 0 | 2016-04-12T03:02:34Z | [
"python",
"django",
"forms",
"autocomplete"
] |
Django TestCase testing order | 2,581,005 | <p>If there are several methods in the test class, I found that the order to execute is alphabetical. But I want to customize the order of execution. How to define the execution order?</p>
<p>For example: testTestA will be loaded first than testTestB.</p>
<pre><code>class Test(TestCase):
def setUp(self):
... | 16 | 2010-04-05T20:34:26Z | 2,581,056 | <p>As far as I know, there is no way to order tests other than rename them. Could you explain why you need to run test cases in the specific order? In unit testing it usually considered as bad practice since it means that your cases are not independent.</p>
| 9 | 2010-04-05T20:43:40Z | [
"python",
"django",
"unit-testing"
] |
Django TestCase testing order | 2,581,005 | <p>If there are several methods in the test class, I found that the order to execute is alphabetical. But I want to customize the order of execution. How to define the execution order?</p>
<p>For example: testTestA will be loaded first than testTestB.</p>
<pre><code>class Test(TestCase):
def setUp(self):
... | 16 | 2010-04-05T20:34:26Z | 2,581,160 | <p>A tenet of unit-testing is that each test should be independent of all others.
If in your case the code in testTestA must come before testTestB, then you could
combine both into one test:</p>
<pre><code>def testTestA_and_TestB(self):
# test code from testTestA
...
# test code from testTestB
</code></pre... | 33 | 2010-04-05T21:01:29Z | [
"python",
"django",
"unit-testing"
] |
Django TestCase testing order | 2,581,005 | <p>If there are several methods in the test class, I found that the order to execute is alphabetical. But I want to customize the order of execution. How to define the execution order?</p>
<p>For example: testTestA will be loaded first than testTestB.</p>
<pre><code>class Test(TestCase):
def setUp(self):
... | 16 | 2010-04-05T20:34:26Z | 28,518,651 | <p>To update on the topic (from documentation):</p>
<blockquote>
<p><a href="https://docs.djangoproject.com/en/1.7/topics/testing/overview/#order-in-which-tests-are-executed" rel="nofollow">Order in which tests are executed</a></p>
<p>In order to guarantee that all <strong><code>TestCase</code></strong> code st... | 0 | 2015-02-14T18:12:27Z | [
"python",
"django",
"unit-testing"
] |
Python list as *args? | 2,581,217 | <p>I have two Python functions, both of which take variable arguments in their function definitions. To give a simple example:</p>
<pre><code>def func1(*args):
for arg in args:
print arg
def func2(*args):
return [2 * arg for arg in args]
</code></pre>
<p>I'd like to compose them -- as in <code>func1(... | 3 | 2010-04-05T21:15:19Z | 2,581,280 | <p>You can consider writing function decorator that checks if the first argument is a list. Applying decorator to existing functions is a bit simpler than modifying functions.</p>
| 4 | 2010-04-05T21:27:50Z | [
"python",
"function-composition"
] |
Python list as *args? | 2,581,217 | <p>I have two Python functions, both of which take variable arguments in their function definitions. To give a simple example:</p>
<pre><code>def func1(*args):
for arg in args:
print arg
def func2(*args):
return [2 * arg for arg in args]
</code></pre>
<p>I'd like to compose them -- as in <code>func1(... | 3 | 2010-04-05T21:15:19Z | 2,581,283 | <blockquote>
<p>Normally, I would just use <code>func1(*func2(3, 4, 5))</code> or have func1 check to see if <code>args[0]</code> was a <code>list</code>. Unfortunately, I can't use the first solution in this particular instance and to apply the second would require doing such a check in many places (there are a lot ... | 1 | 2010-04-05T21:28:12Z | [
"python",
"function-composition"
] |
Python list as *args? | 2,581,217 | <p>I have two Python functions, both of which take variable arguments in their function definitions. To give a simple example:</p>
<pre><code>def func1(*args):
for arg in args:
print arg
def func2(*args):
return [2 * arg for arg in args]
</code></pre>
<p>I'd like to compose them -- as in <code>func1(... | 3 | 2010-04-05T21:15:19Z | 2,582,299 | <p>You can use a Decorator as posted by Yaroslav.</p>
<p>Minimal example:</p>
<pre><code>def unpack_args(func):
def deco_func(*args):
if isinstance(args, tuple):
args = args[0]
return func(*args)
return deco_func
def func1(*args):
return args
def func2(*args):
return a... | 3 | 2010-04-06T02:18:53Z | [
"python",
"function-composition"
] |
how does django save decimal values? | 2,581,219 | <p>what am i doing wrong?</p>
<pre><code>class MyModel(models.Model):
name = models.CharField(max_length=100, verbose_name=_("Name"), blank=False, null=False)
rating = models.DecimalField(max_digits=2, decimal_places=2, default=0)
</code></pre>
<p>id i do something like that:</p>
<pre><code>average = count/len(v... | 2 | 2010-04-05T21:16:09Z | 2,581,251 | <p>Models do no validation. The types you use pretty much deal with things like syncdb etc. rather than actual formatting of data, that's what a Form is for.</p>
| 1 | 2010-04-05T21:21:57Z | [
"python",
"django",
"decimal"
] |
how does django save decimal values? | 2,581,219 | <p>what am i doing wrong?</p>
<pre><code>class MyModel(models.Model):
name = models.CharField(max_length=100, verbose_name=_("Name"), blank=False, null=False)
rating = models.DecimalField(max_digits=2, decimal_places=2, default=0)
</code></pre>
<p>id i do something like that:</p>
<pre><code>average = count/len(v... | 2 | 2010-04-05T21:16:09Z | 2,581,731 | <p>max_digits is a number of digits <em>before</em> and <em>after</em> the decimal point. With your settings it allows you to store numbers between 0.00 and 0.99. Is it right? I can not figure out the range of values for <em>average</em> variable.</p>
| 2 | 2010-04-05T23:15:07Z | [
"python",
"django",
"decimal"
] |
Use multiple WSGI mount points in Apache with an Nginx reverse proxy | 2,581,474 | <p>I am trying to set up multiple virtual hosts on the same server with Nginx and Apache and have run into a curious configuration issue.</p>
<p>I have nginx is configured with a generic upstream to apache.</p>
<pre><code>upstream backend {
server 1.1.1.1:8080;
}
</code></pre>
<p>I'm trying to set up multiple subd... | 1 | 2010-04-05T22:06:41Z | 2,581,891 | <p>Easiest way is to use following in WSGI script file:</p>
<pre><code>... existing stuff
import django.core.handlers.wsgi
_application = django.core.handlers.wsgi.WSGIHandler()
def application(environ, start_response):
# Wrapper to clear SCRIPT_NAME..
environ['SCRIPT_NAME'] = ''
return _application(envi... | 1 | 2010-04-06T00:06:09Z | [
"python",
"django",
"apache",
"nginx",
"wsgi"
] |
Zoomed PyGTK image without scale pixbuf | 2,581,687 | <p>I want to display a gtk.Image with a high level of zoom, but scale the image to a new pixbuf with the gtk.gdk.Pixbuf methods waste a lot of memory and processor.</p>
<p>Are there some simply way to display a zoomed image? </p>
| 1 | 2010-04-05T23:00:32Z | 2,586,546 | <p>it is not possible with gdk, i'm afraid.</p>
<p>try cairo or opengl.</p>
| 0 | 2010-04-06T16:33:49Z | [
"python",
"gtk",
"pygtk",
"gnome"
] |
Zoomed PyGTK image without scale pixbuf | 2,581,687 | <p>I want to display a gtk.Image with a high level of zoom, but scale the image to a new pixbuf with the gtk.gdk.Pixbuf methods waste a lot of memory and processor.</p>
<p>Are there some simply way to display a zoomed image? </p>
| 1 | 2010-04-05T23:00:32Z | 2,786,456 | <p>I'll recommend Clutter <a href="http://www.clutter-project.org/" rel="nofollow">http://www.clutter-project.org/</a></p>
| 0 | 2010-05-07T05:44:07Z | [
"python",
"gtk",
"pygtk",
"gnome"
] |
Zoomed PyGTK image without scale pixbuf | 2,581,687 | <p>I want to display a gtk.Image with a high level of zoom, but scale the image to a new pixbuf with the gtk.gdk.Pixbuf methods waste a lot of memory and processor.</p>
<p>Are there some simply way to display a zoomed image? </p>
| 1 | 2010-04-05T23:00:32Z | 4,840,358 | <p>Maybe GtkImageView helps: <a href="http://trac.bjourne.webfactional.com/" rel="nofollow">http://trac.bjourne.webfactional.com/</a> </p>
| 1 | 2011-01-30T00:23:57Z | [
"python",
"gtk",
"pygtk",
"gnome"
] |
Can Cython compile to an EXE? | 2,581,784 | <p>I know what Cythons purpose is. It's to write compilable C extensions in a Python-like language in order to produce speedups in your code. What I would like to know (and can't seem to find using my google-fu) is if Cython can somehow compile into an executable format since it already seems to break python code dow... | 37 | 2010-04-05T23:34:34Z | 2,581,826 | <p>In principal it appears to be possible to do something like what you want, according to the <a href="http://www.freenet.org.nz/python/embeddingpyrex/">Embedding Pyrex HOWTO</a>. (Pyrex is effectively a previous generation of Cython.)</p>
<p>Hmm... that name suggests a better search than I first tried: "embedding c... | 28 | 2010-04-05T23:47:51Z | [
"python",
"compilation",
"cython"
] |
Can Cython compile to an EXE? | 2,581,784 | <p>I know what Cythons purpose is. It's to write compilable C extensions in a Python-like language in order to produce speedups in your code. What I would like to know (and can't seem to find using my google-fu) is if Cython can somehow compile into an executable format since it already seems to break python code dow... | 37 | 2010-04-05T23:34:34Z | 2,743,448 | <p><a href="https://github.com/cython/cython/wiki/EmbeddingCython">Here's the wiki page on embedding cython</a></p>
<p>Assuming you installed python to <code>C:\Python31</code> and you want to use Microsoft Compiler.</p>
<p><code>smalltest1.py</code> - is the file you want to compile.</p>
<p><code>test.exe</code> - ... | 31 | 2010-04-30T09:12:40Z | [
"python",
"compilation",
"cython"
] |
Python subprocess: callback when cmd exits | 2,581,817 | <p>I'm currently launching a programme using <code>subprocess.Popen(cmd, shell=TRUE)</code></p>
<p>I'm fairly new to Python, but it 'feels' like there ought to be some api that lets me do something similar to:</p>
<pre><code>subprocess.Popen(cmd, shell=TRUE, postexec_fn=function_to_call_on_exit)
</code></pre>
<p>I ... | 32 | 2010-04-05T23:45:06Z | 2,581,843 | <p>AFAIK there is no such API, at least not in <code>subprocess</code> module. You need to roll something on your own, possibly using threads.</p>
| 0 | 2010-04-05T23:52:26Z | [
"python",
"callback",
"subprocess",
"exit"
] |
Python subprocess: callback when cmd exits | 2,581,817 | <p>I'm currently launching a programme using <code>subprocess.Popen(cmd, shell=TRUE)</code></p>
<p>I'm fairly new to Python, but it 'feels' like there ought to be some api that lets me do something similar to:</p>
<pre><code>subprocess.Popen(cmd, shell=TRUE, postexec_fn=function_to_call_on_exit)
</code></pre>
<p>I ... | 32 | 2010-04-05T23:45:06Z | 2,581,943 | <p>You're right - there is no nice API for this. You're also right on your second point - it's trivially easy to design a function that does this for you using threading.</p>
<pre><code>import threading
import subprocess
def popenAndCall(onExit, popenArgs):
"""
Runs the given args in a subprocess.Popen, and t... | 33 | 2010-04-06T00:27:04Z | [
"python",
"callback",
"subprocess",
"exit"
] |
Python subprocess: callback when cmd exits | 2,581,817 | <p>I'm currently launching a programme using <code>subprocess.Popen(cmd, shell=TRUE)</code></p>
<p>I'm fairly new to Python, but it 'feels' like there ought to be some api that lets me do something similar to:</p>
<pre><code>subprocess.Popen(cmd, shell=TRUE, postexec_fn=function_to_call_on_exit)
</code></pre>
<p>I ... | 32 | 2010-04-05T23:45:06Z | 4,636,673 | <p>I had same problem, and solved it using <code>multiprocessing.Pool</code>. There are two hacky tricks involved:</p>
<ol>
<li>make size of pool 1</li>
<li>pass iterable arguments within an iterable of length 1</li>
</ol>
<p>result is one function executed with callback on completion</p>
<pre><code>def sub(arg):
... | 4 | 2011-01-08T23:03:53Z | [
"python",
"callback",
"subprocess",
"exit"
] |
Python subprocess: callback when cmd exits | 2,581,817 | <p>I'm currently launching a programme using <code>subprocess.Popen(cmd, shell=TRUE)</code></p>
<p>I'm fairly new to Python, but it 'feels' like there ought to be some api that lets me do something similar to:</p>
<pre><code>subprocess.Popen(cmd, shell=TRUE, postexec_fn=function_to_call_on_exit)
</code></pre>
<p>I ... | 32 | 2010-04-05T23:45:06Z | 5,209,230 | <p>I was inspired by Daniel G. answer and implemented a very simple use case - in my work I often need to make repeated calls to the same (external) process with different arguments. I had hacked a way to determine when each specific call was done, but now I have a much cleaner way to issue callbacks. </p>
<p>I like t... | 0 | 2011-03-06T07:14:22Z | [
"python",
"callback",
"subprocess",
"exit"
] |
Python subprocess: callback when cmd exits | 2,581,817 | <p>I'm currently launching a programme using <code>subprocess.Popen(cmd, shell=TRUE)</code></p>
<p>I'm fairly new to Python, but it 'feels' like there ought to be some api that lets me do something similar to:</p>
<pre><code>subprocess.Popen(cmd, shell=TRUE, postexec_fn=function_to_call_on_exit)
</code></pre>
<p>I ... | 32 | 2010-04-05T23:45:06Z | 5,209,746 | <p>There is <a href="http://docs.python.org/dev/library/concurrent.futures"><code>concurrent.futures</code></a> module in Python 3.2 (available via <code>pip install futures</code> for older Python < 3.2):</p>
<pre><code>pool = Pool(max_workers=1)
f = pool.submit(subprocess.call, "sleep 2; echo done", shell=True)
f... | 5 | 2011-03-06T09:43:22Z | [
"python",
"callback",
"subprocess",
"exit"
] |
Python subprocess: callback when cmd exits | 2,581,817 | <p>I'm currently launching a programme using <code>subprocess.Popen(cmd, shell=TRUE)</code></p>
<p>I'm fairly new to Python, but it 'feels' like there ought to be some api that lets me do something similar to:</p>
<pre><code>subprocess.Popen(cmd, shell=TRUE, postexec_fn=function_to_call_on_exit)
</code></pre>
<p>I ... | 32 | 2010-04-05T23:45:06Z | 10,823,905 | <p>I modified Daniel G's answer to simply pass the subprocess.Popen args and kwargs as themselves instead of as a separate tupple/list, since I wanted to use keyword arguments with subprocess.Popen.</p>
<p>In my case I had a method <code>postExec()</code> that I wanted to run after <code>subprocess.Popen('exe', cwd=WO... | 5 | 2012-05-30T20:39:33Z | [
"python",
"callback",
"subprocess",
"exit"
] |
Getting traceback from Python C API | 2,581,953 | <p>I have a Python C API extension module which occassionally falls over with an uninformative "MemoryError". It's clearly not an error that's catered for by the module's exception handlers. How do I get a more informative error traceback so I can figure out what's gone wrong in the extension module? </p>
<p>Perhaps t... | 1 | 2010-04-06T00:29:33Z | 2,581,976 | <p>Looks like the extension module is claiming to be out of memory -- whether that's true or false, of course, it's impossible to tell without looking at the extension's sources. Just in case it's true, so that the scarcity of memory might impede a traceback, an old trick is to get some memory earlier and drop it in t... | 2 | 2010-04-06T00:37:18Z | [
"python",
"python-c-api"
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.