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 |
|---|---|---|---|---|---|---|---|---|---|
Cannot import SQLite with Python 2.6 | 233,320 | <p>I'm running Python 2.6 on Unix and when I run the interactive prompt (<a href="http://en.wikipedia.org/wiki/SQLite">SQLite</a> is supposed to be preinstalled) I get:</p>
<pre><code>[root@idev htdocs]# python
Python 2.6 (r26:66714, Oct 23 2008, 16:25:34)
[GCC 3.2.2 20030222 (Red Hat Linux 3.2.2-5)] on linux2
Type "h... | 10 | 2008-10-24T12:33:24Z | 233,336 | <pre><code>import sqlite3
</code></pre>
<p><a href="http://docs.python.org/library/sqlite3.html#module-sqlite3">sqlite3</a> - DB-API 2.0 interface for SQLite databases.</p>
<p>You are missing the <code>.so</code> (shared object) - probably an installation step. In my Linux python installation, <code>_sqlite3</code> i... | 10 | 2008-10-24T12:36:50Z | [
"python",
"sqlite"
] |
Cannot import SQLite with Python 2.6 | 233,320 | <p>I'm running Python 2.6 on Unix and when I run the interactive prompt (<a href="http://en.wikipedia.org/wiki/SQLite">SQLite</a> is supposed to be preinstalled) I get:</p>
<pre><code>[root@idev htdocs]# python
Python 2.6 (r26:66714, Oct 23 2008, 16:25:34)
[GCC 3.2.2 20030222 (Red Hat Linux 3.2.2-5)] on linux2
Type "h... | 10 | 2008-10-24T12:33:24Z | 233,865 | <p>The error: </p>
<pre><code>ImportError: No module named _sqlite3
</code></pre>
<p>means that <a href="http://en.wikipedia.org/wiki/SQLite">SQLite</a> 3 does not find the associated shared library. On Mac OS X it's _sqlite3.so and it should be the same on other Unix systems. </p>
<p>To resolve the error you have t... | 13 | 2008-10-24T14:52:21Z | [
"python",
"sqlite"
] |
Cannot import SQLite with Python 2.6 | 233,320 | <p>I'm running Python 2.6 on Unix and when I run the interactive prompt (<a href="http://en.wikipedia.org/wiki/SQLite">SQLite</a> is supposed to be preinstalled) I get:</p>
<pre><code>[root@idev htdocs]# python
Python 2.6 (r26:66714, Oct 23 2008, 16:25:34)
[GCC 3.2.2 20030222 (Red Hat Linux 3.2.2-5)] on linux2
Type "h... | 10 | 2008-10-24T12:33:24Z | 233,883 | <p>Try this:</p>
<pre><code>from pysqlite2 import dbapi2 as sqlite
</code></pre>
| 1 | 2008-10-24T14:55:09Z | [
"python",
"sqlite"
] |
Cannot import SQLite with Python 2.6 | 233,320 | <p>I'm running Python 2.6 on Unix and when I run the interactive prompt (<a href="http://en.wikipedia.org/wiki/SQLite">SQLite</a> is supposed to be preinstalled) I get:</p>
<pre><code>[root@idev htdocs]# python
Python 2.6 (r26:66714, Oct 23 2008, 16:25:34)
[GCC 3.2.2 20030222 (Red Hat Linux 3.2.2-5)] on linux2
Type "h... | 10 | 2008-10-24T12:33:24Z | 233,967 | <p>On my system <code>_sqlite3.so</code> located at:</p>
<pre><code>'/usr/lib/python2.6/lib-dynload/_sqlite3.so'
</code></pre>
<p>Check that the directory is in your <code>sys.path</code>:</p>
<pre><code>>>> import sys; print(filter(lambda p: 'lib-dynload' in p, sys.path))
['/usr/lib/python2.6/lib-dynload']... | 1 | 2008-10-24T15:12:53Z | [
"python",
"sqlite"
] |
Cannot import SQLite with Python 2.6 | 233,320 | <p>I'm running Python 2.6 on Unix and when I run the interactive prompt (<a href="http://en.wikipedia.org/wiki/SQLite">SQLite</a> is supposed to be preinstalled) I get:</p>
<pre><code>[root@idev htdocs]# python
Python 2.6 (r26:66714, Oct 23 2008, 16:25:34)
[GCC 3.2.2 20030222 (Red Hat Linux 3.2.2-5)] on linux2
Type "h... | 10 | 2008-10-24T12:33:24Z | 939,030 | <p>Python 2.6 detects where the sqlite3 development headers are installed, and will silently skip building _sqlite3 if it is not available. If you are building from source, install sqlite3 including development headers. In my case, <code>sudo yum install sqlite-devel</code> sorted this out on a CentOS 4.7. Then, rebuil... | 10 | 2009-06-02T11:35:17Z | [
"python",
"sqlite"
] |
Cannot import SQLite with Python 2.6 | 233,320 | <p>I'm running Python 2.6 on Unix and when I run the interactive prompt (<a href="http://en.wikipedia.org/wiki/SQLite">SQLite</a> is supposed to be preinstalled) I get:</p>
<pre><code>[root@idev htdocs]# python
Python 2.6 (r26:66714, Oct 23 2008, 16:25:34)
[GCC 3.2.2 20030222 (Red Hat Linux 3.2.2-5)] on linux2
Type "h... | 10 | 2008-10-24T12:33:24Z | 953,786 | <p>Does that fix your problem?</p>
<pre><code>Python 2.5.4 (r254:67916, May 31 2009, 16:56:01)
[GCC 4.3.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import sqlite
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No mod... | 0 | 2009-06-05T00:44:48Z | [
"python",
"sqlite"
] |
Cannot import SQLite with Python 2.6 | 233,320 | <p>I'm running Python 2.6 on Unix and when I run the interactive prompt (<a href="http://en.wikipedia.org/wiki/SQLite">SQLite</a> is supposed to be preinstalled) I get:</p>
<pre><code>[root@idev htdocs]# python
Python 2.6 (r26:66714, Oct 23 2008, 16:25:34)
[GCC 3.2.2 20030222 (Red Hat Linux 3.2.2-5)] on linux2
Type "h... | 10 | 2008-10-24T12:33:24Z | 2,692,335 | <p>The 2.5.5. Mac port of Python 2.5 now has this hint:</p>
<pre><code>"py25-sqlite3 @2.5.4 (python, databases)
This is a stub. sqlite3 is now built with python25"
</code></pre>
<p>And so an upgrade of the python25 port to <code>python25 @2.5.5_0</code> made the import work again.
Since sqlite3 is among the depen... | 0 | 2010-04-22T15:49:53Z | [
"python",
"sqlite"
] |
Cannot import SQLite with Python 2.6 | 233,320 | <p>I'm running Python 2.6 on Unix and when I run the interactive prompt (<a href="http://en.wikipedia.org/wiki/SQLite">SQLite</a> is supposed to be preinstalled) I get:</p>
<pre><code>[root@idev htdocs]# python
Python 2.6 (r26:66714, Oct 23 2008, 16:25:34)
[GCC 3.2.2 20030222 (Red Hat Linux 3.2.2-5)] on linux2
Type "h... | 10 | 2008-10-24T12:33:24Z | 15,269,590 | <p>I face the same problem.
Steps to solve.</p>
<ol>
<li>Download latest sqlite3 from sqlite website. sqlite-autoconf*</li>
<li>Install that in 3 simple steps
<ol>
<li>./configure</li>
<li>make</li>
<li>make install</li>
</ol></li>
<li>Rebuild the python
make
make install</li>
</ol>
| 0 | 2013-03-07T11:09:00Z | [
"python",
"sqlite"
] |
Lexical closures in Python | 233,673 | <p>While I was investigating a problem I had with lexical closures in Javascript code, I came along this problem in Python:</p>
<pre><code>flist = []
for i in xrange(3):
def func(x): return x * i
flist.append(func)
for f in flist:
print f(2)
</code></pre>
<p>Note that this example mindfully avoids <code... | 113 | 2008-10-24T14:08:25Z | 233,713 | <p>The variable <code>i</code> is a global, whose value is 2 at each time the function <code>f</code> is called.</p>
<p>I would be inclined to implement the behavior you're after as follows:</p>
<pre><code>>>> class f:
... def __init__(self, multiplier): self.multiplier = multiplier
... def __call__(self, ... | 1 | 2008-10-24T14:17:35Z | [
"python",
"closures",
"lazy-evaluation",
"late-binding"
] |
Lexical closures in Python | 233,673 | <p>While I was investigating a problem I had with lexical closures in Javascript code, I came along this problem in Python:</p>
<pre><code>flist = []
for i in xrange(3):
def func(x): return x * i
flist.append(func)
for f in flist:
print f(2)
</code></pre>
<p>Note that this example mindfully avoids <code... | 113 | 2008-10-24T14:08:25Z | 233,800 | <p>look at this:</p>
<pre><code>for f in flist:
print f.func_closure
(<cell at 0x00C980B0: int object at 0x009864B4>,)
(<cell at 0x00C980B0: int object at 0x009864B4>,)
(<cell at 0x00C980B0: int object at 0x009864B4>,)
</code></pre>
<p>It means they all point to the same i variable instance, w... | 12 | 2008-10-24T14:36:07Z | [
"python",
"closures",
"lazy-evaluation",
"late-binding"
] |
Lexical closures in Python | 233,673 | <p>While I was investigating a problem I had with lexical closures in Javascript code, I came along this problem in Python:</p>
<pre><code>flist = []
for i in xrange(3):
def func(x): return x * i
flist.append(func)
for f in flist:
print f(2)
</code></pre>
<p>Note that this example mindfully avoids <code... | 113 | 2008-10-24T14:08:25Z | 233,822 | <p>The problem is that all of the local functions bind to the same environment and thus to the same <code>i</code> variable. The solution (workaround) is to create separate environments (stack frames) for each function (or lambda):</p>
<pre><code>t = [ (lambda x: lambda y : x*y)(x) for x in range(5)]
>>> t[1... | 2 | 2008-10-24T14:42:55Z | [
"python",
"closures",
"lazy-evaluation",
"late-binding"
] |
Lexical closures in Python | 233,673 | <p>While I was investigating a problem I had with lexical closures in Javascript code, I came along this problem in Python:</p>
<pre><code>flist = []
for i in xrange(3):
def func(x): return x * i
flist.append(func)
for f in flist:
print f(2)
</code></pre>
<p>Note that this example mindfully avoids <code... | 113 | 2008-10-24T14:08:25Z | 233,835 | <p>Python is actually behaving as defined. <b>Three separate functions</b> are created, but they each have the <b>closure of the environment they're defined in</b> - in this case, the global environment (or the outer function's environment if the loop is placed inside another function). This is exactly the problem, th... | 123 | 2008-10-24T14:47:08Z | [
"python",
"closures",
"lazy-evaluation",
"late-binding"
] |
Lexical closures in Python | 233,673 | <p>While I was investigating a problem I had with lexical closures in Javascript code, I came along this problem in Python:</p>
<pre><code>flist = []
for i in xrange(3):
def func(x): return x * i
flist.append(func)
for f in flist:
print f(2)
</code></pre>
<p>Note that this example mindfully avoids <code... | 113 | 2008-10-24T14:08:25Z | 235,764 | <p>The functions defined in the loop keep accessing the same variable <code>i</code> while its value changes. At the end of the loop, all the functions point to the same variable, which is holding the last value in the loop: the effect is what reported in the example.</p>
<p>In order to evaluate <code>i</code> and use... | 133 | 2008-10-25T01:56:42Z | [
"python",
"closures",
"lazy-evaluation",
"late-binding"
] |
Lexical closures in Python | 233,673 | <p>While I was investigating a problem I had with lexical closures in Javascript code, I came along this problem in Python:</p>
<pre><code>flist = []
for i in xrange(3):
def func(x): return x * i
flist.append(func)
for f in flist:
print f(2)
</code></pre>
<p>Note that this example mindfully avoids <code... | 113 | 2008-10-24T14:08:25Z | 236,044 | <p>I'm still not entirely convinced why in some languages this works one way, and in some another way. In Common Lisp it's like Python:</p>
<pre><code>(defvar *flist* '())
(dotimes (i 3 t)
(setf *flist*
(cons (lambda (x) (* x i)) *flist*)))
(dolist (f *flist*)
(format t "~a~%" (funcall f 2)))
</code></pre... | 4 | 2008-10-25T07:20:03Z | [
"python",
"closures",
"lazy-evaluation",
"late-binding"
] |
Lexical closures in Python | 233,673 | <p>While I was investigating a problem I had with lexical closures in Javascript code, I came along this problem in Python:</p>
<pre><code>flist = []
for i in xrange(3):
def func(x): return x * i
flist.append(func)
for f in flist:
print f(2)
</code></pre>
<p>Note that this example mindfully avoids <code... | 113 | 2008-10-24T14:08:25Z | 236,253 | <p>What is happening is that the variable i is captured, and the functions are returning the value it is bound to at the time it is called. In functional languages this kind of situation never arises, as i wouldn't be rebound. However with python, and also as you've seen with lisp, this is no longer true.</p>
<p>The... | 7 | 2008-10-25T11:28:04Z | [
"python",
"closures",
"lazy-evaluation",
"late-binding"
] |
Lexical closures in Python | 233,673 | <p>While I was investigating a problem I had with lexical closures in Javascript code, I came along this problem in Python:</p>
<pre><code>flist = []
for i in xrange(3):
def func(x): return x * i
flist.append(func)
for f in flist:
print f(2)
</code></pre>
<p>Note that this example mindfully avoids <code... | 113 | 2008-10-24T14:08:25Z | 6,805,307 | <p>Here's how you do it using the <code>functools</code> library (whom I'm not sure was available at the time the question was posed).</p>
<pre><code>from functools import partial
flist = []
def func(i, x): return x * i
for i in xrange(3):
flist.append(partial(func, i))
for f in flist:
print f(2)
</code></... | 23 | 2011-07-24T06:24:40Z | [
"python",
"closures",
"lazy-evaluation",
"late-binding"
] |
Lexical closures in Python | 233,673 | <p>While I was investigating a problem I had with lexical closures in Javascript code, I came along this problem in Python:</p>
<pre><code>flist = []
for i in xrange(3):
def func(x): return x * i
flist.append(func)
for f in flist:
print f(2)
</code></pre>
<p>Note that this example mindfully avoids <code... | 113 | 2008-10-24T14:08:25Z | 11,626,867 | <p>The reasoning behind the behavior has already been explained, and multiple solutions have been posted, but I think this is the most pythonic (remember, everything in Python is an object!):</p>
<pre><code>flist = []
for i in xrange(3):
def func(x): return x * func.i
func.i=i
flist.append(func)
for f in... | 0 | 2012-07-24T08:20:04Z | [
"python",
"closures",
"lazy-evaluation",
"late-binding"
] |
Splitting strings in python | 234,512 | <p>I have a string which is like this:</p>
<p>this is [bracket test] "and quotes test "</p>
<p>I'm trying to write something in Python to split it up by space while ignoring spaces within square braces and quotes. The result I'm looking for is:</p>
<p>['this','is','bracket test','and quotes test '] </p>
| 6 | 2008-10-24T17:33:41Z | 234,645 | <p>Here's a simplistic solution that works with your test input:</p>
<pre><code>import re
re.findall('\[[^\]]*\]|\"[^\"]*\"|\S+',s)
</code></pre>
<p>This will return any code that matches either </p>
<ul>
<li>a open bracket followed by zero or more non-close-bracket characters followed by a close bracket, </li>
<li>... | 8 | 2008-10-24T17:57:26Z | [
"python",
"string",
"split",
"parsing",
"tokenize"
] |
Splitting strings in python | 234,512 | <p>I have a string which is like this:</p>
<p>this is [bracket test] "and quotes test "</p>
<p>I'm trying to write something in Python to split it up by space while ignoring spaces within square braces and quotes. The result I'm looking for is:</p>
<p>['this','is','bracket test','and quotes test '] </p>
| 6 | 2008-10-24T17:33:41Z | 234,674 | <p>Here's a simplistic parser (tested against your example input) that introduces the State design pattern.</p>
<p>In real world, you probably want to build a real parser using something like <a href="http://www.dabeaz.com/ply/" rel="nofollow">PLY</a>.</p>
<pre><code>class SimpleParser(object):
def __init__(self... | 1 | 2008-10-24T18:04:26Z | [
"python",
"string",
"split",
"parsing",
"tokenize"
] |
Splitting strings in python | 234,512 | <p>I have a string which is like this:</p>
<p>this is [bracket test] "and quotes test "</p>
<p>I'm trying to write something in Python to split it up by space while ignoring spaces within square braces and quotes. The result I'm looking for is:</p>
<p>['this','is','bracket test','and quotes test '] </p>
| 6 | 2008-10-24T17:33:41Z | 234,855 | <p>Works for quotes only. </p>
<pre><code>rrr = []
qqq = s.split('\"')
[ rrr.extend( qqq[x].split(), [ qqq[x] ] )[ x%2]) for x in range( len( qqq ) )]
print rrr
</code></pre>
| -2 | 2008-10-24T18:56:54Z | [
"python",
"string",
"split",
"parsing",
"tokenize"
] |
Splitting strings in python | 234,512 | <p>I have a string which is like this:</p>
<p>this is [bracket test] "and quotes test "</p>
<p>I'm trying to write something in Python to split it up by space while ignoring spaces within square braces and quotes. The result I'm looking for is:</p>
<p>['this','is','bracket test','and quotes test '] </p>
| 6 | 2008-10-24T17:33:41Z | 234,957 | <p>Here's a more procedural approach:</p>
<pre><code>#!/usr/bin/env python
a = 'this is [bracket test] "and quotes test "'
words = a.split()
wordlist = []
while True:
try:
word = words.pop(0)
except IndexError:
break
if word[0] in '"[':
buildlist = [word[1:]]
while True:
... | 0 | 2008-10-24T19:28:32Z | [
"python",
"string",
"split",
"parsing",
"tokenize"
] |
Splitting strings in python | 234,512 | <p>I have a string which is like this:</p>
<p>this is [bracket test] "and quotes test "</p>
<p>I'm trying to write something in Python to split it up by space while ignoring spaces within square braces and quotes. The result I'm looking for is:</p>
<p>['this','is','bracket test','and quotes test '] </p>
| 6 | 2008-10-24T17:33:41Z | 235,412 | <p>To complete Bryan post and match exactly the answer :</p>
<pre><code>>>> import re
>>> txt = 'this is [bracket test] "and quotes test "'
>>> [x[1:-1] if x[0] in '["' else x for x in re.findall('\[[^\]]*\]|\"[^\"]*\"|\S+', txt)]
['this', 'is', 'bracket test', 'and quotes test ']
</code></p... | 5 | 2008-10-24T22:07:04Z | [
"python",
"string",
"split",
"parsing",
"tokenize"
] |
Splitting strings in python | 234,512 | <p>I have a string which is like this:</p>
<p>this is [bracket test] "and quotes test "</p>
<p>I'm trying to write something in Python to split it up by space while ignoring spaces within square braces and quotes. The result I'm looking for is:</p>
<p>['this','is','bracket test','and quotes test '] </p>
| 6 | 2008-10-24T17:33:41Z | 238,476 | <p>Well, I've encountered this problem quite a few times, which led me to write my own system for parsing any kind of syntax.</p>
<p>The result of this can be found <a href="http://gist.github.com/19929" rel="nofollow">here</a>; note that this may be overkill, and it will provide you with something that lets you parse... | 0 | 2008-10-26T19:17:49Z | [
"python",
"string",
"split",
"parsing",
"tokenize"
] |
Solving the shared-server security problem for Python | 234,590 | <p>So my group is trying to set up a shared-server environment for various and sundry web services. I think we've settled on setting <code>disable_functions</code> and <code>disable_classes</code> site wide in <code>php.ini</code> and <code>php_admin_value</code> to force <code>open_basedir</code> in each app's <code>... | 2 | 2008-10-24T17:47:21Z | 238,564 | <p>Well, there is a system called <a href="http://pypi.python.org/pypi/virtualenv" rel="nofollow">virtualenv</a> which allows you to run Python in a sort of safe environment, and configure/load/shutdown these environments on the fly. I don't know much about it, but you should take a serious look into it; here is the de... | 3 | 2008-10-26T20:25:54Z | [
"php",
"python",
"mysql",
"ruby",
"security"
] |
Default parameters to actions with Django | 234,695 | <p>Is there a way to have a default parameter passed to a action in the case where the regex didnt match anything using django?</p>
<pre><code>
urlpatterns = patterns('',(r'^test/(?P<name>.*)?$','myview.displayName'))
#myview.py
def displayName(request,name):
# write name to response or something
</code><... | 3 | 2008-10-24T18:12:00Z | 234,741 | <p>I <em>thought</em> you could <code>def displayName(request, name=defaultObj)</code>; that's what I've done in the past, at least. What were you setting the default value to?</p>
| 0 | 2008-10-24T18:25:42Z | [
"python",
"django",
"django-urls"
] |
Default parameters to actions with Django | 234,695 | <p>Is there a way to have a default parameter passed to a action in the case where the regex didnt match anything using django?</p>
<pre><code>
urlpatterns = patterns('',(r'^test/(?P<name>.*)?$','myview.displayName'))
#myview.py
def displayName(request,name):
# write name to response or something
</code><... | 3 | 2008-10-24T18:12:00Z | 234,995 | <p>The problem is that when the pattern is matched against 'test/' the groupdict captured by the regex contains the mapping 'name' => None:</p>
<pre><code>>>> url.match("test/").groupdict()
{'name': None}
</code></pre>
<p>This means that when the view is invoked, using something I expect that is similar to b... | 8 | 2008-10-24T19:39:04Z | [
"python",
"django",
"django-urls"
] |
Trailing slashes in Pylons Routes | 235,191 | <p>What is the best way to make trailing slashes not matter in the latest version of Routes (1.10)? I currently am using the clearly non-DRY:</p>
<pre><code>map.connect('/logs/', controller='logs', action='logs')
map.connect('/logs', controller='logs', action='logs')
</code></pre>
<p>I think that turning minimization... | 7 | 2008-10-24T20:42:08Z | 235,238 | <p>There are two possible ways to solve this:</p>
<ol>
<li><a href="http://wiki.pylonshq.com/display/pylonscookbook/Adding+trailing+slash+to+pages+automatically" rel="nofollow">Do it entirely in pylons</a>.</li>
<li><a href="http://enarion.net/web/apache/htaccess/trailing-slash/" rel="nofollow">Add an htaccess rule to... | 7 | 2008-10-24T20:58:16Z | [
"python",
"routes",
"pylons"
] |
Trailing slashes in Pylons Routes | 235,191 | <p>What is the best way to make trailing slashes not matter in the latest version of Routes (1.10)? I currently am using the clearly non-DRY:</p>
<pre><code>map.connect('/logs/', controller='logs', action='logs')
map.connect('/logs', controller='logs', action='logs')
</code></pre>
<p>I think that turning minimization... | 7 | 2008-10-24T20:42:08Z | 975,529 | <p><a href="http://www.siafoo.net/snippet/275" rel="nofollow">http://www.siafoo.net/snippet/275</a> has a basic piece of middleware which removes a trailing slash from requests. Clever idea, and I understood the concept of middleware in WSGI applications much better after I realised what this does.</p>
| 2 | 2009-06-10T13:19:46Z | [
"python",
"routes",
"pylons"
] |
Trailing slashes in Pylons Routes | 235,191 | <p>What is the best way to make trailing slashes not matter in the latest version of Routes (1.10)? I currently am using the clearly non-DRY:</p>
<pre><code>map.connect('/logs/', controller='logs', action='logs')
map.connect('/logs', controller='logs', action='logs')
</code></pre>
<p>I think that turning minimization... | 7 | 2008-10-24T20:42:08Z | 1,441,104 | <p>The following snippet added as the very last route worked for me:</p>
<pre><code>map.redirect('/*(url)/', '/{url}',
_redirect_code='301 Moved Permanently')
</code></pre>
| 16 | 2009-09-17T20:19:09Z | [
"python",
"routes",
"pylons"
] |
how do I implement a custom code page used by a serial device so I can convert text to it in Python? | 235,416 | <p>I have a scrolling LED sign that takes messages in either ASCII or (using some specific code) characters from a custom code page.</p>
<p>For example, the euro sign should be sent as</p>
<pre><code><U00>
</code></pre>
<p>and ä is</p>
<pre><code><U64>
</code></pre>
<p>(You can find the full code page... | 2 | 2008-10-24T22:07:57Z | 235,438 | <ol>
<li>Pick a name for your encoding, maybe "led_display", whatever.</li>
<li>Implement and register a <a href="http://docs.python.org/library/codecs.html" rel="nofollow">codec</a> with the standard library.</li>
<li>Pythonic profit!</li>
</ol>
| 3 | 2008-10-24T22:13:59Z | [
"python",
"encoding",
"utf"
] |
Environment Variables in Python on Linux | 235,435 | <p>Python's access to environment variables does not accurately reflect the operating system's view of the processes environment.</p>
<p>os.getenv and os.environ do not function as expected in particular cases.</p>
<p>Is there a way to properly get the running process' environment?</p>
<p><hr /></p>
<p>To demonstra... | 12 | 2008-10-24T22:13:54Z | 235,448 | <p>Looking at the Python source code (2.4.5):</p>
<ul>
<li><p>Modules/posixmodule.c gets the environ in convertenviron() which gets run at startup (see INITFUNC) and stores the environment in a platform-specific module (nt, os2, or posix)</p></li>
<li><p>Lib/os.py looks at sys.builtin_module_names, and imports all sym... | 1 | 2008-10-24T22:16:52Z | [
"python",
"gdb",
"environment-variables"
] |
Environment Variables in Python on Linux | 235,435 | <p>Python's access to environment variables does not accurately reflect the operating system's view of the processes environment.</p>
<p>os.getenv and os.environ do not function as expected in particular cases.</p>
<p>Is there a way to properly get the running process' environment?</p>
<p><hr /></p>
<p>To demonstra... | 12 | 2008-10-24T22:13:54Z | 235,475 | <p>That's a very good question.</p>
<p>It turns out that the <code>os</code> module initializes <code>os.environ</code> to the value of <a href="http://docs.python.org/library/posix.html"><code>posix</code></a><code>.environ</code>, which is set on interpreter start up. In other words, the standard library does not ap... | 13 | 2008-10-24T22:28:38Z | [
"python",
"gdb",
"environment-variables"
] |
Environment Variables in Python on Linux | 235,435 | <p>Python's access to environment variables does not accurately reflect the operating system's view of the processes environment.</p>
<p>os.getenv and os.environ do not function as expected in particular cases.</p>
<p>Is there a way to properly get the running process' environment?</p>
<p><hr /></p>
<p>To demonstra... | 12 | 2008-10-24T22:13:54Z | 236,523 | <p>I don't believe many programs EVER expect to have their environment externally modified, so loading a copy of the passed environment at startup is equivalent. You have simply stumbled on an implementation choice.</p>
<p>If you are seeing all the set-at-startup values and putenv/setenv from within your program work... | 3 | 2008-10-25T14:53:21Z | [
"python",
"gdb",
"environment-variables"
] |
Environment Variables in Python on Linux | 235,435 | <p>Python's access to environment variables does not accurately reflect the operating system's view of the processes environment.</p>
<p>os.getenv and os.environ do not function as expected in particular cases.</p>
<p>Is there a way to properly get the running process' environment?</p>
<p><hr /></p>
<p>To demonstra... | 12 | 2008-10-24T22:13:54Z | 237,217 | <p>Another possibility is to use pdb, or some other python debugger instead, and change os.environ at the python level, rather than the C level. <a href="http://stackoverflow.com/questions/132058/getting-stack-trace-from-a-running-python-application#133384">Here's</a> a small recipe I posted to interrupt a running pyt... | 4 | 2008-10-25T23:50:56Z | [
"python",
"gdb",
"environment-variables"
] |
Environment Variables in Python on Linux | 235,435 | <p>Python's access to environment variables does not accurately reflect the operating system's view of the processes environment.</p>
<p>os.getenv and os.environ do not function as expected in particular cases.</p>
<p>Is there a way to properly get the running process' environment?</p>
<p><hr /></p>
<p>To demonstra... | 12 | 2008-10-24T22:13:54Z | 242,175 | <p>You can use <code>ctypes</code> to do this pretty simply:</p>
<pre><code>>>> from ctypes import CDLL, c_char_p
>>> getenv = CDLL("libc.so.6").getenv
>>> getenv.restype = c_char_p
>>> getenv("HOME")
'/home/glyph'
</code></pre>
| 10 | 2008-10-28T03:38:23Z | [
"python",
"gdb",
"environment-variables"
] |
Are there any web based email clients written in python? | 236,205 | <p>I need to integrate a email client in my current python web app.
Anything available?</p>
<p>L.E.: I'm building my app on top of CherryPy</p>
| 3 | 2008-10-25T10:30:57Z | 236,221 | <p>You can build one, using <a href="http://docs.python.org/library/email.html" rel="nofollow">email</a> for generating and parsing mail, <a href="http://docs.python.org/library/imaplib.html#module-imaplib" rel="nofollow">imaplib</a> for reading (and managing) incoming mail from your mail server, and <a href="http://do... | 1 | 2008-10-25T10:45:09Z | [
"python",
"email-integration"
] |
Are there any web based email clients written in python? | 236,205 | <p>I need to integrate a email client in my current python web app.
Anything available?</p>
<p>L.E.: I'm building my app on top of CherryPy</p>
| 3 | 2008-10-25T10:30:57Z | 236,549 | <p>Looking up <a href="http://pypi.python.org/pypi?%3Aaction=search&term=webmail&submit=search" rel="nofollow">webmail</a> on <a href="http://pypi.python.org/pypi" rel="nofollow">pypi</a> gives <a href="http://pypi.python.org/pypi/Posterity/" rel="nofollow">Posterity</a>.</p>
<p>There is very probably some way... | 1 | 2008-10-25T15:14:41Z | [
"python",
"email-integration"
] |
Are there any web based email clients written in python? | 236,205 | <p>I need to integrate a email client in my current python web app.
Anything available?</p>
<p>L.E.: I'm building my app on top of CherryPy</p>
| 3 | 2008-10-25T10:30:57Z | 242,144 | <p>You could try <a href="http://divmod.org/trac/wiki/DivmodQuotient" rel="nofollow">Quotient</a>. It's a somewhat unusual webmail system, and it definitely won't fit into the same process as CherryPy - but it is in Python ;).</p>
| 1 | 2008-10-28T03:23:37Z | [
"python",
"email-integration"
] |
Are there any web based email clients written in python? | 236,205 | <p>I need to integrate a email client in my current python web app.
Anything available?</p>
<p>L.E.: I'm building my app on top of CherryPy</p>
| 3 | 2008-10-25T10:30:57Z | 20,042,475 | <p>For others who might find this thread, check out <a href="http://www.mailpile.is/" rel="nofollow">Mailpile</a>. I haven't used it yet, it is a python-based mail client, and I am sure it could be modified to work as a webmail app as well.</p>
| 0 | 2013-11-18T07:40:16Z | [
"python",
"email-integration"
] |
What is your convention to distinguish between object methods to be called by the outside, and object methods to be called by a subclass? | 236,359 | <p>I know most of the ins and outs of Python's approach to private variables/members/functions/...</p>
<p>However, I can't make my mind up on how to distinguish between methods for external use or subclassing use.</p>
<p>Consider the following example:</p>
<pre><code>class EventMixin(object):
def subscribe(self,... | 1 | 2008-10-25T12:54:37Z | 236,402 | <pre><code>use no underscores for the external API,
one underscore for the subclassable API,
and two underscores for the private/internal API
</code></pre>
<p>This is a reasonable and relatively common way of doing it, yes. The double-underline-for-actually-private (as opposed to âprotectedâ in C++ terms) is in pr... | 3 | 2008-10-25T13:26:57Z | [
"python",
"subclass",
"private"
] |
What is your convention to distinguish between object methods to be called by the outside, and object methods to be called by a subclass? | 236,359 | <p>I know most of the ins and outs of Python's approach to private variables/members/functions/...</p>
<p>However, I can't make my mind up on how to distinguish between methods for external use or subclassing use.</p>
<p>Consider the following example:</p>
<pre><code>class EventMixin(object):
def subscribe(self,... | 1 | 2008-10-25T12:54:37Z | 236,596 | <p>I generally find using double __ to be more trouble that they are worth, as it makes unit testing very painful. using single _ as convention for methods/attributes that are not intended to be part of the public interface of a particular class/module is my preferred approach. </p>
| 2 | 2008-10-25T15:45:28Z | [
"python",
"subclass",
"private"
] |
What is your convention to distinguish between object methods to be called by the outside, and object methods to be called by a subclass? | 236,359 | <p>I know most of the ins and outs of Python's approach to private variables/members/functions/...</p>
<p>However, I can't make my mind up on how to distinguish between methods for external use or subclassing use.</p>
<p>Consider the following example:</p>
<pre><code>class EventMixin(object):
def subscribe(self,... | 1 | 2008-10-25T12:54:37Z | 237,976 | <p>I'd like to make the suggestion that when you find yourself encountering this kind of distinction, it may be a good idea to consider using composition instead of inheritance; in other words, instantiating <code>EventMixin</code> (presumably the name would change) instead of inheriting it.</p>
| 2 | 2008-10-26T12:48:00Z | [
"python",
"subclass",
"private"
] |
How can I use Python for large scale development? | 236,407 | <p>I would be interested to learn about large scale development in Python and especially in how do you maintain a large code base?</p>
<ul>
<li><p>When you make incompatibility changes to the signature of a method, how do you find all the places where that method is being called. In C++/Java the compiler will find it ... | 50 | 2008-10-25T13:30:27Z | 236,421 | <p>my 0.10 EUR:</p>
<p>i have several python application in 'production'-state. our company use java, c++ and python. we develop with the eclipse ide (pydev for python)</p>
<p><strong>unittests are the key-solution for the problem.</strong> (also for c++ and java)</p>
<p>the less secure world of "dynamic-typing" wil... | 14 | 2008-10-25T13:44:41Z | [
"python",
"development-environment"
] |
How can I use Python for large scale development? | 236,407 | <p>I would be interested to learn about large scale development in Python and especially in how do you maintain a large code base?</p>
<ul>
<li><p>When you make incompatibility changes to the signature of a method, how do you find all the places where that method is being called. In C++/Java the compiler will find it ... | 50 | 2008-10-25T13:30:27Z | 236,445 | <p>I had some experience with modifying "Frets On Fire", an open source python "Guitar Hero" clone.</p>
<p>as I see it, python is not really suitable for a really large scale project.</p>
<p>I found myself spending a large part of the development time debugging issues related to assignment of incompatible types, thin... | 31 | 2008-10-25T14:01:28Z | [
"python",
"development-environment"
] |
How can I use Python for large scale development? | 236,407 | <p>I would be interested to learn about large scale development in Python and especially in how do you maintain a large code base?</p>
<ul>
<li><p>When you make incompatibility changes to the signature of a method, how do you find all the places where that method is being called. In C++/Java the compiler will find it ... | 50 | 2008-10-25T13:30:27Z | 236,470 | <p>The usual answer to that is testing testing testing. You're supposed to have an extensive unit test suite and run it often, particularly before a new version goes online.</p>
<p>Proponents of dynamically typed languages make the case that you have to test anyway because even in a statically typed language conforman... | 2 | 2008-10-25T14:24:17Z | [
"python",
"development-environment"
] |
How can I use Python for large scale development? | 236,407 | <p>I would be interested to learn about large scale development in Python and especially in how do you maintain a large code base?</p>
<ul>
<li><p>When you make incompatibility changes to the signature of a method, how do you find all the places where that method is being called. In C++/Java the compiler will find it ... | 50 | 2008-10-25T13:30:27Z | 236,515 | <h2>Don't use a screw driver as a hammer</h2>
<p>Python is not a statically typed language, so don't try to use it that way.</p>
<p>When you use a specific tool, you use it for what it has been built. For Python, it means:</p>
<ul>
<li><p><strong>Duck typing</strong> : no type checking. Only behavior matters. Theref... | 50 | 2008-10-25T14:46:30Z | [
"python",
"development-environment"
] |
How can I use Python for large scale development? | 236,407 | <p>I would be interested to learn about large scale development in Python and especially in how do you maintain a large code base?</p>
<ul>
<li><p>When you make incompatibility changes to the signature of a method, how do you find all the places where that method is being called. In C++/Java the compiler will find it ... | 50 | 2008-10-25T13:30:27Z | 236,537 | <p>Since nobody pointed out pychecker, pylint and similar tools, I will: pychecker and pylint are tools that can help you find incorrect assumptions (about function signatures, object attributes, etc.) They won't find everything that a compiler might find in a statically typed language -- but they can find problems tha... | 21 | 2008-10-25T15:05:10Z | [
"python",
"development-environment"
] |
How can I use Python for large scale development? | 236,407 | <p>I would be interested to learn about large scale development in Python and especially in how do you maintain a large code base?</p>
<ul>
<li><p>When you make incompatibility changes to the signature of a method, how do you find all the places where that method is being called. In C++/Java the compiler will find it ... | 50 | 2008-10-25T13:30:27Z | 236,570 | <p>My general rule of thumb is to use dynamic languages for small non-mission-critical projects and statically-typed languages for big projects. I find that code written in a dynamic language such as python gets "tangled" more quickly. Partly that is because it is much quicker to write code in a dynamic language and th... | 2 | 2008-10-25T15:26:39Z | [
"python",
"development-environment"
] |
How can I use Python for large scale development? | 236,407 | <p>I would be interested to learn about large scale development in Python and especially in how do you maintain a large code base?</p>
<ul>
<li><p>When you make incompatibility changes to the signature of a method, how do you find all the places where that method is being called. In C++/Java the compiler will find it ... | 50 | 2008-10-25T13:30:27Z | 236,589 | <p>Here are some items that have helped me maintain a fairly large system in python.</p>
<ul>
<li><p>Structure your code in layers. i.e separate biz logic, presentaion logic and your persistence layers. Invest a bit of time in defining these layers and make sure everyone on the project is bought in. For large syst... | 11 | 2008-10-25T15:36:01Z | [
"python",
"development-environment"
] |
How can I use Python for large scale development? | 236,407 | <p>I would be interested to learn about large scale development in Python and especially in how do you maintain a large code base?</p>
<ul>
<li><p>When you make incompatibility changes to the signature of a method, how do you find all the places where that method is being called. In C++/Java the compiler will find it ... | 50 | 2008-10-25T13:30:27Z | 236,718 | <p><strong>Incompatible changes to the signature of a method.</strong> This doesn't happen as much in Python as it does in Java and C++. </p>
<p>Python has optional arguments, default values, and far more flexibility in defining method signatures. Also, duck typing means that -- for example -- you don't have to swit... | 6 | 2008-10-25T17:21:41Z | [
"python",
"development-environment"
] |
How do I convert any image to a 4-color paletted image using the Python Imaging Library? | 236,692 | <p>I have a device that supports 4-color graphics (much like CGA in the old days).</p>
<p>I wanted to use <a href="http://www.pythonware.com/products/pil/">PIL</a> to read the image and convert it using my 4-color palette (of red, green, yellow, black), but I can't figure out if it's even possible at all. I found som... | 11 | 2008-10-25T17:00:09Z | 236,802 | <p>You're trying to do <a href="http://en.wikipedia.org/wiki/Color_quantization" rel="nofollow">quantization</a> of the image. There's some tips here for that sort of thing here:</p>
<p><a href="https://web.archive.org/web/20080825200550/http://nadiana.com/pil-tips-converting-png-gif" rel="nofollow">https://web.archi... | 4 | 2008-10-25T18:21:02Z | [
"python",
"image-processing",
"python-imaging-library"
] |
How do I convert any image to a 4-color paletted image using the Python Imaging Library? | 236,692 | <p>I have a device that supports 4-color graphics (much like CGA in the old days).</p>
<p>I wanted to use <a href="http://www.pythonware.com/products/pil/">PIL</a> to read the image and convert it using my 4-color palette (of red, green, yellow, black), but I can't figure out if it's even possible at all. I found som... | 11 | 2008-10-25T17:00:09Z | 237,193 | <p>First: your four colour palette (black, green, red, yellow) has <em>no</em> blue component. So, you have to accept that your output image will hardly approximate the input image, unless there is no blue component to start with.</p>
<p>Try this code:</p>
<pre><code>import Image
def estimate_color(c, bit, c_error):... | 16 | 2008-10-25T23:26:14Z | [
"python",
"image-processing",
"python-imaging-library"
] |
How do I convert any image to a 4-color paletted image using the Python Imaging Library? | 236,692 | <p>I have a device that supports 4-color graphics (much like CGA in the old days).</p>
<p>I wanted to use <a href="http://www.pythonware.com/products/pil/">PIL</a> to read the image and convert it using my 4-color palette (of red, green, yellow, black), but I can't figure out if it's even possible at all. I found som... | 11 | 2008-10-25T17:00:09Z | 237,747 | <p>John, I found that first link as well, but it didn't directly help me with the problem. It did make me look deeper into quantize though.</p>
<p>I came up with this yesterday before going to bed:</p>
<pre><code>import sys
import PIL
import Image
PALETTE = [
0, 0, 0, # black, 00
0, 255, 0, # gree... | 5 | 2008-10-26T08:41:58Z | [
"python",
"image-processing",
"python-imaging-library"
] |
Any python libs for parsing Bind zone files? | 236,859 | <p>Any python libs for parsing Bind zone files?
Basically something that will aid in adding/removing zones and records.
This needs to work even if someone modifies the zone file by hand so overwriting the zone files every time is not a solution. </p>
| 5 | 2008-10-25T19:12:33Z | 237,236 | <p>See answer above about bicop.</p>
<p>As an aside, the Python Package Index at <a href="http://pypi.python.org/pypi" rel="nofollow">http://pypi.python.org/pypi</a> is a great place to look for Python packages.</p>
<p><strong>EDIT</strong>: The below may still be helpful to someone trying to figure out simple parsin... | 1 | 2008-10-26T00:09:16Z | [
"python",
"bind"
] |
Any python libs for parsing Bind zone files? | 236,859 | <p>Any python libs for parsing Bind zone files?
Basically something that will aid in adding/removing zones and records.
This needs to work even if someone modifies the zone file by hand so overwriting the zone files every time is not a solution. </p>
| 5 | 2008-10-25T19:12:33Z | 242,140 | <p>You might try <a href="http://pypi.python.org/pypi/bicop" rel="nofollow"><code>bicop</code></a>, "a python library to process ISC bind-style configuration files".</p>
| 1 | 2008-10-28T03:19:04Z | [
"python",
"bind"
] |
Any python libs for parsing Bind zone files? | 236,859 | <p>Any python libs for parsing Bind zone files?
Basically something that will aid in adding/removing zones and records.
This needs to work even if someone modifies the zone file by hand so overwriting the zone files every time is not a solution. </p>
| 5 | 2008-10-25T19:12:33Z | 2,145,812 | <p>I was unable to use bicop for classical zone files like these:</p>
<pre><code> $TTL 86400
@ IN SOA ns1.first-ns.de. postmaster.robot.first-ns.de. (
2006040800 ; serial
14400 ; refresh
1800 ; retry
604800 ; expire
86400 ) ; minimum
@
IN NS ... | 4 | 2010-01-27T09:48:52Z | [
"python",
"bind"
] |
Any python libs for parsing Bind zone files? | 236,859 | <p>Any python libs for parsing Bind zone files?
Basically something that will aid in adding/removing zones and records.
This needs to work even if someone modifies the zone file by hand so overwriting the zone files every time is not a solution. </p>
| 5 | 2008-10-25T19:12:33Z | 6,710,660 | <p>I know this is old but the only working one I could find is called iscpy. You can do an easy_install.</p>
<pre><code>easy_install iscpy
</code></pre>
<p>Then in python:</p>
<pre><code>import iscpy
iscpy.ParseISCString(open('somefile.conf', 'r').read())
</code></pre>
<p>Which returns a dictionary.</p>
| 2 | 2011-07-15T17:05:56Z | [
"python",
"bind"
] |
Any python libs for parsing Bind zone files? | 236,859 | <p>Any python libs for parsing Bind zone files?
Basically something that will aid in adding/removing zones and records.
This needs to work even if someone modifies the zone file by hand so overwriting the zone files every time is not a solution. </p>
| 5 | 2008-10-25T19:12:33Z | 8,004,435 | <p><a href="http://pypi.python.org/pypi/easyzone" rel="nofollow">easyzone</a> is a nice layer over dnspython</p>
<p><a href="http://pypi.python.org/pypi/zoner/1.4.1" rel="nofollow">Zoner</a> provides a web-interface for editing zone files and makes use of easyzone.</p>
| 4 | 2011-11-04T02:59:19Z | [
"python",
"bind"
] |
How to get file creation & modification date/times in Python? | 237,079 | <p>I have a script that needs to do some stuff based on file creation & modification dates but has to run on Linux & Windows.</p>
<p>What's the best <strong>cross-platform</strong> way to get file creation & modification date/times in Python?</p>
| 478 | 2008-10-25T21:54:56Z | 237,082 | <p>os.stat <a href="http://www.python.org/doc/2.5.2/lib/module-stat.html">http://www.python.org/doc/2.5.2/lib/module-stat.html</a></p>
<p>edit: In newer code you should probably use <a href="http://docs.python.org/library/os.path.html#os.path.getmtime">os.path.getmtime()</a> (thanks Christian Oudard)<br>
but note tha... | 47 | 2008-10-25T21:58:01Z | [
"python",
"file"
] |
How to get file creation & modification date/times in Python? | 237,079 | <p>I have a script that needs to do some stuff based on file creation & modification dates but has to run on Linux & Windows.</p>
<p>What's the best <strong>cross-platform</strong> way to get file creation & modification date/times in Python?</p>
| 478 | 2008-10-25T21:54:56Z | 237,084 | <p>You have a couple of choices. For one, you can use the <a href="https://docs.python.org/library/os.path.html#os.path.getmtime">os.path.getmtime</a> and <a href="https://docs.python.org/library/os.path.html#os.path.getctime">os.path.getctime</a> functions:</p>
<pre><code>import os.path, time
print "last modified: %s... | 531 | 2008-10-25T22:00:54Z | [
"python",
"file"
] |
How to get file creation & modification date/times in Python? | 237,079 | <p>I have a script that needs to do some stuff based on file creation & modification dates but has to run on Linux & Windows.</p>
<p>What's the best <strong>cross-platform</strong> way to get file creation & modification date/times in Python?</p>
| 478 | 2008-10-25T21:54:56Z | 237,092 | <p>There are two methods to get the mod time, os.path.getmtime() or os.stat(), but the ctime is not reliable cross-platform (see below).</p>
<h3><a href="http://www.python.org/doc/2.5.2/lib/module-os.path.html">os.path.getmtime()</a></h3>
<p><strong>getmtime</strong>(<em>path</em>)<br />
*Return the time of last modi... | 34 | 2008-10-25T22:05:20Z | [
"python",
"file"
] |
How to get file creation & modification date/times in Python? | 237,079 | <p>I have a script that needs to do some stuff based on file creation & modification dates but has to run on Linux & Windows.</p>
<p>What's the best <strong>cross-platform</strong> way to get file creation & modification date/times in Python?</p>
| 478 | 2008-10-25T21:54:56Z | 237,093 | <p><code>os.stat</code> returns a named tuple with <code>st_mtime</code> and <code>st_ctime</code> attributes. The modification time is <code>st_mtime</code> on both platforms; unfortunately, on Windows, <code>ctime</code> means "creation time", whereas on POSIX it means "change time". I'm not aware of any way to get t... | 10 | 2008-10-25T22:06:37Z | [
"python",
"file"
] |
How to get file creation & modification date/times in Python? | 237,079 | <p>I have a script that needs to do some stuff based on file creation & modification dates but has to run on Linux & Windows.</p>
<p>What's the best <strong>cross-platform</strong> way to get file creation & modification date/times in Python?</p>
| 478 | 2008-10-25T21:54:56Z | 237,094 | <pre><code>>>> import os
>>> os.stat('feedparser.py').st_mtime
1136961142.0
>>> os.stat('feedparser.py').st_ctime
1222664012.233
>>>
</code></pre>
| 2 | 2008-10-25T22:07:44Z | [
"python",
"file"
] |
How to get file creation & modification date/times in Python? | 237,079 | <p>I have a script that needs to do some stuff based on file creation & modification dates but has to run on Linux & Windows.</p>
<p>What's the best <strong>cross-platform</strong> way to get file creation & modification date/times in Python?</p>
| 478 | 2008-10-25T21:54:56Z | 367,166 | <p><code>os.stat</code> does include the creation time. There's just no definition of st_anything for the element of <code>os.stat()</code> that contains the time.</p>
<p>So try this:</p>
<p><code>os.stat('feedparser.py')[8]</code></p>
<p>Compare that with your create date on the file in ls -lah</p>
<p>They should... | 0 | 2008-12-14T23:39:46Z | [
"python",
"file"
] |
How to get file creation & modification date/times in Python? | 237,079 | <p>I have a script that needs to do some stuff based on file creation & modification dates but has to run on Linux & Windows.</p>
<p>What's the best <strong>cross-platform</strong> way to get file creation & modification date/times in Python?</p>
| 478 | 2008-10-25T21:54:56Z | 1,526,089 | <p>The best function to use for this is <a href="http://docs.python.org/library/os.path.html#os.path.getmtime">os.path.getmtime()</a>. Internally, this just uses <code>os.stat(filename).st_mtime</code>.</p>
<p>The datetime module is the best manipulating timestamps, so you can get the modification date as a <code>date... | 287 | 2009-10-06T14:51:26Z | [
"python",
"file"
] |
How to get file creation & modification date/times in Python? | 237,079 | <p>I have a script that needs to do some stuff based on file creation & modification dates but has to run on Linux & Windows.</p>
<p>What's the best <strong>cross-platform</strong> way to get file creation & modification date/times in Python?</p>
| 478 | 2008-10-25T21:54:56Z | 18,520,782 | <p>I was able to get creation time on posix by running the system's stat command and parsing the output.</p>
<pre><code>commands.getoutput('stat FILENAME').split('\"')[7]
</code></pre>
<p>Running stat outside of python from Terminal (OS X) returned:</p>
<pre><code>805306374 3382786932 -rwx------ 1 km staff 0 1098083... | 0 | 2013-08-29T20:54:51Z | [
"python",
"file"
] |
How to get file creation & modification date/times in Python? | 237,079 | <p>I have a script that needs to do some stuff based on file creation & modification dates but has to run on Linux & Windows.</p>
<p>What's the best <strong>cross-platform</strong> way to get file creation & modification date/times in Python?</p>
| 478 | 2008-10-25T21:54:56Z | 28,444,315 | <p>If following symbolic links is not important, you can also use the <code>os.lstat</code> builtin.</p>
<pre><code>>>> os.lstat("2048.py")
posix.stat_result(st_mode=33188, st_ino=4172202, st_dev=16777218L, st_nlink=1, st_uid=501, st_gid=20, st_size=2078, st_atime=1423378041, st_mtime=1423377552, st_ctime=142... | 1 | 2015-02-11T00:13:15Z | [
"python",
"file"
] |
How to get file creation & modification date/times in Python? | 237,079 | <p>I have a script that needs to do some stuff based on file creation & modification dates but has to run on Linux & Windows.</p>
<p>What's the best <strong>cross-platform</strong> way to get file creation & modification date/times in Python?</p>
| 478 | 2008-10-25T21:54:56Z | 39,501,288 | <p>Getting some sort of modification date in a cross-platform way is easy - just call <a href="https://docs.python.org/library/os.path.html#os.path.getmtime"><code>os.path.getmtime(path)</code></a> and you'll get the Unix timestamp of when the file at <code>path</code> was last modified.</p>
<p>Getting file <em>creati... | 20 | 2016-09-14T23:51:54Z | [
"python",
"file"
] |
Is there a reason Python strings don't have a string length method? | 237,128 | <p>I know that python has a <code>len()</code> function that is used to determine the size of a string, but I was wondering why its not a method of the string object.</p>
<h2><strong>Update</strong></h2>
<p>Ok, I realized I was embarrassingly mistaken. <code>__len__()</code> is actually a method of a string object. I... | 169 | 2008-10-25T22:37:03Z | 237,133 | <pre><code>met% python -c 'import this' | grep 'only one'
There should be one-- and preferably only one --obvious way to do it.
</code></pre>
| 12 | 2008-10-25T22:38:58Z | [
"python"
] |
Is there a reason Python strings don't have a string length method? | 237,128 | <p>I know that python has a <code>len()</code> function that is used to determine the size of a string, but I was wondering why its not a method of the string object.</p>
<h2><strong>Update</strong></h2>
<p>Ok, I realized I was embarrassingly mistaken. <code>__len__()</code> is actually a method of a string object. I... | 169 | 2008-10-25T22:37:03Z | 237,149 | <p>There is a <code>len</code> method:</p>
<pre><code>>>> a = 'a string of some length'
>>> a.__len__()
23
>>> a.__len__
<method-wrapper '__len__' of str object at 0x02005650>
</code></pre>
| 35 | 2008-10-25T22:49:54Z | [
"python"
] |
Is there a reason Python strings don't have a string length method? | 237,128 | <p>I know that python has a <code>len()</code> function that is used to determine the size of a string, but I was wondering why its not a method of the string object.</p>
<h2><strong>Update</strong></h2>
<p>Ok, I realized I was embarrassingly mistaken. <code>__len__()</code> is actually a method of a string object. I... | 169 | 2008-10-25T22:37:03Z | 237,150 | <p>Strings do have a length method: <code>__len__()</code></p>
<p>The protocol in Python is to implement this method on objects which have a length and use the built-in <a href="http://www.python.org/doc/2.5.2/lib/built-in-funcs.html#l2h-45"><code>len()</code></a> function, which calls it for you, similar to the way y... | 155 | 2008-10-25T22:51:19Z | [
"python"
] |
Is there a reason Python strings don't have a string length method? | 237,128 | <p>I know that python has a <code>len()</code> function that is used to determine the size of a string, but I was wondering why its not a method of the string object.</p>
<h2><strong>Update</strong></h2>
<p>Ok, I realized I was embarrassingly mistaken. <code>__len__()</code> is actually a method of a string object. I... | 169 | 2008-10-25T22:37:03Z | 237,312 | <p>Jim's answer to <a href="http://stackoverflow.com/questions/83983/why-isnt-the-len-function-inherited-by-dictionaries-and-lists-in-python">this question</a> may help; I copy it here. Quoting Guido van Rossum:</p>
<blockquote>
<p>First of all, I chose len(x) over x.len() for HCI reasons (def __len__... | 80 | 2008-10-26T01:11:08Z | [
"python"
] |
Is there a reason Python strings don't have a string length method? | 237,128 | <p>I know that python has a <code>len()</code> function that is used to determine the size of a string, but I was wondering why its not a method of the string object.</p>
<h2><strong>Update</strong></h2>
<p>Ok, I realized I was embarrassingly mistaken. <code>__len__()</code> is actually a method of a string object. I... | 169 | 2008-10-25T22:37:03Z | 237,362 | <p>It doesn't?</p>
<pre><code>>>> "abc".__len__()
3
</code></pre>
| 1 | 2008-10-26T01:50:18Z | [
"python"
] |
Is there a reason Python strings don't have a string length method? | 237,128 | <p>I know that python has a <code>len()</code> function that is used to determine the size of a string, but I was wondering why its not a method of the string object.</p>
<h2><strong>Update</strong></h2>
<p>Ok, I realized I was embarrassingly mistaken. <code>__len__()</code> is actually a method of a string object. I... | 169 | 2008-10-25T22:37:03Z | 14,166,860 | <p>You can also say </p>
<pre><code>>> x = 'test'
>> len(x)
4
</code></pre>
<p>Using Python 2.7.3.</p>
| 4 | 2013-01-04T23:44:59Z | [
"python"
] |
Is there a reason Python strings don't have a string length method? | 237,128 | <p>I know that python has a <code>len()</code> function that is used to determine the size of a string, but I was wondering why its not a method of the string object.</p>
<h2><strong>Update</strong></h2>
<p>Ok, I realized I was embarrassingly mistaken. <code>__len__()</code> is actually a method of a string object. I... | 169 | 2008-10-25T22:37:03Z | 23,192,800 | <p>Python is a pragmatic programming language, and the reasons for <code>len()</code> being a function and not a method of <code>str</code>, <code>list</code>, <code>dict</code> etc. are pragmatic.</p>
<p>The <code>len()</code> built-in function deals directly with built-in types: the CPython implementation of <code>l... | 26 | 2014-04-21T07:19:39Z | [
"python"
] |
Multiple mouse pointers? | 237,155 | <p>Is there a way to accept input from more than one mouse separately? I'm interested in making a multi-user application and I thought it would be great if I could have 2 or more users holding wireless mice each interacting with the app individually with a separate mouse arrow.</p>
<p>Is this something I should try to... | 15 | 2008-10-25T22:54:43Z | 237,170 | <p>Yes. I know of at least one program that does this, <a href="http://www.cs.umd.edu/hcil/kiddesign/introduction.shtml" rel="nofollow">KidPad</a>. I think it's written in Java and was developed by <a href="http://www.cs.uiowa.edu/~hourcade/" rel="nofollow">Juan Pablo Hourcade</a>, now at the University of Iowa. You... | 5 | 2008-10-25T23:06:20Z | [
"python",
"user-interface",
"mouse",
"multi-user"
] |
Multiple mouse pointers? | 237,155 | <p>Is there a way to accept input from more than one mouse separately? I'm interested in making a multi-user application and I thought it would be great if I could have 2 or more users holding wireless mice each interacting with the app individually with a separate mouse arrow.</p>
<p>Is this something I should try to... | 15 | 2008-10-25T22:54:43Z | 237,190 | <p>You could use DirectInput with C/C++ (there's probably also bindings in other languages). You use <a href="http://msdn.microsoft.com/en-us/library/bb205950(VS.85).aspx" rel="nofollow"><code>IDirectInput8::EnumDevices()</code></a> (using DX8; same function, different interface in other versions of DirectX) to get a ... | 1 | 2008-10-25T23:25:04Z | [
"python",
"user-interface",
"mouse",
"multi-user"
] |
Multiple mouse pointers? | 237,155 | <p>Is there a way to accept input from more than one mouse separately? I'm interested in making a multi-user application and I thought it would be great if I could have 2 or more users holding wireless mice each interacting with the app individually with a separate mouse arrow.</p>
<p>Is this something I should try to... | 15 | 2008-10-25T22:54:43Z | 237,410 | <p>I have this vague feeling that BeOS used to let one pair a mouse and keyboard and have separate active windows and inputs. Wow... that was a long time ago. I thought that it would be very interesting for "paired" programming.</p>
| 1 | 2008-10-26T02:35:35Z | [
"python",
"user-interface",
"mouse",
"multi-user"
] |
Multiple mouse pointers? | 237,155 | <p>Is there a way to accept input from more than one mouse separately? I'm interested in making a multi-user application and I thought it would be great if I could have 2 or more users holding wireless mice each interacting with the app individually with a separate mouse arrow.</p>
<p>Is this something I should try to... | 15 | 2008-10-25T22:54:43Z | 262,789 | <p>You could try the <a href="http://www.microsoft.com/downloads/details.aspx?familyid=F851122A-4925-4788-BC39-409644CE0F9B&displaylang=en" rel="nofollow">Microsoft Windows MultiPoint Software Development Kit 1.1</a></p>
<p>or the new
<a href="http://www.microsoft.com/downloads/details.aspx?FamilyID=0eb18c26-5e02-... | 8 | 2008-11-04T18:14:04Z | [
"python",
"user-interface",
"mouse",
"multi-user"
] |
Multiple mouse pointers? | 237,155 | <p>Is there a way to accept input from more than one mouse separately? I'm interested in making a multi-user application and I thought it would be great if I could have 2 or more users holding wireless mice each interacting with the app individually with a separate mouse arrow.</p>
<p>Is this something I should try to... | 15 | 2008-10-25T22:54:43Z | 280,552 | <p>See my answer here (avoid the JNI stuff): <a href="http://stackoverflow.com/questions/262125/java-multiple-mouse-inputs#263886">http://stackoverflow.com/questions/262125/java-multiple-mouse-inputs#263886</a></p>
| 1 | 2008-11-11T10:40:11Z | [
"python",
"user-interface",
"mouse",
"multi-user"
] |
Multiple mouse pointers? | 237,155 | <p>Is there a way to accept input from more than one mouse separately? I'm interested in making a multi-user application and I thought it would be great if I could have 2 or more users holding wireless mice each interacting with the app individually with a separate mouse arrow.</p>
<p>Is this something I should try to... | 15 | 2008-10-25T22:54:43Z | 467,732 | <p><a href="http://code.google.com/p/pymultimouse/" rel="nofollow">http://code.google.com/p/pymultimouse/</a> is a library using windows raw input, it worked in a test with 2 mice. </p>
| 2 | 2009-01-22T01:06:27Z | [
"python",
"user-interface",
"mouse",
"multi-user"
] |
Any python libs for parsing apache config files? | 237,209 | <p>Any python libs for parsing apache config files or if not python anyone aware of such thing in other languages (perl, php, java, c#)?
As i'll be able to rewrite them in python.</p>
| 8 | 2008-10-25T23:36:52Z | 237,215 | <p>No Python libraries exist that I know of, but here's a perl one:
<a href="http://packages.debian.org/sid/libapache-configfile-perl" rel="nofollow">http://packages.debian.org/sid/libapache-configfile-perl</a></p>
<pre><code>Package: libapache-configfile-perl
Priority: optional
Section: interpreters
Installed-Size: 1... | 1 | 2008-10-25T23:50:12Z | [
"python",
"parsing",
"apache-config"
] |
Any python libs for parsing apache config files? | 237,209 | <p>Any python libs for parsing apache config files or if not python anyone aware of such thing in other languages (perl, php, java, c#)?
As i'll be able to rewrite them in python.</p>
| 8 | 2008-10-25T23:36:52Z | 237,530 | <p>ZConfig, I think, used to ship with a schema for parsing Apache configuration files; it doesn't seem to anymore, but it's oriented around parsing those types of files and turning the config into a Python object. A quick glance at the documentation suggests it wouldn't be too hard to set up a ZConfig schema correspon... | 0 | 2008-10-26T04:04:52Z | [
"python",
"parsing",
"apache-config"
] |
Any python libs for parsing apache config files? | 237,209 | <p>Any python libs for parsing apache config files or if not python anyone aware of such thing in other languages (perl, php, java, c#)?
As i'll be able to rewrite them in python.</p>
| 8 | 2008-10-25T23:36:52Z | 237,599 | <p>Red Hat's Emerging Technologies group has <A HREF="http://augeas.net/" rel="nofollow">Augeas</A> (written in C, but with Python bindings available), a generic system configuration tool with "lenses" for reading and writing several different configuration file formats. I would consider investigating the availability ... | 3 | 2008-10-26T05:12:34Z | [
"python",
"parsing",
"apache-config"
] |
Any python libs for parsing apache config files? | 237,209 | <p>Any python libs for parsing apache config files or if not python anyone aware of such thing in other languages (perl, php, java, c#)?
As i'll be able to rewrite them in python.</p>
| 8 | 2008-10-25T23:36:52Z | 2,450,905 | <p>I did find an interesting Apache Config parser for python here: <a href="http://www.poldylicious.de/node/25">http://www.poldylicious.de/node/25</a></p>
<p>The Apache Config Parser mentioned is not documented, but it does work.</p>
| 7 | 2010-03-15T22:27:46Z | [
"python",
"parsing",
"apache-config"
] |
Any python libs for parsing apache config files? | 237,209 | <p>Any python libs for parsing apache config files or if not python anyone aware of such thing in other languages (perl, php, java, c#)?
As i'll be able to rewrite them in python.</p>
| 8 | 2008-10-25T23:36:52Z | 10,617,432 | <p>There is also one new parser released.</p>
<ul>
<li><a href="http://pypi.python.org/pypi/apache_conf_parser/" rel="nofollow">http://pypi.python.org/pypi/apache_conf_parser/</a></li>
</ul>
<p>It still lacks documentation, however is quite straightforward for understanding.</p>
<hr>
<p>Example</p>
<pre><code>impo... | 1 | 2012-05-16T11:18:05Z | [
"python",
"parsing",
"apache-config"
] |
How do you programmatically reorder children of an ATFolder subclass? | 237,211 | <p>I have Plone product that uses a custom folder type for containing a set of custom content objects. The folder type was created by subclassing BaseFolder and it has a schema with a couple of text fields. Currently, when custom objects are added to the custom folder, the objects are sorted alphabetically by their i... | 6 | 2008-10-25T23:41:52Z | 240,456 | <p>Quickest solution: subclass from ATFolder instead of BaseFolder. That gives you all the "normal" reordering and other commmon plone folder capabilities (which I suspect you also want).</p>
<p>If you want to be more selective, look into Products/ATContentTypes/content/base.py: ATCTOrderedFolder and OrderedBaseFolder... | 4 | 2008-10-27T16:13:39Z | [
"python",
"plone",
"zope",
"archetypes"
] |
How to disable HTML encoding when using Context in django | 237,235 | <p>In my django application I am using a template to construct email body, one of the parameters is url, note there are two parametes separated by ampersand in the url.</p>
<pre><code>t = loader.get_template("sometemplate")
c = Context({
'foo': 'bar',
'url': 'http://127.0.0.1/test?a=1&b=2',
})
print t.render... | 13 | 2008-10-26T00:09:08Z | 237,243 | <p>To turn it off for a single variable, use <code>mark_safe</code>:</p>
<pre><code>from django.utils.safestring import mark_safe
t = loader.get_template("sometemplate")
c = Context({
'foo': 'bar',
'url': mark_safe('http://127.0.0.1/test?a=1&b=2'),
})
print t.render(c)
</code></pre>
<p>Alternatively, to to... | 15 | 2008-10-26T00:13:28Z | [
"python",
"django",
"django-templates"
] |
How to disable HTML encoding when using Context in django | 237,235 | <p>In my django application I am using a template to construct email body, one of the parameters is url, note there are two parametes separated by ampersand in the url.</p>
<pre><code>t = loader.get_template("sometemplate")
c = Context({
'foo': 'bar',
'url': 'http://127.0.0.1/test?a=1&b=2',
})
print t.render... | 13 | 2008-10-26T00:09:08Z | 237,443 | <p>Or just use the "safe" filter in your template.</p>
<p>Also, I cannot stress enough how important it is to be familiar with Django's documentation; many common questions like this have easy-to-find answers and explanations (<a href="http://docs.djangoproject.com/en/dev/topics/templates/#id2">like this one</a>), and... | 6 | 2008-10-26T02:59:43Z | [
"python",
"django",
"django-templates"
] |
python properties and inheritance | 237,432 | <p>I have a base class with a property which (the get method) I want to overwrite in the subclass. My first thought was something like:</p>
<pre><code>class Foo(object):
def _get_age(self):
return 11
age = property(_get_age)
class Bar(Foo):
def _get_age(self):
return 44
</code></pre>
<p... | 49 | 2008-10-26T02:49:09Z | 237,445 | <p>I agree with your solution, which seems an on-the-fly template method.
<a href="http://www.artima.com/forums/flat.jsp?forum=122&thread=153649" rel="nofollow">This article</a> deals with your problem and provides exactly your solution.</p>
| 2 | 2008-10-26T03:01:04Z | [
"python",
"inheritance",
"properties",
"polymorphism"
] |
python properties and inheritance | 237,432 | <p>I have a base class with a property which (the get method) I want to overwrite in the subclass. My first thought was something like:</p>
<pre><code>class Foo(object):
def _get_age(self):
return 11
age = property(_get_age)
class Bar(Foo):
def _get_age(self):
return 44
</code></pre>
<p... | 49 | 2008-10-26T02:49:09Z | 237,447 | <p>Yes, this is the way to do it; the property declaration executes at the time the parent class' definition is executed, which means it can only "see" the versions of the methods which exist on the parent class. So when you redefine one or more of those methods on a child class, you need to re-declare the property usi... | 7 | 2008-10-26T03:07:11Z | [
"python",
"inheritance",
"properties",
"polymorphism"
] |
python properties and inheritance | 237,432 | <p>I have a base class with a property which (the get method) I want to overwrite in the subclass. My first thought was something like:</p>
<pre><code>class Foo(object):
def _get_age(self):
return 11
age = property(_get_age)
class Bar(Foo):
def _get_age(self):
return 44
</code></pre>
<p... | 49 | 2008-10-26T02:49:09Z | 237,461 | <p>Something like this will work</p>
<pre><code>class HackedProperty(object):
def __init__(self, f):
self.f = f
def __get__(self, inst, owner):
return getattr(inst, self.f.__name__)()
class Foo(object):
def _get_age(self):
return 11
age = HackedProperty(_get_age)
class Bar... | 2 | 2008-10-26T03:17:07Z | [
"python",
"inheritance",
"properties",
"polymorphism"
] |
python properties and inheritance | 237,432 | <p>I have a base class with a property which (the get method) I want to overwrite in the subclass. My first thought was something like:</p>
<pre><code>class Foo(object):
def _get_age(self):
return 11
age = property(_get_age)
class Bar(Foo):
def _get_age(self):
return 44
</code></pre>
<p... | 49 | 2008-10-26T02:49:09Z | 237,858 | <p>I simply prefer to repeat the <code>property()</code> as well as you will repeat the <code>@classmethod</code> decorator when overriding a class method. </p>
<p>While this seems very verbose, at least for Python standards, you may notice:</p>
<p>1) for read only properties, <code>property</code> can be used as a d... | 61 | 2008-10-26T10:50:15Z | [
"python",
"inheritance",
"properties",
"polymorphism"
] |
python properties and inheritance | 237,432 | <p>I have a base class with a property which (the get method) I want to overwrite in the subclass. My first thought was something like:</p>
<pre><code>class Foo(object):
def _get_age(self):
return 11
age = property(_get_age)
class Bar(Foo):
def _get_age(self):
return 44
</code></pre>
<p... | 49 | 2008-10-26T02:49:09Z | 291,707 | <p>Another way to do it, without having to create any additional classes. I've added a set method to show what you do if you only override one of the two:</p>
<pre><code>class Foo(object):
def _get_age(self):
return 11
def _set_age(self, age):
self._age = age
age = property(_get_age, _set... | 10 | 2008-11-14T22:52:52Z | [
"python",
"inheritance",
"properties",
"polymorphism"
] |
python properties and inheritance | 237,432 | <p>I have a base class with a property which (the get method) I want to overwrite in the subclass. My first thought was something like:</p>
<pre><code>class Foo(object):
def _get_age(self):
return 11
age = property(_get_age)
class Bar(Foo):
def _get_age(self):
return 44
</code></pre>
<p... | 49 | 2008-10-26T02:49:09Z | 14,349,742 | <p>I don't agree that the chosen answer is the ideal way to allow for overriding the property methods. If you expect the getters and setters to be overridden, then you can use lambda to provide access to self, with something like <code>lambda self: self.<property func></code>.</p>
<p>This works (at least) for P... | 6 | 2013-01-16T00:55:18Z | [
"python",
"inheritance",
"properties",
"polymorphism"
] |
python properties and inheritance | 237,432 | <p>I have a base class with a property which (the get method) I want to overwrite in the subclass. My first thought was something like:</p>
<pre><code>class Foo(object):
def _get_age(self):
return 11
age = property(_get_age)
class Bar(Foo):
def _get_age(self):
return 44
</code></pre>
<p... | 49 | 2008-10-26T02:49:09Z | 30,600,839 | <p>I ran into problems setting a property in a parent class from a child class. The following workround extends a property of a parent but does so by calling the _set_age method of the parent directly. Wrinkled should always be correct. It is a little javathonic though.</p>
<pre><code>import threading
class Foo(obje... | 0 | 2015-06-02T15:52:52Z | [
"python",
"inheritance",
"properties",
"polymorphism"
] |
python properties and inheritance | 237,432 | <p>I have a base class with a property which (the get method) I want to overwrite in the subclass. My first thought was something like:</p>
<pre><code>class Foo(object):
def _get_age(self):
return 11
age = property(_get_age)
class Bar(Foo):
def _get_age(self):
return 44
</code></pre>
<p... | 49 | 2008-10-26T02:49:09Z | 37,355,919 | <p>Same as <a href="http://stackoverflow.com/a/14349742/4522780]">@mr-b</a>'s but with decorator. </p>
<pre><code>class Foo(object):
def _get_meow(self):
return self._meow + ' from a Foo'
def _set_meow(self, value):
self._meow = value
@property
def meow(self):
return self._get_... | 0 | 2016-05-20T21:11:55Z | [
"python",
"inheritance",
"properties",
"polymorphism"
] |
How do I parse a listing of files to get just the filenames in python? | 237,699 | <p>So lets say I'm using Python's <a href="http://www.python.org/doc/2.5.2/lib/module-ftplib.html" rel="nofollow">ftplib</a> to retrieve a list of log files from an FTP server. How would I parse that list of files to get just the file names (the last column) inside a list? See the link above for example output.</p>
| 2 | 2008-10-26T07:42:17Z | 237,704 | <p>I believe it should work for you.</p>
<pre><code>file_name_list = [' '.join(each_file.split()).split()[-1] for each_file_detail in file_list_from_log]
</code></pre>
<p>NOTES - </p>
<ol>
<li><p>Here I am making a assumption that you want the data in the program (as list), not on console.</p></li>
<li><p>each_file_... | 0 | 2008-10-26T07:52:53Z | [
"python",
"parsing",
"scripting"
] |
How do I parse a listing of files to get just the filenames in python? | 237,699 | <p>So lets say I'm using Python's <a href="http://www.python.org/doc/2.5.2/lib/module-ftplib.html" rel="nofollow">ftplib</a> to retrieve a list of log files from an FTP server. How would I parse that list of files to get just the file names (the last column) inside a list? See the link above for example output.</p>
| 2 | 2008-10-26T07:42:17Z | 237,705 | <p>Using retrlines() probably isn't the best idea there, since it just prints to the console and so you'd have to do tricky things to even get at that output. A likely better bet would be to use the nlst() method, which returns exactly what you want: a list of the file names.</p>
| 10 | 2008-10-26T07:55:46Z | [
"python",
"parsing",
"scripting"
] |
How do I parse a listing of files to get just the filenames in python? | 237,699 | <p>So lets say I'm using Python's <a href="http://www.python.org/doc/2.5.2/lib/module-ftplib.html" rel="nofollow">ftplib</a> to retrieve a list of log files from an FTP server. How would I parse that list of files to get just the file names (the last column) inside a list? See the link above for example output.</p>
| 2 | 2008-10-26T07:42:17Z | 237,708 | <p>And a slightly less-optimal method, by the way, if you're stuck using retrlines() for some reason, is to pass a function as the second argument to retrlines(); it'll be called for each item in the list. So something like this (assuming you have an FTP object named 'ftp') would work as well:</p>
<pre><code>filenames... | 0 | 2008-10-26T07:59:52Z | [
"python",
"parsing",
"scripting"
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.