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 |
|---|---|---|---|---|---|---|---|---|---|
Big List Of Portability in Python | 1,883,118 | <p>I thought it would be a good idea to compile a list of things to watch out for when making a Python app portable. There are a lot of subtle 'gotchas' in portability that are only discovered through experience and thorough testing; there needs to be some sort of list addressing the more common ones.</p>
<p>Please po... | 4 | 2009-12-10T18:41:56Z | 1,883,137 | <p>I'll start off:</p>
<p>Windows uses backslashes for path separators --> '\'</p>
<p>Unix uses forward slashes for path separators --> '/'</p>
<p>The os module comes with <code>os.sep</code>, which contains the path separator for the current platform that the script is being run on. Use <code>os.sep</code> instead ... | 1 | 2009-12-10T18:45:19Z | [
"python",
"portability"
] |
Big List Of Portability in Python | 1,883,118 | <p>I thought it would be a good idea to compile a list of things to watch out for when making a Python app portable. There are a lot of subtle 'gotchas' in portability that are only discovered through experience and thorough testing; there needs to be some sort of list addressing the more common ones.</p>
<p>Please po... | 4 | 2009-12-10T18:41:56Z | 1,883,312 | <p><a href="http://polyphrase.blogspot.com/2008/09/do-you-know-universal-newline-support.html" rel="nofollow">'Universal newline support'</a> (as descrived in <a href="http://www.python.org/dev/peps/pep-0278/" rel="nofollow">PEP278</a>) can come in handy for portability reasons.<br>
It makes sure python code only gets ... | 3 | 2009-12-10T19:18:42Z | [
"python",
"portability"
] |
Big List Of Portability in Python | 1,883,118 | <p>I thought it would be a good idea to compile a list of things to watch out for when making a Python app portable. There are a lot of subtle 'gotchas' in portability that are only discovered through experience and thorough testing; there needs to be some sort of list addressing the more common ones.</p>
<p>Please po... | 4 | 2009-12-10T18:41:56Z | 1,883,350 | <p>Getting away from the syntax side of things, I think the biggest thing to watch out for is that typically when people think of python, they might not think of all the libraries it is composed of. </p>
<p>Many python packages depend on C libraries which may or may not be cross platform compatible. In addition, Pytho... | 2 | 2009-12-10T19:25:13Z | [
"python",
"portability"
] |
Big List Of Portability in Python | 1,883,118 | <p>I thought it would be a good idea to compile a list of things to watch out for when making a Python app portable. There are a lot of subtle 'gotchas' in portability that are only discovered through experience and thorough testing; there needs to be some sort of list addressing the more common ones.</p>
<p>Please po... | 4 | 2009-12-10T18:41:56Z | 1,883,472 | <p>There are subtle differences in UCS2 and UCS4 (Windows and Linux, for example) builds of Python due to bugs, conflicting or deprecated standards, etc.</p>
<h3>Example: <a href="http://bugs.python.org/issue3297" rel="nofollow">Issue 3297</a></h3>
<p><a href="http://bugs.python.org/file10880/unicodetest.py" rel="no... | 1 | 2009-12-10T19:45:15Z | [
"python",
"portability"
] |
Big List Of Portability in Python | 1,883,118 | <p>I thought it would be a good idea to compile a list of things to watch out for when making a Python app portable. There are a lot of subtle 'gotchas' in portability that are only discovered through experience and thorough testing; there needs to be some sort of list addressing the more common ones.</p>
<p>Please po... | 4 | 2009-12-10T18:41:56Z | 1,883,501 | <p>If you deal with binary file formats in Python, note that the <code>struct</code> and <code>array</code> modules uses machine dependent size and endianness. <code>struct</code> can be used portably by always using <code><</code> or <code>></code> in the format string. <code>array</code> can't. It will probably... | 4 | 2009-12-10T19:48:23Z | [
"python",
"portability"
] |
Big List Of Portability in Python | 1,883,118 | <p>I thought it would be a good idea to compile a list of things to watch out for when making a Python app portable. There are a lot of subtle 'gotchas' in portability that are only discovered through experience and thorough testing; there needs to be some sort of list addressing the more common ones.</p>
<p>Please po... | 4 | 2009-12-10T18:41:56Z | 1,883,817 | <p>Some modules are not cross-platform. Two that come to mind are both <code>curses</code> (Linux) and <code>msvcrt</code> (Windows). The fix to this simple problem is simply not to use them but find an alternative instead.</p>
| 2 | 2009-12-10T20:32:51Z | [
"python",
"portability"
] |
Big List Of Portability in Python | 1,883,118 | <p>I thought it would be a good idea to compile a list of things to watch out for when making a Python app portable. There are a lot of subtle 'gotchas' in portability that are only discovered through experience and thorough testing; there needs to be some sort of list addressing the more common ones.</p>
<p>Please po... | 4 | 2009-12-10T18:41:56Z | 1,891,918 | <p>Unix vs. Windows: Using <code>Popen</code> in the <code>subprocess</code> module will exhibit different behavior when <code>shell=True</code>. I won't offer a fix because the discussion is covered so well <a href="http://stackoverflow.com/questions/1253122/why-does-subprocess-popen-with-shelltrue-work-differently-... | 2 | 2009-12-12T01:40:49Z | [
"python",
"portability"
] |
Pinging first available host in network subnets | 1,883,136 | <p>I've written a small script in Python that pings all subnets of my school's wireless network and prints out the IP addresses and hostnames of computers that are connected to each subnet of the network. My current setup is that I'm relying on creating threads to handle each of the ping requests. </p>
<pre><code>from... | 2 | 2009-12-10T18:44:49Z | 1,885,002 | <p>Simplest thing would be to have a thread work through a whole subnet and exit when it finds a host.</p>
<p><strong>UNTESTED</strong></p>
<pre><code>from Queue import Queue
import time
import socket
#wraps system ping command
def ping(i, q):
"""Pings address"""
while True:
subnet = q.get()
... | 1 | 2009-12-11T00:08:49Z | [
"python",
"networking",
"subnet"
] |
Pinging first available host in network subnets | 1,883,136 | <p>I've written a small script in Python that pings all subnets of my school's wireless network and prints out the IP addresses and hostnames of computers that are connected to each subnet of the network. My current setup is that I'm relying on creating threads to handle each of the ping requests. </p>
<pre><code>from... | 2 | 2009-12-10T18:44:49Z | 1,885,065 | <p>Since you know how many threads you got in the beginning of the run, you could periodically check the current number of threads running to see if nowThreadCount < startThreadCount. If it's true terminate the current thread.</p>
<p>PS: Easiest way would be to just clear the queue object too, but I can't find that... | 0 | 2009-12-11T00:27:52Z | [
"python",
"networking",
"subnet"
] |
How to parse through script tag using python and beautifulsoup | 1,883,273 | <p>I am trying to extract the attributes of a frame tag which is inside <code>document.write</code> function on a page as follows:</p>
<pre><code><script language="javascript">
.
.
.
document.write('<frame name="nav" src="/nav/index_nav.html" marginwidth="0" marginheight="0" scrolling="no" frameborder="0" bor... | 1 | 2009-12-10T19:11:58Z | 1,883,287 | <p>You can't do it with BeautifulSoup alone. BeautifulSoup parses HTML as it would arrive to the browser (before any rewriting or DOM manipulation), and it does not parse (let alone execute) Javascript. </p>
<p>You might want to use a simple regular expression in this special case.</p>
| 2 | 2009-12-10T19:14:25Z | [
"python",
"beautifulsoup"
] |
How to parse through script tag using python and beautifulsoup | 1,883,273 | <p>I am trying to extract the attributes of a frame tag which is inside <code>document.write</code> function on a page as follows:</p>
<pre><code><script language="javascript">
.
.
.
document.write('<frame name="nav" src="/nav/index_nav.html" marginwidth="0" marginheight="0" scrolling="no" frameborder="0" bor... | 1 | 2009-12-10T19:11:58Z | 1,884,050 | <p>Pyparsing might help you bridge this mix of JS and HTML. This parser looks for <code>document.write</code> statements containing a quoted string or a string expression of several quoted strings and identifiers, quasi-evaluates the string expression, parses it for an embedded <code><frame></code> tag, and retu... | 1 | 2009-12-10T21:10:57Z | [
"python",
"beautifulsoup"
] |
Contents of PyString in Qt Creator debugger? | 1,883,316 | <p>I've got a PyString* object that I would like to see the contents of. Is there any way to see the text of the PyString using Qt Creator's debugger?</p>
<pre><code>PyObject *import_str = PyString_InternFromString("__import__");
</code></pre>
<p>If it makes a difference, Qt Creator is a front end to GDB.</p>
| 1 | 2009-12-10T19:19:59Z | 2,059,080 | <p>I doubt that Qt Creator can display the contents of the string like it does with <code>QString</code>, etc. This is because <code>PyObject</code> is a custom class that Qt Creator/gdbv does not know how to handle.</p>
<p>For instance: <code>QString</code> is a custom class as well, but Qt Creator loads some specia... | 0 | 2010-01-13T18:08:46Z | [
"python",
"qt",
"debugging",
"qt-creator",
"cpython"
] |
Contents of PyString in Qt Creator debugger? | 1,883,316 | <p>I've got a PyString* object that I would like to see the contents of. Is there any way to see the text of the PyString using Qt Creator's debugger?</p>
<pre><code>PyObject *import_str = PyString_InternFromString("__import__");
</code></pre>
<p>If it makes a difference, Qt Creator is a front end to GDB.</p>
| 1 | 2009-12-10T19:19:59Z | 2,059,165 | <p>You can write debugging info to be displayed in QtCreator for any class using Python with the latest QtCreator. It's actually quite simple. This is thanks to gdb 7 that added support for Python in addition to C++.</p>
<p>You can see the ones that ship with QtCreator in <code>/usr/share/qtcreator/gdbmacros</code>.<... | 0 | 2010-01-13T18:22:18Z | [
"python",
"qt",
"debugging",
"qt-creator",
"cpython"
] |
Where should django manager code live? | 1,883,322 | <p>This is a pretty simple django patterns question. My manager code usually lives in models.py, but what happens when models.py is really huge? Is there any other alternative pattern to letting your manager code live in models.py for maintainability and to avoid circular imports?</p>
<p>A question may be asked as to ... | 19 | 2009-12-10T19:21:00Z | 1,883,342 | <p>What I did when building Django apps was to create a [modelname].py file with just the specific model code, manager code and sometimes form code and used an __init__.py file to import then all in the models directory. This helped me atleast in keeping it managable.</p>
| 3 | 2009-12-10T19:24:17Z | [
"python",
"django",
"design-patterns",
"django-models",
"django-managers"
] |
Where should django manager code live? | 1,883,322 | <p>This is a pretty simple django patterns question. My manager code usually lives in models.py, but what happens when models.py is really huge? Is there any other alternative pattern to letting your manager code live in models.py for maintainability and to avoid circular imports?</p>
<p>A question may be asked as to ... | 19 | 2009-12-10T19:21:00Z | 1,883,460 | <p>I prefer to keep my models in models.py and managers in managers.py (forms in forms.py) all within the same app. For more generic managers, I prefer to keep them in core.managers if they can be re-used for other apps. In some of our larger apps with models/modelname.py that will contains a manager and the model co... | 20 | 2009-12-10T19:43:06Z | [
"python",
"django",
"design-patterns",
"django-models",
"django-managers"
] |
Where should django manager code live? | 1,883,322 | <p>This is a pretty simple django patterns question. My manager code usually lives in models.py, but what happens when models.py is really huge? Is there any other alternative pattern to letting your manager code live in models.py for maintainability and to avoid circular imports?</p>
<p>A question may be asked as to ... | 19 | 2009-12-10T19:21:00Z | 1,883,526 | <p>I always place mine in managers.py. If you have a circular import issue remember that a) You can reference the model class for a manager at self.model, and b) You can do imports inside of functions.</p>
| 6 | 2009-12-10T19:51:03Z | [
"python",
"django",
"design-patterns",
"django-models",
"django-managers"
] |
Where should django manager code live? | 1,883,322 | <p>This is a pretty simple django patterns question. My manager code usually lives in models.py, but what happens when models.py is really huge? Is there any other alternative pattern to letting your manager code live in models.py for maintainability and to avoid circular imports?</p>
<p>A question may be asked as to ... | 19 | 2009-12-10T19:21:00Z | 1,883,633 | <p>Your best bet with a large set of models is to use django modules to your advantage, and simply create a folder named models. Move your old models.py into this models folder, and rename it <code>__init__.py</code>. This will allow you to then separate each model into more specific files inside of this model folder.<... | 7 | 2009-12-10T20:07:18Z | [
"python",
"django",
"design-patterns",
"django-models",
"django-managers"
] |
Using Python, how do I to read/write data in memory like I would with a file? | 1,883,326 | <p>I'm used to C++, and I build my data handling classes/functions to handle stream objects instead of files. I'd like to know how I might modify the following code, so that it can handle a stream of binary data in memory, rather than a file handle.</p>
<pre><code>def get_count(self):
curr = self.file.tell()
s... | 9 | 2009-12-10T19:21:38Z | 1,883,352 | <p>You can use an instance of <a href="http://docs.python.org/library/stringio.html?highlight=stringio#StringIO.StringIO">StringIO.StringIO</a> (or <a href="http://docs.python.org/library/stringio.html?highlight=stringio#module-cStringIO">cStringIO.StringIO</a>, faster) to give a file-like interface to in-memory data.<... | 16 | 2009-12-10T19:25:19Z | [
"python",
"file",
"stream"
] |
Using Python, how do I to read/write data in memory like I would with a file? | 1,883,326 | <p>I'm used to C++, and I build my data handling classes/functions to handle stream objects instead of files. I'd like to know how I might modify the following code, so that it can handle a stream of binary data in memory, rather than a file handle.</p>
<pre><code>def get_count(self):
curr = self.file.tell()
s... | 9 | 2009-12-10T19:21:38Z | 1,883,353 | <p>Have a look at <a href="http://docs.python.org/library/stringio.html">'StringIO'</a> (Read and write strings as files)</p>
| 5 | 2009-12-10T19:25:24Z | [
"python",
"file",
"stream"
] |
Using Python, how do I to read/write data in memory like I would with a file? | 1,883,326 | <p>I'm used to C++, and I build my data handling classes/functions to handle stream objects instead of files. I'd like to know how I might modify the following code, so that it can handle a stream of binary data in memory, rather than a file handle.</p>
<pre><code>def get_count(self):
curr = self.file.tell()
s... | 9 | 2009-12-10T19:21:38Z | 1,883,354 | <p>Use <a href="http://docs.python.org/library/stringio.html">StringIO</a>.</p>
| 5 | 2009-12-10T19:25:43Z | [
"python",
"file",
"stream"
] |
Using Python, how do I to read/write data in memory like I would with a file? | 1,883,326 | <p>I'm used to C++, and I build my data handling classes/functions to handle stream objects instead of files. I'd like to know how I might modify the following code, so that it can handle a stream of binary data in memory, rather than a file handle.</p>
<pre><code>def get_count(self):
curr = self.file.tell()
s... | 9 | 2009-12-10T19:21:38Z | 1,883,355 | <p>Take a look at Python's StringIO module, <a href="http://docs.python.org/library/stringio.html">docs here</a>, which could be pretty much what you're after.</p>
| 6 | 2009-12-10T19:25:50Z | [
"python",
"file",
"stream"
] |
Using Python, how do I to read/write data in memory like I would with a file? | 1,883,326 | <p>I'm used to C++, and I build my data handling classes/functions to handle stream objects instead of files. I'd like to know how I might modify the following code, so that it can handle a stream of binary data in memory, rather than a file handle.</p>
<pre><code>def get_count(self):
curr = self.file.tell()
s... | 9 | 2009-12-10T19:21:38Z | 40,132,849 | <p>I like the timing of the answer. (except mine)</p>
<p>We can see response time in milliseconds ?</p>
<blockquote>
<p>of-course <strong><code>StringIO</code></strong></p>
</blockquote>
| 0 | 2016-10-19T13:31:01Z | [
"python",
"file",
"stream"
] |
wxPython progress bar | 1,883,528 | <p>I can't use <a href="http://www.wxpython.org/docs/api/wx.ProgressDialog-class.html"><code>wx.ProgressDialog</code></a> because I need to add extra contents to the dialog box (a pause button and information about what is currently being processed). Is there a control for just the progress bar that I can use in my ow... | 5 | 2009-12-10T19:51:29Z | 1,883,558 | <p>What about wxGauge which displays a horizontal or vertical bar?<br>
<a href="http://www.wxpython.org/docs/api/wx.Gauge-class.html">http://www.wxpython.org/docs/api/wx.Gauge-class.html</a></p>
<p>More complete C++ doc:
<a href="http://docs.wxwidgets.org/2.6/wx%5Fwxgauge.html#wxgauge">http://docs.wxwidgets.org/2.6/wx... | 6 | 2009-12-10T19:56:40Z | [
"python",
"wxpython"
] |
wxPython progress bar | 1,883,528 | <p>I can't use <a href="http://www.wxpython.org/docs/api/wx.ProgressDialog-class.html"><code>wx.ProgressDialog</code></a> because I need to add extra contents to the dialog box (a pause button and information about what is currently being processed). Is there a control for just the progress bar that I can use in my ow... | 5 | 2009-12-10T19:51:29Z | 1,943,412 | <p>You could always create your own derivative of wx.Dialog and using a sizer, add in the widgets you require.</p>
<p>Here's one from my program, for example:</p>
<pre><code>class ProgressDialog(wx.Dialog):
"""
Shows a Progres Gauge while an operation is taking place. May be cancellable
which is possible ... | 2 | 2009-12-21T23:58:31Z | [
"python",
"wxpython"
] |
Reading utf-8 characters from a gzip file in python | 1,883,604 | <p>I am trying to read a gunzipped file (.gz) in python and am having some trouble.</p>
<p>I used the gzip module to read it but the file is encoded as a utf-8 text file so eventually it reads an invalid character and crashes. </p>
<p>Does anyone know how to read gzip files encoded as utf-8 files? I know that there's... | 15 | 2009-12-10T20:02:26Z | 1,883,673 | <p>I don't see why this should be so hard.</p>
<p>What are you doing exactly? Please explain "eventually it reads an invalid character".</p>
<p>It should be as simple as:</p>
<pre><code>import gzip
fp = gzip.open('foo.gz')
contents = fp.read() # contents now has the uncompressed bytes of foo.gz
fp.close()
u_str = c... | 10 | 2009-12-10T20:11:27Z | [
"python",
"file-io",
"utf-8",
"gzip"
] |
Reading utf-8 characters from a gzip file in python | 1,883,604 | <p>I am trying to read a gunzipped file (.gz) in python and am having some trouble.</p>
<p>I used the gzip module to read it but the file is encoded as a utf-8 text file so eventually it reads an invalid character and crashes. </p>
<p>Does anyone know how to read gzip files encoded as utf-8 files? I know that there's... | 15 | 2009-12-10T20:02:26Z | 1,883,734 | <p>Maybe</p>
<pre><code>import codecs
zf = gzip.open(fname, 'rb')
reader = codecs.getreader("utf-8")
contents = reader( zf )
for line in contents:
pass
</code></pre>
| 14 | 2009-12-10T20:21:02Z | [
"python",
"file-io",
"utf-8",
"gzip"
] |
Reading utf-8 characters from a gzip file in python | 1,883,604 | <p>I am trying to read a gunzipped file (.gz) in python and am having some trouble.</p>
<p>I used the gzip module to read it but the file is encoded as a utf-8 text file so eventually it reads an invalid character and crashes. </p>
<p>Does anyone know how to read gzip files encoded as utf-8 files? I know that there's... | 15 | 2009-12-10T20:02:26Z | 1,883,774 | <p>In pythonic form (2.5 or greater)</p>
<pre><code>from __future__ import with_statement # for 2.5, does nothing in 2.6
from gzip import open as gzopen
with gzopen('foo.gz') as gzfile:
for line in gzfile:
print line.decode('utf-8')
</code></pre>
| 0 | 2009-12-10T20:26:12Z | [
"python",
"file-io",
"utf-8",
"gzip"
] |
Reading utf-8 characters from a gzip file in python | 1,883,604 | <p>I am trying to read a gunzipped file (.gz) in python and am having some trouble.</p>
<p>I used the gzip module to read it but the file is encoded as a utf-8 text file so eventually it reads an invalid character and crashes. </p>
<p>Does anyone know how to read gzip files encoded as utf-8 files? I know that there's... | 15 | 2009-12-10T20:02:26Z | 19,794,943 | <p>This is possible in Python 3.3:</p>
<pre><code>import gzip
gzip.open('file.gz', 'rt', encoding='utf-8')
</code></pre>
<p>Notice that gzip.open() requires you to explicitly specify text mode ('t').</p>
| 12 | 2013-11-05T17:20:37Z | [
"python",
"file-io",
"utf-8",
"gzip"
] |
Reading utf-8 characters from a gzip file in python | 1,883,604 | <p>I am trying to read a gunzipped file (.gz) in python and am having some trouble.</p>
<p>I used the gzip module to read it but the file is encoded as a utf-8 text file so eventually it reads an invalid character and crashes. </p>
<p>Does anyone know how to read gzip files encoded as utf-8 files? I know that there's... | 15 | 2009-12-10T20:02:26Z | 25,232,585 | <p>The above produced tons of decoding errors. I used this:</p>
<pre><code>for line in io.TextIOWrapper(io.BufferedReader(gzip.open(filePath)), encoding='utf8', errors='ignore'):
...
</code></pre>
| 2 | 2014-08-10T20:13:14Z | [
"python",
"file-io",
"utf-8",
"gzip"
] |
AJAX URLs and GET requests | 1,883,626 | <p>Ok, a great example of what I am trying to achieve is at Google Translate. The URL: <a href="http://translate.google.com/#en|es|this%20is%20what%20I%20am%20trying%20to%20do" rel="nofollow">http://translate.google.com/#en|es|this is what I am trying to do</a> makes a GET request using this URL: <code>http://translate... | 1 | 2009-12-10T20:06:25Z | 1,883,769 | <p>Hey, you can make a customized URL by getting the values of the input fields you wish and then just concatenate this with you url.</p>
<pre><code>$.getJSON("http://translate?lang=" + $(".lang").attr("value") + "&text=bla");
</code></pre>
<p>i just simplized here the usage to show you how it works. if this don'... | 0 | 2009-12-10T20:25:33Z | [
"jquery",
"python",
"ajax",
"url"
] |
AJAX URLs and GET requests | 1,883,626 | <p>Ok, a great example of what I am trying to achieve is at Google Translate. The URL: <a href="http://translate.google.com/#en|es|this%20is%20what%20I%20am%20trying%20to%20do" rel="nofollow">http://translate.google.com/#en|es|this is what I am trying to do</a> makes a GET request using this URL: <code>http://translate... | 1 | 2009-12-10T20:06:25Z | 1,883,868 | <p>What you're looking for is JQuery's <a href="http://docs.jquery.com/Ajax/serialize" rel="nofollow">Serialization</a> functionality.</p>
| 1 | 2009-12-10T20:40:39Z | [
"jquery",
"python",
"ajax",
"url"
] |
AJAX URLs and GET requests | 1,883,626 | <p>Ok, a great example of what I am trying to achieve is at Google Translate. The URL: <a href="http://translate.google.com/#en|es|this%20is%20what%20I%20am%20trying%20to%20do" rel="nofollow">http://translate.google.com/#en|es|this is what I am trying to do</a> makes a GET request using this URL: <code>http://translate... | 1 | 2009-12-10T20:06:25Z | 1,884,442 | <p>Please see <a href="http://whiffdoc.appspot.com/docs/W1100%5F1400.calc" rel="nofollow">http://whiffdoc.appspot.com/docs/W1100_1400.calc</a> for a tutorial that describes how to do stuff like this.</p>
| 0 | 2009-12-10T22:07:54Z | [
"jquery",
"python",
"ajax",
"url"
] |
Linting Python: what is good? | 1,883,725 | <p>Are there any good modules that you can run against your code to catch coding errors? I expected pylint to catch mistakes in the use of default arguments to functions <a href="http://www.deadlybloodyserious.com/2008/05/default-argument-blunders/" rel="nofollow">like this</a>:</p>
<pre><code>>>> def spam(eg... | 2 | 2009-12-10T20:19:11Z | 1,883,781 | <p>I tried the first example and PyLint 0.18.1 gave me the warning:</p>
<pre><code>W: 1:spam: Dangerous default value [] as argument
</code></pre>
| 5 | 2009-12-10T20:27:27Z | [
"python",
"pylint"
] |
Linting Python: what is good? | 1,883,725 | <p>Are there any good modules that you can run against your code to catch coding errors? I expected pylint to catch mistakes in the use of default arguments to functions <a href="http://www.deadlybloodyserious.com/2008/05/default-argument-blunders/" rel="nofollow">like this</a>:</p>
<pre><code>>>> def spam(eg... | 2 | 2009-12-10T20:19:11Z | 1,883,849 | <p>That is not an error in your code if that is what you want to do. However, as specified in the accepted answer, an empty list is a "dangerous" default value in that it is easy to introduce hard-to-find problems.</p>
| 1 | 2009-12-10T20:38:32Z | [
"python",
"pylint"
] |
Linting Python: what is good? | 1,883,725 | <p>Are there any good modules that you can run against your code to catch coding errors? I expected pylint to catch mistakes in the use of default arguments to functions <a href="http://www.deadlybloodyserious.com/2008/05/default-argument-blunders/" rel="nofollow">like this</a>:</p>
<pre><code>>>> def spam(eg... | 2 | 2009-12-10T20:19:11Z | 1,895,484 | <p>I bookmarked <a href="http://infinitemonkeycorps.net/docs/pph/" rel="nofollow">this site</a> the other day, partly because it has a section titled "Python code quality tools" that lists many utilities for checking code, including pylint and five others.</p>
<p>I've been thinking of integrating <em>all</em> of them ... | 2 | 2009-12-13T03:42:42Z | [
"python",
"pylint"
] |
Find the nth occurrence of substring in a string | 1,883,980 | <p>This seems like it should be pretty trivial, but I am new at Python and want to do it the most Pythonic way.</p>
<p>I want to find the n'th occurrence of a substring in a string.</p>
<p>There's got to be something equivalent to what I WANT to do which is </p>
<p><code>mystring.find("substring", 2nd)</code></p>
<... | 55 | 2009-12-10T20:58:50Z | 1,884,065 | <p>I'd probably do something like this, using the find function that takes an index parameter:</p>
<pre><code>def find_nth(s, x, n):
i = -1
for _ in range(n):
i = s.find(x, i + len(x))
if i == -1:
break
return i
print find_nth('bananabanana', 'an', 3)
</code></pre>
<p>It's not... | 2 | 2009-12-10T21:14:24Z | [
"python",
"string",
"substring"
] |
Find the nth occurrence of substring in a string | 1,883,980 | <p>This seems like it should be pretty trivial, but I am new at Python and want to do it the most Pythonic way.</p>
<p>I want to find the n'th occurrence of a substring in a string.</p>
<p>There's got to be something equivalent to what I WANT to do which is </p>
<p><code>mystring.find("substring", 2nd)</code></p>
<... | 55 | 2009-12-10T20:58:50Z | 1,884,151 | <p>Mark's iterative approach would be the usual way, I think.</p>
<p>Here's an alternative with string-splitting, which can often be useful for finding-related processes:</p>
<pre><code>def findnth(haystack, needle, n):
parts= haystack.split(needle, n+1)
if len(parts)<=n+1:
return -1
return len... | 35 | 2009-12-10T21:26:39Z | [
"python",
"string",
"substring"
] |
Find the nth occurrence of substring in a string | 1,883,980 | <p>This seems like it should be pretty trivial, but I am new at Python and want to do it the most Pythonic way.</p>
<p>I want to find the n'th occurrence of a substring in a string.</p>
<p>There's got to be something equivalent to what I WANT to do which is </p>
<p><code>mystring.find("substring", 2nd)</code></p>
<... | 55 | 2009-12-10T20:58:50Z | 1,884,216 | <p>Understanding that regex is not always the best solution, I'd probably use one here:</p>
<pre><code>>>> import re
>>> s = "ababdfegtduab"
>>> [m.start() for m in re.finditer(r"ab",s)]
[0, 2, 11]
>>> [m.start() for m in re.finditer(r"ab",s)][2] #index 2 is third occurrence
11
</c... | 16 | 2009-12-10T21:36:42Z | [
"python",
"string",
"substring"
] |
Find the nth occurrence of substring in a string | 1,883,980 | <p>This seems like it should be pretty trivial, but I am new at Python and want to do it the most Pythonic way.</p>
<p>I want to find the n'th occurrence of a substring in a string.</p>
<p>There's got to be something equivalent to what I WANT to do which is </p>
<p><code>mystring.find("substring", 2nd)</code></p>
<... | 55 | 2009-12-10T20:58:50Z | 1,884,276 | <p>Here is another approach using re.finditer.<br>
The difference is that this only looks into the haystack as far as necessary</p>
<pre><code>from re import finditer
from itertools import dropwhile
needle='an'
haystack='bananabanana'
n=2
next(dropwhile(lambda x: x[0]<n, enumerate(re.finditer(needle,haystack))))[1]... | 1 | 2009-12-10T21:45:18Z | [
"python",
"string",
"substring"
] |
Find the nth occurrence of substring in a string | 1,883,980 | <p>This seems like it should be pretty trivial, but I am new at Python and want to do it the most Pythonic way.</p>
<p>I want to find the n'th occurrence of a substring in a string.</p>
<p>There's got to be something equivalent to what I WANT to do which is </p>
<p><code>mystring.find("substring", 2nd)</code></p>
<... | 55 | 2009-12-10T20:58:50Z | 1,884,277 | <p>Here's a more Pythonic version of the straightforward iterative solution:</p>
<pre><code>def find_nth(haystack, needle, n):
start = haystack.find(needle)
while start >= 0 and n > 1:
start = haystack.find(needle, start+len(needle))
n -= 1
return start
</code></pre>
<p><em>Example:<... | 37 | 2009-12-10T21:45:22Z | [
"python",
"string",
"substring"
] |
Find the nth occurrence of substring in a string | 1,883,980 | <p>This seems like it should be pretty trivial, but I am new at Python and want to do it the most Pythonic way.</p>
<p>I want to find the n'th occurrence of a substring in a string.</p>
<p>There's got to be something equivalent to what I WANT to do which is </p>
<p><code>mystring.find("substring", 2nd)</code></p>
<... | 55 | 2009-12-10T20:58:50Z | 1,885,049 | <pre><code>>>> s="abcdefabcdefababcdef"
>>> j=0
>>> for n,i in enumerate(s):
... if s[n:n+2] =="ab":
... print n,i
... j=j+1
... if j==2: print "2nd occurence at index position: ",n
...
0 a
6 a
2nd occurence at index position: 6
12 a
14 a
</code></pre>
| 1 | 2009-12-11T00:22:29Z | [
"python",
"string",
"substring"
] |
Find the nth occurrence of substring in a string | 1,883,980 | <p>This seems like it should be pretty trivial, but I am new at Python and want to do it the most Pythonic way.</p>
<p>I want to find the n'th occurrence of a substring in a string.</p>
<p>There's got to be something equivalent to what I WANT to do which is </p>
<p><code>mystring.find("substring", 2nd)</code></p>
<... | 55 | 2009-12-10T20:58:50Z | 1,888,673 | <p>Here's another <code>re</code> + <code>itertools</code> version that should work when searching for either a <code>str</code> or a <code>RegexpObject</code>. I will freely admit that this is likely over-engineered, but for some reason it entertained me.</p>
<pre><code>import itertools
import re
def find_nth(haysta... | 2 | 2009-12-11T15:06:23Z | [
"python",
"string",
"substring"
] |
Find the nth occurrence of substring in a string | 1,883,980 | <p>This seems like it should be pretty trivial, but I am new at Python and want to do it the most Pythonic way.</p>
<p>I want to find the n'th occurrence of a substring in a string.</p>
<p>There's got to be something equivalent to what I WANT to do which is </p>
<p><code>mystring.find("substring", 2nd)</code></p>
<... | 55 | 2009-12-10T20:58:50Z | 13,094,326 | <p>This will find the second occurrence of substring in string.</p>
<pre><code>def find_2nd(string, substring):
return string.find(substring, string.find(substring) + 1)
</code></pre>
| 11 | 2012-10-26T20:59:02Z | [
"python",
"string",
"substring"
] |
Find the nth occurrence of substring in a string | 1,883,980 | <p>This seems like it should be pretty trivial, but I am new at Python and want to do it the most Pythonic way.</p>
<p>I want to find the n'th occurrence of a substring in a string.</p>
<p>There's got to be something equivalent to what I WANT to do which is </p>
<p><code>mystring.find("substring", 2nd)</code></p>
<... | 55 | 2009-12-10T20:58:50Z | 16,071,638 | <p>The replace one liner is great but only works because XX and bar have the same lentgh</p>
<p>A good and general def would be:</p>
<pre><code>def findN(s,sub,N,replaceString="XXX"):
return s.replace(sub,replaceString,N-1).find(sub) - (len(replaceString)-len(sub))*(N-1)
</code></pre>
| 0 | 2013-04-17T22:53:29Z | [
"python",
"string",
"substring"
] |
Find the nth occurrence of substring in a string | 1,883,980 | <p>This seems like it should be pretty trivial, but I am new at Python and want to do it the most Pythonic way.</p>
<p>I want to find the n'th occurrence of a substring in a string.</p>
<p>There's got to be something equivalent to what I WANT to do which is </p>
<p><code>mystring.find("substring", 2nd)</code></p>
<... | 55 | 2009-12-10T20:58:50Z | 23,479,065 | <p>I'm offering some benchmarking results comparing the most prominent approaches presented so far, namely @bobince's <code>findnth()</code> (based on <code>str.split()</code>) vs. @tgamblin's or @Mark Byers' <code>find_nth()</code> (based on <code>str.find()</code>). I will also compare with a C extension (<code>_find... | 7 | 2014-05-05T18:16:34Z | [
"python",
"string",
"substring"
] |
Find the nth occurrence of substring in a string | 1,883,980 | <p>This seems like it should be pretty trivial, but I am new at Python and want to do it the most Pythonic way.</p>
<p>I want to find the n'th occurrence of a substring in a string.</p>
<p>There's got to be something equivalent to what I WANT to do which is </p>
<p><code>mystring.find("substring", 2nd)</code></p>
<... | 55 | 2009-12-10T20:58:50Z | 29,361,324 | <p>Providing another "tricky" solution, which use <code>split</code> and <code>join</code>.</p>
<p>In your example, we can use</p>
<pre><code>len("substring".join([s for s in ori.split("substring")[:2]]))
</code></pre>
| 0 | 2015-03-31T05:40:02Z | [
"python",
"string",
"substring"
] |
Find the nth occurrence of substring in a string | 1,883,980 | <p>This seems like it should be pretty trivial, but I am new at Python and want to do it the most Pythonic way.</p>
<p>I want to find the n'th occurrence of a substring in a string.</p>
<p>There's got to be something equivalent to what I WANT to do which is </p>
<p><code>mystring.find("substring", 2nd)</code></p>
<... | 55 | 2009-12-10T20:58:50Z | 32,357,318 | <p>Simplest way?</p>
<pre><code>text = "This is a test from a test ok"
firstTest = text.find('test')
print text.find('test', firstTest + 1)
</code></pre>
| 1 | 2015-09-02T15:32:41Z | [
"python",
"string",
"substring"
] |
Find the nth occurrence of substring in a string | 1,883,980 | <p>This seems like it should be pretty trivial, but I am new at Python and want to do it the most Pythonic way.</p>
<p>I want to find the n'th occurrence of a substring in a string.</p>
<p>There's got to be something equivalent to what I WANT to do which is </p>
<p><code>mystring.find("substring", 2nd)</code></p>
<... | 55 | 2009-12-10T20:58:50Z | 37,794,340 | <p>How about:</p>
<pre><code>c = os.getcwd().split('\\')
print '\\'.join(c[0:-2])
</code></pre>
| 0 | 2016-06-13T16:01:08Z | [
"python",
"string",
"substring"
] |
Find the nth occurrence of substring in a string | 1,883,980 | <p>This seems like it should be pretty trivial, but I am new at Python and want to do it the most Pythonic way.</p>
<p>I want to find the n'th occurrence of a substring in a string.</p>
<p>There's got to be something equivalent to what I WANT to do which is </p>
<p><code>mystring.find("substring", 2nd)</code></p>
<... | 55 | 2009-12-10T20:58:50Z | 38,466,390 | <p>This is the answer you really want:</p>
<pre><code>def Find(String,ToFind,Occurence = 1):
index = 0
count = 0
while index <= len(String):
try:
if String[index:index + len(ToFind)] == ToFind:
count += 1
if count == Occurence:
return index
break
... | 0 | 2016-07-19T18:53:32Z | [
"python",
"string",
"substring"
] |
Converting a list of lists to a tuple in Python | 1,884,323 | <p>I have a list of lists (generated with a simple list comprehension):</p>
<pre><code>>>> base_lists = [[a, b] for a in range(1, 3) for b in range(1, 6)]
>>> base_lists
[[1,1],[1,2],[1,3],[1,4],[1,5],[2,1],[2,2],[2,3],[2,4],[2,5]]
</code></pre>
<p>I want to turn this entire list into a tuple conta... | 5 | 2009-12-10T21:53:38Z | 1,884,377 | <pre><code>tuple(x for sublist in base_lists for x in sublist)
</code></pre>
<p><strong>Edit</strong>: note that, with <code>base_lists</code> so short, the genexp (with unlimited memory available) is slow. Consider the following file <code>tu.py</code>:</p>
<pre><code>base_lists = [[a, b] for a in range(1, 3) for b... | 11 | 2009-12-10T22:00:10Z | [
"python",
"list-comprehension",
"itertools",
"tuple-packing"
] |
Converting a list of lists to a tuple in Python | 1,884,323 | <p>I have a list of lists (generated with a simple list comprehension):</p>
<pre><code>>>> base_lists = [[a, b] for a in range(1, 3) for b in range(1, 6)]
>>> base_lists
[[1,1],[1,2],[1,3],[1,4],[1,5],[2,1],[2,2],[2,3],[2,4],[2,5]]
</code></pre>
<p>I want to turn this entire list into a tuple conta... | 5 | 2009-12-10T21:53:38Z | 1,884,393 | <pre><code>>>> sum(base_lists,[])
[1, 1, 1, 2, 1, 3, 1, 4, 1, 5, 2, 1, 2, 2, 2, 3, 2, 4, 2, 5]
>>> tuple(sum(base_lists,[]))
(1, 1, 1, 2, 1, 3, 1, 4, 1, 5, 2, 1, 2, 2, 2, 3, 2, 4, 2, 5)
</code></pre>
| 3 | 2009-12-10T22:02:08Z | [
"python",
"list-comprehension",
"itertools",
"tuple-packing"
] |
Converting a list of lists to a tuple in Python | 1,884,323 | <p>I have a list of lists (generated with a simple list comprehension):</p>
<pre><code>>>> base_lists = [[a, b] for a in range(1, 3) for b in range(1, 6)]
>>> base_lists
[[1,1],[1,2],[1,3],[1,4],[1,5],[2,1],[2,2],[2,3],[2,4],[2,5]]
</code></pre>
<p>I want to turn this entire list into a tuple conta... | 5 | 2009-12-10T21:53:38Z | 1,884,421 | <p><code>resulting_tuple = tuple(item for l in base_lists for item in l)</code></p>
| 2 | 2009-12-10T22:05:18Z | [
"python",
"list-comprehension",
"itertools",
"tuple-packing"
] |
Converting a list of lists to a tuple in Python | 1,884,323 | <p>I have a list of lists (generated with a simple list comprehension):</p>
<pre><code>>>> base_lists = [[a, b] for a in range(1, 3) for b in range(1, 6)]
>>> base_lists
[[1,1],[1,2],[1,3],[1,4],[1,5],[2,1],[2,2],[2,3],[2,4],[2,5]]
</code></pre>
<p>I want to turn this entire list into a tuple conta... | 5 | 2009-12-10T21:53:38Z | 1,884,440 | <pre><code>from itertools import chain
base_lists = [[a, b] for a in range(1, 3) for b in range(1, 6)]
print tuple(chain(*base_lists))
</code></pre>
| 5 | 2009-12-10T22:07:38Z | [
"python",
"list-comprehension",
"itertools",
"tuple-packing"
] |
Converting a list of lists to a tuple in Python | 1,884,323 | <p>I have a list of lists (generated with a simple list comprehension):</p>
<pre><code>>>> base_lists = [[a, b] for a in range(1, 3) for b in range(1, 6)]
>>> base_lists
[[1,1],[1,2],[1,3],[1,4],[1,5],[2,1],[2,2],[2,3],[2,4],[2,5]]
</code></pre>
<p>I want to turn this entire list into a tuple conta... | 5 | 2009-12-10T21:53:38Z | 1,886,381 | <pre><code>>>> arr=[]
>>> base_lists = [[a, b] for a in range(1, 3) for b in range(1, 6)]
>>> [ arr.extend(i) for i in base_lists ]
[None, None, None, None, None, None, None, None, None, None]
>>> arr
[1, 1, 1, 2, 1, 3, 1, 4, 1, 5, 2, 1, 2, 2, 2, 3, 2, 4, 2, 5]
>>> tuple(arr... | 0 | 2009-12-11T07:16:20Z | [
"python",
"list-comprehension",
"itertools",
"tuple-packing"
] |
Named parameters with Python C API? | 1,884,327 | <p>How can I simulate the following Python function using the Python C API?</p>
<pre><code>def foo(bar, baz="something or other"):
print bar, baz
</code></pre>
<p>(i.e., so that it is possible to call it via:</p>
<pre><code>>>> foo("hello")
hello something or other
>>> foo("hello", baz="world!"... | 4 | 2009-12-10T21:54:21Z | 1,884,369 | <p>See <a href="http://docs.python.org/extending/extending.html#keyword-parameters-for-extension-functions">the docs</a>: you want to use <code>PyArg_ParseTupleAndKeywords</code>, documented at the URL I gave.</p>
<p>So for example:</p>
<pre><code>def foo(bar, baz="something or other"):
print bar, baz
</code></pr... | 12 | 2009-12-10T21:59:11Z | [
"python",
"c",
"python-c-api",
"named-parameters"
] |
CSV to JSON script | 1,884,395 | <p>I took this script from <a href="http://www.johntron.com/creations/csv-to-json/">here</a>: </p>
<pre><code>import csv
from itertools import izip
f = open( '/django/sw2/wkw2/csvtest1.csv', 'r' )
reader = csv.reader( f )
keys = ( "firm_url", "firm_name", "first", "last", "school", "year_graduated" )
out = []
for prop... | 7 | 2009-12-10T22:02:23Z | 1,884,444 | <p>Maybe you are trying to parse an empty line at the end of the file</p>
<pre><code>for property in reader:
print repr(property) # <---try adding a print here
property = iter( property )
</code></pre>
<p>Also csv.DictReader may do what you want already</p>
<pre><code>csv.DictReader(f,fields=("fir... | 0 | 2009-12-10T22:08:11Z | [
"python",
"json",
"csv"
] |
CSV to JSON script | 1,884,395 | <p>I took this script from <a href="http://www.johntron.com/creations/csv-to-json/">here</a>: </p>
<pre><code>import csv
from itertools import izip
f = open( '/django/sw2/wkw2/csvtest1.csv', 'r' )
reader = csv.reader( f )
keys = ( "firm_url", "firm_name", "first", "last", "school", "year_graduated" )
out = []
for prop... | 7 | 2009-12-10T22:02:23Z | 1,884,446 | <p>Since you're not actually creating JSON, I'm not sure about the last question. You're just printing a Python dictionary. They're mostly JSON, but not always. </p>
<p>So you should find a good <code>json</code> module and use that. If you have Python 2.6: <a href="http://docs.python.org/library/json.html" rel="n... | 0 | 2009-12-10T22:08:39Z | [
"python",
"json",
"csv"
] |
CSV to JSON script | 1,884,395 | <p>I took this script from <a href="http://www.johntron.com/creations/csv-to-json/">here</a>: </p>
<pre><code>import csv
from itertools import izip
f = open( '/django/sw2/wkw2/csvtest1.csv', 'r' )
reader = csv.reader( f )
keys = ( "firm_url", "firm_name", "first", "last", "school", "year_graduated" )
out = []
for prop... | 7 | 2009-12-10T22:02:23Z | 1,884,455 | <p>Change the nested <code>for</code> loop to:</p>
<pre><code>out = [dict(zip(keys, property)) for property in reader]
</code></pre>
<p>and, no, <code>print out</code> will not emit valid JSON -- use <code>print json.dumps(out)</code> (you'll need to <code>import json</code> too of course -- that's a Python 2.6 stand... | 15 | 2009-12-10T22:10:57Z | [
"python",
"json",
"csv"
] |
CSV to JSON script | 1,884,395 | <p>I took this script from <a href="http://www.johntron.com/creations/csv-to-json/">here</a>: </p>
<pre><code>import csv
from itertools import izip
f = open( '/django/sw2/wkw2/csvtest1.csv', 'r' )
reader = csv.reader( f )
keys = ( "firm_url", "firm_name", "first", "last", "school", "year_graduated" )
out = []
for prop... | 7 | 2009-12-10T22:02:23Z | 15,843,751 | <p>With the <a href="http://docs.python.org/2/library/csv.html" rel="nofollow">CSV Module</a> you already have a <a href="http://docs.python.org/2/library/csv.html#csv.DictReader" rel="nofollow">dict reader</a> built in! Here's an example script which can be used as a command line tool:</p>
<pre><code>import csv
impor... | 3 | 2013-04-05T21:18:13Z | [
"python",
"json",
"csv"
] |
CSV to JSON script | 1,884,395 | <p>I took this script from <a href="http://www.johntron.com/creations/csv-to-json/">here</a>: </p>
<pre><code>import csv
from itertools import izip
f = open( '/django/sw2/wkw2/csvtest1.csv', 'r' )
reader = csv.reader( f )
keys = ( "firm_url", "firm_name", "first", "last", "school", "year_graduated" )
out = []
for prop... | 7 | 2009-12-10T22:02:23Z | 16,095,547 | <pre><code>import csv
import json
reader = csv.reader(f, delimiter=',', quotechar='"')
keys = next(reader) #skip the headers
out = [{key: val for key, val in zip(keys, prop)} for prop in reader]
json.dumps(out)
</code></pre>
| 1 | 2013-04-19T00:57:33Z | [
"python",
"json",
"csv"
] |
Handling UTF-16 in a Django uploaded file | 1,884,399 | <p>In my Django webapp, in one location users can upload a text file where each line contains a string which will be operated on - the file isn't being stored on the server or anything like that.</p>
<p>My code looks like this:</p>
<pre><code>roFile = request.FILES['uploadFileName']
ros = roFile.read().strip()
ros = ... | 1 | 2009-12-10T22:02:39Z | 1,884,518 | <p>This first part doesn't answer your question (I know nothing about django); I'd just like to point out that when you supply code that you say works or doesn't work, you should copy/past the actual code that you ran,; don't type it from memory.</p>
<p>This code:</p>
<pre><code>import codecs
from django.utils.encodi... | 1 | 2009-12-10T22:25:36Z | [
"python",
"django",
"utf-8"
] |
When are property validations run in Google App Engine (GAE)? | 1,884,635 | <p>So I was reading <a href="http://code.google.com/appengine/articles/extending%5Fmodels.html" rel="nofollow">the following</a> documentation on defining your own property types in GAE. I noticed that I could also include a .validate() method when extending a new Property. This validate method will be called "when an ... | 1 | 2009-12-10T22:46:34Z | 1,884,731 | <p>Before put, and during the transaction, respectively (it may abort the transaction if validation fails of course). "When an assignment is made" to a property of your entity is when you write <code>theentity.theproperty = somevalue</code> (or when you perform it implicitly).</p>
<p>I believe that queries of unrelat... | 2 | 2009-12-10T23:06:20Z | [
"python",
"google-app-engine"
] |
An Exercise: map or reduce a map in Python without list comprehensions? | 1,884,682 | <p>When I started writing this question, I didn't think of the easy solution with nested lists, but now anyway want to find one.</p>
<p>Here's an ugly code:</p>
<pre><code>fun0(
fun1(fun2(fun3(arg1))),
fun1(fun2(fun3(arg4))),
fun1(fun2(fun3(arg4))),
fun1(fun2(fun3(arg4))))
</code></pre>
<p>Ouch! Name... | 0 | 2009-12-10T22:55:13Z | 1,884,714 | <p>your 3 examples do 3 different things.</p>
<p>your original is the same as</p>
<pre><code>fun0(map(lambda x:fun1(fun2(fun3(x))), [arg1,arg2,arg3,arg4])
</code></pre>
<p>your second example, if you absolutely want a functional form, is probably something like</p>
<pre><code>fun0(map(apply, itertools.product([fun1... | 2 | 2009-12-10T23:03:35Z | [
"python",
"functional-programming",
"map"
] |
An Exercise: map or reduce a map in Python without list comprehensions? | 1,884,682 | <p>When I started writing this question, I didn't think of the easy solution with nested lists, but now anyway want to find one.</p>
<p>Here's an ugly code:</p>
<pre><code>fun0(
fun1(fun2(fun3(arg1))),
fun1(fun2(fun3(arg4))),
fun1(fun2(fun3(arg4))),
fun1(fun2(fun3(arg4))))
</code></pre>
<p>Ouch! Name... | 0 | 2009-12-10T22:55:13Z | 1,884,769 | <pre><code>def composed(x): return fun1(fun2(fun3(x)))
fun0(*map(composed, (arg1, arg2, arg3, arg4)))
</code></pre>
<p>You could use a <code>lambda</code>, of course, instead of naming intermediate function <code>composed</code>, but I find this way more readable.</p>
<p>Note that the <code>*</code> is crucial, othe... | 1 | 2009-12-10T23:13:16Z | [
"python",
"functional-programming",
"map"
] |
An Exercise: map or reduce a map in Python without list comprehensions? | 1,884,682 | <p>When I started writing this question, I didn't think of the easy solution with nested lists, but now anyway want to find one.</p>
<p>Here's an ugly code:</p>
<pre><code>fun0(
fun1(fun2(fun3(arg1))),
fun1(fun2(fun3(arg4))),
fun1(fun2(fun3(arg4))),
fun1(fun2(fun3(arg4))))
</code></pre>
<p>Ouch! Name... | 0 | 2009-12-10T22:55:13Z | 1,884,772 | <p>The most functional way to rewrite your first code block would be to compose the three functions, map the composed function over the list of arguments, then apply fun0 to the list. Python doesn't really have a natural way to do function composition, so something like Jimmy's solution is where you'll end up.</p>
<p>... | -1 | 2009-12-10T23:13:45Z | [
"python",
"functional-programming",
"map"
] |
How important is it to check return values when using the Python C API? | 1,884,684 | <p>It seems that everytime I call a function that returns a PyObject*, I have to add four lines of error checking. Example:</p>
<pre><code>py_fullname = PyObject_CallMethod(os, "path.join", "ss", folder, filename);
if (!py_fullname) {
Py_DECREF(pygame);
Py_DECREF(os);
return NULL;
}
image = PyObject_CallMe... | 3 | 2009-12-10T22:55:33Z | 1,884,716 | <p>This is the C API. If you code in C only, you may have to live with it, but if your application is coded in C++, you might want a take a look at a <a href="http://davidf.sjsoft.com/mirrors/mcmillan-inc/scxx.html" rel="nofollow">C++/Python wrapper</a>.</p>
| 2 | 2009-12-10T23:03:47Z | [
"python",
"c",
"memory-management"
] |
How important is it to check return values when using the Python C API? | 1,884,684 | <p>It seems that everytime I call a function that returns a PyObject*, I have to add four lines of error checking. Example:</p>
<pre><code>py_fullname = PyObject_CallMethod(os, "path.join", "ss", folder, filename);
if (!py_fullname) {
Py_DECREF(pygame);
Py_DECREF(os);
return NULL;
}
image = PyObject_CallMe... | 3 | 2009-12-10T22:55:33Z | 1,884,752 | <p>That's why <code>goto</code> is alive (though not entirely well;-) in C coding (as opposed to C++ and other languages that support exceptions): it's the only decent way to NOT have such repeated blocks of termination all over the mainline of your code -- a conditional forward jump to <code>errorexit</code> at each r... | 8 | 2009-12-10T23:08:44Z | [
"python",
"c",
"memory-management"
] |
How important is it to check return values when using the Python C API? | 1,884,684 | <p>It seems that everytime I call a function that returns a PyObject*, I have to add four lines of error checking. Example:</p>
<pre><code>py_fullname = PyObject_CallMethod(os, "path.join", "ss", folder, filename);
if (!py_fullname) {
Py_DECREF(pygame);
Py_DECREF(os);
return NULL;
}
image = PyObject_CallMe... | 3 | 2009-12-10T22:55:33Z | 1,885,162 | <p>This is one of the reasons why C++ introduces exception handling and RAII. Assuming you can use C++, you can create a function that invokes the C function, tests the result, and throws an exception if an error occurred. That way, you can call the wrapper without any checks... if an error occurs, it will throw the ex... | 0 | 2009-12-11T00:53:30Z | [
"python",
"c",
"memory-management"
] |
How important is it to check return values when using the Python C API? | 1,884,684 | <p>It seems that everytime I call a function that returns a PyObject*, I have to add four lines of error checking. Example:</p>
<pre><code>py_fullname = PyObject_CallMethod(os, "path.join", "ss", folder, filename);
if (!py_fullname) {
Py_DECREF(pygame);
Py_DECREF(os);
return NULL;
}
image = PyObject_CallMe... | 3 | 2009-12-10T22:55:33Z | 1,885,440 | <p>Here are two ways I might write that code, influenced by my experience writing in two heavily macro-ised pseudo-assembler languages, one of which wasn't C. I've moved the deref of fullname, not because it's wrong in your code, but because I want to demonstrate how you handle a longer-lived resource in both schemes. ... | 2 | 2009-12-11T02:19:49Z | [
"python",
"c",
"memory-management"
] |
How important is it to check return values when using the Python C API? | 1,884,684 | <p>It seems that everytime I call a function that returns a PyObject*, I have to add four lines of error checking. Example:</p>
<pre><code>py_fullname = PyObject_CallMethod(os, "path.join", "ss", folder, filename);
if (!py_fullname) {
Py_DECREF(pygame);
Py_DECREF(os);
return NULL;
}
image = PyObject_CallMe... | 3 | 2009-12-10T22:55:33Z | 28,674,453 | <p>While I don't see it often I consider this a good solution for C programmers ("the goto with tie"):</p>
<pre><code>result = NULL;
// make sure all variables are initialized
do
{
py_fullname = PyObject_CallMethod(os, "path.join", "ss", folder, filename);
if (!py_fullname)
{
// some additional er... | 0 | 2015-02-23T13:02:18Z | [
"python",
"c",
"memory-management"
] |
How to populate sqlite3 in django? | 1,884,694 | <p>My plan is to collect data from websites in batches (lawyer bios from each firm's website; since they are all different, I will use a modified spider for each site) and convert each batch into a csv file; then to json; and then load it to database. So I will need to append each new file to the existing database. Ple... | 0 | 2009-12-10T22:58:31Z | 1,885,417 | <p>Just load the database directly. Collect data from websites in batches, loading the SQlite3 directly. Just write simple batch applications that use the Django ORM. Collect data from websites and load SQLite3 immediately. Do not create CSV. Do not create JSON. Do not create intermediate results. Do not do any ... | 4 | 2009-12-11T02:11:27Z | [
"python",
"django",
"json",
"csv"
] |
Use Python's easy_install in intranet | 1,884,791 | <p>Increasingly I found myself using tools based upon python, particularly that use installation processes involving easy_install. The trouble for me is that I am </p>
<ol>
<li>On an intranet with no internet access</li>
<li>On windows (which always complicates things a little!)</li>
</ol>
<p>Any advice on how to se... | 2 | 2009-12-10T23:17:42Z | 1,885,255 | <p>I think you can use .egg files with easy_install, you could host those on your intranet and point easy_install to it. See <a href="http://peak.telecommunity.com/DevCenter/EasyInstall#using-easy-install" rel="nofollow">http://peak.telecommunity.com/DevCenter/EasyInstall#using-easy-install</a> for a good reference.</p... | 3 | 2009-12-11T01:16:13Z | [
"python",
"easy-install"
] |
Set django-notification to be opt in rather than the default of opt out | 1,884,801 | <p>I'm using <a href="http://github.com/jtauber/django-notification/" rel="nofollow">django-notification</a> to allow my users to opt out of certain alerts I generate in my web-application. </p>
<p>By default when I create a new notice type it is enabled rather than disabled In the users notification interface (checke... | 2 | 2009-12-10T23:19:21Z | 1,902,925 | <p>Its automatically set based on the 'default' column in the type itself, by default e-mail is a sensitivity of 2, so if you set the default to your new notice type default '1' it will no longer set it on by default for your users, the default when creating new notice types is '2' which would allow it to be sent to ev... | 3 | 2009-12-14T19:22:48Z | [
"python",
"django",
"pinax",
"code-reuse"
] |
Set django-notification to be opt in rather than the default of opt out | 1,884,801 | <p>I'm using <a href="http://github.com/jtauber/django-notification/" rel="nofollow">django-notification</a> to allow my users to opt out of certain alerts I generate in my web-application. </p>
<p>By default when I create a new notice type it is enabled rather than disabled In the users notification interface (checke... | 2 | 2009-12-10T23:19:21Z | 1,912,127 | <p>Looking at the code, the determining factor to sending the notice is a comparison between the 'default' column and the sensitivity filter NOTICE_MEDIA_DEFAULTS[medium]. </p>
<p>Does this work</p>
<pre><code>from notification import models as notification
notification.create_notice_type("friends_invite", "Invitati... | 0 | 2009-12-16T03:46:57Z | [
"python",
"django",
"pinax",
"code-reuse"
] |
Django loaddata error | 1,884,827 | <p>I created a "fixtures" folder in the app directory and put data1.json in there.</p>
<p>This is what is in the file:</p>
<pre><code>[{"firm_url": "http://www.graychase.com/kadam", "firm_name": "Gray & Chase", "first": " Karin ", "last": "Adam", "school": "Ernst Moritz Arndt University Greifswald", "year_gradua... | 2 | 2009-12-10T23:24:13Z | 1,884,837 | <p>It looks like the problem is within the fixture you've created. The following might cause problems:</p>
<ul>
<li>Changing the database schema after creating a fixture, then loading the fixture into your new schema</li>
<li>Manually fiddling with the contents of the fixture.</li>
</ul>
<p>Did you create the fixture... | 1 | 2009-12-10T23:26:17Z | [
"python",
"django"
] |
Django loaddata error | 1,884,827 | <p>I created a "fixtures" folder in the app directory and put data1.json in there.</p>
<p>This is what is in the file:</p>
<pre><code>[{"firm_url": "http://www.graychase.com/kadam", "firm_name": "Gray & Chase", "first": " Karin ", "last": "Adam", "school": "Ernst Moritz Arndt University Greifswald", "year_gradua... | 2 | 2009-12-10T23:24:13Z | 1,885,124 | <p>it looks like you are not defining your fixtures properly. Take a look at the <a href="http://docs.djangoproject.com/en/dev/howto/initial-data/#howto-initial-data">Django Documentation</a>. You need to define the model that you are loading, then define the fields like this </p>
<pre><code> [
{
"model": "mya... | 5 | 2009-12-11T00:41:36Z | [
"python",
"django"
] |
Lost connection to MySQL server during query | 1,884,859 | <p>I have a huge table and I need to process all rows in it. I'm always getting this Lost connection message and I'm not able to reconnect and restore the cursor to the last position it was. This is basically the code I have here:</p>
<pre><code>#
import MySQLdb
class DB:
conn = None
def connect(self):
self.... | 28 | 2009-12-10T23:29:47Z | 1,884,913 | <p>You need to increase the timeout on your connection. If you can't or don't want to do that for some reason, you could try calling:</p>
<pre><code>data = db.query(sql).store_result()
</code></pre>
<p>This will fetch all the results immediately, then your connection won't time out halfway through iterating over them... | 7 | 2009-12-10T23:40:50Z | [
"python",
"mysql"
] |
Lost connection to MySQL server during query | 1,884,859 | <p>I have a huge table and I need to process all rows in it. I'm always getting this Lost connection message and I'm not able to reconnect and restore the cursor to the last position it was. This is basically the code I have here:</p>
<pre><code>#
import MySQLdb
class DB:
conn = None
def connect(self):
self.... | 28 | 2009-12-10T23:29:47Z | 1,884,918 | <p>The mysql docs have a whole page dedicated to this error:
<a href="http://dev.mysql.com/doc/refman/5.0/en/gone-away.html">http://dev.mysql.com/doc/refman/5.0/en/gone-away.html</a></p>
<p>of note are</p>
<ul>
<li><p>You can also get these errors if you send a query to the server that is incorrect or too large. If m... | 27 | 2009-12-10T23:41:59Z | [
"python",
"mysql"
] |
Lost connection to MySQL server during query | 1,884,859 | <p>I have a huge table and I need to process all rows in it. I'm always getting this Lost connection message and I'm not able to reconnect and restore the cursor to the last position it was. This is basically the code I have here:</p>
<pre><code>#
import MySQLdb
class DB:
conn = None
def connect(self):
self.... | 28 | 2009-12-10T23:29:47Z | 9,603,681 | <p>Make sure you close cursor before connection. I've resolved my problem with this:</p>
<pre><code>if cur and con:
cur.close()
con.close()
</code></pre>
| 7 | 2012-03-07T14:51:24Z | [
"python",
"mysql"
] |
Lost connection to MySQL server during query | 1,884,859 | <p>I have a huge table and I need to process all rows in it. I'm always getting this Lost connection message and I'm not able to reconnect and restore the cursor to the last position it was. This is basically the code I have here:</p>
<pre><code>#
import MySQLdb
class DB:
conn = None
def connect(self):
self.... | 28 | 2009-12-10T23:29:47Z | 10,820,239 | <p>Set the 'max_allowed_packet' setting to 64M and restart your MySql server. If that did not fixed your issues, the problem may lie elsewhere.</p>
<p>I've a multi-threaded PHP CLI application that does simultaneous queries and I recently noticed this issue. It's now obvious to me that MySql server consider all connec... | 3 | 2012-05-30T16:19:29Z | [
"python",
"mysql"
] |
Lost connection to MySQL server during query | 1,884,859 | <p>I have a huge table and I need to process all rows in it. I'm always getting this Lost connection message and I'm not able to reconnect and restore the cursor to the last position it was. This is basically the code I have here:</p>
<pre><code>#
import MySQLdb
class DB:
conn = None
def connect(self):
self.... | 28 | 2009-12-10T23:29:47Z | 16,454,269 | <p>There are three ways to enlarge the max_allowed_packet of mysql server:</p>
<ol>
<li>Change <code>max_allowed_packet=64M</code> in file <code>/etc/mysql/my.cnf</code> on the mysql server machine and restart the server</li>
<li>Execute the sql on the mysql server: <code>set global max_allowed_packet=67108864;</code>... | 6 | 2013-05-09T04:16:54Z | [
"python",
"mysql"
] |
Lost connection to MySQL server during query | 1,884,859 | <p>I have a huge table and I need to process all rows in it. I'm always getting this Lost connection message and I'm not able to reconnect and restore the cursor to the last position it was. This is basically the code I have here:</p>
<pre><code>#
import MySQLdb
class DB:
conn = None
def connect(self):
self.... | 28 | 2009-12-10T23:29:47Z | 18,181,337 | <blockquote>
<p>You can also encounter this error with applications that fork child processes, all of which try to use the same connection to the MySQL server. This can be avoided by using a separate connection for each child process.</p>
</blockquote>
<p>Forks might hit you. Beware not in this case though.</p>
| 4 | 2013-08-12T07:11:43Z | [
"python",
"mysql"
] |
Lost connection to MySQL server during query | 1,884,859 | <p>I have a huge table and I need to process all rows in it. I'm always getting this Lost connection message and I'm not able to reconnect and restore the cursor to the last position it was. This is basically the code I have here:</p>
<pre><code>#
import MySQLdb
class DB:
conn = None
def connect(self):
self.... | 28 | 2009-12-10T23:29:47Z | 21,975,482 | <p>This was happening to me with mariadb because I made a <code>varchar(255)</code> column a <code>unique key</code>.. guess that's too heavy for a unique, as the insert was timing out.</p>
| 1 | 2014-02-23T22:23:29Z | [
"python",
"mysql"
] |
Lost connection to MySQL server during query | 1,884,859 | <p>I have a huge table and I need to process all rows in it. I'm always getting this Lost connection message and I'm not able to reconnect and restore the cursor to the last position it was. This is basically the code I have here:</p>
<pre><code>#
import MySQLdb
class DB:
conn = None
def connect(self):
self.... | 28 | 2009-12-10T23:29:47Z | 22,328,082 | <p>I my case the reason for the </p>
<blockquote>
<p>ERROR 2013 (HY000): Lost connection to MySQL server during query</p>
</blockquote>
<p>error was that parts of my table were <strong>corrupted</strong>. I was also not able to <code>mysqldump</code> my table because some rows broke it.
The error was not related to... | 3 | 2014-03-11T14:04:45Z | [
"python",
"mysql"
] |
Lost connection to MySQL server during query | 1,884,859 | <p>I have a huge table and I need to process all rows in it. I'm always getting this Lost connection message and I'm not able to reconnect and restore the cursor to the last position it was. This is basically the code I have here:</p>
<pre><code>#
import MySQLdb
class DB:
conn = None
def connect(self):
self.... | 28 | 2009-12-10T23:29:47Z | 29,101,615 | <p>This can also happen if someone or something kills your connection using the <a href="http://dev.mysql.com/doc/refman/5.5/en/kill.html" rel="nofollow">KILL command</a>.</p>
| 0 | 2015-03-17T14:23:32Z | [
"python",
"mysql"
] |
Lost connection to MySQL server during query | 1,884,859 | <p>I have a huge table and I need to process all rows in it. I'm always getting this Lost connection message and I'm not able to reconnect and restore the cursor to the last position it was. This is basically the code I have here:</p>
<pre><code>#
import MySQLdb
class DB:
conn = None
def connect(self):
self.... | 28 | 2009-12-10T23:29:47Z | 34,272,668 | <p>This happened to me when I tried to update a table whose size on disk was bigger than the available disk space. The solution for me was simply to increase the available disk space.</p>
| 1 | 2015-12-14T17:04:16Z | [
"python",
"mysql"
] |
Lost connection to MySQL server during query | 1,884,859 | <p>I have a huge table and I need to process all rows in it. I'm always getting this Lost connection message and I'm not able to reconnect and restore the cursor to the last position it was. This is basically the code I have here:</p>
<pre><code>#
import MySQLdb
class DB:
conn = None
def connect(self):
self.... | 28 | 2009-12-10T23:29:47Z | 36,771,995 | <p>In my case, I ran into this problem when sourcing an SQL dump which had placed the tables in the wrong order. The CREATE in question included a CONSTRAINT ... REFERENCES that referenced a table that had not been created yet.</p>
<p>I located the table in question, and moved its CREATE statement to above the offend... | 0 | 2016-04-21T14:01:44Z | [
"python",
"mysql"
] |
Lost connection to MySQL server during query | 1,884,859 | <p>I have a huge table and I need to process all rows in it. I'm always getting this Lost connection message and I'm not able to reconnect and restore the cursor to the last position it was. This is basically the code I have here:</p>
<pre><code>#
import MySQLdb
class DB:
conn = None
def connect(self):
self.... | 28 | 2009-12-10T23:29:47Z | 39,062,475 | <p>This happend to me when my <code>CONSTRAINT</code> name have the same name with other <code>CONSTRAINT</code> name.</p>
<p>Changing my <code>CONSTRAINT</code> name solved this.</p>
| 0 | 2016-08-21T08:50:02Z | [
"python",
"mysql"
] |
Lost connection to MySQL server during query | 1,884,859 | <p>I have a huge table and I need to process all rows in it. I'm always getting this Lost connection message and I'm not able to reconnect and restore the cursor to the last position it was. This is basically the code I have here:</p>
<pre><code>#
import MySQLdb
class DB:
conn = None
def connect(self):
self.... | 28 | 2009-12-10T23:29:47Z | 39,921,479 | <p>I encountered similar problems too. In my case it was solved by getting the cursor in this way:</p>
<pre><code>cursor = self.conn.cursor(buffered=True)
</code></pre>
| 0 | 2016-10-07T16:01:59Z | [
"python",
"mysql"
] |
Killing the children with the parent | 1,884,941 | <p>I have a program spawning and communicating with CPU heavy, unstable processes, not created by me. If my app crashes or is killed by <code>SIGKILL</code>, I want the subprocesses to get killed as well, so the user don´t have to track them down and kill them manually.</p>
<p>I know this topic has been covered befor... | 14 | 2009-12-10T23:46:56Z | 1,884,986 | <p>I thought the double fork was to detach from a controlling terminal. I'm not sure how you are trying to use it.</p>
<p>It's a hack, but you could always call 'ps' and search for the process name your trying to kill. </p>
| 1 | 2009-12-11T00:02:36Z | [
"python",
"subprocess",
"sigkill"
] |
Killing the children with the parent | 1,884,941 | <p>I have a program spawning and communicating with CPU heavy, unstable processes, not created by me. If my app crashes or is killed by <code>SIGKILL</code>, I want the subprocesses to get killed as well, so the user don´t have to track them down and kill them manually.</p>
<p>I know this topic has been covered befor... | 14 | 2009-12-10T23:46:56Z | 1,885,012 | <p>I've seen very nasty ways of "clean-up" using things like <code>ps xuawww | grep myApp | awk '{ print $1}' | xargs -n1 kill -9</code></p>
<p>The client process, if popened, can catch SIG_PIPE and die. There are many ways to go about this, but it really depends on a lot of factors. If you throw some ping code (ping ... | 1 | 2009-12-11T00:10:22Z | [
"python",
"subprocess",
"sigkill"
] |
Killing the children with the parent | 1,884,941 | <p>I have a program spawning and communicating with CPU heavy, unstable processes, not created by me. If my app crashes or is killed by <code>SIGKILL</code>, I want the subprocesses to get killed as well, so the user don´t have to track them down and kill them manually.</p>
<p>I know this topic has been covered befor... | 14 | 2009-12-10T23:46:56Z | 1,885,026 | <p><a href="http://linux.die.net/man/2/prctl">prctl</a>'s <code>PR_SET_DEATHSIG</code> can only be set <strong>for this very process that's calling prctl</strong> -- not for any other process, including this specific process's children. The way the man page I'm pointing to expresses this is "This value is cleared upon... | 6 | 2009-12-11T00:16:41Z | [
"python",
"subprocess",
"sigkill"
] |
Killing the children with the parent | 1,884,941 | <p>I have a program spawning and communicating with CPU heavy, unstable processes, not created by me. If my app crashes or is killed by <code>SIGKILL</code>, I want the subprocesses to get killed as well, so the user don´t have to track them down and kill them manually.</p>
<p>I know this topic has been covered befor... | 14 | 2009-12-10T23:46:56Z | 12,726,922 | <p>I'm wondering if the <code>PR_SET_PDEATHSIG</code> flag is getting cleared, even though you set it after you <code>fork</code> (and before <code>exec</code>), so it seems from the docs like it <em>shouldn't</em> get cleared.</p>
<p>In order to test that theory, you could try the following: use the same code to run ... | 1 | 2012-10-04T12:06:11Z | [
"python",
"subprocess",
"sigkill"
] |
Killing the children with the parent | 1,884,941 | <p>I have a program spawning and communicating with CPU heavy, unstable processes, not created by me. If my app crashes or is killed by <code>SIGKILL</code>, I want the subprocesses to get killed as well, so the user don´t have to track them down and kill them manually.</p>
<p>I know this topic has been covered befor... | 14 | 2009-12-10T23:46:56Z | 13,280,892 | <p>I know it's been years, but I found a simple (slightly hacky) solution to this problem. From your parent process, wrapping all your calls around a very simple C program that calls prctl() and then exec() solves this problem on Linux. I call it "yeshup":</p>
<pre><code>#include <linux/prctl.h>
#include <sig... | 11 | 2012-11-08T00:58:05Z | [
"python",
"subprocess",
"sigkill"
] |
Killing the children with the parent | 1,884,941 | <p>I have a program spawning and communicating with CPU heavy, unstable processes, not created by me. If my app crashes or is killed by <code>SIGKILL</code>, I want the subprocesses to get killed as well, so the user don´t have to track them down and kill them manually.</p>
<p>I know this topic has been covered befor... | 14 | 2009-12-10T23:46:56Z | 17,600,382 | <p>Actually I found that your original approach worked just fine for me - here's the exact example code I tested with which worked:</p>
<p><strong>echoer.py</strong></p>
<pre><code>#!/bin/env python
import time
import sys
i = 0
try:
while True:
i += 1
print i
time.sleep(1)
except Keyboard... | 3 | 2013-07-11T18:05:43Z | [
"python",
"subprocess",
"sigkill"
] |
Killing the children with the parent | 1,884,941 | <p>I have a program spawning and communicating with CPU heavy, unstable processes, not created by me. If my app crashes or is killed by <code>SIGKILL</code>, I want the subprocesses to get killed as well, so the user don´t have to track them down and kill them manually.</p>
<p>I know this topic has been covered befor... | 14 | 2009-12-10T23:46:56Z | 24,019,959 | <p>There is some security restriction to take into account because if we call setuid after execv he child cannot receive signal. The complete list of this restrictions is <a href="http://www.isec.pl/vulnerabilities/isec-0024-death-signal.txt" rel="nofollow">here</a></p>
<p>good luck !<br/>
/Mohamed</p>
| 1 | 2014-06-03T16:11:13Z | [
"python",
"subprocess",
"sigkill"
] |
Liteweight CGI Server to use on local machine to serve KML to Google Earth via Python or similar? | 1,885,113 | <p>Greetings,</p>
<p>I want to write a script that handles simple http requests from Google Earth and sends back KML to display map tiles that are stored locally. I would LIKE to use Python but any language is fine. I have not ever done anything with CGI, but I think this is the simplest way to accomplish my task. ... | 2 | 2009-12-11T00:39:05Z | 1,885,183 | <p>If I were you I'd use <a href="http://mapserver.org/" rel="nofollow">MapServer</a> and <a href="http://tilecache.org/" rel="nofollow">Tilecache</a> to do exactly that (serving up georeferenced raster imagery over http / python mapscript bindings available).</p>
<p>If you want plain cgi you can probably use lighthtt... | 1 | 2009-12-11T01:00:41Z | [
"python",
"cgi",
"kml",
"google-earth"
] |
Liteweight CGI Server to use on local machine to serve KML to Google Earth via Python or similar? | 1,885,113 | <p>Greetings,</p>
<p>I want to write a script that handles simple http requests from Google Earth and sends back KML to display map tiles that are stored locally. I would LIKE to use Python but any language is fine. I have not ever done anything with CGI, but I think this is the simplest way to accomplish my task. ... | 2 | 2009-12-11T00:39:05Z | 1,885,188 | <p><a href="http://docs.python.org/library/cgihttpserver.html" rel="nofollow">CGIHTTPServer</a> in the standard library.</p>
<pre><code># current directory containing cgi-bin directory with scripts in
# subclass CGIHTTPRequestHandler and override cgi_directories to change this
#
os.chdir('/path/to/htdocs')
BaseHTTPSe... | 1 | 2009-12-11T01:03:08Z | [
"python",
"cgi",
"kml",
"google-earth"
] |
How can I get optparse's OptionParser to ignore invalid options? | 1,885,161 | <p>In python's <CODE><a href="http://docs.python.org/library/optparse.html#optparse.OptionParser">OptionParser</a></CODE>, how can I instruct it to ignore undefined options supplied to method <CODE>parse_args</CODE>?</p>
<p>e.g.<BR>
I've only defined option <CODE>--foo</CODE> for my <CODE>OptionParser</CODE> instance,... | 18 | 2009-12-11T00:53:21Z | 1,885,285 | <p>By default there is no way to modify the behavior of the call to <code>error()</code> that is raised when an undefined option is passed. From the documentation at the bottom of the section on <a href="http://docs.python.org/library/optparse.html#how-optparse-handles-errors">how optparse handles errors</a>:</p>
<bl... | 9 | 2009-12-11T01:28:29Z | [
"python",
"optparse"
] |
How can I get optparse's OptionParser to ignore invalid options? | 1,885,161 | <p>In python's <CODE><a href="http://docs.python.org/library/optparse.html#optparse.OptionParser">OptionParser</a></CODE>, how can I instruct it to ignore undefined options supplied to method <CODE>parse_args</CODE>?</p>
<p>e.g.<BR>
I've only defined option <CODE>--foo</CODE> for my <CODE>OptionParser</CODE> instance,... | 18 | 2009-12-11T00:53:21Z | 2,148,751 | <p>Per synack's request in a different answer's comments, I'm posting my hack of a solution which sanitizes the inputs before passing them to the parent <code>OptionParser</code>:</p>
<pre><code>import optparse
import re
import copy
import SCons
class NoErrOptionParser(optparse.OptionParser):
def __init__(self,*a... | 1 | 2010-01-27T16:56:43Z | [
"python",
"optparse"
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.