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 listlengths 1 5 |
|---|---|---|---|---|---|---|---|---|---|
Error in nested for loops (Python) | 1,487,561 | <p>I am getting an error in the following code. The Error message is <code>"Error: Inconsistent indentation detected!"</code></p>
<pre><code>s=[30,40,50]
a=[5e6,6e6,7e6,8e6,8.5e6,9e6,10e6,12e6]
p=[0.0,0.002,0.004,0.006,0.008,0.01,0.015,0.05,0.1,0.15,0.2]
j=0
b=0
x=0
for j in s:
h=s[j]
print "here is the firs... | 1 | 2009-09-28T15:05:01Z | 1,487,573 | <p>Your three lines initing your variable to zero are at a different indentation than the rest of your code. Even the code display here on stackoverflow shows that. </p>
<p>Also, check that you haven't mixed tabs and spaces.</p>
| 2 | 2009-09-28T15:06:09Z | [
"python",
"syntax"
] |
Error in nested for loops (Python) | 1,487,561 | <p>I am getting an error in the following code. The Error message is <code>"Error: Inconsistent indentation detected!"</code></p>
<pre><code>s=[30,40,50]
a=[5e6,6e6,7e6,8e6,8.5e6,9e6,10e6,12e6]
p=[0.0,0.002,0.004,0.006,0.008,0.01,0.015,0.05,0.1,0.15,0.2]
j=0
b=0
x=0
for j in s:
h=s[j]
print "here is the firs... | 1 | 2009-09-28T15:05:01Z | 1,487,586 | <p>Once you cleaned your tabs and spaces (you should have only tabs or only spaces), you'd need to fix your loops:</p>
<pre><code>s = [30,40,50]
a = [5e6,6e6,7e6,8e6,8.5e6,9e6,10e6,12e6]
p = [0.0,0.002,0.004,0.006,0.008,0.01,0.015,0.05,0.1,0.15,0.2]
for j in s: # within loop j is being 30 then 40 then 50, same... | 6 | 2009-09-28T15:09:28Z | [
"python",
"syntax"
] |
Error in nested for loops (Python) | 1,487,561 | <p>I am getting an error in the following code. The Error message is <code>"Error: Inconsistent indentation detected!"</code></p>
<pre><code>s=[30,40,50]
a=[5e6,6e6,7e6,8e6,8.5e6,9e6,10e6,12e6]
p=[0.0,0.002,0.004,0.006,0.008,0.01,0.015,0.05,0.1,0.15,0.2]
j=0
b=0
x=0
for j in s:
h=s[j]
print "here is the firs... | 1 | 2009-09-28T15:05:01Z | 1,487,630 | <p>I also think it's a tab/space mixing problem. Some editors, like Textmate, has the option for displaying 'invisible' characters, like tab and newline. Comes very handy when you code, especially in Python.</p>
| 1 | 2009-09-28T15:17:04Z | [
"python",
"syntax"
] |
Error in nested for loops (Python) | 1,487,561 | <p>I am getting an error in the following code. The Error message is <code>"Error: Inconsistent indentation detected!"</code></p>
<pre><code>s=[30,40,50]
a=[5e6,6e6,7e6,8e6,8.5e6,9e6,10e6,12e6]
p=[0.0,0.002,0.004,0.006,0.008,0.01,0.015,0.05,0.1,0.15,0.2]
j=0
b=0
x=0
for j in s:
h=s[j]
print "here is the firs... | 1 | 2009-09-28T15:05:01Z | 1,487,639 | <p>SilentGhost is correct -- unlike languages like Javascript, when you write</p>
<pre><code>s = [30, 40, 50]
for j in s:
</code></pre>
<p>Then j is not assigned 0, 1, and 2 -- it is assigned the actual values 30, 40, and 50. So there is no need to say, on another line,</p>
<pre><code>h = s[j]
</code></pre>
<p>In f... | 5 | 2009-09-28T15:18:42Z | [
"python",
"syntax"
] |
Error in nested for loops (Python) | 1,487,561 | <p>I am getting an error in the following code. The Error message is <code>"Error: Inconsistent indentation detected!"</code></p>
<pre><code>s=[30,40,50]
a=[5e6,6e6,7e6,8e6,8.5e6,9e6,10e6,12e6]
p=[0.0,0.002,0.004,0.006,0.008,0.01,0.015,0.05,0.1,0.15,0.2]
j=0
b=0
x=0
for j in s:
h=s[j]
print "here is the firs... | 1 | 2009-09-28T15:05:01Z | 1,487,767 | <p>This part:</p>
<pre> for b in a:
c=a[b] #too much indentation
</pre>
<p>the "c=a[b]" is indented 8 spaces instead of 4. It needs to be only 4 spaces (ie. one python indentation).</p>
<p>And Ian is right, the "for x in y" syntax is different than other languages.</p>
... | 0 | 2009-09-28T15:40:54Z | [
"python",
"syntax"
] |
Type of object from udp buffer in python using metaclasses/reflection | 1,487,582 | <p>Is it possible to extract type of object or class name from message received on a udp socket in python using metaclasses/reflection ?</p>
<p>The scenario is like this:</p>
<ol>
<li><p>Receive udp buffer on a socket.</p></li>
<li><p>The UDP buffer is a serialized binary string(a message). But the type of message is... | 1 | 2009-09-28T15:08:34Z | 1,487,602 | <p>Updated answer after updated question:</p>
<p>"But the type of message is not known at this time. So can't de-serialize into appropriate message."</p>
<p>What you get is a sequence of bytes. How that sequence of types should be interpreted is a question of how the protocol looks. Only you know what protocol you us... | 0 | 2009-09-28T15:12:17Z | [
"python",
"sockets",
"udp"
] |
Type of object from udp buffer in python using metaclasses/reflection | 1,487,582 | <p>Is it possible to extract type of object or class name from message received on a udp socket in python using metaclasses/reflection ?</p>
<p>The scenario is like this:</p>
<ol>
<li><p>Receive udp buffer on a socket.</p></li>
<li><p>The UDP buffer is a serialized binary string(a message). But the type of message is... | 1 | 2009-09-28T15:08:34Z | 1,487,612 | <p>You need to use a serialization module. <a href="http://docs.python.org/library/pickle.html" rel="nofollow">pickle</a> and <a href="http://docs.python.org/library/marshal.html" rel="nofollow">marshal</a> are both options. They provide functions to turn objects into bytestreams, and back again.</p>
| 0 | 2009-09-28T15:13:37Z | [
"python",
"sockets",
"udp"
] |
Type of object from udp buffer in python using metaclasses/reflection | 1,487,582 | <p>Is it possible to extract type of object or class name from message received on a udp socket in python using metaclasses/reflection ?</p>
<p>The scenario is like this:</p>
<ol>
<li><p>Receive udp buffer on a socket.</p></li>
<li><p>The UDP buffer is a serialized binary string(a message). But the type of message is... | 1 | 2009-09-28T15:08:34Z | 1,487,619 | <p>What you receive from the udp socket is a byte string -- that's all the "type of object or class name" that's actually <em>there</em>. If the byte string was built as a serialized object (e.g. via <code>pickle</code>, or maybe <code>marshal</code> etc) then you can deserialize it back to an object (using e.g. <code... | 2 | 2009-09-28T15:14:52Z | [
"python",
"sockets",
"udp"
] |
Server side clusters of coordinates based on zoom level | 1,487,704 | <p>Thanks to this <a href="http://stackoverflow.com/questions/986852/clustering-coordinates-on-server-side/995876#995876">answer </a> I managed to come up with a temporary solution to my problem.</p>
<p>However, with a list of 6000 points that grows everyday it's becoming slower and slower.</p>
<p>I can't use a third... | 1 | 2009-09-28T15:28:20Z | 1,487,750 | <p>I don't see why you have to "cluster" on the fly. Summarize at each zoom level at a resolution you're happy with.</p>
<p>Have a simply structure of X, Y, # of links. When someone adds a link, you insert the real locations (Zoom level max, or whatever), then start bubbling up from there.</p>
<p>Eventually you'll ha... | 2 | 2009-09-28T15:37:08Z | [
"python",
"google-maps",
"postgresql",
"google-maps-markers",
"cluster-analysis"
] |
Server side clusters of coordinates based on zoom level | 1,487,704 | <p>Thanks to this <a href="http://stackoverflow.com/questions/986852/clustering-coordinates-on-server-side/995876#995876">answer </a> I managed to come up with a temporary solution to my problem.</p>
<p>However, with a list of 6000 points that grows everyday it's becoming slower and slower.</p>
<p>I can't use a third... | 1 | 2009-09-28T15:28:20Z | 1,488,040 | <p>I am currently doing dynamic server-side clustering of about 2,000 markers, but it runs pretty quick up to 20,000. You can see discussion of my algorithm here:</p>
<p><a href="http://stackoverflow.com/questions/1434222/">Map Clustering Algorithm</a></p>
<p>Whenever the user moves the map I send a request with the... | 1 | 2009-09-28T16:34:55Z | [
"python",
"google-maps",
"postgresql",
"google-maps-markers",
"cluster-analysis"
] |
Python object inspector? | 1,487,952 | <p>besides from using a completely integrated IDE with debugger for python (like with Eclipse), is there any little tool for achieving this:</p>
<ul>
<li>when running a program, i want to be able to hook somewhere into it (similar to inserting a print statement) and call a window with an object inspector (a tree view)... | 2 | 2009-09-28T16:17:53Z | 1,488,064 | <p>You can use ipython, with the <code>%debug</code> statement. Once your code crashes, you can add breakpoints, see objects etc. A very crude way to kickoff the debugger is to <code>raise Exception</code> at some line of your code, run it in ipython, the type <code>%debug</code> when it crashes.</p>
| 0 | 2009-09-28T16:39:38Z | [
"python",
"debugging",
"introspection"
] |
Python object inspector? | 1,487,952 | <p>besides from using a completely integrated IDE with debugger for python (like with Eclipse), is there any little tool for achieving this:</p>
<ul>
<li>when running a program, i want to be able to hook somewhere into it (similar to inserting a print statement) and call a window with an object inspector (a tree view)... | 2 | 2009-09-28T16:17:53Z | 1,488,102 | <p>pdb isn't windowed, it runs in a console, but it's the standard way to debug in Python programs.</p>
<p>Insert this where you want to stop:</p>
<pre><code>import pdb;pdb.set_trace()
</code></pre>
<p>you'll get a prompt on stdout.</p>
| 3 | 2009-09-28T16:44:42Z | [
"python",
"debugging",
"introspection"
] |
Python object inspector? | 1,487,952 | <p>besides from using a completely integrated IDE with debugger for python (like with Eclipse), is there any little tool for achieving this:</p>
<ul>
<li>when running a program, i want to be able to hook somewhere into it (similar to inserting a print statement) and call a window with an object inspector (a tree view)... | 2 | 2009-09-28T16:17:53Z | 1,488,138 | <p>If a commercial solution is acceptable, <a href="http://www.wingware.com/" rel="nofollow">Wingware</a> may be the answer to the OP's desires (Wingware does have free versions, but I don't think they have the full debugging power he requires, which the for-pay versions do provide).</p>
| 1 | 2009-09-28T16:53:57Z | [
"python",
"debugging",
"introspection"
] |
Python object inspector? | 1,487,952 | <p>besides from using a completely integrated IDE with debugger for python (like with Eclipse), is there any little tool for achieving this:</p>
<ul>
<li>when running a program, i want to be able to hook somewhere into it (similar to inserting a print statement) and call a window with an object inspector (a tree view)... | 2 | 2009-09-28T16:17:53Z | 1,488,917 | <p><a href="http://winpdb.org/">Winpdb</a> is a <strong>platform independent</strong> graphical GPL Python debugger with an object inspector.</p>
<p>It supports remote debugging over a network, multiple threads, namespace modification, embedded debugging, encrypted communication and is up to 20 times faster than pdb.<... | 5 | 2009-09-28T19:29:55Z | [
"python",
"debugging",
"introspection"
] |
Python object inspector? | 1,487,952 | <p>besides from using a completely integrated IDE with debugger for python (like with Eclipse), is there any little tool for achieving this:</p>
<ul>
<li>when running a program, i want to be able to hook somewhere into it (similar to inserting a print statement) and call a window with an object inspector (a tree view)... | 2 | 2009-09-28T16:17:53Z | 1,490,283 | <p><a href="http://aymanh.com/python-debugging-techniques" rel="nofollow">Python Debugging Techniques</a> is worth reading. and <a href="http://www.reddit.com/r/programming/comments/9fst4/python%5Fdebugging%5Ftechniques/" rel="nofollow">it's Reddit's comment</a> is worth reading too. I have really find some nice debug ... | 1 | 2009-09-29T02:23:25Z | [
"python",
"debugging",
"introspection"
] |
scipy 'Minimize the sum of squares of a set of equations' | 1,488,227 | <p>I face a problem in scipy 'leastsq' optimisation routine, if i execute the following program it says</p>
<pre><code> raise errors[info][1], errors[info][0]
TypeError: Improper input parameters.
</code></pre>
<p>and sometimes <code>index out of range for an array</code>...</p>
<pre><code>from scipy import *
imp... | 1 | 2009-09-28T17:12:23Z | 1,488,516 | <p>Just looking at the <a href="http://docs.scipy.org/doc/scipy/reference/generated/scipy.optimize.leastsq.html" rel="nofollow">least squares docs</a>, it might be that your function <code>func</code> is defined incorrectly. You're assuming that you always receive an array of at least length 2, but the optimize functio... | 1 | 2009-09-28T18:10:54Z | [
"python",
"scipy"
] |
scipy 'Minimize the sum of squares of a set of equations' | 1,488,227 | <p>I face a problem in scipy 'leastsq' optimisation routine, if i execute the following program it says</p>
<pre><code> raise errors[info][1], errors[info][0]
TypeError: Improper input parameters.
</code></pre>
<p>and sometimes <code>index out of range for an array</code>...</p>
<pre><code>from scipy import *
imp... | 1 | 2009-09-28T17:12:23Z | 1,488,889 | <p><code>leastsq</code> works with vectors so the residual function, <code>func</code>, needs to return a vector of length at least two. So if you replace <code>return eqn</code> with <code>return [eqn, 0.]</code>, your example will work. Running it gives:</p>
<pre><code>optimized parameters: (array([10., 10.]), 2)... | 2 | 2009-09-28T19:24:23Z | [
"python",
"scipy"
] |
scipy 'Minimize the sum of squares of a set of equations' | 1,488,227 | <p>I face a problem in scipy 'leastsq' optimisation routine, if i execute the following program it says</p>
<pre><code> raise errors[info][1], errors[info][0]
TypeError: Improper input parameters.
</code></pre>
<p>and sometimes <code>index out of range for an array</code>...</p>
<pre><code>from scipy import *
imp... | 1 | 2009-09-28T17:12:23Z | 1,489,194 | <p>Since you want to minimize a simple scalar function (<code>func()</code> returns a single value, not a list of values), <code>scipy.optimize.leastsq()</code> should be replaced by a call to one of the <code>fmin</code> functions (with the appropriate arguments):</p>
<pre><code>x = optimize.fmin(func, Init)
</code><... | 1 | 2009-09-28T20:26:18Z | [
"python",
"scipy"
] |
Mimic Python's strip() function in C | 1,488,372 | <p>I started on a little toy project in C lately and have been scratching my head over the best way to mimic the strip() functionality that is part of the python string objects. </p>
<p>Reading around for fscanf or sscanf says that the string is processed upto the first whitespace that is encountered.</p>
<p>fgets do... | 3 | 2009-09-28T17:41:06Z | 1,488,398 | <p>Seems like you want something like trim, a quick search on google leads to <a href="http://www.unix.com/high-level-programming/21264-how-trim-white-space-around-string-c-program.html" rel="nofollow">this</a> forum thread.</p>
| 0 | 2009-09-28T17:47:02Z | [
"python",
"c",
"string",
"fgets"
] |
Mimic Python's strip() function in C | 1,488,372 | <p>I started on a little toy project in C lately and have been scratching my head over the best way to mimic the strip() functionality that is part of the python string objects. </p>
<p>Reading around for fscanf or sscanf says that the string is processed upto the first whitespace that is encountered.</p>
<p>fgets do... | 3 | 2009-09-28T17:41:06Z | 1,488,403 | <p>Python strings' <code>strip</code> method removes both trailing and leading whitespace. The two halves of the problem are very different when working on a C "string" (array of char, \0 terminated).</p>
<p>For trailing whitespace: set a pointer (or equivalently index) to the existing trailing \0. Keep decrementing t... | 12 | 2009-09-28T17:48:10Z | [
"python",
"c",
"string",
"fgets"
] |
Mimic Python's strip() function in C | 1,488,372 | <p>I started on a little toy project in C lately and have been scratching my head over the best way to mimic the strip() functionality that is part of the python string objects. </p>
<p>Reading around for fscanf or sscanf says that the string is processed upto the first whitespace that is encountered.</p>
<p>fgets do... | 3 | 2009-09-28T17:41:06Z | 1,488,419 | <p>There is no standard C implementation for a strip() or trim() function. That said, here's the one included in the Linux kernel:</p>
<pre><code>char *strstrip(char *s)
{
size_t size;
char *end;
size = strlen(s);
if (!size)
return s;
end = s + size - 1;
... | 9 | 2009-09-28T17:51:07Z | [
"python",
"c",
"string",
"fgets"
] |
Mimic Python's strip() function in C | 1,488,372 | <p>I started on a little toy project in C lately and have been scratching my head over the best way to mimic the strip() functionality that is part of the python string objects. </p>
<p>Reading around for fscanf or sscanf says that the string is processed upto the first whitespace that is encountered.</p>
<p>fgets do... | 3 | 2009-09-28T17:41:06Z | 1,488,503 | <p>If you want to remove, <b>in place</b>, the final newline on a line, you can use this snippet:</p>
<pre><code>size_t s = strlen(buf);
if (s && (buf[s-1] == '\n')) buf[--s] = 0;
</code></pre>
<p>To faithfully mimic Python's <code>str.strip([chars])</code> method (the way I interpreted its workings), you nee... | 0 | 2009-09-28T18:07:47Z | [
"python",
"c",
"string",
"fgets"
] |
Mimic Python's strip() function in C | 1,488,372 | <p>I started on a little toy project in C lately and have been scratching my head over the best way to mimic the strip() functionality that is part of the python string objects. </p>
<p>Reading around for fscanf or sscanf says that the string is processed upto the first whitespace that is encountered.</p>
<p>fgets do... | 3 | 2009-09-28T17:41:06Z | 1,489,407 | <p>I wrote C code to implement this function. I also wrote a few trivial tests to make sure my function does sensible things.</p>
<p>This function writes to a buffer you provide, and should never write past the end of the buffer, so it should not be prone to buffer overflow security issues.</p>
<p>Note: only Test() ... | 0 | 2009-09-28T21:13:15Z | [
"python",
"c",
"string",
"fgets"
] |
Mimic Python's strip() function in C | 1,488,372 | <p>I started on a little toy project in C lately and have been scratching my head over the best way to mimic the strip() functionality that is part of the python string objects. </p>
<p>Reading around for fscanf or sscanf says that the string is processed upto the first whitespace that is encountered.</p>
<p>fgets do... | 3 | 2009-09-28T17:41:06Z | 1,489,496 | <p>I asked a very similar question long ago. See <a href="http://stackoverflow.com/questions/122616/painless-way-to-trim-leading-trailing-whitespace-in-c">here</a>; there are ways to do it both in-place and with a new copy.</p>
| 0 | 2009-09-28T21:34:48Z | [
"python",
"c",
"string",
"fgets"
] |
What are good python libraries for the following needs? | 1,488,691 | <p>What are good python libraries for the following needs:</p>
<ul>
<li>MVC</li>
<li>Domain Abstraction</li>
<li>Database Abstraction</li>
<li>Video library (just to create thumbnails) </li>
</ul>
<p>I already know that SQLAlchemy is really good for Database Abstraction so don't bother with it unless you want to sug... | 2 | 2009-09-28T18:45:36Z | 1,488,707 | <p><a href="http://www.djangoproject.com/" rel="nofollow" title="django">django</a> is a pretty good mvc framework with an orm</p>
| 1 | 2009-09-28T18:48:14Z | [
"python",
"model-view-controller",
"libraries",
"domain-model",
"database-abstraction"
] |
What are good python libraries for the following needs? | 1,488,691 | <p>What are good python libraries for the following needs:</p>
<ul>
<li>MVC</li>
<li>Domain Abstraction</li>
<li>Database Abstraction</li>
<li>Video library (just to create thumbnails) </li>
</ul>
<p>I already know that SQLAlchemy is really good for Database Abstraction so don't bother with it unless you want to sug... | 2 | 2009-09-28T18:45:36Z | 1,488,731 | <p>You could go with <a href="http://turbogears.org/" rel="nofollow">http://turbogears.org/</a> . Its like Django, but uses "of the shelves" existing modules.</p>
<blockquote>
<p>TurboGears 2 is the built on top of the experience of several next generation web frameworks including TurboGears 1 (of course), Django, a... | 1 | 2009-09-28T18:52:03Z | [
"python",
"model-view-controller",
"libraries",
"domain-model",
"database-abstraction"
] |
What are good python libraries for the following needs? | 1,488,691 | <p>What are good python libraries for the following needs:</p>
<ul>
<li>MVC</li>
<li>Domain Abstraction</li>
<li>Database Abstraction</li>
<li>Video library (just to create thumbnails) </li>
</ul>
<p>I already know that SQLAlchemy is really good for Database Abstraction so don't bother with it unless you want to sug... | 2 | 2009-09-28T18:45:36Z | 1,488,832 | <p>Have you tried wxWidgets (well, <a href="http://www.wxpython.org" rel="nofollow">wxPython</a> in fact)? </p>
<p>It has nice documentation (which is always a good thing), and allows creating code in MVC manner. It's just the GUI library, but allows some simple image manipulation (if it's not good enough for you try ... | 4 | 2009-09-28T19:13:23Z | [
"python",
"model-view-controller",
"libraries",
"domain-model",
"database-abstraction"
] |
save method in a view | 1,489,041 | <p>I have a very simple model:</p>
<pre><code>class Artist(models.Model):
name = models.CharField(max_length=64, unique=False)
band = models.CharField(max_length=64, unique=False)
instrument = models.CharField(max_length=64, unique=False)
def __unicode__ (self):
return self.name
</code></pre>
<p>that I'm using... | 1 | 2009-09-28T19:57:35Z | 1,490,428 | <p>Apparently the problem resided in my template. I was using </p>
<pre><code> <form action="display/" method="POST">
</code></pre>
<p>as opposed to</p>
<pre><code> <form action="." method="POST">
</code></pre>
<p>also changed my HttpRequest object from <code>render_to_response</code> to <code>H... | 1 | 2009-09-29T03:24:33Z | [
"python",
"django",
"django-forms"
] |
Managing Perl habits in a Python environment | 1,489,355 | <p>Perl habits die hard. Variable declaration, scoping, global/local is different between the 2 languages. Is there a set of recommended python language idioms that will render the transition from perl coding to python coding less painful. </p>
<p>Subtle variable misspelling can waste an extraordinary amount of time.<... | 6 | 2009-09-28T21:02:51Z | 1,489,505 | <p>I like the question, but I don't have any experience in Perl so I'm not sure how to best advise you.</p>
<p>I suggest you do a Google search for "Python idioms". You will find some gems. In particular:</p>
<p><a href="http://python.net/~goodger/projects/pycon/2007/idiomatic/handout.html" rel="nofollow">http://py... | 1 | 2009-09-28T21:36:16Z | [
"python",
"perl",
"transitions"
] |
Managing Perl habits in a Python environment | 1,489,355 | <p>Perl habits die hard. Variable declaration, scoping, global/local is different between the 2 languages. Is there a set of recommended python language idioms that will render the transition from perl coding to python coding less painful. </p>
<p>Subtle variable misspelling can waste an extraordinary amount of time.<... | 6 | 2009-09-28T21:02:51Z | 1,489,635 | <p>In python $_ does not exist except in the python shell and variables with global scope are frowned upon.</p>
<p>In practice this has two major effects:</p>
<ol>
<li>In Python you can't use regular expressions as naturally as Perl, s0 matching each iterated $_ and similarly catching matches is more cumbersome</li>
... | 1 | 2009-09-28T22:11:47Z | [
"python",
"perl",
"transitions"
] |
Managing Perl habits in a Python environment | 1,489,355 | <p>Perl habits die hard. Variable declaration, scoping, global/local is different between the 2 languages. Is there a set of recommended python language idioms that will render the transition from perl coding to python coding less painful. </p>
<p>Subtle variable misspelling can waste an extraordinary amount of time.<... | 6 | 2009-09-28T21:02:51Z | 1,489,799 | <p>Don't mis-type your variable names. Seriously. Use short, easy, descriptive ones, use them locally, and don't rely on the global scope. </p>
<p>If you're doing a larger project that isn't served well by this, use pylint, unit tests and coverage.py to make SURE your code does what you expect.</p>
<p>Copied from a c... | 0 | 2009-09-28T23:06:07Z | [
"python",
"perl",
"transitions"
] |
Managing Perl habits in a Python environment | 1,489,355 | <p>Perl habits die hard. Variable declaration, scoping, global/local is different between the 2 languages. Is there a set of recommended python language idioms that will render the transition from perl coding to python coding less painful. </p>
<p>Subtle variable misspelling can waste an extraordinary amount of time.<... | 6 | 2009-09-28T21:02:51Z | 1,490,948 | <p>Splitting Python classes into separate files (like in Java, one class per file) helps find scoping problems, although this is not idiomatic python (that is, not pythonic).</p>
<p>I have been writing python after much perl and found this from tchrist to be useful, even though it is old:</p>
<p><a href="http://linux... | 2 | 2009-09-29T06:42:14Z | [
"python",
"perl",
"transitions"
] |
Managing Perl habits in a Python environment | 1,489,355 | <p>Perl habits die hard. Variable declaration, scoping, global/local is different between the 2 languages. Is there a set of recommended python language idioms that will render the transition from perl coding to python coding less painful. </p>
<p>Subtle variable misspelling can waste an extraordinary amount of time.<... | 6 | 2009-09-28T21:02:51Z | 1,491,218 | <p>Read, understand, follow, and love <strong><a href="http://python.org/dev/peps/pep-0008/" rel="nofollow">PEP 8</a></strong>, which details the style guidelines for <em>everything</em> about Python.</p>
<p>Seriously, if you want to know about the recommended idioms and habits of Python, that's the source.</p>
| 1 | 2009-09-29T08:17:38Z | [
"python",
"perl",
"transitions"
] |
When is it advisable to use a ret_val variable? | 1,489,372 | <p>I have seen conflicting advice on whether the following code is better</p>
<pre><code>def function():
ret_val = 0
if some_condition():
ret_val = 2
else:
ret_val = 3
return ret_val
</code></pre>
<p>or whether this is better:</p>
<pre><code>def function():
if some_condition():
... | 3 | 2009-09-28T21:06:45Z | 1,489,400 | <p>It depends on the language to a large extent, however I would go with the second method returning the value directly rather than imposing another superfluous variable. The second method is cleaner, more precise and therefore more maintainable in my opinion.</p>
| 1 | 2009-09-28T21:11:45Z | [
"python",
"coding-style",
"return-value"
] |
When is it advisable to use a ret_val variable? | 1,489,372 | <p>I have seen conflicting advice on whether the following code is better</p>
<pre><code>def function():
ret_val = 0
if some_condition():
ret_val = 2
else:
ret_val = 3
return ret_val
</code></pre>
<p>or whether this is better:</p>
<pre><code>def function():
if some_condition():
... | 3 | 2009-09-28T21:06:45Z | 1,489,404 | <p>In Python, it is quite common to have a return statement in the middle of the function - in particular, if it is an early exit. Your example often is rewritten as</p>
<pre><code>def function():
if some_condition():
return 2
return 3
</code></pre>
<p>I.e. you drop the else case when the if ends with... | 5 | 2009-09-28T21:12:36Z | [
"python",
"coding-style",
"return-value"
] |
When is it advisable to use a ret_val variable? | 1,489,372 | <p>I have seen conflicting advice on whether the following code is better</p>
<pre><code>def function():
ret_val = 0
if some_condition():
ret_val = 2
else:
ret_val = 3
return ret_val
</code></pre>
<p>or whether this is better:</p>
<pre><code>def function():
if some_condition():
... | 3 | 2009-09-28T21:06:45Z | 1,489,409 | <p>In a language with function prototypes like C++ or Java, the compiler enforces that you return <em>something</em> of the correct type, even if execution would otherwise fall off the end of the function. In Python, since there are no function prototypes, falling off the end of the function will return the special val... | 0 | 2009-09-28T21:13:24Z | [
"python",
"coding-style",
"return-value"
] |
When is it advisable to use a ret_val variable? | 1,489,372 | <p>I have seen conflicting advice on whether the following code is better</p>
<pre><code>def function():
ret_val = 0
if some_condition():
ret_val = 2
else:
ret_val = 3
return ret_val
</code></pre>
<p>or whether this is better:</p>
<pre><code>def function():
if some_condition():
... | 3 | 2009-09-28T21:06:45Z | 1,489,463 | <p>Returning values directly is not terrible for small functions like your example. However, if you have a large or complex function then multiple return points can be more difficult to debug. If you have a coding standard I'd refer to it (here the variable is preferred according to our company coding standard).</p>
| 0 | 2009-09-28T21:24:09Z | [
"python",
"coding-style",
"return-value"
] |
When is it advisable to use a ret_val variable? | 1,489,372 | <p>I have seen conflicting advice on whether the following code is better</p>
<pre><code>def function():
ret_val = 0
if some_condition():
ret_val = 2
else:
ret_val = 3
return ret_val
</code></pre>
<p>or whether this is better:</p>
<pre><code>def function():
if some_condition():
... | 3 | 2009-09-28T21:06:45Z | 1,489,466 | <p>I suppose it's more a question of style and coding conventions. Generally, theory tells us that multiple exit points are bad. In practice it can be easier to follow to simply return inside each condition. The code is likely to be compiled down to very similar if not identical instructions, so it has little to no fun... | 1 | 2009-09-28T21:25:11Z | [
"python",
"coding-style",
"return-value"
] |
When is it advisable to use a ret_val variable? | 1,489,372 | <p>I have seen conflicting advice on whether the following code is better</p>
<pre><code>def function():
ret_val = 0
if some_condition():
ret_val = 2
else:
ret_val = 3
return ret_val
</code></pre>
<p>or whether this is better:</p>
<pre><code>def function():
if some_condition():
... | 3 | 2009-09-28T21:06:45Z | 1,489,468 | <p>Don't use an accumulator unless it's absolutely unavoidable. It introduces unnecessary statefulness and branching into your procedures, which you then have to track manually. By returning early, you can reduce the state and branch count of your code.</p>
<blockquote>
<p>Specifically in the past I've heard that st... | 5 | 2009-09-28T21:26:25Z | [
"python",
"coding-style",
"return-value"
] |
When is it advisable to use a ret_val variable? | 1,489,372 | <p>I have seen conflicting advice on whether the following code is better</p>
<pre><code>def function():
ret_val = 0
if some_condition():
ret_val = 2
else:
ret_val = 3
return ret_val
</code></pre>
<p>or whether this is better:</p>
<pre><code>def function():
if some_condition():
... | 3 | 2009-09-28T21:06:45Z | 1,489,470 | <p>A further alternative in recent versions of Python (since 2.6?) is a ternary operator statement like this:</p>
<pre><code>def function():
return (2 if some_condition() else 3)
</code></pre>
<p>Just in case you like that better.</p>
| 1 | 2009-09-28T21:27:29Z | [
"python",
"coding-style",
"return-value"
] |
When is it advisable to use a ret_val variable? | 1,489,372 | <p>I have seen conflicting advice on whether the following code is better</p>
<pre><code>def function():
ret_val = 0
if some_condition():
ret_val = 2
else:
ret_val = 3
return ret_val
</code></pre>
<p>or whether this is better:</p>
<pre><code>def function():
if some_condition():
... | 3 | 2009-09-28T21:06:45Z | 1,489,654 | <p>For primitives, it doesn't matter. In a language like C++ (& presumably with structs in C it's the compiler will do something similar), the compiler is able to optimize the <a href="http://www.parashift.com/c++-faq-lite/ctors.html#faq-10.9" rel="nofollow">copy constructor</a> out if you ensure all code paths re... | 1 | 2009-09-28T22:16:42Z | [
"python",
"coding-style",
"return-value"
] |
When is it advisable to use a ret_val variable? | 1,489,372 | <p>I have seen conflicting advice on whether the following code is better</p>
<pre><code>def function():
ret_val = 0
if some_condition():
ret_val = 2
else:
ret_val = 3
return ret_val
</code></pre>
<p>or whether this is better:</p>
<pre><code>def function():
if some_condition():
... | 3 | 2009-09-28T21:06:45Z | 1,489,690 | <p>Although people advocate single exit strategy, I find it useful to return early. That way you don't have to keep track when you are adding code later.</p>
| 1 | 2009-09-28T22:26:49Z | [
"python",
"coding-style",
"return-value"
] |
When is it advisable to use a ret_val variable? | 1,489,372 | <p>I have seen conflicting advice on whether the following code is better</p>
<pre><code>def function():
ret_val = 0
if some_condition():
ret_val = 2
else:
ret_val = 3
return ret_val
</code></pre>
<p>or whether this is better:</p>
<pre><code>def function():
if some_condition():
... | 3 | 2009-09-28T21:06:45Z | 1,489,917 | <p>Stylistics aside, let's take a look at the disassembly for the two approaches:</p>
<pre><code>>>> def foo():
... r = 0
... if bar():
... r = 2
... else:
... r = 3
... return r
...
>>> dis.dis(foo)
2 0 LOAD_CONST 1 (0)
... | 2 | 2009-09-28T23:53:41Z | [
"python",
"coding-style",
"return-value"
] |
When is it advisable to use a ret_val variable? | 1,489,372 | <p>I have seen conflicting advice on whether the following code is better</p>
<pre><code>def function():
ret_val = 0
if some_condition():
ret_val = 2
else:
ret_val = 3
return ret_val
</code></pre>
<p>or whether this is better:</p>
<pre><code>def function():
if some_condition():
... | 3 | 2009-09-28T21:06:45Z | 1,490,154 | <p>Did we forget why "multiple exit points" was considered harmful in the first place? Back in the day (before widespread access to good exception handling and finally constructs, or managing objects like <code>auto_ptr</code> that do cleanup when they leave scope), this was the problem that haunted many multi-exit fu... | 8 | 2009-09-29T01:35:54Z | [
"python",
"coding-style",
"return-value"
] |
How do I find out my python path using python? | 1,489,599 | <p>How do I find out which directories are listed in my systemâs <code>PYTHONPATH</code> variable, from within a Python script (or the interactive shell)?</p>
| 174 | 2009-09-28T22:01:26Z | 1,489,625 | <p><code>sys.path</code> might include items that aren't specifically in your <code>PYTHONPATH</code> environment variable. To query the variable directly, use:</p>
<pre><code>import os
try:
user_paths = os.environ['PYTHONPATH'].split(os.pathsep)
except KeyError:
user_paths = []
</code></pre>
| 118 | 2009-09-28T22:08:36Z | [
"python",
"python-module",
"pythonpath"
] |
How do I find out my python path using python? | 1,489,599 | <p>How do I find out which directories are listed in my systemâs <code>PYTHONPATH</code> variable, from within a Python script (or the interactive shell)?</p>
| 174 | 2009-09-28T22:01:26Z | 1,489,694 | <p>Can't seem to edit the other answer. Has a minor error in that it is Windows-only. The more generic solution is to use os.sep as below:</p>
<p>sys.path might include items that aren't specifically in your PYTHONPATH environment variable. To query the variable directly, use:</p>
<pre><code>import os
os.environ['P... | 9 | 2009-09-28T22:27:31Z | [
"python",
"python-module",
"pythonpath"
] |
How do I find out my python path using python? | 1,489,599 | <p>How do I find out which directories are listed in my systemâs <code>PYTHONPATH</code> variable, from within a Python script (or the interactive shell)?</p>
| 174 | 2009-09-28T22:01:26Z | 13,178,935 | <p>You would probably also want this:</p>
<pre><code>import sys
print(sys.path)
</code></pre>
<p>Or as a one liner from the terminal:</p>
<pre><code>python -c "import sys; print '\n'.join(sys.path)"
</code></pre>
| 297 | 2012-11-01T14:15:11Z | [
"python",
"python-module",
"pythonpath"
] |
How to exit the entire application from a Python thread? | 1,489,669 | <p>How can I exit my entire Python application from one of its threads? sys.exit() only terminates the thread in which it is called, so that is no help.</p>
<p>I would not like to use an os.kill() solution, as this isn't very clean.</p>
| 24 | 2009-09-28T22:20:59Z | 1,489,838 | <p>Short answer: use <a href="http://docs.python.org/library/os.html#os.%5Fexit"><code>os._exit</code></a>.</p>
<p>Long answer with example:</p>
<p>I yanked and slightly modified a simple threading example from <a href="http://www.devshed.com/c/a/Python/Basic-Threading-in-Python/1/">a tutorial on DevShed</a>:</p>
<p... | 16 | 2009-09-28T23:21:53Z | [
"python",
"multithreading"
] |
How to exit the entire application from a Python thread? | 1,489,669 | <p>How can I exit my entire Python application from one of its threads? sys.exit() only terminates the thread in which it is called, so that is no help.</p>
<p>I would not like to use an os.kill() solution, as this isn't very clean.</p>
| 24 | 2009-09-28T22:20:59Z | 1,489,972 | <p>If all your threads except the main ones are daemons, the best approach is generally <a href="https://docs.python.org/2/library/thread.html#thread.interrupt_main" rel="nofollow">thread.interrupt_main()</a> -- any thread can use it to raise a <code>KeyboardInterrupt</code> in the main thread, which can normally lead ... | 24 | 2009-09-29T00:17:28Z | [
"python",
"multithreading"
] |
How to exit the entire application from a Python thread? | 1,489,669 | <p>How can I exit my entire Python application from one of its threads? sys.exit() only terminates the thread in which it is called, so that is no help.</p>
<p>I would not like to use an os.kill() solution, as this isn't very clean.</p>
| 24 | 2009-09-28T22:20:59Z | 25,419,716 | <p>Using <code>thread.interrupt_main()</code> may not help in some situation. <code>KeyboardInterrupt</code>s are often used in command line applications to exit the current command or to clean the input line.</p>
<p>In addition, <code>os._exit</code> will kill the process immediately without running any <code>finally... | 6 | 2014-08-21T06:37:29Z | [
"python",
"multithreading"
] |
Migration to GAE | 1,489,886 | <p>What is the best way to migrate MySQL tables to Google Datastore and create python models for them?</p>
<p>I have a PHP+MySQL project that I want to migrate to Python+GAE project. So far the big obstacle is migrating the tables and creating corresponding models. Each table is about 110 columns wide. Creating a m... | 2 | 2009-09-28T23:39:58Z | 1,489,954 | <p>In your shoes, I'd write a one-shot Python script to read the existing MySQL schema (with <a href="http://sourceforge.net/projects/mysql-python/" rel="nofollow">MySQLdb</a>), generating a models.py to match (then do some manual checks and edits on the generated code, just in case). That's assuming that a data model... | 1 | 2009-09-29T00:11:18Z | [
"python",
"django",
"google-app-engine",
"gae-datastore"
] |
Migration to GAE | 1,489,886 | <p>What is the best way to migrate MySQL tables to Google Datastore and create python models for them?</p>
<p>I have a PHP+MySQL project that I want to migrate to Python+GAE project. So far the big obstacle is migrating the tables and creating corresponding models. Each table is about 110 columns wide. Creating a m... | 2 | 2009-09-28T23:39:58Z | 1,491,862 | <p>In general, generating your models automatically shouldn't be <em>too</em> difficult. Suppose you have a csv file for each table, with lines consisting of (field name, data type), then something like this would do the job:</p>
<pre><code># Maps MySQL types to Datastore property classes
type_map = {
'char': 'Str... | 4 | 2009-09-29T10:57:15Z | [
"python",
"django",
"google-app-engine",
"gae-datastore"
] |
Migration to GAE | 1,489,886 | <p>What is the best way to migrate MySQL tables to Google Datastore and create python models for them?</p>
<p>I have a PHP+MySQL project that I want to migrate to Python+GAE project. So far the big obstacle is migrating the tables and creating corresponding models. Each table is about 110 columns wide. Creating a m... | 2 | 2009-09-28T23:39:58Z | 1,491,888 | <p><a href="http://code.google.com/p/approcket/" rel="nofollow">approcket</a> can mysqlâgae or gae builtin remote api from google </p>
| 2 | 2009-09-29T11:04:17Z | [
"python",
"django",
"google-app-engine",
"gae-datastore"
] |
Migration to GAE | 1,489,886 | <p>What is the best way to migrate MySQL tables to Google Datastore and create python models for them?</p>
<p>I have a PHP+MySQL project that I want to migrate to Python+GAE project. So far the big obstacle is migrating the tables and creating corresponding models. Each table is about 110 columns wide. Creating a m... | 2 | 2009-09-28T23:39:58Z | 1,492,132 | <p>You could <a href="http://docs.djangoproject.com/en/dev/howto/legacy-databases/" rel="nofollow">migrate them to django models first</a></p>
<p>In particular use</p>
<pre><code>python manage.py inspectdb > models.py
</code></pre>
<p>And edit models.py until satisfied. You might have to put ForeignKeys in, adju... | 1 | 2009-09-29T12:03:24Z | [
"python",
"django",
"google-app-engine",
"gae-datastore"
] |
Migration to GAE | 1,489,886 | <p>What is the best way to migrate MySQL tables to Google Datastore and create python models for them?</p>
<p>I have a PHP+MySQL project that I want to migrate to Python+GAE project. So far the big obstacle is migrating the tables and creating corresponding models. Each table is about 110 columns wide. Creating a m... | 2 | 2009-09-28T23:39:58Z | 7,971,333 | <p>you don't need to</p>
<p><a href="http://code.google.com/apis/sql/" rel="nofollow">http://code.google.com/apis/sql/</a></p>
<p>:)</p>
| 1 | 2011-11-01T18:47:28Z | [
"python",
"django",
"google-app-engine",
"gae-datastore"
] |
Chat server with Twisted framework in python can't receive data from flash client | 1,489,931 | <p>I've develop a chat server using Twisted framework in Python. It works fine with a Telnet client. But when I use my flash client problem appear... </p>
<p>(the flash client work find with my old php chat server, I rewrote the server in python to gain performance) </p>
<p>The connexion is establish between the f... | 1 | 2009-09-29T00:02:51Z | 1,490,530 | <p>I find out that the default delimiter for line, use by Twisted is '\r\n'. It can be overwrite in a your children class with:</p>
<p>LineOnlyReceiver.delimiter = '\n' </p>
| 0 | 2009-09-29T04:13:14Z | [
"python",
"flash",
"twisted"
] |
Chat server with Twisted framework in python can't receive data from flash client | 1,489,931 | <p>I've develop a chat server using Twisted framework in Python. It works fine with a Telnet client. But when I use my flash client problem appear... </p>
<p>(the flash client work find with my old php chat server, I rewrote the server in python to gain performance) </p>
<p>The connexion is establish between the f... | 1 | 2009-09-29T00:02:51Z | 1,729,776 | <p>Changing <code>LineOnlyReceiver.delimiter</code> is a pretty bad idea, since that changes the delivery for <em>all</em> instances of <code>LineOnlyReceiver</code> (unless they've changed it themselves on a subclass or on the instance). If you ever happen to use any such code, it will probably break.</p>
<p>You sho... | 1 | 2009-11-13T15:06:58Z | [
"python",
"flash",
"twisted"
] |
ElementTree in Python 2.6.2 Processing Instructions support? | 1,489,949 | <p>I'm trying to create XML using the ElementTree object structure in python. It all works very well except when it comes to processing instructions. I can create a PI easily using the factory function ProcessingInstruction(), but it doesn't get added into the elementtree. I can add it manually, but I can't figure o... | 4 | 2009-09-29T00:09:27Z | 1,490,057 | <p>Yeah, I don't believe it's possible, sorry. ElementTree provides a simpler interface to (non-namespaced) element-centric XML processing than DOM, but the price for that is that it doesn't support the whole XML infoset.</p>
<p>There is no apparent way to represent the content that lives outside the root element (com... | 2 | 2009-09-29T00:52:37Z | [
"python",
"xml",
"elementtree"
] |
ElementTree in Python 2.6.2 Processing Instructions support? | 1,489,949 | <p>I'm trying to create XML using the ElementTree object structure in python. It all works very well except when it comes to processing instructions. I can create a PI easily using the factory function ProcessingInstruction(), but it doesn't get added into the elementtree. I can add it manually, but I can't figure o... | 4 | 2009-09-29T00:09:27Z | 1,490,588 | <p>I don't know much about ElementTree. But it is possible that you might be able to solve your problem using a library I wrote called "xe".</p>
<p>xe is a set of Python classes designed to make it easy to create structured XML. I haven't worked on it in a long time, for various reasons, but I'd be willing to help y... | 1 | 2009-09-29T04:35:44Z | [
"python",
"xml",
"elementtree"
] |
ElementTree in Python 2.6.2 Processing Instructions support? | 1,489,949 | <p>I'm trying to create XML using the ElementTree object structure in python. It all works very well except when it comes to processing instructions. I can create a PI easily using the factory function ProcessingInstruction(), but it doesn't get added into the elementtree. I can add it manually, but I can't figure o... | 4 | 2009-09-29T00:09:27Z | 1,494,992 | <p>Try the <code>lxml</code> library: it follows the ElementTree api, plus adds a lot of extra's. From the <a href="http://codespeak.net/lxml/compatibility.html" rel="nofollow">compatibility overview</a>:</p>
<blockquote>
<p>ElementTree ignores comments and processing instructions when parsing XML, while etree will ... | 4 | 2009-09-29T21:15:50Z | [
"python",
"xml",
"elementtree"
] |
ElementTree in Python 2.6.2 Processing Instructions support? | 1,489,949 | <p>I'm trying to create XML using the ElementTree object structure in python. It all works very well except when it comes to processing instructions. I can create a PI easily using the factory function ProcessingInstruction(), but it doesn't get added into the elementtree. I can add it manually, but I can't figure o... | 4 | 2009-09-29T00:09:27Z | 8,200,120 | <p>With the lxml API it couldn't be easier, though it is a bit "underdocumented":</p>
<p>If you need a top-level processing instruction, create it like this:</p>
<pre><code>from lxml import etree
root = etree.Element("anytagname")
root.addprevious(etree.ProcessingInstruction("anypi", "anypicontent"))
</code></pre>
... | 2 | 2011-11-20T07:38:15Z | [
"python",
"xml",
"elementtree"
] |
ElementTree in Python 2.6.2 Processing Instructions support? | 1,489,949 | <p>I'm trying to create XML using the ElementTree object structure in python. It all works very well except when it comes to processing instructions. I can create a PI easily using the factory function ProcessingInstruction(), but it doesn't get added into the elementtree. I can add it manually, but I can't figure o... | 4 | 2009-09-29T00:09:27Z | 34,194,103 | <pre><code>f = open('D:\Python\XML\test.xml', 'r+')
old = f.read()
f.seek(44,0) #place cursor after xml declaration
f.write('<?xml-stylesheet type="text/xsl" href="C:\Stylesheets\expand.xsl"?>'+ old[44:])
</code></pre>
<p>I was facing the same problem and came up with this crude solution after failing to in... | 0 | 2015-12-10T05:08:16Z | [
"python",
"xml",
"elementtree"
] |
Precise response to tablet/mouse events in Windows | 1,490,011 | <p>How can I tell Windows not to do unhelpful pre-processing on tablet pen events?</p>
<p>I am programming in Python 2.6, targetting tablet PCs running Windows 7 (though I would like my program to work with little modification on XP with a SMART interactive whiteboard, and for mouse users on Linux/Mac). I've written a... | 0 | 2009-09-29T00:36:39Z | 1,492,026 | <p>For raw mouse messages, you can use <a href="http://msdn.microsoft.com/en-us/library/ms645590%28VS.85%29.aspx" rel="nofollow"><code>WM_INPUT</code></a> on XP and later. Seven added some touch specific stuff: <a href="http://msdn.microsoft.com/en-us/library/dd353242%28VS.85%29.aspx" rel="nofollow"><code>WM_GESTURE</c... | 1 | 2009-09-29T11:41:04Z | [
"python",
"winapi",
"tablet-pc"
] |
calling Objective C functions from Python? | 1,490,039 | <p>Is there a way to dynamically call an Objective C function from Python?</p>
<p>For example, On the mac I would like to call this Objective C function</p>
<pre><code>[NSSpeechSynthesizer availableVoices]
</code></pre>
<p>without having to precompile any special Python wrapper module.</p>
| 7 | 2009-09-29T00:47:28Z | 1,490,077 | <p>You probably want <a href="http://pyobjc.sourceforge.net/" rel="nofollow">PyObjC</a>. That said, I've never actually used it myself (I've only ever seen demos), so I'm not certain that it will do what you need.</p>
| 3 | 2009-09-29T00:59:07Z | [
"python",
"objective-c",
"osx"
] |
calling Objective C functions from Python? | 1,490,039 | <p>Is there a way to dynamically call an Objective C function from Python?</p>
<p>For example, On the mac I would like to call this Objective C function</p>
<pre><code>[NSSpeechSynthesizer availableVoices]
</code></pre>
<p>without having to precompile any special Python wrapper module.</p>
| 7 | 2009-09-29T00:47:28Z | 1,490,078 | <p>Mac OS X from 10.5 onward has shipped with Python and the objc module that will let you do what you want.</p>
<p>An example:</p>
<pre><code>from Foundation import *
thing = NSKeyedUnarchiver.unarchiveObjectWithFile_(some_plist_file)
</code></pre>
<p>You can find more documentation <a href="http://pyobjc.sourcefo... | 4 | 2009-09-29T00:59:27Z | [
"python",
"objective-c",
"osx"
] |
calling Objective C functions from Python? | 1,490,039 | <p>Is there a way to dynamically call an Objective C function from Python?</p>
<p>For example, On the mac I would like to call this Objective C function</p>
<pre><code>[NSSpeechSynthesizer availableVoices]
</code></pre>
<p>without having to precompile any special Python wrapper module.</p>
| 7 | 2009-09-29T00:47:28Z | 1,490,461 | <p>Since OS X 10.5, OS X has shipped with the <a href="http://pyobjc.sourceforge.net/">PyObjC</a> bridge, a Python-Objective-C bridge. It uses the <a href="http://bridgesupport.macosforge.org/trac/">BridgeSupport</a> framework to map Objective-C frameworks to Python. Unlike, MacRuby, PyObjC is a classical bridge--there... | 6 | 2009-09-29T03:38:21Z | [
"python",
"objective-c",
"osx"
] |
calling Objective C functions from Python? | 1,490,039 | <p>Is there a way to dynamically call an Objective C function from Python?</p>
<p>For example, On the mac I would like to call this Objective C function</p>
<pre><code>[NSSpeechSynthesizer availableVoices]
</code></pre>
<p>without having to precompile any special Python wrapper module.</p>
| 7 | 2009-09-29T00:47:28Z | 1,490,644 | <p>As others have mentioned, PyObjC is the way to go. But, for completeness' sake, here's how you can do it with <a href="http://docs.python.org/library/ctypes.html">ctypes</a>, in case you need it to work on versions of OS X prior to 10.5 that do not have PyObjC installed:</p>
<pre><code>import ctypes
import ctypes.... | 18 | 2009-09-29T04:58:47Z | [
"python",
"objective-c",
"osx"
] |
Python Modules most worthwhile reading | 1,490,190 | <p>I have been programming Python for a while and I have a very good understanding of its features, but I would like to improve my coding style. I think reading the source code of the Python Modules would be a good idea. Can anyone recommend any ones in particular?</p>
<p>Related Threads:</p>
<ul>
<li><a href="http:/... | 9 | 2009-09-29T01:48:51Z | 1,490,204 | <p>I vote for <a href="http://docs.python.org/library/itertools.html">itertools</a>. You'll learn a lot of functional programming style from using this code, though perhaps not from reading the source.</p>
<p>For a good module-by-module tutorial, try Doug Hellmann's <a href="http://www.doughellmann.com/PyMOTW/modindex... | 6 | 2009-09-29T01:53:23Z | [
"python"
] |
Python Modules most worthwhile reading | 1,490,190 | <p>I have been programming Python for a while and I have a very good understanding of its features, but I would like to improve my coding style. I think reading the source code of the Python Modules would be a good idea. Can anyone recommend any ones in particular?</p>
<p>Related Threads:</p>
<ul>
<li><a href="http:/... | 9 | 2009-09-29T01:48:51Z | 1,490,205 | <p>I am learning Django and I really like their coding style,</p>
<p><a href="http://www.djangoproject.com/" rel="nofollow">http://www.djangoproject.com/</a></p>
| 0 | 2009-09-29T01:54:10Z | [
"python"
] |
Python Modules most worthwhile reading | 1,490,190 | <p>I have been programming Python for a while and I have a very good understanding of its features, but I would like to improve my coding style. I think reading the source code of the Python Modules would be a good idea. Can anyone recommend any ones in particular?</p>
<p>Related Threads:</p>
<ul>
<li><a href="http:/... | 9 | 2009-09-29T01:48:51Z | 1,490,212 | <p><a href="http://www.python.org/dev/peps/pep-0008/" rel="nofollow">PEP 8</a> is the "standard" Python coding style, for whatever version of "standard" you want to use. =)</p>
| 0 | 2009-09-29T01:56:46Z | [
"python"
] |
Python Modules most worthwhile reading | 1,490,190 | <p>I have been programming Python for a while and I have a very good understanding of its features, but I would like to improve my coding style. I think reading the source code of the Python Modules would be a good idea. Can anyone recommend any ones in particular?</p>
<p>Related Threads:</p>
<ul>
<li><a href="http:/... | 9 | 2009-09-29T01:48:51Z | 1,490,216 | <p><a href="http://svn.python.org/view/python/trunk/Lib/Queue.py?revision=70405&view=markup" rel="nofollow">Queue.py</a> shows you how to make a class thread-safe, and the proper use of the <a href="http://en.wikipedia.org/wiki/Template%5Fmethod%5Fpattern" rel="nofollow">Template Method</a> design pattern.</p>
<p>... | 18 | 2009-09-29T01:59:29Z | [
"python"
] |
In python, how do you launch an Amazon EC2 instance from within a Google App Engine app? | 1,490,429 | <p>In python, what is the best way to launch an Amazon EC2 instance from within a Google App Engine app? I would like to keep my AWS keys as secure as possible and be able to retrieve the public DNS for the newly launched EC2 instance. </p>
| 3 | 2009-09-29T03:25:00Z | 1,490,484 | <p>I believe you can use <a href="http://code.google.com/p/boto/">boto</a> with the current App Engine release (and maybe <a href="http://code.google.com/p/app-engine-patch/">AEP</a> to help, though maybe that's not needed for your specific task of starting an instance and retrieving its public domain name). <a href="... | 5 | 2009-09-29T03:46:51Z | [
"python",
"google-app-engine",
"amazon-ec2"
] |
Difference between attributes and style tags in lxml | 1,490,474 | <p>I am trying to learn lxml after having used BeautifulSoup. However, I am not a strong programmer in general.</p>
<p>I have the following code in some source html:</p>
<pre><code><p style="font-family:times;text-align:justify"><font size="2"><b><i> The reasons to eat pickles include: </... | 0 | 2009-09-29T03:41:44Z | 1,490,790 | <p>Using the CSS API really isn't the right approach. If you want to find all b elements, do</p>
<pre><code>strHTM=open(r'c:\myfile.htm','r').read() # no need to split it into lines first
newHTM=html.fromString(strHTM)
bELements = newHTM.findall('b')
for b in bElements:
print b.text_content()
</code></pre>
| 0 | 2009-09-29T05:59:08Z | [
"python",
"lxml"
] |
Django slugified urls - how to handle collisions? | 1,490,559 | <p>I'm currently working on a toy project in Django.</p>
<p>Part of my app allows users to leave reviews. I'd like to take the title of the review and slugify it to create a url.</p>
<p>So, if a user writes a review called "The best thing ever!", the url would be something like: <code>www.example.com/reviews/the-be... | 6 | 2009-09-29T04:23:55Z | 1,490,624 | <pre><code>from django.template.defaultfilters import slugify
def slugify_unique(value, model, slugfield="slug"):
suffix = 0
potential = base = slugify(value)
while True:
if suffix:
potential = "-".join([base, str(suffix)])
if not model.objects.filter(**{... | 2 | 2009-09-29T04:53:03Z | [
"python",
"django",
"url",
"slug",
"collision"
] |
Django slugified urls - how to handle collisions? | 1,490,559 | <p>I'm currently working on a toy project in Django.</p>
<p>Part of my app allows users to leave reviews. I'd like to take the title of the review and slugify it to create a url.</p>
<p>So, if a user writes a review called "The best thing ever!", the url would be something like: <code>www.example.com/reviews/the-be... | 6 | 2009-09-29T04:23:55Z | 1,490,682 | <p>I would recommend something like <a href="http://bitbucket.org/neithere/django-autoslug/wiki/Home">AutoSlugField</a>. It has a few options available with respect to configuring uniqueness (<code>unique</code> and <code>unique_with</code>), and has the added benefit of being able to automatically generate slugs base... | 6 | 2009-09-29T05:21:33Z | [
"python",
"django",
"url",
"slug",
"collision"
] |
Django slugified urls - how to handle collisions? | 1,490,559 | <p>I'm currently working on a toy project in Django.</p>
<p>Part of my app allows users to leave reviews. I'd like to take the title of the review and slugify it to create a url.</p>
<p>So, if a user writes a review called "The best thing ever!", the url would be something like: <code>www.example.com/reviews/the-be... | 6 | 2009-09-29T04:23:55Z | 1,492,882 | <p>One thing I never liked about the unique slug fields/methods is that if you have a lot of clashes for a single title, you'll end up running several queries to try and determine an available slug. I know you mentioned you don't want to show the id for non-clashing slugs, but, as far as performance, I think it's the b... | 6 | 2009-09-29T14:25:10Z | [
"python",
"django",
"url",
"slug",
"collision"
] |
Django slugified urls - how to handle collisions? | 1,490,559 | <p>I'm currently working on a toy project in Django.</p>
<p>Part of my app allows users to leave reviews. I'd like to take the title of the review and slugify it to create a url.</p>
<p>So, if a user writes a review called "The best thing ever!", the url would be something like: <code>www.example.com/reviews/the-be... | 6 | 2009-09-29T04:23:55Z | 2,340,063 | <p>I would (in the form validation) just check to see if the slug is used, and then add something to it, either a number "my-cool-idea_2" or the actual id</p>
| 0 | 2010-02-26T07:24:34Z | [
"python",
"django",
"url",
"slug",
"collision"
] |
Comparing performance between ruby and python code | 1,490,841 | <p>I have a memory and CPU intensive problem to solve and I need to benchmark the different solutions in ruby and python on different platforms.</p>
<p>To do the benchmark, I need to measure the time taken and the memory occupied by objects (not the entire program, but a selected list of objects) in both python and ru... | 1 | 2009-09-29T06:15:28Z | 1,490,987 | <p>For Python I recommend <a href="http://guppy-pe.sourceforge.net/" rel="nofollow">heapy</a></p>
<pre><code>from guppy import hpy
h = hpy()
print h.heap()
</code></pre>
<p>or <a href="http://www.aminus.net/wiki/Dowser" rel="nofollow">Dowser</a> or <a href="http://pysizer.8325.org/" rel="nofollow">PySizer</a></p>
<p... | 3 | 2009-09-29T06:57:34Z | [
"python",
"ruby",
"performance",
"memory-management"
] |
Comparing performance between ruby and python code | 1,490,841 | <p>I have a memory and CPU intensive problem to solve and I need to benchmark the different solutions in ruby and python on different platforms.</p>
<p>To do the benchmark, I need to measure the time taken and the memory occupied by objects (not the entire program, but a selected list of objects) in both python and ru... | 1 | 2009-09-29T06:15:28Z | 1,491,010 | <p>If you are using Python for CPU intensive algorithmic tasks I suggest use Numpy/Scipy to speed up your numerical calculations and use the Psyco JIT compiler for everything else. Your speeds can approach that of much lower-level languages if you use optimized components.</p>
| 2 | 2009-09-29T07:05:20Z | [
"python",
"ruby",
"performance",
"memory-management"
] |
Comparing performance between ruby and python code | 1,490,841 | <p>I have a memory and CPU intensive problem to solve and I need to benchmark the different solutions in ruby and python on different platforms.</p>
<p>To do the benchmark, I need to measure the time taken and the memory occupied by objects (not the entire program, but a selected list of objects) in both python and ru... | 1 | 2009-09-29T06:15:28Z | 1,491,746 | <p>If you really need to write fast code in a language like this (and not a language far more suited to CPU intensive operations and close control over memory usage such as C++) then I'd recommend pushing the bulk of the work out to <a href="http://www.cython.org/" rel="nofollow">Cython</a>.</p>
<blockquote>
<p>Cyth... | 3 | 2009-09-29T10:30:03Z | [
"python",
"ruby",
"performance",
"memory-management"
] |
Comparing performance between ruby and python code | 1,490,841 | <p>I have a memory and CPU intensive problem to solve and I need to benchmark the different solutions in ruby and python on different platforms.</p>
<p>To do the benchmark, I need to measure the time taken and the memory occupied by objects (not the entire program, but a selected list of objects) in both python and ru... | 1 | 2009-09-29T06:15:28Z | 1,497,527 | <p>I'd be wary of trying to measure just the memory consumption of an object graph over the lifecycle of an application. After all, you really don't care about that, in the end. You care that your application, in its entirety, has a sufficiently low footprint.</p>
<p>If you choose to limit your observation of memory... | 1 | 2009-09-30T11:20:31Z | [
"python",
"ruby",
"performance",
"memory-management"
] |
Comparing performance between ruby and python code | 1,490,841 | <p>I have a memory and CPU intensive problem to solve and I need to benchmark the different solutions in ruby and python on different platforms.</p>
<p>To do the benchmark, I need to measure the time taken and the memory occupied by objects (not the entire program, but a selected list of objects) in both python and ru... | 1 | 2009-09-29T06:15:28Z | 1,498,047 | <p>(you didn't specify py 2.5, 2.6 or 3; or ruby 1.8 or 1.9, jruby, MRI; The JVM has a wealth of tools to attack memory issues; Generally it 's helpful to zero in on memory depletion by posting stripped down versions of programs that replicate the problem</p>
<p>Heapy, ruby-prof, bleak house are all good tools, here a... | 0 | 2009-09-30T13:15:29Z | [
"python",
"ruby",
"performance",
"memory-management"
] |
Mapping std::map to Python | 1,491,037 | <p>Sometimes it makes sense to have a key-ordered dictionary. In C++, this is often implemented with a Red-black tree. But any self-balancing binary search tree will do (fwiw, Knuth is particularly clear on this subject). The best solution I've been able to come up with so far is to take <a href="http://sourceforge.net... | 6 | 2009-09-29T07:14:53Z | 1,491,055 | <p>I got exactly the same need, and Alex Martelli's answer has totally convinced me: best is keeping a dictionary and a list of partially sorted keys, then sort when needed. This is efficient because of the very particular behaviour of python's sort algorithm (AKA Timsort).
<a href="http://stackoverflow.com/questions/1... | 2 | 2009-09-29T07:23:38Z | [
"python",
"dictionary"
] |
Mapping std::map to Python | 1,491,037 | <p>Sometimes it makes sense to have a key-ordered dictionary. In C++, this is often implemented with a Red-black tree. But any self-balancing binary search tree will do (fwiw, Knuth is particularly clear on this subject). The best solution I've been able to come up with so far is to take <a href="http://sourceforge.net... | 6 | 2009-09-29T07:14:53Z | 1,491,109 | <p>As you said, you can roll your own implementation with bisect:</p>
<pre><code>class OrderedDict:
def __init__(self, keyvalues_iter):
self.__srtlst__ = sorted(keyvalues_iter)
def __len__(self):
return len(self.__srtlst__)
def __contains__(self, key):
index = bisect(self.__srtlst__, key)
if inde... | -1 | 2009-09-29T07:48:42Z | [
"python",
"dictionary"
] |
Mapping std::map to Python | 1,491,037 | <p>Sometimes it makes sense to have a key-ordered dictionary. In C++, this is often implemented with a Red-black tree. But any self-balancing binary search tree will do (fwiw, Knuth is particularly clear on this subject). The best solution I've been able to come up with so far is to take <a href="http://sourceforge.net... | 6 | 2009-09-29T07:14:53Z | 1,491,476 | <p>Lists are a miserable substitute for a tree.</p>
<p>Insertions need to move the whole list around to make space; deletions need to move the list back down. Adding or deleting stuff in batch is fine when it's possible, but it's very often not, or takes unnatural contortions to arrange it. A fundamental attribute o... | 1 | 2009-09-29T09:23:37Z | [
"python",
"dictionary"
] |
Mapping std::map to Python | 1,491,037 | <p>Sometimes it makes sense to have a key-ordered dictionary. In C++, this is often implemented with a Red-black tree. But any self-balancing binary search tree will do (fwiw, Knuth is particularly clear on this subject). The best solution I've been able to come up with so far is to take <a href="http://sourceforge.net... | 6 | 2009-09-29T07:14:53Z | 1,491,569 | <p>For a list that stays sorted, you can try module heapq.</p>
| 0 | 2009-09-29T09:45:41Z | [
"python",
"dictionary"
] |
Mapping std::map to Python | 1,491,037 | <p>Sometimes it makes sense to have a key-ordered dictionary. In C++, this is often implemented with a Red-black tree. But any self-balancing binary search tree will do (fwiw, Knuth is particularly clear on this subject). The best solution I've been able to come up with so far is to take <a href="http://sourceforge.net... | 6 | 2009-09-29T07:14:53Z | 4,936,985 | <p>I stumbled on this question needing an OrderedMap myself, and found to my horror that the accepted answer is complete garbage. So I rolled my own, in case anyone finds it useful:</p>
<pre><code>from bisect import *
class OrderedMap:
"""Much less efficient than a dict,
but keys don't need to be hashable.""... | 1 | 2011-02-08T18:45:00Z | [
"python",
"dictionary"
] |
Mapping std::map to Python | 1,491,037 | <p>Sometimes it makes sense to have a key-ordered dictionary. In C++, this is often implemented with a Red-black tree. But any self-balancing binary search tree will do (fwiw, Knuth is particularly clear on this subject). The best solution I've been able to come up with so far is to take <a href="http://sourceforge.net... | 6 | 2009-09-29T07:14:53Z | 11,381,235 | <p>You might be looking for a SortedCollection:
<a href="http://code.activestate.com/recipes/577197-sortedcollection/" rel="nofollow">http://code.activestate.com/recipes/577197-sortedcollection/</a></p>
| 1 | 2012-07-08T06:48:07Z | [
"python",
"dictionary"
] |
Mapping std::map to Python | 1,491,037 | <p>Sometimes it makes sense to have a key-ordered dictionary. In C++, this is often implemented with a Red-black tree. But any self-balancing binary search tree will do (fwiw, Knuth is particularly clear on this subject). The best solution I've been able to come up with so far is to take <a href="http://sourceforge.net... | 6 | 2009-09-29T07:14:53Z | 25,988,280 | <p>The Python <a href="http://www.grantjenks.com/docs/sortedcontainers/" rel="nofollow">sortedcontainers</a> module provides a <a href="http://www.grantjenks.com/docs/sortedcontainers/sorteddict.html" rel="nofollow">SortedDict</a> data type for exactly these purposes. It uses a modified B-tree type data structure and i... | 0 | 2014-09-23T06:28:09Z | [
"python",
"dictionary"
] |
deploying django to UserDir | 1,491,102 | <p>I would like to deploy my django pet-project on our student server. We have apache2 with UserDir mod and I don't have access to apache2 config files. How do I deploy? :-D</p>
<p>I come from PHP background and I deploy my PHP scripts by uploading them to my <code>public_html</code> dir and everything shows up on <a ... | 0 | 2009-09-29T07:46:51Z | 1,491,295 | <p>Are <code>mod_python</code> or <code>mod_wsgi</code> enabled on the base Apache? You'll need that as a minimum.</p>
| 0 | 2009-09-29T08:36:33Z | [
"python",
"django",
"apache"
] |
deploying django to UserDir | 1,491,102 | <p>I would like to deploy my django pet-project on our student server. We have apache2 with UserDir mod and I don't have access to apache2 config files. How do I deploy? :-D</p>
<p>I come from PHP background and I deploy my PHP scripts by uploading them to my <code>public_html</code> dir and everything shows up on <a ... | 0 | 2009-09-29T07:46:51Z | 1,496,042 | <p>Would you be allowed to run your own long-running server process on some port other than 80? This might allow you to serve Django content either with a Django test server or your own copy of Apache with local configuration files.</p>
| 0 | 2009-09-30T03:54:36Z | [
"python",
"django",
"apache"
] |
deploying django to UserDir | 1,491,102 | <p>I would like to deploy my django pet-project on our student server. We have apache2 with UserDir mod and I don't have access to apache2 config files. How do I deploy? :-D</p>
<p>I come from PHP background and I deploy my PHP scripts by uploading them to my <code>public_html</code> dir and everything shows up on <a ... | 0 | 2009-09-29T07:46:51Z | 1,496,446 | <p>If mod_python installed, first see if you can actually use it without needing administrator to do anything. Read:</p>
<p><a href="http://www.dscpl.com.au/wiki/ModPython/Articles/GettingModPythonWorking" rel="nofollow">http://www.dscpl.com.au/wiki/ModPython/Articles/GettingModPythonWorking</a></p>
<p>Unless you are... | 1 | 2009-09-30T06:43:19Z | [
"python",
"django",
"apache"
] |
deploying django to UserDir | 1,491,102 | <p>I would like to deploy my django pet-project on our student server. We have apache2 with UserDir mod and I don't have access to apache2 config files. How do I deploy? :-D</p>
<p>I come from PHP background and I deploy my PHP scripts by uploading them to my <code>public_html</code> dir and everything shows up on <a ... | 0 | 2009-09-29T07:46:51Z | 1,506,113 | <p>Have you tried using <code><Directory></code> instead of <code><Location></code>? If that isn't blocked by local policy you should be able to do something like this:</p>
<pre><code><Directory /path/to/your/home/public_html>
# mod_python stuff here
</Directory>
</code></pre>
<p>I'd go with e... | 0 | 2009-10-01T19:59:52Z | [
"python",
"django",
"apache"
] |
deploying django to UserDir | 1,491,102 | <p>I would like to deploy my django pet-project on our student server. We have apache2 with UserDir mod and I don't have access to apache2 config files. How do I deploy? :-D</p>
<p>I come from PHP background and I deploy my PHP scripts by uploading them to my <code>public_html</code> dir and everything shows up on <a ... | 0 | 2009-09-29T07:46:51Z | 2,067,690 | <p>If mod_fcgi is configured, you can use that. See <a href="http://docs.djangoproject.com/en/dev/howto/deployment/fastcgi/" rel="nofollow">http://docs.djangoproject.com/en/dev/howto/deployment/fastcgi/</a></p>
| 0 | 2010-01-14T21:26:41Z | [
"python",
"django",
"apache"
] |
Python WebkitGtk: How to respond to the default context menu items? | 1,491,179 | <p>The default context menu contains items like "Open link in new window" and "Download linked file", which don't seem to do anything. I obviously like to react on these items, but can't figure out how, since the port's documentation is a bit sparse. Does anybody know?</p>
| 2 | 2009-09-29T08:08:45Z | 1,493,356 | <p>In the C port, you have to connect to the '<code>create-web-view</code>', '<code>new-window-policy-decision-requested</code>', and '<code>download-requested</code>' signals. I think the Python port works the same way. See this page for the documentation on the C versions of those signals:</p>
<p><a href="http://web... | 2 | 2009-09-29T15:36:45Z | [
"python",
"gtk",
"webkit"
] |
Python Regex "object has no attribute" | 1,491,277 | <p>I've been putting together a list of pages that we need to update with new content (we're switching media formats). In the process I'm cataloging pages that correctly have the new content. </p>
<p>Here's the general idea of what I'm doing: </p>
<ol>
<li>Iterate through a file structure and get a list of files <... | 6 | 2009-09-29T08:32:01Z | 1,491,439 | <p>Your exception means that urla has a value of None. Since urla's value is determined by the re.search call, it follows that re.search returns None. And this happens when the string doesn't match the pattern.</p>
<p>So basically you should use:</p>
<pre><code>urla = re.search(pattern2, match)
if urla is not None:
... | 15 | 2009-09-29T09:13:49Z | [
"python",
"regex"
] |
Python Regex "object has no attribute" | 1,491,277 | <p>I've been putting together a list of pages that we need to update with new content (we're switching media formats). In the process I'm cataloging pages that correctly have the new content. </p>
<p>Here's the general idea of what I'm doing: </p>
<ol>
<li>Iterate through a file structure and get a list of files <... | 6 | 2009-09-29T08:32:01Z | 1,491,448 | <p>The reason for <code>TypeError</code> is that <code>search</code> or <code>match</code> usually return either a <code>MatchObject</code> or a <code>None</code>. Only one of these has a <code>group</code> method. And it's not a <code>None</code>. So you need to do:</p>
<pre><code>url = re.search(pattern2, match)
if ... | 2 | 2009-09-29T09:14:54Z | [
"python",
"regex"
] |
Python Regex "object has no attribute" | 1,491,277 | <p>I've been putting together a list of pages that we need to update with new content (we're switching media formats). In the process I'm cataloging pages that correctly have the new content. </p>
<p>Here's the general idea of what I'm doing: </p>
<ol>
<li>Iterate through a file structure and get a list of files <... | 6 | 2009-09-29T08:32:01Z | 1,496,037 | <p>Please also note your mistaken assumption that the error was in the <em>third</em> match, when it was in fact in the second. This seems to have led to the mistaken assumption that the second match was doing something to invalidate the third, sending you way off track.</p>
| 0 | 2009-09-30T03:50:00Z | [
"python",
"regex"
] |
Python Regex "object has no attribute" | 1,491,277 | <p>I've been putting together a list of pages that we need to update with new content (we're switching media formats). In the process I'm cataloging pages that correctly have the new content. </p>
<p>Here's the general idea of what I'm doing: </p>
<ol>
<li>Iterate through a file structure and get a list of files <... | 6 | 2009-09-29T08:32:01Z | 5,692,616 | <p>I got the same problem.</p>
<p>Using python2.6, you can solve it in this way:</p>
<pre>
for match in matches:
if len(match) > 0:
urla = re.search(pattern2, match)
try:
urla.group(1):
print filename, urla.group(1)
excpet:
print "Problem with",pattern2
urlb = re.search(pattern3, match)
try:
... | 2 | 2011-04-17T09:06:03Z | [
"python",
"regex"
] |
Telnet automation / scripting | 1,491,494 | <p>I have already checked <a href="http://stackoverflow.com/questions/709801/creating-a-script-for-a-telnet-session">This Question</a> but could not find what i'm looking for. I am running Windows (the client), and the server is a legacy mainframe type server.</p>
<p>Basically I need to write a script, python code or... | 5 | 2009-09-29T09:29:42Z | 1,491,516 | <p>There's a <a href="http://docs.python.org/library/telnetlib.html">python library for telnet</a> connections that reads and writes from/to a telnet connection.</p>
<p>Check the link. It has some basic examples of what you are looking for.</p>
<p>Here's an example from the link:</p>
<pre><code>import getpass
import... | 15 | 2009-09-29T09:33:54Z | [
"python",
"windows",
"scripting",
"automation",
"telnet"
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.