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 |
|---|---|---|---|---|---|---|---|---|---|
On the google app engine, why does my 'import' statement fail on Live, but work on Dev(localmachine)? | 1,914,881 | <p>I have a python/django application that runs on the google app engine.</p>
<p>My views.py file has some imports...</p>
<pre><code>from commands.userCommands import RegisterUserCommand
from commands.accountCommands import CreateNewAccountCommand, RenameAccountCommand
</code></pre>
<p>These imports work fine on my ... | 1 | 2009-12-16T14:11:38Z | 1,915,011 | <p>The <code>__init__.py</code> files are required to make Python treat the directories as containing packages, so you need a </p>
<pre><code>commands/__init__.py
</code></pre>
<p>file in your directory structure. See <a href="http://docs.python.org/tutorial/modules.html" rel="nofollow">http://docs.python.org/tutoria... | 2 | 2009-12-16T14:33:37Z | [
"python",
"django",
"google-app-engine"
] |
On the google app engine, why does my 'import' statement fail on Live, but work on Dev(localmachine)? | 1,914,881 | <p>I have a python/django application that runs on the google app engine.</p>
<p>My views.py file has some imports...</p>
<pre><code>from commands.userCommands import RegisterUserCommand
from commands.accountCommands import CreateNewAccountCommand, RenameAccountCommand
</code></pre>
<p>These imports work fine on my ... | 1 | 2009-12-16T14:11:38Z | 1,915,547 | <p>You could be running into a clash with Python's own <a href="http://docs.python.org/library/commands.html?highlight=commands#module-commands" rel="nofollow"><code>commands</code></a> module (which doesn't have submodules like yours) -- naming your own modules and packages in ways that are meant to hide ones in the s... | 5 | 2009-12-16T15:52:51Z | [
"python",
"django",
"google-app-engine"
] |
Python: List to ints to a single number? | 1,914,883 | <p>Say i have a several list if ints:</p>
<pre><code>x = [['48', '5', '0'], ['77', '56', '0'],
['23', '76', '34', '0']]
</code></pre>
<p>I want this list to be converted to a single number, but the the single number type is still an integer i.e.:</p>
<pre><code>4850775602376340
</code></pre>
<p>i have been using t... | 0 | 2009-12-16T14:11:51Z | 1,914,906 | <pre><code>>>> x = [['48', '5', '0'], ['77', '56', '0'], ['23', '76', '34', '0']]
>>> int(''.join([''.join(i) for i in x ] ))
4850775602376340
</code></pre>
| 1 | 2009-12-16T14:15:39Z | [
"python",
"list"
] |
Python: List to ints to a single number? | 1,914,883 | <p>Say i have a several list if ints:</p>
<pre><code>x = [['48', '5', '0'], ['77', '56', '0'],
['23', '76', '34', '0']]
</code></pre>
<p>I want this list to be converted to a single number, but the the single number type is still an integer i.e.:</p>
<pre><code>4850775602376340
</code></pre>
<p>i have been using t... | 0 | 2009-12-16T14:11:51Z | 1,914,908 | <p>Its a list of lists, so </p>
<pre><code>num = int(''.join(''.join(l) for l in lists))
</code></pre>
<p>or</p>
<pre><code>def flatten( nested ):
for inner in nested:
for x in inner:
yield x
num = ''.join(flatten(lists))
</code></pre>
| 2 | 2009-12-16T14:16:07Z | [
"python",
"list"
] |
Python: List to ints to a single number? | 1,914,883 | <p>Say i have a several list if ints:</p>
<pre><code>x = [['48', '5', '0'], ['77', '56', '0'],
['23', '76', '34', '0']]
</code></pre>
<p>I want this list to be converted to a single number, but the the single number type is still an integer i.e.:</p>
<pre><code>4850775602376340
</code></pre>
<p>i have been using t... | 0 | 2009-12-16T14:11:51Z | 1,914,909 | <pre><code>>>> int(''.join(reduce(lambda a, b: a + b, x)))
4850775602376340
</code></pre>
| 6 | 2009-12-16T14:16:07Z | [
"python",
"list"
] |
Python: List to ints to a single number? | 1,914,883 | <p>Say i have a several list if ints:</p>
<pre><code>x = [['48', '5', '0'], ['77', '56', '0'],
['23', '76', '34', '0']]
</code></pre>
<p>I want this list to be converted to a single number, but the the single number type is still an integer i.e.:</p>
<pre><code>4850775602376340
</code></pre>
<p>i have been using t... | 0 | 2009-12-16T14:11:51Z | 1,914,943 | <pre><code>>>> int(''.join(j for i in x for j in i))
4850775602376340
</code></pre>
| 3 | 2009-12-16T14:22:57Z | [
"python",
"list"
] |
Python: List to ints to a single number? | 1,914,883 | <p>Say i have a several list if ints:</p>
<pre><code>x = [['48', '5', '0'], ['77', '56', '0'],
['23', '76', '34', '0']]
</code></pre>
<p>I want this list to be converted to a single number, but the the single number type is still an integer i.e.:</p>
<pre><code>4850775602376340
</code></pre>
<p>i have been using t... | 0 | 2009-12-16T14:11:51Z | 1,914,951 | <p>I'd use <a href="http://docs.python.org/library/itertools.html#itertools.itertools.chain.from%5Fiterable" rel="nofollow"><code>itertools.chain.from_iterable</code></a> for this (new in python 2.6)</p>
<p>Example code:</p>
<pre><code>import itertools
x = [['48', '5', '0'], ['77', '56', '0'], ['23', '76', '34', '0']... | 6 | 2009-12-16T14:24:38Z | [
"python",
"list"
] |
Python: List to ints to a single number? | 1,914,883 | <p>Say i have a several list if ints:</p>
<pre><code>x = [['48', '5', '0'], ['77', '56', '0'],
['23', '76', '34', '0']]
</code></pre>
<p>I want this list to be converted to a single number, but the the single number type is still an integer i.e.:</p>
<pre><code>4850775602376340
</code></pre>
<p>i have been using t... | 0 | 2009-12-16T14:11:51Z | 1,915,066 | <p>Enough good answers already ... just wanted to add the treatment of unlimited nesting:</p>
<pre><code>def flatten(obj):
if not isinstance(obj, list):
return obj
else:
return ''.join([flatten(x) for x in obj])
>>> x = [['48', '5', '0'], ['77', '56', '0'], ['23', '76', '34', '0']]
&g... | 1 | 2009-12-16T14:41:13Z | [
"python",
"list"
] |
Python: List to ints to a single number? | 1,914,883 | <p>Say i have a several list if ints:</p>
<pre><code>x = [['48', '5', '0'], ['77', '56', '0'],
['23', '76', '34', '0']]
</code></pre>
<p>I want this list to be converted to a single number, but the the single number type is still an integer i.e.:</p>
<pre><code>4850775602376340
</code></pre>
<p>i have been using t... | 0 | 2009-12-16T14:11:51Z | 1,915,540 | <p>simply put:</p>
<ol>
<li><p>flattening the list</p>
<pre><code>[e for e in (itertools.chain(*x))]
</code></pre></li>
<li><p>removing the negative sign</p>
<pre><code>e.replace('-','')
</code></pre></li>
<li><p>joining the numbers in a list into a string and turning it into a number</p>
<pre><code>int(''.join(x))... | 1 | 2009-12-16T15:51:38Z | [
"python",
"list"
] |
split a generator/iterable every n items in python (splitEvery) | 1,915,170 | <p>I'm trying to write the Haskel function 'splitEvery' in Python. Here is it's definition:</p>
<pre><code>splitEvery :: Int -> [e] -> [[e]]
@'splitEvery' n@ splits a list into length-n pieces. The last
piece will be shorter if @n@ does not evenly divide the length of
the list.
</code></pre>
<p>The... | 16 | 2009-12-16T14:58:28Z | 1,915,220 | <p>Why not do it like this? Looks almost like your <code>splitEvery_2</code> function.</p>
<pre><code>def splitEveryN(n, it):
return [it[i:i+n] for i in range(0, len(it), n)]
</code></pre>
<p>Actually it only takes away the unnecessary step interval from the slice in your solution. :)</p>
| 1 | 2009-12-16T15:06:18Z | [
"python",
"iterator",
"split"
] |
split a generator/iterable every n items in python (splitEvery) | 1,915,170 | <p>I'm trying to write the Haskel function 'splitEvery' in Python. Here is it's definition:</p>
<pre><code>splitEvery :: Int -> [e] -> [[e]]
@'splitEvery' n@ splits a list into length-n pieces. The last
piece will be shorter if @n@ does not evenly divide the length of
the list.
</code></pre>
<p>The... | 16 | 2009-12-16T14:58:28Z | 1,915,274 | <p>Here is how you deal with list vs iterator:</p>
<pre><code>def isList(L): # Implement it somehow - returns True or false
...
return (list, lambda x:x)[int(islist(L))](result)
</code></pre>
| 0 | 2009-12-16T15:15:48Z | [
"python",
"iterator",
"split"
] |
split a generator/iterable every n items in python (splitEvery) | 1,915,170 | <p>I'm trying to write the Haskel function 'splitEvery' in Python. Here is it's definition:</p>
<pre><code>splitEvery :: Int -> [e] -> [[e]]
@'splitEvery' n@ splits a list into length-n pieces. The last
piece will be shorter if @n@ does not evenly divide the length of
the list.
</code></pre>
<p>The... | 16 | 2009-12-16T14:58:28Z | 1,915,307 | <pre><code>from itertools import islice
def split_every(n, iterable):
i = iter(iterable)
piece = list(islice(i, n))
while piece:
yield piece
piece = list(islice(i, n))
</code></pre>
<p>Some tests:</p>
<pre><code>>>> list(split_every(5, range(9)))
[[0, 1, 2, 3, 4], [5, 6, 7, 8]]
... | 25 | 2009-12-16T15:21:05Z | [
"python",
"iterator",
"split"
] |
split a generator/iterable every n items in python (splitEvery) | 1,915,170 | <p>I'm trying to write the Haskel function 'splitEvery' in Python. Here is it's definition:</p>
<pre><code>splitEvery :: Int -> [e] -> [[e]]
@'splitEvery' n@ splits a list into length-n pieces. The last
piece will be shorter if @n@ does not evenly divide the length of
the list.
</code></pre>
<p>The... | 16 | 2009-12-16T14:58:28Z | 1,915,367 | <p>I think <a href="http://stackoverflow.com/questions/434287/what-is-the-most-pythonic-way-to-iterate-over-a-list-in-chunks">those</a> <a href="http://stackoverflow.com/questions/312443/how-do-you-split-a-list-into-evenly-sized-chunks-in-python">questions</a> are almost equal</p>
<p>Changing a little bit to crop the ... | 2 | 2009-12-16T15:29:16Z | [
"python",
"iterator",
"split"
] |
split a generator/iterable every n items in python (splitEvery) | 1,915,170 | <p>I'm trying to write the Haskel function 'splitEvery' in Python. Here is it's definition:</p>
<pre><code>splitEvery :: Int -> [e] -> [[e]]
@'splitEvery' n@ splits a list into length-n pieces. The last
piece will be shorter if @n@ does not evenly divide the length of
the list.
</code></pre>
<p>The... | 16 | 2009-12-16T14:58:28Z | 9,255,766 | <pre><code>def chunks(iterable,n):
"""assumes n is an integer>0
"""
iterable=iter(iterable)
while True:
result=[]
for i in range(n):
try:
a=next(iterable)
except StopIteration:
break
else:
result.appen... | 0 | 2012-02-13T04:53:47Z | [
"python",
"iterator",
"split"
] |
split a generator/iterable every n items in python (splitEvery) | 1,915,170 | <p>I'm trying to write the Haskel function 'splitEvery' in Python. Here is it's definition:</p>
<pre><code>splitEvery :: Int -> [e] -> [[e]]
@'splitEvery' n@ splits a list into length-n pieces. The last
piece will be shorter if @n@ does not evenly divide the length of
the list.
</code></pre>
<p>The... | 16 | 2009-12-16T14:58:28Z | 11,572,276 | <p>this will do the trick</p>
<pre><code>from itertools import izip_longest
izip_longest(it[::2], it[1::2])
</code></pre>
<p>where *it* is some iterable</p>
<hr>
<p>Example:</p>
<pre><code>izip_longest('abcdef'[::2], 'abcdef'[1::2]) -> ('a', 'b'), ('c', 'd'), ('e', 'f')
</code></pre>
<p>Let's break this down</... | -1 | 2012-07-20T03:05:21Z | [
"python",
"iterator",
"split"
] |
split a generator/iterable every n items in python (splitEvery) | 1,915,170 | <p>I'm trying to write the Haskel function 'splitEvery' in Python. Here is it's definition:</p>
<pre><code>splitEvery :: Int -> [e] -> [[e]]
@'splitEvery' n@ splits a list into length-n pieces. The last
piece will be shorter if @n@ does not evenly divide the length of
the list.
</code></pre>
<p>The... | 16 | 2009-12-16T14:58:28Z | 22,919,323 | <p>Here's a quick one-liner version. Like Haskell's, it is lazy.</p>
<pre><code>from itertools import islice, takewhile, count
split_every = (lambda n, it:
takewhile(bool, (list(islice(it, n)) for _ in count(0))))
</code></pre>
<p>This requires that you use <code>iter</code> <strong>before</strong> calling <code>... | 11 | 2014-04-07T17:36:55Z | [
"python",
"iterator",
"split"
] |
split a generator/iterable every n items in python (splitEvery) | 1,915,170 | <p>I'm trying to write the Haskel function 'splitEvery' in Python. Here is it's definition:</p>
<pre><code>splitEvery :: Int -> [e] -> [[e]]
@'splitEvery' n@ splits a list into length-n pieces. The last
piece will be shorter if @n@ does not evenly divide the length of
the list.
</code></pre>
<p>The... | 16 | 2009-12-16T14:58:28Z | 23,420,050 | <p>This is an answer that works for both list and generator:</p>
<pre><code>from itertools import count, groupby
def split_every(size, iterable):
c = count()
for k, g in groupby(iterable, lambda x: next(c)//size):
yield list(g) # or yield g if you want to output a generator
</code></pre>
| 1 | 2014-05-02T02:58:37Z | [
"python",
"iterator",
"split"
] |
split a generator/iterable every n items in python (splitEvery) | 1,915,170 | <p>I'm trying to write the Haskel function 'splitEvery' in Python. Here is it's definition:</p>
<pre><code>splitEvery :: Int -> [e] -> [[e]]
@'splitEvery' n@ splits a list into length-n pieces. The last
piece will be shorter if @n@ does not evenly divide the length of
the list.
</code></pre>
<p>The... | 16 | 2009-12-16T14:58:28Z | 28,562,419 | <p>A one-liner solution to this (supports iterators, uses standard library and a single generator comprehension):</p>
<pre><code>import itertools
def split_groups(iter_in, group_size):
return (item for _, item in itertools.groupby(enumerate(iter_in), key=lambda x: x[0] // group_size))
</code></pre>
| 1 | 2015-02-17T13:15:18Z | [
"python",
"iterator",
"split"
] |
Python: List of lists of integers to absolute value to single number | 1,915,342 | <p>If i had a list of list of integers say:</p>
<blockquote>
<p>[['12' '-4' '66' '0'], ['23' '4' '-5'
'0'], ['23' '77' '89' '-1' '0']]</p>
</blockquote>
<p>I wanted to convert the numbers to their absolute values and then to a single number, so the output would be:</p>
<blockquote>
<p>1246602345023778910</p>
<... | -1 | 2009-12-16T15:25:35Z | 1,915,422 | <p>What you gave above is a list of lists of strings.</p>
<p>I suggest a two-pass approach:</p>
<ol>
<li><p>Get integers from strings and take their absolutes:</p>
<p>[ abs(int(s)) for s in list ]</p></li>
<li><p>Combine these numbers into a string and turn it into an integer</p>
<p>''.join([ ''.join(x) for x in li... | 1 | 2009-12-16T15:36:44Z | [
"python",
"list",
"mapping",
"integer",
"absolute"
] |
Python: List of lists of integers to absolute value to single number | 1,915,342 | <p>If i had a list of list of integers say:</p>
<blockquote>
<p>[['12' '-4' '66' '0'], ['23' '4' '-5'
'0'], ['23' '77' '89' '-1' '0']]</p>
</blockquote>
<p>I wanted to convert the numbers to their absolute values and then to a single number, so the output would be:</p>
<blockquote>
<p>1246602345023778910</p>
<... | -1 | 2009-12-16T15:25:35Z | 1,915,452 | <p>You can use itertools.chain here to get rid of the nesting, concatenate the number-strings, remove the '-' signs and then turn them into a number. </p>
<pre><code>import itertools
mylist = [['12' '-4' '66' '0'], ['23' '4' '-5' '0'], ['23' '77' '89' '-1' '0']]
num = int( ''.join(itertools.chain(*mylist)).replace('-'... | 1 | 2009-12-16T15:39:53Z | [
"python",
"list",
"mapping",
"integer",
"absolute"
] |
Python: List of lists of integers to absolute value to single number | 1,915,342 | <p>If i had a list of list of integers say:</p>
<blockquote>
<p>[['12' '-4' '66' '0'], ['23' '4' '-5'
'0'], ['23' '77' '89' '-1' '0']]</p>
</blockquote>
<p>I wanted to convert the numbers to their absolute values and then to a single number, so the output would be:</p>
<blockquote>
<p>1246602345023778910</p>
<... | -1 | 2009-12-16T15:25:35Z | 1,915,473 | <p>What you're showing is (maybe) a list of lists of strings, and the syntax is extremely peculiar -- the sublists are shown with the normal, usual commas, but inside each there are just literal strings with spaces between them. If you actually type that into Python, you'll get a list where each sublist contains a sin... | 2 | 2009-12-16T15:42:51Z | [
"python",
"list",
"mapping",
"integer",
"absolute"
] |
Python: List of lists of integers to absolute value to single number | 1,915,342 | <p>If i had a list of list of integers say:</p>
<blockquote>
<p>[['12' '-4' '66' '0'], ['23' '4' '-5'
'0'], ['23' '77' '89' '-1' '0']]</p>
</blockquote>
<p>I wanted to convert the numbers to their absolute values and then to a single number, so the output would be:</p>
<blockquote>
<p>1246602345023778910</p>
<... | -1 | 2009-12-16T15:25:35Z | 1,915,587 | <p>I am new to Python, so please forgive me if there is a more efficient way :)</p>
<pre><code>#!/usr/bin/python
str = ''
lists = [['12' '-4' '66' '0'], ['23' '4' '-5' '0'], ['23' '77' '89' '-1' '0']]
for list in lists:
str += list[0].replace('-', '')
print int(str)
</code></pre>
| 0 | 2009-12-16T15:57:04Z | [
"python",
"list",
"mapping",
"integer",
"absolute"
] |
Python: List of lists of integers to absolute value to single number | 1,915,342 | <p>If i had a list of list of integers say:</p>
<blockquote>
<p>[['12' '-4' '66' '0'], ['23' '4' '-5'
'0'], ['23' '77' '89' '-1' '0']]</p>
</blockquote>
<p>I wanted to convert the numbers to their absolute values and then to a single number, so the output would be:</p>
<blockquote>
<p>1246602345023778910</p>
<... | -1 | 2009-12-16T15:25:35Z | 1,915,591 | <p>As pointed out in the other answers, your inner lists are not as 'listy' as they appear. Since commas are missing, Python will (I think) concatenate them all into one string thus giving you a list of one item. This will be the same as this:</p>
<pre><code>[['12-4660'], ['234-50'], ['237789-10']]
</code></pre>
<p... | 0 | 2009-12-16T15:57:29Z | [
"python",
"list",
"mapping",
"integer",
"absolute"
] |
Is python's sorted() function guaranteed to be stable? | 1,915,376 | <p>The <a href="http://docs.python.org/library/functions.html#sorted">documentation</a> doesn't guarantee that. Is there any other place that it is documented? </p>
<p>I'm guessing it might be stable since the sort method on lists is <a href="http://docs.python.org/library/stdtypes.html#mutable-sequence-types">guarant... | 40 | 2009-12-16T15:30:01Z | 1,915,418 | <p>Yes, the intention of the manual is indeed to guarantee that <code>sorted</code> is stable and indeed that it uses exactly the same algorithm as the <code>sort</code> method. I do realize that the docs aren't 100% clear about this identity; doc patches are always happily accepted!</p>
| 47 | 2009-12-16T15:36:08Z | [
"python",
"sorted",
"stable-sort"
] |
Is python's sorted() function guaranteed to be stable? | 1,915,376 | <p>The <a href="http://docs.python.org/library/functions.html#sorted">documentation</a> doesn't guarantee that. Is there any other place that it is documented? </p>
<p>I'm guessing it might be stable since the sort method on lists is <a href="http://docs.python.org/library/stdtypes.html#mutable-sequence-types">guarant... | 40 | 2009-12-16T15:30:01Z | 1,915,435 | <p>The <a href="http://www.python.org/doc/2.4.4/whatsnew/node12.html" rel="nofollow">"What's New" docs for Python 2.4</a> effectively make the point that sorted() first creates a list, then calls sort() on it, providing you with the guarantee you need though not in the "official" docs. You could also just check the so... | 1 | 2009-12-16T15:38:39Z | [
"python",
"sorted",
"stable-sort"
] |
Is python's sorted() function guaranteed to be stable? | 1,915,376 | <p>The <a href="http://docs.python.org/library/functions.html#sorted">documentation</a> doesn't guarantee that. Is there any other place that it is documented? </p>
<p>I'm guessing it might be stable since the sort method on lists is <a href="http://docs.python.org/library/stdtypes.html#mutable-sequence-types">guarant... | 40 | 2009-12-16T15:30:01Z | 1,971,943 | <p>They are <a href="http://wiki.python.org/moin/HowTo/Sorting/">stable</a>. Although you don't need to know if sort and sorted are stable, because you don't need to sort in two steps when having multiple keys.</p>
<p>For example, if you want to sort objects based on their <code>last_name</code>, <code>first_name</cod... | 16 | 2009-12-28T22:42:14Z | [
"python",
"sorted",
"stable-sort"
] |
python, convert a dictionary to a sorted list by value instead of key | 1,915,564 | <p>I have a collections.defaultdict(int) that I'm building to keep count of how many times a key shows up in a set of data. I later want to be able to sort it (obviously by turning it into a list first) in a descending fashion, ordered with the highest values first. I created my dictionary like the following:</p>
<pre... | 13 | 2009-12-16T15:54:15Z | 1,915,589 | <p>Just sort the resulting dict by values:</p>
<pre><code>for k, v in sorted(adict.items(), key=lambda kv: kv[1], reverse=True):
print("%s => %s" % (k,v))
</code></pre>
| 3 | 2009-12-16T15:57:27Z | [
"python",
"sorting"
] |
python, convert a dictionary to a sorted list by value instead of key | 1,915,564 | <p>I have a collections.defaultdict(int) that I'm building to keep count of how many times a key shows up in a set of data. I later want to be able to sort it (obviously by turning it into a list first) in a descending fashion, ordered with the highest values first. I created my dictionary like the following:</p>
<pre... | 13 | 2009-12-16T15:54:15Z | 1,915,598 | <pre><code>from collections import defaultdict
adict = defaultdict(int)
adict['a'] += 1
adict['b'] += 3
adict['c'] += 5
adict['d'] += 2
for key, value in sorted(adict.items(), lambda a, b: cmp(a[1], b[1]), reverse=True):
print "%r => %r" % (key, value)
>>>
'c' => 5
'b' => 3
'd' => 2
'a' =&g... | 2 | 2009-12-16T15:58:16Z | [
"python",
"sorting"
] |
python, convert a dictionary to a sorted list by value instead of key | 1,915,564 | <p>I have a collections.defaultdict(int) that I'm building to keep count of how many times a key shows up in a set of data. I later want to be able to sort it (obviously by turning it into a list first) in a descending fashion, ordered with the highest values first. I created my dictionary like the following:</p>
<pre... | 13 | 2009-12-16T15:54:15Z | 1,915,602 | <p>To get the dictionary sorted:</p>
<pre><code>from operator import itemgetter
sorted(adict.iteritems(), key=itemgetter(1), reverse=True)
</code></pre>
| 37 | 2009-12-16T15:58:48Z | [
"python",
"sorting"
] |
python, convert a dictionary to a sorted list by value instead of key | 1,915,564 | <p>I have a collections.defaultdict(int) that I'm building to keep count of how many times a key shows up in a set of data. I later want to be able to sort it (obviously by turning it into a list first) in a descending fashion, ordered with the highest values first. I created my dictionary like the following:</p>
<pre... | 13 | 2009-12-16T15:54:15Z | 1,915,631 | <p>A dict's keys, reverse-sorted by the corresponding values, can best be gotten as</p>
<pre><code>sorted(adict, key=adict.get, reverse=True)
</code></pre>
<p>since you want key/value pairs, you could work on the items as all other answers suggest, or (to use the nifty <code>adict.get</code> bound method instead of i... | 32 | 2009-12-16T16:02:48Z | [
"python",
"sorting"
] |
python, convert a dictionary to a sorted list by value instead of key | 1,915,564 | <p>I have a collections.defaultdict(int) that I'm building to keep count of how many times a key shows up in a set of data. I later want to be able to sort it (obviously by turning it into a list first) in a descending fashion, ordered with the highest values first. I created my dictionary like the following:</p>
<pre... | 13 | 2009-12-16T15:54:15Z | 1,915,665 | <p>"Invert" a dictionary.</p>
<pre><code>from collections import defaultdict
inv_dict = defaultdict( list )
for key, value in adict:
inv_dict[value].append( key )
max_value= max( inv_dict.keys() )
</code></pre>
<p>The set of keys with the maximum occurrence -- </p>
<pre><code>inv_dict[max_value]
</code></pre>
<... | 0 | 2009-12-16T16:06:28Z | [
"python",
"sorting"
] |
python, convert a dictionary to a sorted list by value instead of key | 1,915,564 | <p>I have a collections.defaultdict(int) that I'm building to keep count of how many times a key shows up in a set of data. I later want to be able to sort it (obviously by turning it into a list first) in a descending fashion, ordered with the highest values first. I created my dictionary like the following:</p>
<pre... | 13 | 2009-12-16T15:54:15Z | 1,916,298 | <p>If you're using the newest python 2.7 alpha, then you can use the <a href="http://docs.python.org/dev/library/collections.html#collections.Counter" rel="nofollow"><code>Counter</code></a> class in collections module:</p>
<pre><code>c = Counter()
c['someval'] += 1
c['anotherval'] += 1
c['someval'] += 1
print c.mos... | 2 | 2009-12-16T17:33:36Z | [
"python",
"sorting"
] |
python, convert a dictionary to a sorted list by value instead of key | 1,915,564 | <p>I have a collections.defaultdict(int) that I'm building to keep count of how many times a key shows up in a set of data. I later want to be able to sort it (obviously by turning it into a list first) in a descending fashion, ordered with the highest values first. I created my dictionary like the following:</p>
<pre... | 13 | 2009-12-16T15:54:15Z | 1,925,135 | <p><em>Note: I'm putting this in as an answer so that it gets seen. I don't want upvotes. If you want to upvote anyone, upvote Nadia.</em></p>
<p><strong>The <em>currently</em> accepted answer gives timing results which are based on a trivially small dataset</strong> (size == 6 - (-5) == 11). The differences in cost o... | 2 | 2009-12-17T22:48:01Z | [
"python",
"sorting"
] |
python descriptors sharing values across classes | 1,915,643 | <p>A python descriptor that I'm working with is sharing its value across all instances of its owner class. How can I make each instance's descriptor contain its own internal values?</p>
<pre><code>class Desc(object):
def __init__(self, initval=None,name='val'):
self.val = initval
self.name = name
... | 3 | 2009-12-16T16:03:50Z | 1,915,712 | <p>There is only one descriptor object, stored on the class object, so <code>self</code> is always the same. If you want to store data per-object and access it through the descriptor, you either have to store the data on each object (probably the better idea) or in some data-structure keyed by each object (an idea I do... | 7 | 2009-12-16T16:11:00Z | [
"python",
"descriptor"
] |
with statement - backport for Python 2.5 | 1,915,927 | <p>I'd like to use <code>with</code> statement in Python 2.5 in some production code. It was backported, should I expect any problems (e.g. with availability/compatibility on other machines/etc)?</p>
<p>Is this code</p>
<pre><code>from __future__ import with_statement
</code></pre>
<p>compatible with Python 2.6?</p>... | 4 | 2009-12-16T16:37:52Z | 1,915,956 | <p>Yes, that statement is a no-operation in Python 2.6, so you can freely use it to make <code>with</code> a keyword in your 2.5 code as well, without affecting your code's operation in 2.6. This is in fact the general design intention of "importing from the future" in Python!</p>
| 7 | 2009-12-16T16:41:35Z | [
"python",
"with-statement",
"backport"
] |
with statement - backport for Python 2.5 | 1,915,927 | <p>I'd like to use <code>with</code> statement in Python 2.5 in some production code. It was backported, should I expect any problems (e.g. with availability/compatibility on other machines/etc)?</p>
<p>Is this code</p>
<pre><code>from __future__ import with_statement
</code></pre>
<p>compatible with Python 2.6?</p>... | 4 | 2009-12-16T16:37:52Z | 1,915,957 | <p>You can call this in Python 2.6 and 3.0/1 without problems (it's a no-op there).</p>
| 4 | 2009-12-16T16:41:39Z | [
"python",
"with-statement",
"backport"
] |
with statement - backport for Python 2.5 | 1,915,927 | <p>I'd like to use <code>with</code> statement in Python 2.5 in some production code. It was backported, should I expect any problems (e.g. with availability/compatibility on other machines/etc)?</p>
<p>Is this code</p>
<pre><code>from __future__ import with_statement
</code></pre>
<p>compatible with Python 2.6?</p>... | 4 | 2009-12-16T16:37:52Z | 1,915,987 | <p>with_statement wasn't back ported but implemented in Python 2.5. Adding new keywords or syntax can break existing applications. With Python the way they decided to handle this is allow people to opt-in to those features early so you can slowly transition your code over.</p>
<p>From <a href="http://python.org/doc/... | 3 | 2009-12-16T16:46:04Z | [
"python",
"with-statement",
"backport"
] |
App engine app design questions | 1,916,009 | <p>I want to load info from another site (this part is done), but i am doing this every time the page is loaded and that wont do. So i was thinking of having a variable in a table of settings like 'last checked bbc site' and when the page loads it would check if its been long enough since last check to check again. Is ... | 1 | 2009-12-16T16:49:51Z | 1,916,026 | <p>You could also use <a href="http://code.google.com/appengine/docs/python/config/cron.html" rel="nofollow">Scheduled Tasks</a>.</p>
<p>Also, you don't absolutely need to use the Datastore for configuration parameters: you could have this in a script / config file.</p>
| 1 | 2009-12-16T16:52:24Z | [
"python",
"google-app-engine"
] |
App engine app design questions | 1,916,009 | <p>I want to load info from another site (this part is done), but i am doing this every time the page is loaded and that wont do. So i was thinking of having a variable in a table of settings like 'last checked bbc site' and when the page loads it would check if its been long enough since last check to check again. Is ... | 1 | 2009-12-16T16:49:51Z | 1,916,805 | <p>If you want some handler on your GAE app (including one for a scheduled task, reception of messages, web page visits, etc) to store some new information in such a way that some handler in the future can recover that information, then GAE's storage is the only good general way (memcache could expire from under you, f... | 0 | 2009-12-16T18:49:23Z | [
"python",
"google-app-engine"
] |
App engine app design questions | 1,916,009 | <p>I want to load info from another site (this part is done), but i am doing this every time the page is loaded and that wont do. So i was thinking of having a variable in a table of settings like 'last checked bbc site' and when the page loads it would check if its been long enough since last check to check again. Is ... | 1 | 2009-12-16T16:49:51Z | 1,917,064 | <p>I think there are 2 options that would work for you, besides creating a entity in the datastore to keep track of "last visited time".</p>
<p>One way is to just check the external page periodically, using the cron api as described by jldupont. </p>
<p>The second way is to store the last visited time in memcache. ... | 2 | 2009-12-16T19:29:23Z | [
"python",
"google-app-engine"
] |
Simplest way to publish over Zeroconf/Bonjour? | 1,916,017 | <p>I've got some apps I would like to make visible with zeroconf.</p>
<ol>
<li>Is there an easy scriptable way to do this?</li>
<li>Is there anything that needs to be done by my network admin to enable this?</li>
</ol>
<p>Python or sh would be preferrable. OS-specific suggestions welcome for Linux and OS X.</p>
| 10 | 2009-12-16T16:51:17Z | 1,916,044 | <p>Through the <a href="http://avahi.org/wiki/Bindings" rel="nofollow">Avahi Python bindings</a>, it's very easy.</p>
| 2 | 2009-12-16T16:54:35Z | [
"python",
"bonjour",
"zeroconf"
] |
Simplest way to publish over Zeroconf/Bonjour? | 1,916,017 | <p>I've got some apps I would like to make visible with zeroconf.</p>
<ol>
<li>Is there an easy scriptable way to do this?</li>
<li>Is there anything that needs to be done by my network admin to enable this?</li>
</ol>
<p>Python or sh would be preferrable. OS-specific suggestions welcome for Linux and OS X.</p>
| 10 | 2009-12-16T16:51:17Z | 1,916,772 | <p>I'd recommend <a href="http://code.google.com/p/pybonjour/">pybonjour</a>.</p>
| 9 | 2009-12-16T18:44:52Z | [
"python",
"bonjour",
"zeroconf"
] |
Simplest way to publish over Zeroconf/Bonjour? | 1,916,017 | <p>I've got some apps I would like to make visible with zeroconf.</p>
<ol>
<li>Is there an easy scriptable way to do this?</li>
<li>Is there anything that needs to be done by my network admin to enable this?</li>
</ol>
<p>Python or sh would be preferrable. OS-specific suggestions welcome for Linux and OS X.</p>
| 10 | 2009-12-16T16:51:17Z | 2,083,341 | <p>Or you can just use bash:</p>
<pre><code>dns-sd -R <Name> <Type> <Domain> <Port> [<TXT>...]
</code></pre>
<p>This works by default on OS X. For other *nixes, refer to <a href="http://www.iphonebookshelf.com/forum/read.php?9,829,829">this easy workaround</a>.</p>
| 5 | 2010-01-18T01:01:22Z | [
"python",
"bonjour",
"zeroconf"
] |
Simplest way to publish over Zeroconf/Bonjour? | 1,916,017 | <p>I've got some apps I would like to make visible with zeroconf.</p>
<ol>
<li>Is there an easy scriptable way to do this?</li>
<li>Is there anything that needs to be done by my network admin to enable this?</li>
</ol>
<p>Python or sh would be preferrable. OS-specific suggestions welcome for Linux and OS X.</p>
| 10 | 2009-12-16T16:51:17Z | 38,870,582 | <p>pybonjour doesn't seem to be actively maintained. I'm using <a href="https://github.com/jstasiak/python-zeroconf" rel="nofollow">python-zeroconf</a>.</p>
<pre><code>pip install zeroconf
</code></pre>
<p>Here is an excerpt from a script I use to announce a <a href="http://autobahn.ws/python/" rel="nofollow">Twisted... | 1 | 2016-08-10T10:19:00Z | [
"python",
"bonjour",
"zeroconf"
] |
Expressing an SConscript's Own Dependencies | 1,916,251 | <p>I have an SCons project set up as follows:</p>
<pre><code>Project/
SConstruct # "SConscript('stuff/SConscript', variant_dir = 'build')
stuff/
SConscript # "import configuration"
configuration/
__init__.py
Thing.py
</code></pre>
<p>When building, the SConscript is co... | 0 | 2009-12-16T17:27:42Z | 1,918,937 | <p>I have two workarounds for you. I call them workarounds because they don't express the dependency in the SConscript. </p>
<ol>
<li><p>Do the 'import configuration' from your SConstruct (you'll need to edit sys.path)</p></li>
<li><p>In stuff/SConscript, add the source directory to sys.path:</p></li>
</ol>
<pre><cod... | 1 | 2009-12-17T01:32:38Z | [
"python",
"import",
"module",
"scons"
] |
Expressing an SConscript's Own Dependencies | 1,916,251 | <p>I have an SCons project set up as follows:</p>
<pre><code>Project/
SConstruct # "SConscript('stuff/SConscript', variant_dir = 'build')
stuff/
SConscript # "import configuration"
configuration/
__init__.py
Thing.py
</code></pre>
<p>When building, the SConscript is co... | 0 | 2009-12-16T17:27:42Z | 1,922,027 | <p>Firstly, do you really need dependence on your SCons script source files? How often do they change, and if they change is it really so onerous to require that your user does a clean build if they muck with the SConscript.py configuration file(s).</p>
<p>If you do require this, are you currently not seeing this? I... | 0 | 2009-12-17T14:08:09Z | [
"python",
"import",
"module",
"scons"
] |
Determining Build Directory from SConscript | 1,916,473 | <p>I have an SConscript which is being copied to a build directory (<code>variant_dir = ...</code>) for construction. As a workaround for <a href="http://stackoverflow.com/questions/1916251">not being able to express dependencies</a>, I'm trying to copy some additional files into the build directory.</p>
<p>How do I d... | 1 | 2009-12-16T17:59:06Z | 1,916,910 | <p>My answer seems too simple, so maybe I misunderstood the question, but ...</p>
<p>For me, in subdir/SConscript: </p>
<pre><code>my_build_directory = '.'
echo_cmd = Command('always.echo', [], "echo %s" % (Dir('.').abspath))
Alias('echo', echo_cmd)
</code></pre>
<p>produces:</p>
<pre><code># => cd test-scon... | 2 | 2009-12-16T19:06:31Z | [
"python",
"build-automation",
"scons"
] |
Python: List to Hex | 1,916,493 | <p>I am writing a small forensics python app and I am having trouble converting a List entry to Hex. I have tried the encode/decode methood but get bogus conversions or odd-length string Type Errors. I have pasted the code below, and as you can see I need the address in hex, so I can add the count to it. </p>
<pre>... | -1 | 2009-12-16T18:02:38Z | 1,916,561 | <p>The <code>hex</code> function converts integers to their hexadecimal representation:</p>
<pre><code>>>> a = 123
>>> hex(a)
'0x7b'
</code></pre>
| 2 | 2009-12-16T18:11:55Z | [
"python",
"hex"
] |
Does Django support model classes that inherit after many non-abstract models? | 1,916,522 | <p>Lets say I have three django model classes - lets call them A, B and C. If A and B are abstract, I can do something like:</p>
<pre><code>class C(A,B):
pass
</code></pre>
<p>What if they aren't abstract and I do the same? Will everything still work correctly or no? Or have I got it wrong and this should not be ... | 1 | 2009-12-16T18:07:10Z | 1,916,591 | <p>Yes, you can use normal Python multiple-inheritance with models. Bear in mind this warning though:</p>
<blockquote>
<p>Just as with Python's subclassing,
it's possible for a Django model to
inherit from multiple parent models.
Keep in mind that normal Python name
resolution rules apply. The first base
c... | 2 | 2009-12-16T18:16:46Z | [
"python",
"django",
"django-models"
] |
In Python, how can I test if I'm in Google App Engine SDK? | 1,916,579 | <p>Whilst developing I want to handle some things slight differently than I will when I eventually upload to the Google servers. </p>
<p>Is there a quick test that I can do to find out if I'm in the SDK or live?</p>
| 32 | 2009-12-16T18:14:30Z | 1,916,594 | <p>See: <a href="http://code.google.com/appengine/docs/python/runtime.html#The_Environment" rel="nofollow">https://cloud.google.com/appengine/docs/python/how-requests-are-handled#Python_The_environment</a></p>
<blockquote>
<p>The following environment variables are part of the CGI standard, with special behavior in ... | 52 | 2009-12-16T18:17:22Z | [
"python",
"google-app-engine"
] |
In Python, how can I test if I'm in Google App Engine SDK? | 1,916,579 | <p>Whilst developing I want to handle some things slight differently than I will when I eventually upload to the Google servers. </p>
<p>Is there a quick test that I can do to find out if I'm in the SDK or live?</p>
| 32 | 2009-12-16T18:14:30Z | 1,936,947 | <p>Based on the same trick, I use this function in my code:</p>
<pre><code>def isLocal():
return os.environ["SERVER_NAME"] in ("localhost", "www.lexample.com")
</code></pre>
<p>I have customized my <code>/etc/hosts</code> file in order to be able to access the local version by prepending a "l" to my domain name, ... | 5 | 2009-12-20T20:37:34Z | [
"python",
"google-app-engine"
] |
In Python, how can I test if I'm in Google App Engine SDK? | 1,916,579 | <p>Whilst developing I want to handle some things slight differently than I will when I eventually upload to the Google servers. </p>
<p>Is there a quick test that I can do to find out if I'm in the SDK or live?</p>
| 32 | 2009-12-16T18:14:30Z | 5,816,348 | <p>I just check the httplib (which is a wrapper around appengine fetch)</p>
<pre><code>def _is_gae():
import httplib
return 'appengine' in str(httplib.HTTP)
</code></pre>
| 3 | 2011-04-28T09:17:35Z | [
"python",
"google-app-engine"
] |
In Python, how can I test if I'm in Google App Engine SDK? | 1,916,579 | <p>Whilst developing I want to handle some things slight differently than I will when I eventually upload to the Google servers. </p>
<p>Is there a quick test that I can do to find out if I'm in the SDK or live?</p>
| 32 | 2009-12-16T18:14:30Z | 37,082,850 | <p><b>A more general solution</b><br>
A more general solution (that does not imply to be in a google server) would be to detect if the code is not in a local machine.<br>
I am using this code regardless the server</p>
<pre><code>import socket
if socket.gethostname() == "local computer name":
DEBUG = True
...
... | 0 | 2016-05-06T23:36:27Z | [
"python",
"google-app-engine"
] |
List and Integer query | 1,916,663 | <p>If i had a list of numbers and some maybe negative, how would i ensure all numbers in my list were positive? I can covert the items in the list to integers thats no problem.</p>
<p>Another question, I want to compare items in my list to an integer value say 'x' and sum all the values in my list that are less than x... | 0 | 2009-12-16T18:28:35Z | 1,916,689 | <pre><code># input list is named "lst"
pos_list = [int(a) for a in lst if int(a) > 0]
# And num 2 (notice generator is used instead of list)
return sum(a for a in lst if a < x)
</code></pre>
| 0 | 2009-12-16T18:33:20Z | [
"python",
"list",
"integer"
] |
List and Integer query | 1,916,663 | <p>If i had a list of numbers and some maybe negative, how would i ensure all numbers in my list were positive? I can covert the items in the list to integers thats no problem.</p>
<p>Another question, I want to compare items in my list to an integer value say 'x' and sum all the values in my list that are less than x... | 0 | 2009-12-16T18:28:35Z | 1,916,690 | <pre><code>>>>mylist = [1,2,3,-2]
>>>any(item for item in mylist if item < 0)
True
>>>mylist.pop()
-2
>>>any(item for item in mylist if item < 0)
False
</code></pre>
<p>answers your first question.</p>
<pre><code>>>> x = 3
>>> sum(item for item in mylist if ... | 0 | 2009-12-16T18:33:22Z | [
"python",
"list",
"integer"
] |
List and Integer query | 1,916,663 | <p>If i had a list of numbers and some maybe negative, how would i ensure all numbers in my list were positive? I can covert the items in the list to integers thats no problem.</p>
<p>Another question, I want to compare items in my list to an integer value say 'x' and sum all the values in my list that are less than x... | 0 | 2009-12-16T18:28:35Z | 1,916,691 | <p>If you have a list <code>Ns</code> of numbers (if it's a list of strings as in several similar questions asked recently each will have to be made into an int, or whatever other kind of number, by calling <code>int</code> [[or <code>float</code>, etc]] on it), the list of their absolute values (if that's what you mea... | 4 | 2009-12-16T18:33:34Z | [
"python",
"list",
"integer"
] |
List and Integer query | 1,916,663 | <p>If i had a list of numbers and some maybe negative, how would i ensure all numbers in my list were positive? I can covert the items in the list to integers thats no problem.</p>
<p>Another question, I want to compare items in my list to an integer value say 'x' and sum all the values in my list that are less than x... | 0 | 2009-12-16T18:28:35Z | 1,916,693 | <p>Answer / First part:</p>
<pre><code>>>> a = [1, 2, -3, 4, 5, 6]
>>> b = [1, 2, 3, 4, 5, 6]
>>> max(map(lambda x: x < 0, a))
False
>>> max(map(lambda x: x < 0, b))
True
</code></pre>
<p>Or just use <code>min</code>:</p>
<pre><code>>>> min(a) < 0
True
>>... | 0 | 2009-12-16T18:33:45Z | [
"python",
"list",
"integer"
] |
List and Integer query | 1,916,663 | <p>If i had a list of numbers and some maybe negative, how would i ensure all numbers in my list were positive? I can covert the items in the list to integers thats no problem.</p>
<p>Another question, I want to compare items in my list to an integer value say 'x' and sum all the values in my list that are less than x... | 0 | 2009-12-16T18:28:35Z | 1,916,699 | <p>If I understand correctly your question, I guess you are asking because of some class about functional programming. </p>
<p>In this case, what you are asking for can be accomplished with <a href="http://docs.python.org/tutorial/datastructures.html#functional-programming-tools" rel="nofollow">functional programming... | 0 | 2009-12-16T18:34:36Z | [
"python",
"list",
"integer"
] |
can't open unicode url with python | 1,916,684 | <p>using python 2.5.2 and linux debian i'm trying to get the content from a spanish url that contains a spanish char ('Ã'):</p>
<pre>import urllib
url = u'http://mydomain.es/Ãndice.html'
content = urllib.urlopen(url).read()</pre>
<p>I'm getting this error:</p>
<p><code>UnicodeEncodeError: 'ascii' codec can't encod... | 9 | 2009-12-16T18:31:59Z | 1,916,739 | <p>Encoding the URL as utf-8, should have worked. I wonder if your source file is properly encoded, and whether the interpreter knows it. If your python source file is saved as UTF-8, for example, then you should have</p>
<pre><code># coding=UTF-8
</code></pre>
<p>as the first or second line.</p>
<pre><code>import u... | 3 | 2009-12-16T18:40:45Z | [
"python",
"unicode"
] |
can't open unicode url with python | 1,916,684 | <p>using python 2.5.2 and linux debian i'm trying to get the content from a spanish url that contains a spanish char ('Ã'):</p>
<pre>import urllib
url = u'http://mydomain.es/Ãndice.html'
content = urllib.urlopen(url).read()</pre>
<p>I'm getting this error:</p>
<p><code>UnicodeEncodeError: 'ascii' codec can't encod... | 9 | 2009-12-16T18:31:59Z | 1,916,740 | <p>This works for me: </p>
<pre><code>#!/usr/bin/env python
# define source file encoding, see: http://www.python.org/dev/peps/pep-0263/
# -*- coding: utf-8 -*-
import urllib
url = u'http://example.com/Ãndice.html'
content = urllib.urlopen(url.encode("UTF-8")).read()
</code></pre>
| 6 | 2009-12-16T18:41:14Z | [
"python",
"unicode"
] |
can't open unicode url with python | 1,916,684 | <p>using python 2.5.2 and linux debian i'm trying to get the content from a spanish url that contains a spanish char ('Ã'):</p>
<pre>import urllib
url = u'http://mydomain.es/Ãndice.html'
content = urllib.urlopen(url).read()</pre>
<p>I'm getting this error:</p>
<p><code>UnicodeEncodeError: 'ascii' codec can't encod... | 9 | 2009-12-16T18:31:59Z | 1,916,747 | <p>Per the applicable standard, <a href="http://www.faqs.org/rfcs/rfc1738.html" rel="nofollow">RFC 1378</a>, URLs can only contain ASCII characters. Good explanation <a href="http://www.blooberry.com/indexdot/html/topics/urlencoding.htm" rel="nofollow">here</a>, and I quote:</p>
<blockquote>
<p>"...Only alphanumeri... | 2 | 2009-12-16T18:42:02Z | [
"python",
"unicode"
] |
can't open unicode url with python | 1,916,684 | <p>using python 2.5.2 and linux debian i'm trying to get the content from a spanish url that contains a spanish char ('Ã'):</p>
<pre>import urllib
url = u'http://mydomain.es/Ãndice.html'
content = urllib.urlopen(url).read()</pre>
<p>I'm getting this error:</p>
<p><code>UnicodeEncodeError: 'ascii' codec can't encod... | 9 | 2009-12-16T18:31:59Z | 1,916,757 | <p>It works for me. Make sure you're using a fairly recent version of Python, and your file encoding is correct.
Here's my code:</p>
<pre><code># -*- coding: utf-8 -*-
import urllib
url = u'http://mydomain.es/Ãndice.html'
url = url.encode('utf-8')
content = urllib.urlopen(url).read()
</code></pre>
<p>(mydomain.es do... | 3 | 2009-12-16T18:43:20Z | [
"python",
"unicode"
] |
Programmatic Python Browser with JavaScript | 1,916,711 | <p>I want to screen-scrape a web-site that uses JavaScript. </p>
<p>There is <a href="http://wwwsearch.sourceforge.net/mechanize/">mechanize</a>, the programmatic web browser for Python. However, it (understandably) doesn't interpret javascript. Is there any programmatic browser for Python which does? If not, is there... | 12 | 2009-12-16T18:37:08Z | 1,916,748 | <p>You might be better off using a tool like <a href="http://seleniumhq.org/">Selenium</a> to automate the scraping using a web browser, so the JS executes and the page renders just like it would for a real user.</p>
| 11 | 2009-12-16T18:42:13Z | [
"javascript",
"python",
"browser",
"screen-scraping",
"mechanize"
] |
Programmatic Python Browser with JavaScript | 1,916,711 | <p>I want to screen-scrape a web-site that uses JavaScript. </p>
<p>There is <a href="http://wwwsearch.sourceforge.net/mechanize/">mechanize</a>, the programmatic web browser for Python. However, it (understandably) doesn't interpret javascript. Is there any programmatic browser for Python which does? If not, is there... | 12 | 2009-12-16T18:37:08Z | 1,916,779 | <p>You could also try defining <a href="http://groups.csail.mit.edu/uid/chickenfoot/" rel="nofollow">Chickenfoot</a> page triggers on the pages in question, executing whatever operations you want on the page and saving the results of the operation to a local file, and calling Firefox from the command line inside your p... | 2 | 2009-12-16T18:45:51Z | [
"javascript",
"python",
"browser",
"screen-scraping",
"mechanize"
] |
Programmatic Python Browser with JavaScript | 1,916,711 | <p>I want to screen-scrape a web-site that uses JavaScript. </p>
<p>There is <a href="http://wwwsearch.sourceforge.net/mechanize/">mechanize</a>, the programmatic web browser for Python. However, it (understandably) doesn't interpret javascript. Is there any programmatic browser for Python which does? If not, is there... | 12 | 2009-12-16T18:37:08Z | 1,917,551 | <p>The <a href="http://code.google.com/p/pyv8/">PyV8</a> package nicely wraps <a href="http://code.google.com/apis/v8/">Google's V8 Javascript engine</a> for Python. It's particularly nice because not only can you call from Python to Javascript code, but you can call back from Javascript to Python code. This makes it... | 7 | 2009-12-16T20:43:00Z | [
"javascript",
"python",
"browser",
"screen-scraping",
"mechanize"
] |
Programmatic Python Browser with JavaScript | 1,916,711 | <p>I want to screen-scrape a web-site that uses JavaScript. </p>
<p>There is <a href="http://wwwsearch.sourceforge.net/mechanize/">mechanize</a>, the programmatic web browser for Python. However, it (understandably) doesn't interpret javascript. Is there any programmatic browser for Python which does? If not, is there... | 12 | 2009-12-16T18:37:08Z | 3,009,645 | <p>i recommend that you take a look at some of the options available to you at <a href="http://wiki.python.org/moin/WebBrowserProgramming" rel="nofollow">http://wiki.python.org/moin/WebBrowserProgramming</a> - surprisingly this is coming up as a common question (i've found three on stackoverflow today, by searching for... | 1 | 2010-06-09T20:24:09Z | [
"javascript",
"python",
"browser",
"screen-scraping",
"mechanize"
] |
Programmatic Python Browser with JavaScript | 1,916,711 | <p>I want to screen-scrape a web-site that uses JavaScript. </p>
<p>There is <a href="http://wwwsearch.sourceforge.net/mechanize/">mechanize</a>, the programmatic web browser for Python. However, it (understandably) doesn't interpret javascript. Is there any programmatic browser for Python which does? If not, is there... | 12 | 2009-12-16T18:37:08Z | 3,849,879 | <p>you may try zope browser</p>
<p><a href="http://pypi.python.org/pypi?:action=display&name=zope.testbrowser" rel="nofollow">http://pypi.python.org/pypi?:action=display&name=zope.testbrowser</a></p>
| 1 | 2010-10-03T13:10:58Z | [
"javascript",
"python",
"browser",
"screen-scraping",
"mechanize"
] |
Programmatic Python Browser with JavaScript | 1,916,711 | <p>I want to screen-scrape a web-site that uses JavaScript. </p>
<p>There is <a href="http://wwwsearch.sourceforge.net/mechanize/">mechanize</a>, the programmatic web browser for Python. However, it (understandably) doesn't interpret javascript. Is there any programmatic browser for Python which does? If not, is there... | 12 | 2009-12-16T18:37:08Z | 5,459,345 | <p>There is also spynner " a stateful programmatic web browser module for Python with Javascript/AJAX support based on the QtWebkit framework" : <a href="http://code.google.com/p/spynner/" rel="nofollow">http://code.google.com/p/spynner/</a></p>
| 4 | 2011-03-28T13:01:10Z | [
"javascript",
"python",
"browser",
"screen-scraping",
"mechanize"
] |
Programmatic Python Browser with JavaScript | 1,916,711 | <p>I want to screen-scrape a web-site that uses JavaScript. </p>
<p>There is <a href="http://wwwsearch.sourceforge.net/mechanize/">mechanize</a>, the programmatic web browser for Python. However, it (understandably) doesn't interpret javascript. Is there any programmatic browser for Python which does? If not, is there... | 12 | 2009-12-16T18:37:08Z | 6,603,138 | <p>My favorite is <a href="https://github.com/kanzure/pyphantomjs" rel="nofollow">PyPhantomJS</a>. It's written using Python and PyQt4. It's completely headless and you can control it completely from JavaScript.</p>
<p>However, if you are looking to actually see the page, you can use <code>QWebView</code> from PyQt4 a... | 5 | 2011-07-06T21:19:08Z | [
"javascript",
"python",
"browser",
"screen-scraping",
"mechanize"
] |
resizing of button icons in pyqt4 | 1,916,722 | <p>I want to make image in my <code>QMainWindow</code> so when you click on it you have a signal translating like <code>qpushbutton</code> I use this:</p>
<pre><code>self.quit=QtGui.QPushButton(self)
self.quit.setIcon(QtGui.QIcon('images/9.bmp'))
</code></pre>
<p>But the problem is whene I resize the window <code>qpu... | 0 | 2009-12-16T18:38:52Z | 1,916,781 | <p>Qt won't stretch your image for you - and it's best this way. I recommend to keep the pushbutton of a constant size by adding stretchers to the layout holding it. A resizable pushbutton isn't very appealing visually, and is uncommon in GUIs, anyway.</p>
<p>To make a clickable image, here's the simplest code I can t... | 1 | 2009-12-16T18:46:03Z | [
"python",
"pyqt4"
] |
convert byte array to string without interpreting the bytes? | 1,916,928 | <p>I have a GSM date/time stamp from a PDU encoded SMS it is formatted as so</p>
<p>\x90,\x21,\x51,\x91,\x40,\x33</p>
<p>format yy,mm,dd,hh,mm,ss</p>
<p>I have read them from a binary file into a byte array. I want to convert them to a string but without doing any decoding I want to end up with a string that contain... | 0 | 2009-12-16T19:10:03Z | 1,916,970 | <p>What you mean is that you <em>do</em> want to do some processing! The unprocessed bytes are most easily represented as characters.</p>
<p>I think what you want is something along the lines of:</p>
<pre><code>r = ''
for num in array:
r += '%2X' % num
return r
</code></pre>
<p>Which I'm sure could be wrapped up... | 1 | 2009-12-16T19:15:22Z | [
"python",
"bytearray",
"decode"
] |
convert byte array to string without interpreting the bytes? | 1,916,928 | <p>I have a GSM date/time stamp from a PDU encoded SMS it is formatted as so</p>
<p>\x90,\x21,\x51,\x91,\x40,\x33</p>
<p>format yy,mm,dd,hh,mm,ss</p>
<p>I have read them from a binary file into a byte array. I want to convert them to a string but without doing any decoding I want to end up with a string that contain... | 0 | 2009-12-16T19:10:03Z | 1,916,977 | <p>This should get you started:</p>
<pre><code>>>> s = b'\x90\x21\x51\x91\x40\x33'
>>> lst = [hex(z)[2:] for z in s]
>>> lst
['90', '21', '51', '91', '40', '33']
>>> string = ''.join(hex(z)[3:1:-1] for z in s)
>>> string
'091215190433'
</code></pre>
| 4 | 2009-12-16T19:16:21Z | [
"python",
"bytearray",
"decode"
] |
convert byte array to string without interpreting the bytes? | 1,916,928 | <p>I have a GSM date/time stamp from a PDU encoded SMS it is formatted as so</p>
<p>\x90,\x21,\x51,\x91,\x40,\x33</p>
<p>format yy,mm,dd,hh,mm,ss</p>
<p>I have read them from a binary file into a byte array. I want to convert them to a string but without doing any decoding I want to end up with a string that contain... | 0 | 2009-12-16T19:10:03Z | 1,917,086 | <p>To convert to hex:</p>
<p><code>hexdata = ''.join('%02x' % ord(byte) for byte in bindata)</code></p>
<p>To reverse every other hex character (if I'm understanding correctly):</p>
<p><code>hexdata = ''.join(('%02x' % ord(byte))[::-1] for byte in bindata)</code></p>
| 5 | 2009-12-16T19:33:04Z | [
"python",
"bytearray",
"decode"
] |
convert byte array to string without interpreting the bytes? | 1,916,928 | <p>I have a GSM date/time stamp from a PDU encoded SMS it is formatted as so</p>
<p>\x90,\x21,\x51,\x91,\x40,\x33</p>
<p>format yy,mm,dd,hh,mm,ss</p>
<p>I have read them from a binary file into a byte array. I want to convert them to a string but without doing any decoding I want to end up with a string that contain... | 0 | 2009-12-16T19:10:03Z | 1,917,506 | <p>If, in your question, the string you have provided is the literal set of bytes (as ascii) including the \ and , and you wish to strip them out you could use the binascii module and str.replace:</p>
<pre><code>import binascii
qp = binascii.b2a_qp( bunchabytes )
plainstring = qp.replace( '\\x', '' ).replace( ',', '' ... | 0 | 2009-12-16T20:37:32Z | [
"python",
"bytearray",
"decode"
] |
convert byte array to string without interpreting the bytes? | 1,916,928 | <p>I have a GSM date/time stamp from a PDU encoded SMS it is formatted as so</p>
<p>\x90,\x21,\x51,\x91,\x40,\x33</p>
<p>format yy,mm,dd,hh,mm,ss</p>
<p>I have read them from a binary file into a byte array. I want to convert them to a string but without doing any decoding I want to end up with a string that contain... | 0 | 2009-12-16T19:10:03Z | 1,971,781 | <pre><code>switcher= dict(
(n1*16 + n2, n2*16 + n1)
for n1 in range(16)
for n2 in range(16)
)
def nibble_switcher(bindata):
return type(bindata)(switcher[i] for i in bindata)
# will work with many types, not only bytearray
def nibble_switcher_as_hex_string(bindata):
return ''.join("%02x" % i f... | 0 | 2009-12-28T21:58:51Z | [
"python",
"bytearray",
"decode"
] |
Filter zipcodes by proximity in Django with the Spherical Law of Cosines | 1,916,953 | <p>I'm trying to handle proximity search for a basic store locater in Django. Rather than haul PostGIS around with my app just so I can use GeoDjango's distance filter, I'd like to use the Spherical Law of Cosines distance formula in a model query. I'd like all of the calculations to be done in the database in one quer... | 10 | 2009-12-16T19:12:28Z | 1,917,068 | <p>It's possible the execute <a href="http://docs.djangoproject.com/en/dev/topics/db/sql/" rel="nofollow" title="raw SQL queries in Django">raw SQL queries in Django</a>.</p>
<p>My suggestion is, write the query to pull a list of IDs (which it looks like you're doing now), then use the IDs to pull the associated model... | 8 | 2009-12-16T19:30:08Z | [
"python",
"django",
"zipcode",
"proximity"
] |
Filter zipcodes by proximity in Django with the Spherical Law of Cosines | 1,916,953 | <p>I'm trying to handle proximity search for a basic store locater in Django. Rather than haul PostGIS around with my app just so I can use GeoDjango's distance filter, I'd like to use the Spherical Law of Cosines distance formula in a model query. I'd like all of the calculations to be done in the database in one quer... | 10 | 2009-12-16T19:12:28Z | 2,258,426 | <p>Just to follow up on jboxer's answer, here's the whole thing as part of a custom manager with some of the hard-coded stuff turned into variables:</p>
<pre><code>class LocationManager(models.Manager):
def nearby_locations(self, latitude, longitude, radius, max_results=100, use_miles=True):
if use_miles:
... | 4 | 2010-02-13T17:36:04Z | [
"python",
"django",
"zipcode",
"proximity"
] |
Filter zipcodes by proximity in Django with the Spherical Law of Cosines | 1,916,953 | <p>I'm trying to handle proximity search for a basic store locater in Django. Rather than haul PostGIS around with my app just so I can use GeoDjango's distance filter, I'd like to use the Spherical Law of Cosines distance formula in a model query. I'd like all of the calculations to be done in the database in one quer... | 10 | 2009-12-16T19:12:28Z | 2,310,427 | <p>Following jboxer's response</p>
<pre><code>def find_cars_within_miles_from_postcode(request, miles, postcode=0):
# create cursor for RAW query
cursor = connection.cursor()
# Get lat and lon from google
lat, lon = getLonLatFromPostcode(postcode)
# Gen query
query = "SELECT id, ((ACOS(SIN("... | 1 | 2010-02-22T11:06:41Z | [
"python",
"django",
"zipcode",
"proximity"
] |
Filter zipcodes by proximity in Django with the Spherical Law of Cosines | 1,916,953 | <p>I'm trying to handle proximity search for a basic store locater in Django. Rather than haul PostGIS around with my app just so I can use GeoDjango's distance filter, I'd like to use the Spherical Law of Cosines distance formula in a model query. I'd like all of the calculations to be done in the database in one quer... | 10 | 2009-12-16T19:12:28Z | 3,034,230 | <p>To follow up on Tom's answer, it won't work in SQLite by default because of SQLite's lack of math functions by default. No problem, it's pretty simple to add:</p>
<pre><code>class LocationManager(models.Manager):
def nearby_locations(self, latitude, longitude, radius, max_results=100, use_miles=True):
... | 8 | 2010-06-13T23:02:33Z | [
"python",
"django",
"zipcode",
"proximity"
] |
Filter zipcodes by proximity in Django with the Spherical Law of Cosines | 1,916,953 | <p>I'm trying to handle proximity search for a basic store locater in Django. Rather than haul PostGIS around with my app just so I can use GeoDjango's distance filter, I'd like to use the Spherical Law of Cosines distance formula in a model query. I'd like all of the calculations to be done in the database in one quer... | 10 | 2009-12-16T19:12:28Z | 4,523,820 | <p>To follow up on Tom, if you want to have a query that also works in postgresql, you can not use AS because you will get an error saying 'distance' does not exist.</p>
<p>You should put the whole spherical law expresion in the WHERE clause, like this (It also works in mysql):</p>
<pre><code>import math
from django.... | 5 | 2010-12-24T02:15:15Z | [
"python",
"django",
"zipcode",
"proximity"
] |
Filter zipcodes by proximity in Django with the Spherical Law of Cosines | 1,916,953 | <p>I'm trying to handle proximity search for a basic store locater in Django. Rather than haul PostGIS around with my app just so I can use GeoDjango's distance filter, I'd like to use the Spherical Law of Cosines distance formula in a model query. I'd like all of the calculations to be done in the database in one quer... | 10 | 2009-12-16T19:12:28Z | 26,034,012 | <p>Using some of the proposed answers above, I was getting incosistent results so I decided to check the equation again
using [this link]<a href="http://www.movable-type.co.uk/scripts/latlong.html" rel="nofollow">http://www.movable-type.co.uk/scripts/latlong.html</a> as a reference, the equation is
<code>d = acos(sin(l... | 0 | 2014-09-25T08:34:37Z | [
"python",
"django",
"zipcode",
"proximity"
] |
How to pass value for python for loop? | 1,916,991 | <p>In C/C++:</p>
<pre><code>for(int i=0;i<=5;i++)
</code></pre>
<p>In Python:</p>
<pre><code>for i in range(0,5)
</code></pre>
<p>Question is:</p>
<pre><code>s=[1,2,3,4,1]
for i in s:
for j in s:
</code></pre>
<p>Here i wanna make second for loop j=1 (j value should be start with 1 like this s[1]=2).How d... | 1 | 2009-12-16T10:58:32Z | 1,916,992 | <p>You should ask this on stackoverflow, but the answer is (if I got you right):</p>
<pre><code>for i in s:
for j in s[1:]:
</code></pre>
<p>Read this chapter about <a href="http://docs.python.org/tutorial/datastructures.html" rel="nofollow">lists in python</a>, this will help you.</p>
| 1 | 2009-12-16T11:12:45Z | [
"python"
] |
How to store a dynamic List into MySQL column efficiently? | 1,917,106 | <p>I want to store a list of numbers along with some other fields into MySQL. The number of elements in the list is dynamic (some time it could hold about 60 elements)</p>
<p>Currently I'm storing the list into a column of varchar type and the following operations are done.</p>
<pre><code>e.g. aList = [1234122433,135... | 1 | 2009-12-16T19:35:17Z | 1,917,149 | <p>Since you wish to store integers, an effective way would be to store them in an INT/DECIMAL column.</p>
<p>Create an additional table that will hold these numbers and add an ID column to relate the records to other table(s).</p>
<blockquote>
<p>Also what should be the efficient way
for storing list of strings ... | 2 | 2009-12-16T19:42:47Z | [
"python",
"mysql"
] |
How to store a dynamic List into MySQL column efficiently? | 1,917,106 | <p>I want to store a list of numbers along with some other fields into MySQL. The number of elements in the list is dynamic (some time it could hold about 60 elements)</p>
<p>Currently I'm storing the list into a column of varchar type and the following operations are done.</p>
<pre><code>e.g. aList = [1234122433,135... | 1 | 2009-12-16T19:35:17Z | 1,917,162 | <p>I'd be less worried about storage space and more worried about record retrieveal i.e., indexability/searching.</p>
<p>For example, I imagine performing a LIKE or REGEXP in a WHERE clause to find a single item in the list will be quite bit more expensive than if you normalized each list item into a row in a separate... | 0 | 2009-12-16T19:45:02Z | [
"python",
"mysql"
] |
How to store a dynamic List into MySQL column efficiently? | 1,917,106 | <p>I want to store a list of numbers along with some other fields into MySQL. The number of elements in the list is dynamic (some time it could hold about 60 elements)</p>
<p>Currently I'm storing the list into a column of varchar type and the following operations are done.</p>
<pre><code>e.g. aList = [1234122433,135... | 1 | 2009-12-16T19:35:17Z | 1,918,202 | <p>MySQL also has a SET type, it works like ENUM but can hold multiple items.
Of course you'd have to have a limited list, currently MySQL only supports up to 64 different items.</p>
| 1 | 2009-12-16T22:18:43Z | [
"python",
"mysql"
] |
How to store a dynamic List into MySQL column efficiently? | 1,917,106 | <p>I want to store a list of numbers along with some other fields into MySQL. The number of elements in the list is dynamic (some time it could hold about 60 elements)</p>
<p>Currently I'm storing the list into a column of varchar type and the following operations are done.</p>
<pre><code>e.g. aList = [1234122433,135... | 1 | 2009-12-16T19:35:17Z | 1,918,597 | <p>Since you are using relational database you should know that storing non-atomic values in individual fields breaks even the first normal form. More likely than not you should follow Don's advice and keep those values in related table. I can't say that for certain because I don't know your problem domain. It may well... | 0 | 2009-12-16T23:42:51Z | [
"python",
"mysql"
] |
Installing Fabric On Windows (Error No Module Called Readline) | 1,917,193 | <p>I'm trying to use the <strong>Fabric 0.1.1</strong> deploy tool (<a href="http://docs.fabfile.org/" rel="nofollow">http://docs.fabfile.org/</a>) on Windows and we're running into an issue with the <strong>readline</strong> module. I've been through various threads but can't seem to solve the issue. It's important ... | 3 | 2009-12-16T19:50:04Z | 1,917,347 | <p>The <code>readline</code> module you are trying to install with <code>easy_install</code> is for OS X, not windows. There are Windows-compatible replacements for readline out there but perhaps you should first try updating <code>fabric</code> itself to a more current version (<a href="http://docs.fabfile.org/0.9.0/... | 4 | 2009-12-16T20:11:03Z | [
"python",
"windows",
"deployment",
"fabric"
] |
Installing Fabric On Windows (Error No Module Called Readline) | 1,917,193 | <p>I'm trying to use the <strong>Fabric 0.1.1</strong> deploy tool (<a href="http://docs.fabfile.org/" rel="nofollow">http://docs.fabfile.org/</a>) on Windows and we're running into an issue with the <strong>readline</strong> module. I've been through various threads but can't seem to solve the issue. It's important ... | 3 | 2009-12-16T19:50:04Z | 1,917,361 | <p>Readline should be available with Cygwin, if you want to move your entire stack in that direction.</p>
| 0 | 2009-12-16T20:14:04Z | [
"python",
"windows",
"deployment",
"fabric"
] |
Installing Fabric On Windows (Error No Module Called Readline) | 1,917,193 | <p>I'm trying to use the <strong>Fabric 0.1.1</strong> deploy tool (<a href="http://docs.fabfile.org/" rel="nofollow">http://docs.fabfile.org/</a>) on Windows and we're running into an issue with the <strong>readline</strong> module. I've been through various threads but can't seem to solve the issue. It's important ... | 3 | 2009-12-16T19:50:04Z | 1,917,371 | <p>Give this <a href="http://ipython.scipy.org/moin/PyReadline/Intro" rel="nofollow">readline</a> a try. It is a module for Windows that allows additional features in IPython that aren't native and might work with what you are trying to do.</p>
| 2 | 2009-12-16T20:15:51Z | [
"python",
"windows",
"deployment",
"fabric"
] |
Installing Fabric On Windows (Error No Module Called Readline) | 1,917,193 | <p>I'm trying to use the <strong>Fabric 0.1.1</strong> deploy tool (<a href="http://docs.fabfile.org/" rel="nofollow">http://docs.fabfile.org/</a>) on Windows and we're running into an issue with the <strong>readline</strong> module. I've been through various threads but can't seem to solve the issue. It's important ... | 3 | 2009-12-16T19:50:04Z | 1,936,936 | <p>0.1.1 is an older version, I believe. I have no problem installing <a href="http://code.activestate.com/pypm/fabric/" rel="nofollow">Fabric</a> on Windows with <a href="http://www.activestate.com/activepython/" rel="nofollow">ActivePython</a> (w/ <a href="http://code.activestate.com/pypm/" rel="nofollow">PyPM</a>):<... | 2 | 2009-12-20T20:32:34Z | [
"python",
"windows",
"deployment",
"fabric"
] |
Installing Fabric On Windows (Error No Module Called Readline) | 1,917,193 | <p>I'm trying to use the <strong>Fabric 0.1.1</strong> deploy tool (<a href="http://docs.fabfile.org/" rel="nofollow">http://docs.fabfile.org/</a>) on Windows and we're running into an issue with the <strong>readline</strong> module. I've been through various threads but can't seem to solve the issue. It's important ... | 3 | 2009-12-16T19:50:04Z | 3,053,769 | <ol>
<li>Download and run easy_install installer for your python version from <a href="http://pypi.python.org/pypi/setuptools#downloads" rel="nofollow">http://pypi.python.org/pypi/setuptools#downloads</a> . ie: <code>setuptools-0.6c11.win32-py2.6.exe</code></li>
<li>On the command prompt, lauch <code>easy_install -U fa... | 1 | 2010-06-16T13:42:35Z | [
"python",
"windows",
"deployment",
"fabric"
] |
Installing Fabric On Windows (Error No Module Called Readline) | 1,917,193 | <p>I'm trying to use the <strong>Fabric 0.1.1</strong> deploy tool (<a href="http://docs.fabfile.org/" rel="nofollow">http://docs.fabfile.org/</a>) on Windows and we're running into an issue with the <strong>readline</strong> module. I've been through various threads but can't seem to solve the issue. It's important ... | 3 | 2009-12-16T19:50:04Z | 16,625,327 | <p>Following these steps exactly worked for me:</p>
<p>1) Installed using the <a href="http://www.python.org/ftp/python/2.7.5/python-2.7.5.msi" rel="nofollow">MSI installer</a> for x86 from <a href="http://www.python.org/download/releases/2.7.5/" rel="nofollow">here</a>.</p>
<p>2) Installed in the default C:\Python27... | 4 | 2013-05-18T14:23:34Z | [
"python",
"windows",
"deployment",
"fabric"
] |
How to launch a Python/Tkinter dialog box that self-destructs? | 1,917,198 | <p>Ok, I would like to put together a Python/Tkinter dialog box that displays a simple message and self-destructs after N seconds. Is there a simple way to do this?</p>
| 4 | 2009-12-16T19:50:51Z | 1,917,389 | <p>You can use the <code>after</code> function to call a function after a delay elapsed and the <code>destroy</code> to close the window.</p>
<p>Here is an example</p>
<pre><code>from Tkinter import Label, Tk
root = Tk()
prompt = 'hello'
label1 = Label(root, text=prompt, width=len(prompt))
label1.pack()
def close_af... | 9 | 2009-12-16T20:19:26Z | [
"python",
"tkinter"
] |
How to launch a Python/Tkinter dialog box that self-destructs? | 1,917,198 | <p>Ok, I would like to put together a Python/Tkinter dialog box that displays a simple message and self-destructs after N seconds. Is there a simple way to do this?</p>
| 4 | 2009-12-16T19:50:51Z | 1,917,457 | <p>you could also use a thread.<br>
this example uses a Timer to call destroy() after a specified amount of time.</p>
<pre><code>import threading
import Tkinter
root = Tkinter.Tk()
Tkinter.Frame(root, width=250, height=100).pack()
Tkinter.Label(root, text='Hello').place(x=10, y=10)
threading.Timer(3.0, root.destroy... | 1 | 2009-12-16T20:29:00Z | [
"python",
"tkinter"
] |
Control decimal division precision in MySQLdb | 1,917,385 | <p>MySQLdb does some weirdness where it seems to always return a Decimal object with 2 more significant figures than the numerator of a division operation.</p>
<p>If the denominator is relatively large, this means that sometimes the result gets truncated to zero:</p>
<pre><code>>>> import MySQLdb
>>>... | 1 | 2009-12-16T20:18:28Z | 1,917,874 | <p>You can change the div_precision_increment variable. It defaults to 4.</p>
<p><a href="http://dev.mysql.com/doc/refman/5.0/en/server-system-variables.html#sysvar%5Fdiv%5Fprecision%5Fincrement" rel="nofollow">http://dev.mysql.com/doc/refman/5.0/en/server-system-variables.html#sysvar%5Fdiv%5Fprecision%5Fincrement</a>... | 3 | 2009-12-16T21:29:47Z | [
"python",
"mysql"
] |
Would calling a function like this be considered bad practice? | 1,917,537 | <p>Suppose I have this function signature:</p>
<pre><code>def foo(a=True, b=True, c=True, d=True, e=True):
</code></pre>
<p>I've decided these would be concise ways to call this function, considering all passed parameters should be <code>False</code>:</p>
<pre><code>foo(*5*[False])
foo(*[False]*5)
</code></pre>
<p>... | 1 | 2009-12-16T20:41:02Z | 1,917,550 | <p>if it's hard to read, it's bad style.</p>
<p>remember that code is read <em>a lot</em> more often than written.</p>
| 9 | 2009-12-16T20:42:59Z | [
"python"
] |
Would calling a function like this be considered bad practice? | 1,917,537 | <p>Suppose I have this function signature:</p>
<pre><code>def foo(a=True, b=True, c=True, d=True, e=True):
</code></pre>
<p>I've decided these would be concise ways to call this function, considering all passed parameters should be <code>False</code>:</p>
<pre><code>foo(*5*[False])
foo(*[False]*5)
</code></pre>
<p>... | 1 | 2009-12-16T20:41:02Z | 1,917,571 | <p>Your code should explain itself and be easy to read. The <a href="http://www.python.org/dev/peps/pep-0008/" rel="nofollow">Style Guide for Python</a> gives this example which should help answer your question:</p>
<blockquote>
<p>Use ''.startswith() and ''.endswith()
instead of string slicing to check for
pref... | 1 | 2009-12-16T20:45:47Z | [
"python"
] |
Would calling a function like this be considered bad practice? | 1,917,537 | <p>Suppose I have this function signature:</p>
<pre><code>def foo(a=True, b=True, c=True, d=True, e=True):
</code></pre>
<p>I've decided these would be concise ways to call this function, considering all passed parameters should be <code>False</code>:</p>
<pre><code>foo(*5*[False])
foo(*[False]*5)
</code></pre>
<p>... | 1 | 2009-12-16T20:41:02Z | 1,917,574 | <p>I like following the 80-20 rule with default values. If a function has default values for a parameter and I choose to use a different value, I need to make that evident in the call because that is an important piece of information.</p>
<p>If you are actually going and "violating" five default parameters, I would ex... | 4 | 2009-12-16T20:45:51Z | [
"python"
] |
Relational/Logic Programming in Python? | 1,917,607 | <p>I'm a longtime python developer and recently have been introduced to Prolog. I love the concept of using relationship rules for certain kinds of tasks, and would like to add this to my repertoire.</p>
<p>Are there any good libraries for logic programming in Python? I've done some searching on Google but only foun... | 26 | 2009-12-16T20:50:21Z | 1,917,894 | <p>Perhaps you should google "Logic Programming in Python". <a href="http://pyke.sourceforge.net/" rel="nofollow">Pyke</a> looks promising:</p>
<blockquote>
<p>Pyke introduces a form of Logic Programming (inspired by Prolog) to
the Python community by providing a knowledge-based inference engine
(expert system) ... | 9 | 2009-12-16T21:32:33Z | [
"python",
"prolog",
"logic-programming"
] |
Relational/Logic Programming in Python? | 1,917,607 | <p>I'm a longtime python developer and recently have been introduced to Prolog. I love the concept of using relationship rules for certain kinds of tasks, and would like to add this to my repertoire.</p>
<p>Are there any good libraries for logic programming in Python? I've done some searching on Google but only foun... | 26 | 2009-12-16T20:50:21Z | 3,943,891 | <p>You could also look at Dee, which adds relations to Python: <a href="http://www.quicksort.co.uk" rel="nofollow">http://www.quicksort.co.uk</a></p>
| 2 | 2010-10-15T15:53:11Z | [
"python",
"prolog",
"logic-programming"
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.