title
stringlengths
10
172
question_id
int64
469
40.1M
question_body
stringlengths
22
48.2k
question_score
int64
-44
5.52k
question_date
stringlengths
20
20
answer_id
int64
497
40.1M
answer_body
stringlengths
18
33.9k
answer_score
int64
-38
8.38k
answer_date
stringlengths
20
20
tags
listlengths
1
5
Loading and saving data from m2m relationships in Textarea widgets with ModelForm
1,257,062
<p>I have a Model that looks something like this:</p> <pre><code>class Business(models.Model): name = models.CharField('business name', max_length=100) # ... some other fields emails = models.ManyToManyField(Email, null=True) phone_numbers = models.ManyToManyField(PhoneNumber, null=True) urls = mod...
0
2009-08-10T20:34:50Z
1,257,220
<p>This is not directly an answer to your question. It is more a suggestion to re-think your data model.</p> <p>It looks like your BusinessContactForm presents textarea widgets to insert multiple rows into the database. I would not use a Textarea widget for multiple items of more restricted type: I'd enter phone numbe...
1
2009-08-10T21:07:41Z
[ "python", "django", "django-models", "django-forms" ]
Loading and saving data from m2m relationships in Textarea widgets with ModelForm
1,257,062
<p>I have a Model that looks something like this:</p> <pre><code>class Business(models.Model): name = models.CharField('business name', max_length=100) # ... some other fields emails = models.ManyToManyField(Email, null=True) phone_numbers = models.ManyToManyField(PhoneNumber, null=True) urls = mod...
0
2009-08-10T20:34:50Z
1,257,249
<p>This really isn't a good way to do it. Dealing with related items on forms is what <a href="http://docs.djangoproject.com/en/dev/topics/forms/modelforms/#id1" rel="nofollow">formsets</a> are for.</p> <p>Instead of defining the related fields as extra fields on the BusinessForm model, use a standard form for a conta...
1
2009-08-10T21:13:55Z
[ "python", "django", "django-models", "django-forms" ]
What's Python's equivalent to Java InputStream's available method?
1,257,264
<p>Java's InputStream provides a method named <code>available</code> which returns the number of bytes that can be read without blocking. </p> <p>How can I achieve this in Python?</p>
2
2009-08-10T21:16:47Z
1,257,332
<p>You've got to tell us what type of object you're working with. I'm assuming you're talking about a socket read. Either you read the socket with blocking or you read without blocking. You can measure how you have just read in a non-blocking read, if you are interested in that. However, it sounds like you are tryi...
3
2009-08-10T21:31:21Z
[ "java", "python", "sockets" ]
What's Python's equivalent to Java InputStream's available method?
1,257,264
<p>Java's InputStream provides a method named <code>available</code> which returns the number of bytes that can be read without blocking. </p> <p>How can I achieve this in Python?</p>
2
2009-08-10T21:16:47Z
1,257,532
<p>Maybe the answers to <a href="http://stackoverflow.com/questions/375427">this question</a> will help.</p> <p>Or <a href="http://www.darkcoding.net/software/non-blocking-console-io-is-not-possible/" rel="nofollow">that link</a>.</p> <p>To summarize, you could use <a href="http://www.python.org/doc/2.5.2/lib/module-...
1
2009-08-10T22:16:03Z
[ "java", "python", "sockets" ]
Iterate over pairs in a list (circular fashion) in Python
1,257,413
<p>The problem is easy, I want to iterate over each element of the list and the next one in pairs (wrapping the last one with the first).</p> <p>I've thought about two unpythonic ways of doing it:</p> <pre><code>def pairs(lst): n = len(lst) for i in range(n): yield lst[i],lst[(i+1)%n] </code></pre> <...
31
2009-08-10T21:50:38Z
1,257,446
<pre><code>def pairs(lst): i = iter(lst) first = prev = item = i.next() for item in i: yield prev, item prev = item yield item, first </code></pre> <p>Works on any non-empty sequence, no indexing required.</p>
26
2009-08-10T21:57:01Z
[ "list", "iteration", "tuples", "python" ]
Iterate over pairs in a list (circular fashion) in Python
1,257,413
<p>The problem is easy, I want to iterate over each element of the list and the next one in pairs (wrapping the last one with the first).</p> <p>I've thought about two unpythonic ways of doing it:</p> <pre><code>def pairs(lst): n = len(lst) for i in range(n): yield lst[i],lst[(i+1)%n] </code></pre> <...
31
2009-08-10T21:50:38Z
1,257,463
<p>This might be satisfactory:</p> <pre><code>def pairs(lst): for i in range(1, len(lst)): yield lst[i-1], lst[i] yield lst[-1], lst[0] &gt;&gt;&gt; a = list(range(5)) &gt;&gt;&gt; for a1, a2 in pairs(a): ... print a1, a2 ... 0 1 1 2 2 3 3 4 4 0 </code></pre> <p>If you like this kind of stuff, lo...
5
2009-08-10T22:00:18Z
[ "list", "iteration", "tuples", "python" ]
Iterate over pairs in a list (circular fashion) in Python
1,257,413
<p>The problem is easy, I want to iterate over each element of the list and the next one in pairs (wrapping the last one with the first).</p> <p>I've thought about two unpythonic ways of doing it:</p> <pre><code>def pairs(lst): n = len(lst) for i in range(n): yield lst[i],lst[(i+1)%n] </code></pre> <...
31
2009-08-10T21:50:38Z
1,257,579
<p>To answer your question about solving for the general case:</p> <pre><code>import itertools def pair(series, n): s = list(itertools.tee(series, n)) try: [ s[i].next() for i in range(1, n) for j in range(i)] except StopIteration: pass while True: result = [] try: ...
0
2009-08-10T22:27:19Z
[ "list", "iteration", "tuples", "python" ]
Iterate over pairs in a list (circular fashion) in Python
1,257,413
<p>The problem is easy, I want to iterate over each element of the list and the next one in pairs (wrapping the last one with the first).</p> <p>I've thought about two unpythonic ways of doing it:</p> <pre><code>def pairs(lst): n = len(lst) for i in range(n): yield lst[i],lst[(i+1)%n] </code></pre> <...
31
2009-08-10T21:50:38Z
1,257,624
<p>I've coded myself the tuple general versions, I like the first one for it's ellegant simplicity, the more I look at it, the more Pythonic it feels to me... after all, what is more Pythonic than a one liner with zip, asterisk argument expansion, list comprehensions, list slicing, list concatenation and "range"?</p> ...
7
2009-08-10T22:37:22Z
[ "list", "iteration", "tuples", "python" ]
Iterate over pairs in a list (circular fashion) in Python
1,257,413
<p>The problem is easy, I want to iterate over each element of the list and the next one in pairs (wrapping the last one with the first).</p> <p>I've thought about two unpythonic ways of doing it:</p> <pre><code>def pairs(lst): n = len(lst) for i in range(n): yield lst[i],lst[(i+1)%n] </code></pre> <...
31
2009-08-10T21:50:38Z
1,257,723
<p>I'd do it like this (mostly because I can read this):</p> <pre><code>class Pairs(object): def __init__(self, start): self.i = start def next(self): p, p1 = self.i, self.i + 1 self.i = p1 return p, p1 def __iter__(self): return self if __name__ == "__main__": ...
2
2009-08-10T23:08:30Z
[ "list", "iteration", "tuples", "python" ]
Iterate over pairs in a list (circular fashion) in Python
1,257,413
<p>The problem is easy, I want to iterate over each element of the list and the next one in pairs (wrapping the last one with the first).</p> <p>I've thought about two unpythonic ways of doing it:</p> <pre><code>def pairs(lst): n = len(lst) for i in range(n): yield lst[i],lst[(i+1)%n] </code></pre> <...
31
2009-08-10T21:50:38Z
1,257,966
<p>This infinitely cycles, for good or ill, but is algorithmically very clear. </p> <pre><code>from itertools import tee, cycle def nextn(iterable,n=2): ''' generator that yields a tuple of the next n items in iterable. This generator cycles infinitely ''' cycled = cycle(iterable) gens = tee(cycled,n...
0
2009-08-11T00:42:37Z
[ "list", "iteration", "tuples", "python" ]
Iterate over pairs in a list (circular fashion) in Python
1,257,413
<p>The problem is easy, I want to iterate over each element of the list and the next one in pairs (wrapping the last one with the first).</p> <p>I've thought about two unpythonic ways of doing it:</p> <pre><code>def pairs(lst): n = len(lst) for i in range(n): yield lst[i],lst[(i+1)%n] </code></pre> <...
31
2009-08-10T21:50:38Z
2,231,702
<p>Even shorter version of Fortran's zip * range solution (with lambda this time;):</p> <pre><code>group = lambda t, n: zip(*[t[i::n] for i in range(n)]) group([1, 2, 3, 3], 2) </code></pre> <p>gives:</p> <pre><code>[(1, 2), (3, 4)] </code></pre>
0
2010-02-09T19:05:51Z
[ "list", "iteration", "tuples", "python" ]
Iterate over pairs in a list (circular fashion) in Python
1,257,413
<p>The problem is easy, I want to iterate over each element of the list and the next one in pairs (wrapping the last one with the first).</p> <p>I've thought about two unpythonic ways of doing it:</p> <pre><code>def pairs(lst): n = len(lst) for i in range(n): yield lst[i],lst[(i+1)%n] </code></pre> <...
31
2009-08-10T21:50:38Z
4,590,062
<pre><code>i=(range(10)) for x in len(i): print i[:2] i=i[1:]+[i[1]] </code></pre> <p>more pythonic than this is impossible</p>
0
2011-01-04T01:59:53Z
[ "list", "iteration", "tuples", "python" ]
Iterate over pairs in a list (circular fashion) in Python
1,257,413
<p>The problem is easy, I want to iterate over each element of the list and the next one in pairs (wrapping the last one with the first).</p> <p>I've thought about two unpythonic ways of doing it:</p> <pre><code>def pairs(lst): n = len(lst) for i in range(n): yield lst[i],lst[(i+1)%n] </code></pre> <...
31
2009-08-10T21:50:38Z
5,613,929
<p>Here's a version that supports an optional start index (for example to return (4, 0) as the first pair, use start = -1:</p> <pre><code>import itertools def iterrot(lst, start = 0): if start == 0: i = iter(lst) elif start &gt; 0: i1 = itertools.islice(lst, start, None) i2 = itertool...
0
2011-04-10T18:44:48Z
[ "list", "iteration", "tuples", "python" ]
Iterate over pairs in a list (circular fashion) in Python
1,257,413
<p>The problem is easy, I want to iterate over each element of the list and the next one in pairs (wrapping the last one with the first).</p> <p>I've thought about two unpythonic ways of doing it:</p> <pre><code>def pairs(lst): n = len(lst) for i in range(n): yield lst[i],lst[(i+1)%n] </code></pre> <...
31
2009-08-10T21:50:38Z
6,242,225
<pre><code>[(i,(i+1)%len(range(10))) for i in range(10)] </code></pre> <p>replace range(10) with the list you want.</p> <p>In general "circular indexing" is quite easy in python; just use: </p> <pre><code>a[i%len(a)] </code></pre>
1
2011-06-05T10:05:32Z
[ "list", "iteration", "tuples", "python" ]
Iterate over pairs in a list (circular fashion) in Python
1,257,413
<p>The problem is easy, I want to iterate over each element of the list and the next one in pairs (wrapping the last one with the first).</p> <p>I've thought about two unpythonic ways of doing it:</p> <pre><code>def pairs(lst): n = len(lst) for i in range(n): yield lst[i],lst[(i+1)%n] </code></pre> <...
31
2009-08-10T21:50:38Z
9,885,130
<p>I, as always, like tee:</p> <pre><code>from itertools import tee, izip, chain def pairs(iterable): a, b = tee(iterable) return izip(a, chain(b, [next(b)])) </code></pre>
6
2012-03-27T07:32:21Z
[ "list", "iteration", "tuples", "python" ]
Iterate over pairs in a list (circular fashion) in Python
1,257,413
<p>The problem is easy, I want to iterate over each element of the list and the next one in pairs (wrapping the last one with the first).</p> <p>I've thought about two unpythonic ways of doing it:</p> <pre><code>def pairs(lst): n = len(lst) for i in range(n): yield lst[i],lst[(i+1)%n] </code></pre> <...
31
2009-08-10T21:50:38Z
16,567,465
<pre><code>def pairs(ex_list): for i, v in enumerate(ex_list): if i &lt; len(list) - 1: print v, ex_list[i+1] else: print v, ex_list[0] </code></pre> <p>Enumerate returns a tuple with the index number and the value. I print the value and the following element of the list <co...
0
2013-05-15T14:13:47Z
[ "list", "iteration", "tuples", "python" ]
Iterate over pairs in a list (circular fashion) in Python
1,257,413
<p>The problem is easy, I want to iterate over each element of the list and the next one in pairs (wrapping the last one with the first).</p> <p>I've thought about two unpythonic ways of doing it:</p> <pre><code>def pairs(lst): n = len(lst) for i in range(n): yield lst[i],lst[(i+1)%n] </code></pre> <...
31
2009-08-10T21:50:38Z
23,176,598
<p>Of course, you can always use a <strong>deque</strong>:</p> <pre><code>from collections import deque from itertools import * def pairs(lst, n=2): itlst = iter(lst) start = list(islice(itlst, 0, n-1)) deq = deque(start, n) for elt in chain(itlst, start): deq.append(elt) yield list(de...
0
2014-04-19T23:07:20Z
[ "list", "iteration", "tuples", "python" ]
python: slow timeit() function
1,257,727
<p>When I run the code below outside of timeit(), it appears to complete instantaneously. However when I run it within the timeit() function, it takes much longer. Why?</p> <pre><code>&gt;&gt;&gt; import timeit &gt;&gt;&gt; t = timeit.Timer("3**4**5") &gt;&gt;&gt; t.timeit() 16.55522028637718 </code></pre> <p>Using...
12
2009-08-10T23:09:51Z
1,257,737
<p>The <code>timeit()</code> function runs the code many times (default one million) and takes an average of the timings.</p> <p>To run the code only once, do this:</p> <pre><code>t.timeit(1) </code></pre> <p>but that will give you skewed results - it repeats for good reason.</p> <p>To get the per-loop time having ...
23
2009-08-10T23:12:42Z
[ "python", "timer", "timeit" ]
python: slow timeit() function
1,257,727
<p>When I run the code below outside of timeit(), it appears to complete instantaneously. However when I run it within the timeit() function, it takes much longer. Why?</p> <pre><code>&gt;&gt;&gt; import timeit &gt;&gt;&gt; t = timeit.Timer("3**4**5") &gt;&gt;&gt; t.timeit() 16.55522028637718 </code></pre> <p>Using...
12
2009-08-10T23:09:51Z
1,257,739
<p>Because timeit defaults to running it one million times. The point is to do micro-benchmarks, and the only way to get accurate timings of short events is to repeat them many times.</p>
5
2009-08-10T23:13:25Z
[ "python", "timer", "timeit" ]
python: slow timeit() function
1,257,727
<p>When I run the code below outside of timeit(), it appears to complete instantaneously. However when I run it within the timeit() function, it takes much longer. Why?</p> <pre><code>&gt;&gt;&gt; import timeit &gt;&gt;&gt; t = timeit.Timer("3**4**5") &gt;&gt;&gt; t.timeit() 16.55522028637718 </code></pre> <p>Using...
12
2009-08-10T23:09:51Z
1,257,751
<p>According to the <a href="http://docs.python.org/library/timeit.html" rel="nofollow">docs</a>, Timer.timeit() runs your code one million times by default. Use the "number" parameter to change this default:</p> <pre><code>t.timeit(number=100) </code></pre> <p>for example.</p>
2
2009-08-10T23:18:12Z
[ "python", "timer", "timeit" ]
python: slow timeit() function
1,257,727
<p>When I run the code below outside of timeit(), it appears to complete instantaneously. However when I run it within the timeit() function, it takes much longer. Why?</p> <pre><code>&gt;&gt;&gt; import timeit &gt;&gt;&gt; t = timeit.Timer("3**4**5") &gt;&gt;&gt; t.timeit() 16.55522028637718 </code></pre> <p>Using...
12
2009-08-10T23:09:51Z
1,257,754
<p><a href="http://docs.python.org/library/timeit.html#timeit.Timer.timeit" rel="nofollow">Timeit</a> runs for one million loops by default.</p> <p>You also may have order of operations issues: <code>(3**4)**5 != 3**4**5</code>.</p>
2
2009-08-10T23:18:49Z
[ "python", "timer", "timeit" ]
python: slow timeit() function
1,257,727
<p>When I run the code below outside of timeit(), it appears to complete instantaneously. However when I run it within the timeit() function, it takes much longer. Why?</p> <pre><code>&gt;&gt;&gt; import timeit &gt;&gt;&gt; t = timeit.Timer("3**4**5") &gt;&gt;&gt; t.timeit() 16.55522028637718 </code></pre> <p>Using...
12
2009-08-10T23:09:51Z
1,257,784
<pre><code>&gt;&gt;&gt; 3**4**5 37339184874102004353295975418486658822540977678373400775063693172207904061726525 12299936889388039772204687650654314751581087270545921608585813513369828091873141 91748594262580938807019951956404285571818041046681288797402925517668012340617298 39657473161915238672304623512593489605859058...
0
2009-08-10T23:25:46Z
[ "python", "timer", "timeit" ]
How do I get omnicompletion for Python external libraries?
1,257,742
<p>I've setup my gVim to have omnicompletion, but only for the standard library atm.. How do I include other libraries (Django, Pygame, etc...)?</p> <p>Thanks!</p>
5
2009-08-10T23:13:54Z
1,257,793
<p>Here's a <a href="http://blog.fluther.com/blog/2008/10/17/django-vim/" rel="nofollow">tutorial on using omnicomplete with Django</a>.</p>
1
2009-08-10T23:28:07Z
[ "python", "vim" ]
python/genshi newline to html <p> paragraphs
1,257,746
<p>I'm trying to output the content of a comment with genshi, but I can't figure out how to transform the newlines into HTML paragraphs.</p> <p>Here's a test case of what it should look like:</p> <p>input: <code>'foo\n\n\n\n\nbar\nbaz'</code></p> <p>output: <code>&lt;p&gt;foo&lt;/p&gt;&lt;p&gt;bar&lt;/p&gt;&lt;p&gt;...
3
2009-08-10T23:16:36Z
1,257,780
<p>There may be a built-in function in Genshi, but if not, this will do it for you:</p> <pre><code>output = ''.join([("&lt;p&gt;%s&lt;/p&gt;" % l) for l in input.split('\n')]) </code></pre>
2
2009-08-10T23:24:38Z
[ "python", "turbogears", "genshi" ]
python/genshi newline to html <p> paragraphs
1,257,746
<p>I'm trying to output the content of a comment with genshi, but I can't figure out how to transform the newlines into HTML paragraphs.</p> <p>Here's a test case of what it should look like:</p> <p>input: <code>'foo\n\n\n\n\nbar\nbaz'</code></p> <p>output: <code>&lt;p&gt;foo&lt;/p&gt;&lt;p&gt;bar&lt;/p&gt;&lt;p&gt;...
3
2009-08-10T23:16:36Z
1,258,080
<pre><code>def tohtml(manylinesstr): return ''.join("&lt;p&gt;%s&lt;/p&gt;" % line for line in manylinesstr.splitlines() if line) </code></pre> <p>So for example,</p> <pre><code>print repr(tohtml('foo\n\n\n\n\nbar\nbaz')) </code></pre> <p>emits:</p> <pre><code>'&lt;p&gt;foo&lt;/p&gt;&lt;p&gt...
3
2009-08-11T01:35:32Z
[ "python", "turbogears", "genshi" ]
python/genshi newline to html <p> paragraphs
1,257,746
<p>I'm trying to output the content of a comment with genshi, but I can't figure out how to transform the newlines into HTML paragraphs.</p> <p>Here's a test case of what it should look like:</p> <p>input: <code>'foo\n\n\n\n\nbar\nbaz'</code></p> <p>output: <code>&lt;p&gt;foo&lt;/p&gt;&lt;p&gt;bar&lt;/p&gt;&lt;p&gt;...
3
2009-08-10T23:16:36Z
1,387,182
<p>I know you said TG1 my solution is TG2 but can be backported or simply depend on webhelpers but IMO all other implementations are flawed. </p> <p>Take a look at the <a href="http://bitbucket.org/bbangert/webhelpers/src/tip/webhelpers/html/converters.py" rel="nofollow">converters module</a> both nl2br and format_par...
1
2009-09-07T01:03:11Z
[ "python", "turbogears", "genshi" ]
Problem reading an Integer in java that was written using python’s struct.pack method
1,257,856
<p>First I write the integer using python:<br /> <code>out.write( struct.pack("&gt;i", int(i)) );</code></p> <p>I then read the integer using <code>DataInputStream.readInt()</code> in Java.<br /> I works but when it tries to read the number 10, and probably some other numbers too, it starts to read garbage.<br /> Read...
0
2009-08-10T23:57:19Z
1,257,870
<p>Psychic debugging: You're writing the output in text mode on Windows using code like this:</p> <pre><code>f = open("output.dat", "w") f.write(my_data) </code></pre> <p>and that's making your 13 (which is a newline) become carriage return / newline (10, 13).</p> <p>You need to write your output in binary mode:</p>...
7
2009-08-11T00:02:48Z
[ "java", "python" ]
Starting semantic image recognition
1,257,933
<p>How to recognize (in)appropriate images?</p> <p>To facilitate, enable and easify photo and image moderation and administration targeting gae, I try get started with basic python image recognition ie basic semantic information what the image looks like to hold back doubtful material until human can judge it, and to ...
1
2009-08-11T00:27:02Z
1,258,035
<p>In python you could always:</p> <pre><code>import supreme_court </code></pre> <p>Because when it comes to pornography, they know it when they see it.</p> <p>Mediocre jokes aside, I would develop a bunch of fuzzy image recognizers that match <em>easy</em> things (like how much of the image is made up of a skin col...
2
2009-08-11T01:17:12Z
[ "python", "image", "computer-vision", "pattern-recognition", "image-recognition" ]
Starting semantic image recognition
1,257,933
<p>How to recognize (in)appropriate images?</p> <p>To facilitate, enable and easify photo and image moderation and administration targeting gae, I try get started with basic python image recognition ie basic semantic information what the image looks like to hold back doubtful material until human can judge it, and to ...
1
2009-08-11T00:27:02Z
1,258,045
<p>I believe you will want to start here</p> <p><a href="http://en.wikipedia.org/wiki/Feature_detection_%28computer_vision%29" rel="nofollow">http://en.wikipedia.org/wiki/Feature_detection_%28computer_vision%29</a></p> <p>and then brush up on your statistical theory, reading any papers on the topic.</p>
2
2009-08-11T01:21:35Z
[ "python", "image", "computer-vision", "pattern-recognition", "image-recognition" ]
Generic view 'archive_year' produces blank page
1,257,943
<p>I am using Django's generic views to create a blog site. The templates I created, <code>entry_archive_day</code>, <code>entry_archive_month</code>, <code>entry_archive</code>, and <code>entry_detail</code> all work perfectly. </p> <p>But <strong><code>entry_archive_year</code></strong> does not. Instead, it is s...
3
2009-08-11T00:30:42Z
1,257,956
<p><strong>To solve your problem:</strong></p> <p>If you set <code>make_object_list=True</code> when calling <code>archive_year</code>, then the list of objects for that year will be available as <code>object_list</code>.</p> <p>As a quick example, if your url pattern looks like</p> <pre><code>url(r'^(?P&lt;year&gt;...
5
2009-08-11T00:39:13Z
[ "python", "django", "view", "generics" ]
python datetime strptime wildcard
1,258,199
<p>I want to parse dates like these into a datetime object:</p> <ul> <li>December 12th, 2008 </li> <li>January 1st, 2009</li> </ul> <p>The following will work for the first date:</p> <pre><code>datetime.strptime("December 12th, 2008", "%B %dth, %Y") </code></pre> <p>but will fail for the second because of the suffi...
13
2009-08-11T02:23:47Z
1,258,247
<p>Try using the dateutil.parser module.</p> <pre><code>import dateutil.parser date1 = dateutil.parser.parse("December 12th, 2008") date2 = dateutil.parser.parse("January 1st, 2009") </code></pre> <p>Additional documentation can be found here: <a href="http://labix.org/python-dateutil">http://labix.org/python-dateuti...
18
2009-08-11T02:41:28Z
[ "python", "datetime", "parsing", "strptime" ]
python datetime strptime wildcard
1,258,199
<p>I want to parse dates like these into a datetime object:</p> <ul> <li>December 12th, 2008 </li> <li>January 1st, 2009</li> </ul> <p>The following will work for the first date:</p> <pre><code>datetime.strptime("December 12th, 2008", "%B %dth, %Y") </code></pre> <p>but will fail for the second because of the suffi...
13
2009-08-11T02:23:47Z
1,258,248
<p>strptime is tricky because it relies on the underlying C library for its implementation, so some details differ between platforms. There doesn't seem to be a way to match the characters you need to. But you could clean the data first:</p> <pre><code># Remove ordinal suffixes from numbers. date_in = re.sub(r"(st|n...
7
2009-08-11T02:42:09Z
[ "python", "datetime", "parsing", "strptime" ]
python datetime strptime wildcard
1,258,199
<p>I want to parse dates like these into a datetime object:</p> <ul> <li>December 12th, 2008 </li> <li>January 1st, 2009</li> </ul> <p>The following will work for the first date:</p> <pre><code>datetime.strptime("December 12th, 2008", "%B %dth, %Y") </code></pre> <p>but will fail for the second because of the suffi...
13
2009-08-11T02:23:47Z
1,258,249
<p>You need Gustavo Niemeyer's <a href="http://labix.org/python-dateutil">python_dateutil</a> -- once it's installed,</p> <pre><code>&gt;&gt;&gt; from dateutil import parser &gt;&gt;&gt; parser.parse('December 12th, 2008') datetime.datetime(2008, 12, 12, 0, 0) &gt;&gt;&gt; parser.parse('January 1st, 2009') datetime.da...
8
2009-08-11T02:42:26Z
[ "python", "datetime", "parsing", "strptime" ]
Can you get more information about the online file?
1,258,280
<p>I have a online file: <a href="http://dl_dir.qq.com/qqfile/tm/TM2009Beta_chs.exe" rel="nofollow">http://dl_dir.qq.com/qqfile/tm/TM2009Beta_chs.exe</a> ,please donot download it, i want to determine the software version whether is changed, so i want more information about it. for example, using python,i can get this...
-2
2009-08-11T02:58:01Z
1,258,295
<p>You can get all kinds of information about an EXE Windows file if you download it (the easy way, by running external utilities on it, or up to a point the hard way, via APIs and your own code simulating those utilities) -- a lot depends on what info was put into it when it was built. Without downloading, you can get...
2
2009-08-11T03:04:14Z
[ "python" ]
Can you get more information about the online file?
1,258,280
<p>I have a online file: <a href="http://dl_dir.qq.com/qqfile/tm/TM2009Beta_chs.exe" rel="nofollow">http://dl_dir.qq.com/qqfile/tm/TM2009Beta_chs.exe</a> ,please donot download it, i want to determine the software version whether is changed, so i want more information about it. for example, using python,i can get this...
-2
2009-08-11T02:58:01Z
1,258,304
<ol> <li><p>Download the first thousand bytes or so of the file using the range header.</p></li> <li><p>Use <a href="http://code.google.com/p/pefile/" rel="nofollow">pefile</a> to parse the PE header and extract version information.</p></li> <li><p>With the data, <a href="http://books.google.com/books?id=Pas0YoxygnkC&a...
4
2009-08-11T03:09:39Z
[ "python" ]
Can you get more information about the online file?
1,258,280
<p>I have a online file: <a href="http://dl_dir.qq.com/qqfile/tm/TM2009Beta_chs.exe" rel="nofollow">http://dl_dir.qq.com/qqfile/tm/TM2009Beta_chs.exe</a> ,please donot download it, i want to determine the software version whether is changed, so i want more information about it. for example, using python,i can get this...
-2
2009-08-11T02:58:01Z
1,258,329
<p>Configure your server to provide a <a href="http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.29" rel="nofollow">Last-Modified</a> header, and use <a href="http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.25" rel="nofollow">If-Modified-Since</a> in your request.</p>
2
2009-08-11T03:20:09Z
[ "python" ]
How to make python urllib2 follow redirect and keep post method
1,258,428
<p>I am using urllib2 to post data to a form. The problem is that the form replies with a 302 redirect. According to <a href="http://docs.python.org/library/urllib2.html#urllib2.HTTPRedirectHandler.redirect%5Frequest" rel="nofollow">Python HTTPRedirectHandler</a> the redirect handler will take the request and convert i...
2
2009-08-11T04:06:53Z
1,258,603
<p>This is actually a really bad thing to do the more I thought about it. For instance, if I submit a form to <a href="http://example.com/add">http://example.com/add</a> (with post data to add a item) and the response is a 302 redirect to <a href="http://example.com/add">http://example.com/add</a> and I post the same ...
6
2009-08-11T05:40:57Z
[ "python", "automation", "urllib2" ]
How to get webcam info with WMI
1,258,455
<p>Which class that we can obtain webcam info? Thank</p>
0
2009-08-11T04:28:46Z
1,258,571
<p>I think you may actually need <a href="http://msdn.microsoft.com/en-us/library/ms630827%28VS.85%29.aspx" rel="nofollow">WIA</a> -- though the URL I'm quoting is all about images, not videos, I'm sure WIA also has video functionality, I just can't find good docs on that!-(</p>
1
2009-08-11T05:28:43Z
[ "python", "wmi" ]
How to get user input during a while loop without blocking
1,258,566
<p>I'm trying to write a while loop that constantly updates the screen by using os.system("clear") and then printing out a different text message every few seconds. How do I get user input during the loop? raw_input() just pauses and waits, which is not the functionality I want.</p> <pre><code>import os import time s...
2
2009-08-11T05:27:05Z
1,258,581
<p>The <a href="http://docs.python.org/library/select.html">select</a> module in Python's standard library may be what you're looking for -- standard input has FD 0, though you may also need to put a terminal in "raw" (as opposed to "cooked") mode, on unix-y systems, to get single keypresses from it as opposed to whole...
9
2009-08-11T05:33:24Z
[ "python" ]
How to get user input during a while loop without blocking
1,258,566
<p>I'm trying to write a while loop that constantly updates the screen by using os.system("clear") and then printing out a different text message every few seconds. How do I get user input during the loop? raw_input() just pauses and waits, which is not the functionality I want.</p> <pre><code>import os import time s...
2
2009-08-11T05:27:05Z
1,258,952
<p>You can also check <a href="http://code.activestate.com/recipes/134892/" rel="nofollow">one of the recipes</a> available out there, which gives you the functionality you're looking for for both Unix and Windows.</p>
3
2009-08-11T07:53:02Z
[ "python" ]
How to get user input during a while loop without blocking
1,258,566
<p>I'm trying to write a while loop that constantly updates the screen by using os.system("clear") and then printing out a different text message every few seconds. How do I get user input during the loop? raw_input() just pauses and waits, which is not the functionality I want.</p> <pre><code>import os import time s...
2
2009-08-11T05:27:05Z
1,261,079
<p>You can do that with threads, here is a basic example :</p> <pre><code>import threading, os, time, itertools, Queue # setting a cross platform getch like function # thks to the Python Cookbook # why isn't standard on this battery included language ? try : # on windows from msvcrt import getch except ImportErro...
1
2009-08-11T15:21:46Z
[ "python" ]
storing classmethod reference in tuple does not work as in variable
1,258,690
<pre><code>#!/usr/bin/python class Bar(object): @staticmethod def ruleOn(rule): if isinstance(rule, tuple): print rule[0] print rule[0].__get__(None, Foo) else: print rule class Foo(object): @classmethod def callRule(cls): Bar.ruleOn(cls.RULE1) Bar.ruleOn(cls.RULE2) @cl...
0
2009-08-11T06:19:34Z
1,258,710
<p>This is because method are actually functions in Python. They only become bound methods when you look them up on the constructed class instance. See my answer to <a href="http://stackoverflow.com/questions/852308/how-the-method-resolution-and-invocation-works-internally-in-python/870650#870650">this question</a> for...
0
2009-08-11T06:28:50Z
[ "python" ]
fuzzy timestamp parsing with Python
1,258,712
<p>Is there a Python module to interpret fuzzy timestamps like the date command in unix:</p> <pre><code>&gt; date -d "2 minutes ago" Tue Aug 11 16:24:05 EST 2009 </code></pre> <p>The closest I have found so far is dateutil.parser, which fails for the above example.</p> <p>thanks</p>
5
2009-08-11T06:29:11Z
1,258,858
<p>Check out this open source module: <a href="https://github.com/bear/parsedatetime" rel="nofollow">parsedatetime</a></p>
8
2009-08-11T07:21:47Z
[ "python", "date", "parsing", "timestamp" ]
fuzzy timestamp parsing with Python
1,258,712
<p>Is there a Python module to interpret fuzzy timestamps like the date command in unix:</p> <pre><code>&gt; date -d "2 minutes ago" Tue Aug 11 16:24:05 EST 2009 </code></pre> <p>The closest I have found so far is dateutil.parser, which fails for the above example.</p> <p>thanks</p>
5
2009-08-11T06:29:11Z
1,378,134
<p>I have been dabbling with this using pyparsing - you can find my latest attempt <a href="http://pyparsing.wikispaces.com/UnderDevelopment#toc0" rel="nofollow" title="Time expression parser">here</a>. It works for these test cases:</p> <pre><code>today tomorrow yesterday in a couple of days a couple of days from no...
1
2009-09-04T09:20:43Z
[ "python", "date", "parsing", "timestamp" ]
Python Subprocess - Redirect stdout/err to two places
1,258,863
<p>I have a small python script which invokes an external process using <code>subprocess</code>. I want to redirect stdout and stderr to both a log file and to the terminal.</p> <p>How can this be done?</p>
9
2009-08-11T07:22:29Z
1,258,929
<p>You can do this with <a href="http://docs.python.org/library/subprocess.html#subprocess.PIPE"><code>subprocess.PIPE</code></a>.</p> <p>You can find <a href="http://blog.kagesenshi.org/2008/02/teeing-python-subprocesspopen-output.html">some sample code here</a>.</p>
8
2009-08-11T07:44:36Z
[ "python", "redirect", "subprocess", "stdout" ]
Python: How can I choose which module to import when they are named the same
1,259,106
<p>Lets say I'm in a file called <code>openid.py</code> and I do :</p> <pre><code>from openid.consumer.discover import discover, DiscoveryFailure </code></pre> <p>I have the <code>openid</code> module on my pythonpath but the interpreter seems to be trying to use my <code>openid.py</code> file. How can I get the libr...
6
2009-08-11T08:44:44Z
1,259,132
<p><strong>Rename it</strong>. This is the idea behind name spaces. your <code>openid</code> could be a sub-module in your top module <code>project</code>. your <code>email</code> will clash with top module <code>email</code> in stdlib.</p> <p>because your openid is not universal, it provides a special case for your p...
3
2009-08-11T08:51:01Z
[ "python", "import", "namespaces" ]
Python: How can I choose which module to import when they are named the same
1,259,106
<p>Lets say I'm in a file called <code>openid.py</code> and I do :</p> <pre><code>from openid.consumer.discover import discover, DiscoveryFailure </code></pre> <p>I have the <code>openid</code> module on my pythonpath but the interpreter seems to be trying to use my <code>openid.py</code> file. How can I get the libr...
6
2009-08-11T08:44:44Z
1,259,151
<p>You can use relative or absolute imports (depending on the specifics of your situation), which are covered in <a href="http://www.python.org/dev/peps/pep-0328/" rel="nofollow">PEP 328</a> most recently. Of course, seriously, you should not be creating naming conflicts like this and should rename your file.</p>
1
2009-08-11T08:54:05Z
[ "python", "import", "namespaces" ]
Python: How can I choose which module to import when they are named the same
1,259,106
<p>Lets say I'm in a file called <code>openid.py</code> and I do :</p> <pre><code>from openid.consumer.discover import discover, DiscoveryFailure </code></pre> <p>I have the <code>openid</code> module on my pythonpath but the interpreter seems to be trying to use my <code>openid.py</code> file. How can I get the libr...
6
2009-08-11T08:44:44Z
1,259,275
<p>Thats the reason absolute imports have been chosen as the new default behaviour. However, they are not yet the default in 2.6 (maybe in 2.7...). You can get their behaviour now by importing them from the future:</p> <pre><code>from __future__ import absolute_import </code></pre> <p>You can find out more about this...
9
2009-08-11T09:22:51Z
[ "python", "import", "namespaces" ]
Python: How can I choose which module to import when they are named the same
1,259,106
<p>Lets say I'm in a file called <code>openid.py</code> and I do :</p> <pre><code>from openid.consumer.discover import discover, DiscoveryFailure </code></pre> <p>I have the <code>openid</code> module on my pythonpath but the interpreter seems to be trying to use my <code>openid.py</code> file. How can I get the libr...
6
2009-08-11T08:44:44Z
1,259,955
<p>You could try shuffling <code>sys.path</code>, to move the interesting directories to the front before doing the import.</p>
-1
2009-08-11T12:09:37Z
[ "python", "import", "namespaces" ]
Python: How can I choose which module to import when they are named the same
1,259,106
<p>Lets say I'm in a file called <code>openid.py</code> and I do :</p> <pre><code>from openid.consumer.discover import discover, DiscoveryFailure </code></pre> <p>I have the <code>openid</code> module on my pythonpath but the interpreter seems to be trying to use my <code>openid.py</code> file. How can I get the libr...
6
2009-08-11T08:44:44Z
1,261,060
<p>I won't get into the polemics on renaming and instead focus on showing you how to do what you want (whether it's "good for you" or not;-). The solution is not difficult...</p> <p>Just set <code>__path__</code>! A little demonstration:</p> <pre><code>$ mkdir /tmp/modules /tmp/packages $ mkdir /tmp/packages/openid $...
2
2009-08-11T15:20:26Z
[ "python", "import", "namespaces" ]
django Datefield to Unix timestamp
1,259,219
<p>Hello In a model I have a such field: mydate = models.DateField()</p> <p>now a javascript graph function requires unix timestamp such as "1196550000000", how can I return the unix timestamp of my mydate input.</p> <p>Thanks</p>
26
2009-08-11T09:11:07Z
1,259,333
<p>In your <code>views.py</code>, you can convert the value of <code>mydate</code> to seconds since the Unix epoch as follows:</p> <pre><code>seconds = time.mktime(mydate.timetuple()) </code></pre> <p>Then pass it in the dictionary you use as an argument to <code>render_to_response()</code> (or whatever you're using ...
4
2009-08-11T09:35:22Z
[ "python", "django", "unix-timestamp" ]
django Datefield to Unix timestamp
1,259,219
<p>Hello In a model I have a such field: mydate = models.DateField()</p> <p>now a javascript graph function requires unix timestamp such as "1196550000000", how can I return the unix timestamp of my mydate input.</p> <p>Thanks</p>
26
2009-08-11T09:11:07Z
1,259,378
<p><strong>edit: please check the second answer, it has a much better solution</strong></p> <p>In python code, you can do this to convert a date or datetime to the Unix Epoch</p> <pre><code>import time epoch = int(time.mktime(mydate.timetuple())*1000) </code></pre> <p>This doesn't work in a Django template though, s...
23
2009-08-11T09:45:05Z
[ "python", "django", "unix-timestamp" ]
django Datefield to Unix timestamp
1,259,219
<p>Hello In a model I have a such field: mydate = models.DateField()</p> <p>now a javascript graph function requires unix timestamp such as "1196550000000", how can I return the unix timestamp of my mydate input.</p> <p>Thanks</p>
26
2009-08-11T09:11:07Z
3,376,435
<p>I know another answer was accepted a while ago, but this question appears high on Google's search results, so I will add another answer. </p> <p>If you are working at the template level, you can use the <a href="https://docs.djangoproject.com/en/dev/ref/templates/builtins/?from=olddocs#std%3atemplatefilter-date"><...
82
2010-07-31T01:44:11Z
[ "python", "django", "unix-timestamp" ]
django Datefield to Unix timestamp
1,259,219
<p>Hello In a model I have a such field: mydate = models.DateField()</p> <p>now a javascript graph function requires unix timestamp such as "1196550000000", how can I return the unix timestamp of my mydate input.</p> <p>Thanks</p>
26
2009-08-11T09:11:07Z
7,387,012
<p>And if you're not in the template layer, you can still use the same underlying django utils. Ex:</p> <pre><code>from django.utils.dateformat import format print format(mymodel.mydatefield, 'U') </code></pre>
47
2011-09-12T11:17:02Z
[ "python", "django", "unix-timestamp" ]
django Datefield to Unix timestamp
1,259,219
<p>Hello In a model I have a such field: mydate = models.DateField()</p> <p>now a javascript graph function requires unix timestamp such as "1196550000000", how can I return the unix timestamp of my mydate input.</p> <p>Thanks</p>
26
2009-08-11T09:11:07Z
40,096,453
<p>Another option:</p> <pre><code>import time from django.utils import timezone naive_date = timezone.make_naive(mydate, timezone.get_current_timezone()) print int(time.mktime(naive_date.timetuple())) </code></pre>
0
2016-10-17T22:07:32Z
[ "python", "django", "unix-timestamp" ]
How to find the installation path of IronPython
1,259,296
<p>I have few python scripts of which one is to be executed in IronPython interpreter. How to find the installation path of IronPython. I searched the registry. To my surprise, it was not there.</p>
0
2009-08-11T09:27:34Z
1,259,717
<p>Try this:</p> <pre><code>import sys print sys.executable </code></pre> <p>Disclaimer: I don't know if it will work on IronPython.</p>
1
2009-08-11T11:12:30Z
[ "python", "ironpython" ]
How to find the installation path of IronPython
1,259,296
<p>I have few python scripts of which one is to be executed in IronPython interpreter. How to find the installation path of IronPython. I searched the registry. To my surprise, it was not there.</p>
0
2009-08-11T09:27:34Z
20,639,321
<p>From the registry, you can check HKLM\SOFTWARE\IronPython\2.7\InstallPath</p> <p>It was useful for me.</p> <p><a href="https://ironpython.codeplex.com/workitem/34692" rel="nofollow">https://ironpython.codeplex.com/workitem/34692</a></p> <p>Version number can be retrieved like this (as of IPy 2.7.4):</p> <pre cla...
1
2013-12-17T16:20:19Z
[ "python", "ironpython" ]
Is it a good idea to use super() in Python?
1,259,547
<p>Or should I just explicitly reference the superclasses whose methods I want to call?</p> <p>It seems brittle to repeat the names of super classes when referencing their constructors, but this page <a href="http://fuhm.net/super-harmful/">http://fuhm.net/super-harmful/</a> makes some good arguments against using sup...
10
2009-08-11T10:32:51Z
1,259,584
<p>Yes, just stick to keyword arguments in your <code>__init__</code> methods and you shouldn't have too many problems.</p> <p>I agree that it is brittle, but no less so than using the name of the inherited class.</p>
1
2009-08-11T10:41:19Z
[ "python", "oop", "super" ]
Is it a good idea to use super() in Python?
1,259,547
<p>Or should I just explicitly reference the superclasses whose methods I want to call?</p> <p>It seems brittle to repeat the names of super classes when referencing their constructors, but this page <a href="http://fuhm.net/super-harmful/">http://fuhm.net/super-harmful/</a> makes some good arguments against using sup...
10
2009-08-11T10:32:51Z
1,259,592
<p>You can use super, but as the article says, there are drawbacks. As long as you know them, there is no problem with using the feature. It's like people saying "use composition, not inheritance" or "never use global variables". If the feature exists, there is a reason. Just be sure to understand the why and the what ...
5
2009-08-11T10:42:28Z
[ "python", "oop", "super" ]
Is it a good idea to use super() in Python?
1,259,547
<p>Or should I just explicitly reference the superclasses whose methods I want to call?</p> <p>It seems brittle to repeat the names of super classes when referencing their constructors, but this page <a href="http://fuhm.net/super-harmful/">http://fuhm.net/super-harmful/</a> makes some good arguments against using sup...
10
2009-08-11T10:32:51Z
1,259,594
<p>I like super() more because it allows you to change the inherited class (for example when you're refactoring and add an intermediate class) without changing it on all the methods.</p>
2
2009-08-11T10:43:21Z
[ "python", "oop", "super" ]
Is it a good idea to use super() in Python?
1,259,547
<p>Or should I just explicitly reference the superclasses whose methods I want to call?</p> <p>It seems brittle to repeat the names of super classes when referencing their constructors, but this page <a href="http://fuhm.net/super-harmful/">http://fuhm.net/super-harmful/</a> makes some good arguments against using sup...
10
2009-08-11T10:32:51Z
1,259,665
<p>The book <a href="http://www.packtpub.com/expert-python-programming/" rel="nofollow">Expert Python Programming</a> has discussed the topic of "super pitfalls" in chapter 3. It is worth reading. Below is the book's conclusion:</p> <blockquote> <p>Super usage has to be consistent: In a class hierarchy, super should...
8
2009-08-11T10:59:23Z
[ "python", "oop", "super" ]
Is it a good idea to use super() in Python?
1,259,547
<p>Or should I just explicitly reference the superclasses whose methods I want to call?</p> <p>It seems brittle to repeat the names of super classes when referencing their constructors, but this page <a href="http://fuhm.net/super-harmful/">http://fuhm.net/super-harmful/</a> makes some good arguments against using sup...
10
2009-08-11T10:32:51Z
1,259,935
<p>The problem people have with <code>super</code> is more a problem of multiple inheritance. So it is a little unfair to blame <code>super</code>. Without <code>super</code> multiple inheritance is even worse. Michele Simionato nicely wrapped this up in his <a href="http://www.artima.com/weblogs/viewpost.jsp?thread=23...
3
2009-08-11T12:05:56Z
[ "python", "oop", "super" ]
Is it a good idea to use super() in Python?
1,259,547
<p>Or should I just explicitly reference the superclasses whose methods I want to call?</p> <p>It seems brittle to repeat the names of super classes when referencing their constructors, but this page <a href="http://fuhm.net/super-harmful/">http://fuhm.net/super-harmful/</a> makes some good arguments against using sup...
10
2009-08-11T10:32:51Z
1,261,712
<p>super() tries to solve for you the problem of multiple inheritance; it's hard to replicate its semantics and you certainly shouldn't create any new semantics unless you're completely sure. </p> <p>For single inheritance, there's really no difference between </p> <pre><code>class X(Y): def func(self): Y...
2
2009-08-11T17:05:40Z
[ "python", "oop", "super" ]
iCalendar reader for Python?
1,259,857
<p>I'm looking to automate the status reports that I have to send to my manager. Since I use a to-do software that writes to iCalendar format, I would like be able to format an email out of the ics file.</p> <p>I'm starting my work with: <a href="http://codespeak.net/icalendar/" rel="nofollow">http://codespeak.net/ica...
2
2009-08-11T11:41:45Z
16,740,550
<p>I know this question is old, but this looks to be the most popular Python iCalendar parser these days. It's available on Pypi.</p> <p>Pypi page: <a href="https://pypi.python.org/pypi/icalendar" rel="nofollow">https://pypi.python.org/pypi/icalendar</a><br> Documentation: <a href="http://icalendar.readthedocs.org/en...
2
2013-05-24T17:28:32Z
[ "python", "icalendar" ]
iCalendar reader for Python?
1,259,857
<p>I'm looking to automate the status reports that I have to send to my manager. Since I use a to-do software that writes to iCalendar format, I would like be able to format an email out of the ics file.</p> <p>I'm starting my work with: <a href="http://codespeak.net/icalendar/" rel="nofollow">http://codespeak.net/ica...
2
2009-08-11T11:41:45Z
30,962,466
<p>There is <a href="https://github.com/C4ptainCrunch/ics.py" rel="nofollow">ics.py</a> which has a very "pythonic" interfaces and abstracts away the not very intuitive syntax of the iCalendar format <a href="http://tools.ietf.org/html/rfc5545" rel="nofollow">RFC5545</a>.</p> <p>Example:</p> <pre><code>&gt;&gt;&gt; f...
0
2015-06-21T08:07:40Z
[ "python", "icalendar" ]
How can I use Emacs Flymake mode for python with pyflakes and pylint checking code?
1,259,873
<p>For checking code in python mode I use flymake with <a href="http://www.emacswiki.org/cgi-bin/wiki/PythonMode#toc8">pyflakes</a></p> <p>Also I want check code style (pep8) with pylint (description on the same page with pyflakes)</p> <p>This solutions work. But I can't configure flymake for work with pyflakes and ...
22
2009-08-11T11:47:53Z
1,261,640
<p>You may want to check out the Lisp script here (<a href="http://charlie137-2.blogspot.com/2009/08/check-python-coding-style-on-fly-with.html" rel="nofollow">http://charlie137-2.blogspot.com/2009/08/check-python-coding-style-on-fly-with.html</a>), which should help with checking PEP8 a la pep8.py. I don't use pyflake...
0
2009-08-11T16:54:28Z
[ "python", "emacs", "pylint", "pep8", "pyflakes" ]
How can I use Emacs Flymake mode for python with pyflakes and pylint checking code?
1,259,873
<p>For checking code in python mode I use flymake with <a href="http://www.emacswiki.org/cgi-bin/wiki/PythonMode#toc8">pyflakes</a></p> <p>Also I want check code style (pep8) with pylint (description on the same page with pyflakes)</p> <p>This solutions work. But I can't configure flymake for work with pyflakes and ...
22
2009-08-11T11:47:53Z
1,393,590
<p>Well, flymake is just looking for a executable command thats output lines in a predefined format. You can make a shell script for example that will call successively all the checkers you want...</p> <p>You must also make sure that your script ends by returning errorlevel 0. So this is an example:</p> <p>This is wh...
34
2009-09-08T11:57:18Z
[ "python", "emacs", "pylint", "pep8", "pyflakes" ]
How can I use Emacs Flymake mode for python with pyflakes and pylint checking code?
1,259,873
<p>For checking code in python mode I use flymake with <a href="http://www.emacswiki.org/cgi-bin/wiki/PythonMode#toc8">pyflakes</a></p> <p>Also I want check code style (pep8) with pylint (description on the same page with pyflakes)</p> <p>This solutions work. But I can't configure flymake for work with pyflakes and ...
22
2009-08-11T11:47:53Z
1,621,489
<p>Usually one can enable flymake mode in the python-mode-hook. Unfortunately that causes issues with things like py-execute-buffer which create temporary buffers which invoke the hook and then cause flymake mode to hiccup because of the lack of "real file". The solution is to modify the conditions where you add the ho...
7
2009-10-25T17:31:25Z
[ "python", "emacs", "pylint", "pep8", "pyflakes" ]
How can I use Emacs Flymake mode for python with pyflakes and pylint checking code?
1,259,873
<p>For checking code in python mode I use flymake with <a href="http://www.emacswiki.org/cgi-bin/wiki/PythonMode#toc8">pyflakes</a></p> <p>Also I want check code style (pep8) with pylint (description on the same page with pyflakes)</p> <p>This solutions work. But I can't configure flymake for work with pyflakes and ...
22
2009-08-11T11:47:53Z
16,185,035
<p>Windows batch version of vaab's <code>pychechker</code></p> <pre><code>@echo on pylint %1 pep8 --ignore=E221,E701,E202 --repeat %1 pyflakes %1 </code></pre>
0
2013-04-24T06:39:12Z
[ "python", "emacs", "pylint", "pep8", "pyflakes" ]
Python : Assert that variable is instance method?
1,259,963
<p>How can one check if a variable is an instance method or not? I'm using python 2.5.</p> <p>Something like this:</p> <pre><code>class Test: def method(self): pass assert is_instance_method(Test().method) </code></pre>
25
2009-08-11T12:10:54Z
1,260,881
<p>If you want to know if it is precisely an instance method use the following function. (It considers methods that are defined on a metaclass and accessed on a class class methods, although they could also be considered instance methods)</p> <pre><code>import types def is_instance_method(obj): """Checks if an obj...
8
2009-08-11T14:53:48Z
[ "python", "methods", "instance", "assert" ]
Python : Assert that variable is instance method?
1,259,963
<p>How can one check if a variable is an instance method or not? I'm using python 2.5.</p> <p>Something like this:</p> <pre><code>class Test: def method(self): pass assert is_instance_method(Test().method) </code></pre>
25
2009-08-11T12:10:54Z
1,260,997
<p><a href="http://docs.python.org/library/inspect.html#inspect.ismethod"><code>inspect.ismethod</code></a> is what you want to find out if you definitely have a method, rather than just something you can call.</p> <pre><code>import inspect def foo(): pass class Test(object): def method(self): pass print inspec...
39
2009-08-11T15:10:56Z
[ "python", "methods", "instance", "assert" ]
OS locale support for use in Python
1,259,971
<p>The following Python code works on my Windows machine (Python 2.5.4), but doesn't on my Debian machine (Python 2.5.0). I'm guessing it's OS dependent.</p> <pre><code>import locale locale.setlocale( locale.LC_ALL, 'English_United States.1252' ) </code></pre> <p>I receive the following error:</p> <pre><code>Traceba...
15
2009-08-11T12:12:19Z
1,260,005
<p>It is OS dependent.</p> <p>To get the list of local available you can use <code>locale -a</code> in a shell</p> <p>I think the local you want is something like <a href="http://en.wikipedia.org/wiki/Windows-1252"><code>Windows-1252</code></a></p>
21
2009-08-11T12:20:27Z
[ "python", "locale" ]
OS locale support for use in Python
1,259,971
<p>The following Python code works on my Windows machine (Python 2.5.4), but doesn't on my Debian machine (Python 2.5.0). I'm guessing it's OS dependent.</p> <pre><code>import locale locale.setlocale( locale.LC_ALL, 'English_United States.1252' ) </code></pre> <p>I receive the following error:</p> <pre><code>Traceba...
15
2009-08-11T12:12:19Z
1,260,101
<p>Look inside the <code>locale.locale_alias</code> dictionary.</p> <pre><code>&gt;&gt;&gt; import locale &gt;&gt;&gt; len(locale.locale_alias) 789 &gt;&gt;&gt; locale.locale_alias.keys()[:5] ['ko_kr.euc', 'is_is', 'ja_jp.mscode', 'kw_gb@euro', 'yi_us.cp1255'] &gt;&gt;&gt; </code></pre> <p>(In my 2.6.2 installation t...
7
2009-08-11T12:40:55Z
[ "python", "locale" ]
OS locale support for use in Python
1,259,971
<p>The following Python code works on my Windows machine (Python 2.5.4), but doesn't on my Debian machine (Python 2.5.0). I'm guessing it's OS dependent.</p> <pre><code>import locale locale.setlocale( locale.LC_ALL, 'English_United States.1252' ) </code></pre> <p>I receive the following error:</p> <pre><code>Traceba...
15
2009-08-11T12:12:19Z
5,661,043
<p>try</p> <pre><code>apt-get install locales-all </code></pre> <p>for me it works like a charm</p>
9
2011-04-14T09:24:28Z
[ "python", "locale" ]
OS locale support for use in Python
1,259,971
<p>The following Python code works on my Windows machine (Python 2.5.4), but doesn't on my Debian machine (Python 2.5.0). I'm guessing it's OS dependent.</p> <pre><code>import locale locale.setlocale( locale.LC_ALL, 'English_United States.1252' ) </code></pre> <p>I receive the following error:</p> <pre><code>Traceba...
15
2009-08-11T12:12:19Z
12,976,242
<p>On Ubuntu Precise type</p> <p>sudo locale-gen en_US</p>
1
2012-10-19T14:19:59Z
[ "python", "locale" ]
How to comply to PEP 257 docstrings when using Python's optparse module?
1,259,982
<p>According to <a href="http://www.python.org/dev/peps/pep-0257/#multi-line-docstrings" rel="nofollow">PEP 257</a> the docstring of command line script should be its usage message.</p> <blockquote> <p>The docstring of a script (a stand-alone program) should be usable as its "usage" message, printed when the s...
5
2009-08-11T12:14:49Z
1,260,007
<p>Choice 1: Copy and paste. Not DRY, but workable.</p> <p>Choice 2: Parse your own docstring to strip out the description paragraph. It's always paragraph two, so you can split on '\n\n'.</p> <pre><code>usage, description= __doc__.split('\n\n')[:2] </code></pre> <p>Since <code>optparse</code> generates usage, you...
4
2009-08-11T12:21:22Z
[ "python", "optparse" ]
How to comply to PEP 257 docstrings when using Python's optparse module?
1,259,982
<p>According to <a href="http://www.python.org/dev/peps/pep-0257/#multi-line-docstrings" rel="nofollow">PEP 257</a> the docstring of command line script should be its usage message.</p> <blockquote> <p>The docstring of a script (a stand-alone program) should be usable as its "usage" message, printed when the s...
5
2009-08-11T12:14:49Z
1,261,663
<p>I think we have to be reasonable about this PEP's advice -- I would think it's fine to leave the module with <code>__doc__</code> being the short description that summarizes long usage. But if you're perfectionist:</p> <pre><code>'''&lt;tool name&gt; The full description and usage can be generated by optparse modu...
1
2009-08-11T16:57:39Z
[ "python", "optparse" ]
How to comply to PEP 257 docstrings when using Python's optparse module?
1,259,982
<p>According to <a href="http://www.python.org/dev/peps/pep-0257/#multi-line-docstrings" rel="nofollow">PEP 257</a> the docstring of command line script should be its usage message.</p> <blockquote> <p>The docstring of a script (a stand-alone program) should be usable as its "usage" message, printed when the s...
5
2009-08-11T12:14:49Z
10,065,543
<p>I wrote a module <code>docopt</code> to do exactly what you want – write usage-message in docstring and stay DRY. It also allows to avoid writing tedious <code>OptionParser</code> code at all, since <code>docopt</code> is generating parser based on the usage-message. </p> <p>Check it out: <a href="http://github....
6
2012-04-08T19:02:58Z
[ "python", "optparse" ]
Interrupt Python program deadlocked in a DLL
1,260,259
<p>How can I ensure a python program can be interrupted via Ctrl-C, or a similar mechanism, when it is deadlocked in code within a DLL?</p>
2
2009-08-11T13:12:48Z
1,260,378
<p>Not sure if this is exactly what you are asking, but there are issues when trying to interrupt (via Ctrl-C) a multi-threaded python process. Here is a video of a talk about the python Global Interpreter Lock that also discusses that issue:</p> <p><a href="http://blip.tv/file/2232410" rel="nofollow">Mindblowing Pyt...
1
2009-08-11T13:29:39Z
[ "python", "dll" ]
Interrupt Python program deadlocked in a DLL
1,260,259
<p>How can I ensure a python program can be interrupted via Ctrl-C, or a similar mechanism, when it is deadlocked in code within a DLL?</p>
2
2009-08-11T13:12:48Z
1,261,643
<p>You might want to take a look at <a href="http://mail.python.org/pipermail/python-list/2005-October/346842.html" rel="nofollow">this mailing list</a> for a couple other suggestions, but there aren't any conclusive answers.</p> <p>I've encountered the issue several times, and I can at least confirm that this happens...
0
2009-08-11T16:54:44Z
[ "python", "dll" ]
Locking a custom dictionary
1,260,649
<p>Good day pythonians,</p> <p>I want to make a custom dictionary with two main features:</p> <ol> <li>All keys are declared on creation</li> <li>It is impossible to add new keys or modify current ones (values are still modifiable)</li> </ol> <p>Right now code is this:</p> <pre><code>class pick(dict): """This wi...
2
2009-08-11T14:16:08Z
1,260,683
<p>Override the <code>__setitem__</code> method with your desired behavior, call <code>dict.__setitem__(self, key, value</code>) to modify the base dictionary without going through your base logic.</p> <pre><code>class ImmutableDict(dict): def __setitem__(self, key, value): if key not in self: ...
12
2009-08-11T14:21:13Z
[ "python", "dictionary", "locking" ]
Locking a custom dictionary
1,260,649
<p>Good day pythonians,</p> <p>I want to make a custom dictionary with two main features:</p> <ol> <li>All keys are declared on creation</li> <li>It is impossible to add new keys or modify current ones (values are still modifiable)</li> </ol> <p>Right now code is this:</p> <pre><code>class pick(dict): """This wi...
2
2009-08-11T14:16:08Z
1,260,688
<p>Something like</p> <pre><code>class UniqueDict(dict): def __init__(self, *args, **kwargs): dict.__init__(self, *args, **kwargs) def __setitem__(self, name, value): if name not in self: raise KeyError("%s not present") dict.__setitem__(self, name, value) </code></pre>
2
2009-08-11T14:21:31Z
[ "python", "dictionary", "locking" ]
Locking a custom dictionary
1,260,649
<p>Good day pythonians,</p> <p>I want to make a custom dictionary with two main features:</p> <ol> <li>All keys are declared on creation</li> <li>It is impossible to add new keys or modify current ones (values are still modifiable)</li> </ol> <p>Right now code is this:</p> <pre><code>class pick(dict): """This wi...
2
2009-08-11T14:16:08Z
1,260,695
<p>I suggest you to use delegation, rather than inheritance. If you inherit, all the previous methods of the dict will be inherited, but they could behave as you don't expect, thus ruining the assumptions you have on the class, and doing it silently.</p> <p>If you do delegation, you can fully control the methods you p...
2
2009-08-11T14:22:31Z
[ "python", "dictionary", "locking" ]
Python: import a file from a subdirectory
1,260,792
<p>I have a file called <code>tester.py</code>, located on <code>/project</code>.</p> <p><code>/project</code> has a subdirectory called <code>lib</code>, with a file called <code>BoxTime.py</code>:</p> <pre><code>/project/tester.py /project/lib/BoxTime.py </code></pre> <p>I want to import <code>BoxTime</code> from ...
180
2009-08-11T14:39:05Z
1,260,813
<p>Take a look at the Packages documentation (Section 6.4) here: <a href="http://docs.python.org/tutorial/modules.html">http://docs.python.org/tutorial/modules.html</a></p> <p>In short, you need to put a blank file named </p> <pre><code>__init__.py </code></pre> <p>in the "lib" directory.</p>
232
2009-08-11T14:42:10Z
[ "python", "module", "subdirectory", "python-import" ]
Python: import a file from a subdirectory
1,260,792
<p>I have a file called <code>tester.py</code>, located on <code>/project</code>.</p> <p><code>/project</code> has a subdirectory called <code>lib</code>, with a file called <code>BoxTime.py</code>:</p> <pre><code>/project/tester.py /project/lib/BoxTime.py </code></pre> <p>I want to import <code>BoxTime</code> from ...
180
2009-08-11T14:39:05Z
1,260,814
<p>Try <code>import .lib.BoxTime</code>. For more information read about relative import in <a href="http://dinsdale.python.org/dev/peps/pep-0328/#guido-s-decision">PEP 328</a>.</p>
8
2009-08-11T14:42:13Z
[ "python", "module", "subdirectory", "python-import" ]
Python: import a file from a subdirectory
1,260,792
<p>I have a file called <code>tester.py</code>, located on <code>/project</code>.</p> <p><code>/project</code> has a subdirectory called <code>lib</code>, with a file called <code>BoxTime.py</code>:</p> <pre><code>/project/tester.py /project/lib/BoxTime.py </code></pre> <p>I want to import <code>BoxTime</code> from ...
180
2009-08-11T14:39:05Z
1,260,832
<p>Does your lib directory contain a <code>__init__.py</code> file?</p> <p>Python uses <code>__init__.py</code> to determine if a directory is a module.</p>
15
2009-08-11T14:44:44Z
[ "python", "module", "subdirectory", "python-import" ]
Python: import a file from a subdirectory
1,260,792
<p>I have a file called <code>tester.py</code>, located on <code>/project</code>.</p> <p><code>/project</code> has a subdirectory called <code>lib</code>, with a file called <code>BoxTime.py</code>:</p> <pre><code>/project/tester.py /project/lib/BoxTime.py </code></pre> <p>I want to import <code>BoxTime</code> from ...
180
2009-08-11T14:39:05Z
1,260,846
<ul> <li>Create a subdirectory named lib.</li> <li>Create an empty file named lib\__init__.py.</li> <li><p>In lib\BoxTime.py, write a function foo() like this:</p> <pre><code>def foo(): print "foo!" </code></pre></li> <li><p>In your client code in the directory above lib, write:</p> <pre><code>from lib import Box...
63
2009-08-11T14:46:34Z
[ "python", "module", "subdirectory", "python-import" ]
Python: import a file from a subdirectory
1,260,792
<p>I have a file called <code>tester.py</code>, located on <code>/project</code>.</p> <p><code>/project</code> has a subdirectory called <code>lib</code>, with a file called <code>BoxTime.py</code>:</p> <pre><code>/project/tester.py /project/lib/BoxTime.py </code></pre> <p>I want to import <code>BoxTime</code> from ...
180
2009-08-11T14:39:05Z
14,999,050
<p>You can try inserting it in <code>sys.path</code>:</p> <pre><code>sys.path.insert(0, './lib') import BoxTime </code></pre>
19
2013-02-21T09:47:42Z
[ "python", "module", "subdirectory", "python-import" ]
Python: import a file from a subdirectory
1,260,792
<p>I have a file called <code>tester.py</code>, located on <code>/project</code>.</p> <p><code>/project</code> has a subdirectory called <code>lib</code>, with a file called <code>BoxTime.py</code>:</p> <pre><code>/project/tester.py /project/lib/BoxTime.py </code></pre> <p>I want to import <code>BoxTime</code> from ...
180
2009-08-11T14:39:05Z
32,831,635
<p>try this:</p> <p><code>from lib import BoxTime</code></p>
0
2015-09-28T20:53:28Z
[ "python", "module", "subdirectory", "python-import" ]
Python: import a file from a subdirectory
1,260,792
<p>I have a file called <code>tester.py</code>, located on <code>/project</code>.</p> <p><code>/project</code> has a subdirectory called <code>lib</code>, with a file called <code>BoxTime.py</code>:</p> <pre><code>/project/tester.py /project/lib/BoxTime.py </code></pre> <p>I want to import <code>BoxTime</code> from ...
180
2009-08-11T14:39:05Z
35,272,100
<p>I do this which basically covers all cases (make sure you have the blank <code>__init__.py</code> in relative/path/to/your/lib/folder):</p> <pre><code>import sys, os sys.path.append(os.path.dirname(os.path.realpath(__file__)) + "/relative/path/to/your/lib/folder") import someFileNameWhichIsInTheFolder ... somefile....
2
2016-02-08T14:32:09Z
[ "python", "module", "subdirectory", "python-import" ]
Which credentials should I put in for Google App Engine BulkLoader at development server?
1,260,835
<p>I would like to ask which kind of credentials do I need to put on for importing data using the Google App Engine BulkLoader class</p> <pre><code>appcfg.py upload_data --config_file=models.py --filename=listcountries.csv --kind=CMSCountry --url=http://localhost:8178/remote_api vit/ </code></pre> <p>And then it asks...
5
2009-08-11T14:45:05Z
1,262,651
<p>I recommend you follow the advice given <a href="http://blog.suinova.com/2009/03/tutorial-on-bulkloading-data-onto-app.html" rel="nofollow">here</a>, and I quote:</p> <blockquote> <p>add this to app.yaml file:</p> <pre><code>-- url: /loadusers script: myloader.py login: admin </code></pre> <p>Note that if...
4
2009-08-11T20:12:34Z
[ "python", "google-app-engine" ]
Which credentials should I put in for Google App Engine BulkLoader at development server?
1,260,835
<p>I would like to ask which kind of credentials do I need to put on for importing data using the Google App Engine BulkLoader class</p> <pre><code>appcfg.py upload_data --config_file=models.py --filename=listcountries.csv --kind=CMSCountry --url=http://localhost:8178/remote_api vit/ </code></pre> <p>And then it asks...
5
2009-08-11T14:45:05Z
1,741,088
<p>Next worked for me: </p> <ul> <li><p>removing the line</p> <pre><code>login:admin </code></pre> <p>from app.yaml</p></li> <li><p>Updating app cofig: </p> <pre><code>appcfg.py update [app-id] </code></pre></li> <li><p>(Re)starting local server: </p> <pre><code>appserver [app-id] </code></pre></li> <li><p>Upload...
0
2009-11-16T09:37:49Z
[ "python", "google-app-engine" ]
Which credentials should I put in for Google App Engine BulkLoader at development server?
1,260,835
<p>I would like to ask which kind of credentials do I need to put on for importing data using the Google App Engine BulkLoader class</p> <pre><code>appcfg.py upload_data --config_file=models.py --filename=listcountries.csv --kind=CMSCountry --url=http://localhost:8178/remote_api vit/ </code></pre> <p>And then it asks...
5
2009-08-11T14:45:05Z
1,936,912
<p>Edit: Look at my <a href="#2195685" rel="nofollow">new solution</a></p> <p>This problem is still present. I have opened <a href="http://code.google.com/p/googleappengine/issues/detail?id=2440" rel="nofollow">a ticket</a> to ask if the authentication could be bypassed on the local dev server. Please vote for this is...
3
2009-12-20T20:27:27Z
[ "python", "google-app-engine" ]
Which credentials should I put in for Google App Engine BulkLoader at development server?
1,260,835
<p>I would like to ask which kind of credentials do I need to put on for importing data using the Google App Engine BulkLoader class</p> <pre><code>appcfg.py upload_data --config_file=models.py --filename=listcountries.csv --kind=CMSCountry --url=http://localhost:8178/remote_api vit/ </code></pre> <p>And then it asks...
5
2009-08-11T14:45:05Z
1,954,545
<p>Yes, comment out the admin requirement for the remote_api:</p> <p>[app.yaml] <PRE> - url: /remote_api script: $PYTHON_LIB/google/appengine/ext/remote_api/handler.py # login: admin </PRE></p> <p>Then run this command:</p> <p><PRE> $ bulkloader.py --dump --kind=DbMyKind --url=<a href="http://localhost:8080/remot...
2
2009-12-23T18:33:08Z
[ "python", "google-app-engine" ]
Which credentials should I put in for Google App Engine BulkLoader at development server?
1,260,835
<p>I would like to ask which kind of credentials do I need to put on for importing data using the Google App Engine BulkLoader class</p> <pre><code>appcfg.py upload_data --config_file=models.py --filename=listcountries.csv --kind=CMSCountry --url=http://localhost:8178/remote_api vit/ </code></pre> <p>And then it asks...
5
2009-08-11T14:45:05Z
2,018,126
<p>You need create an admin credential in your local development server first. </p> <p>With your firefox (or chrome safari etc), open <a href="http://localhost:8178/remote_api" rel="nofollow">http://localhost:8178/remote_api</a>, you will be asked to login (without password), enter an email as your login, and tick the...
1
2010-01-07T03:59:15Z
[ "python", "google-app-engine" ]
Which credentials should I put in for Google App Engine BulkLoader at development server?
1,260,835
<p>I would like to ask which kind of credentials do I need to put on for importing data using the Google App Engine BulkLoader class</p> <pre><code>appcfg.py upload_data --config_file=models.py --filename=listcountries.csv --kind=CMSCountry --url=http://localhost:8178/remote_api vit/ </code></pre> <p>And then it asks...
5
2009-08-11T14:45:05Z
2,195,685
<p><strong>EUREKA:</strong> I found the way to use the <code>bulkloader.py</code> tool without having to manually enter login credentials.</p> <p>Here are the 2 steps:</p> <hr> <p>Set your <code>app.yaml</code> file up. Example:</p> <pre><code>- url: /remote_api script: $PYTHON_LIB/google/appengine/ext/remote_api...
5
2010-02-03T21:41:56Z
[ "python", "google-app-engine" ]
Which credentials should I put in for Google App Engine BulkLoader at development server?
1,260,835
<p>I would like to ask which kind of credentials do I need to put on for importing data using the Google App Engine BulkLoader class</p> <pre><code>appcfg.py upload_data --config_file=models.py --filename=listcountries.csv --kind=CMSCountry --url=http://localhost:8178/remote_api vit/ </code></pre> <p>And then it asks...
5
2009-08-11T14:45:05Z
2,534,705
<p>Another solution is to stub out the auth function with lambda: <a href="http://www.carlosble.com/?p=603" rel="nofollow">http://www.carlosble.com/?p=603</a></p>
0
2010-03-28T21:46:54Z
[ "python", "google-app-engine" ]
Which credentials should I put in for Google App Engine BulkLoader at development server?
1,260,835
<p>I would like to ask which kind of credentials do I need to put on for importing data using the Google App Engine BulkLoader class</p> <pre><code>appcfg.py upload_data --config_file=models.py --filename=listcountries.csv --kind=CMSCountry --url=http://localhost:8178/remote_api vit/ </code></pre> <p>And then it asks...
5
2009-08-11T14:45:05Z
10,075,187
<p>I use this commands to transfer data from local to remote server. File's extension (json) is important. Framework: django-nonrel, os: Win7.</p> <pre><code>manage.py dumpdata &gt;dump.json manage.py remote loaddata dump.json </code></pre>
1
2012-04-09T15:02:35Z
[ "python", "google-app-engine" ]
Which credentials should I put in for Google App Engine BulkLoader at development server?
1,260,835
<p>I would like to ask which kind of credentials do I need to put on for importing data using the Google App Engine BulkLoader class</p> <pre><code>appcfg.py upload_data --config_file=models.py --filename=listcountries.csv --kind=CMSCountry --url=http://localhost:8178/remote_api vit/ </code></pre> <p>And then it asks...
5
2009-08-11T14:45:05Z
22,672,978
<p>Use <code>aaa@gmail.com</code> for username.</p> <p>Use <code>a</code> for password.</p> <p>It works. Magically.</p>
2
2014-03-26T21:02:24Z
[ "python", "google-app-engine" ]
Pythonic way of searching for a substring in a list
1,260,947
<p>I have a list of strings - something like </p> <pre><code>mytext = ['This is some text','this is yet more text','This is text that contains the substring foobar123','yet more text'] </code></pre> <p>I want to find the first occurrence of anything that starts with foobar. If I was grepping then I would do search f...
3
2009-08-11T15:03:59Z
1,260,964
<pre><code>for s in lst: if 'foobar' in s: print(s) </code></pre>
6
2009-08-11T15:06:50Z
[ "string", "list", "python", "substrings" ]