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
Check if the integer in a list is not duplicated, and sequential
2,429,073
<p>testGroupList is a list of integer. I need to check the numbers in testGroupList is sequential and not duplicate numbers. Ignore the negative integer. </p> <p>For example, [1,2,-1,2,3,4] is an error as 2 is duplicated, but [-1,3,2,4,1,5] is OK. </p> <p>I implemented it as follows, and it's pretty ugly. Is there an...
1
2010-03-11T22:11:56Z
5,857,464
<p>If you are just trying to determine a list has no duplicates, then you can create a set() with the list's elements, and compare the length of the two. Same length means no duplicates.</p> <p>Determining if they are sequential can look at the difference of max and min of the list, which should be one less than the ...
0
2011-05-02T13:04:10Z
[ "python" ]
How to treat the last element in list differently in Python?
2,429,098
<p>I need to do some special operation for the last element in a list. Is there any better way than this?</p> <pre> array = [1,2,3,4,5] for i, val in enumerate(array): if (i+1) == len(array): // Process for the last element else: // Process for the other element </pre>
28
2010-03-11T22:15:02Z
2,429,118
<pre><code>for item in list[:-1]: print "Not last: ", item print "Last: ", list[-1] </code></pre> <p>If you don't want to make a copy of list, you can make a simple generator:</p> <pre><code># itr is short for "iterable" and can be any sequence, iterator, or generator def notlast(itr): itr = iter(itr) # ens...
32
2010-03-11T22:17:48Z
[ "python" ]
How to treat the last element in list differently in Python?
2,429,098
<p>I need to do some special operation for the last element in a list. Is there any better way than this?</p> <pre> array = [1,2,3,4,5] for i, val in enumerate(array): if (i+1) == len(array): // Process for the last element else: // Process for the other element </pre>
28
2010-03-11T22:15:02Z
2,429,129
<p>If your sequence isn't terribly long then you can just slice it:</p> <pre><code>for val in array[:-1]: do_something(val) else: do_something_else(array[-1]) </code></pre>
20
2010-03-11T22:18:41Z
[ "python" ]
How to treat the last element in list differently in Python?
2,429,098
<p>I need to do some special operation for the last element in a list. Is there any better way than this?</p> <pre> array = [1,2,3,4,5] for i, val in enumerate(array): if (i+1) == len(array): // Process for the last element else: // Process for the other element </pre>
28
2010-03-11T22:15:02Z
2,429,260
<p>using itertools</p> <pre><code>&gt;&gt;&gt; from itertools import repeat, chain,izip &gt;&gt;&gt; for val,special in izip(array, chain(repeat(False,len(array)-1),[True])): ... print val, special ... 1 False 2 False 3 False 4 False 5 True </code></pre> <p>Version of liori's answer to work on any iterable (does...
3
2010-03-11T22:36:54Z
[ "python" ]
How to treat the last element in list differently in Python?
2,429,098
<p>I need to do some special operation for the last element in a list. Is there any better way than this?</p> <pre> array = [1,2,3,4,5] for i, val in enumerate(array): if (i+1) == len(array): // Process for the last element else: // Process for the other element </pre>
28
2010-03-11T22:15:02Z
26,423,497
<pre><code>for i in items: if i == items[-1]: print 'The last item is: '+i </code></pre>
-1
2014-10-17T10:55:44Z
[ "python" ]
How to determine if the given object is of given type in Python?
2,429,164
<p>I always thought operator <code>is</code> determined if the given variable is of the given type. But I just determined it was not true:</p> <pre><code>&gt;&gt;&gt; class A(): pass ... &gt;&gt;&gt; a = A() &gt;&gt;&gt; a is A False </code></pre> <p>How do I test if <code>a</code> is of type <code>class A</co...
4
2010-03-11T22:23:55Z
2,429,175
<p>You want <code>isinstance(a, A)</code>.</p> <p>Keep in mind, it might be better to avoid the <code>isinstance</code> check by adding methods to <code>A</code> that make it do what you want without explicitly determining that it is an <code>A</code>.</p> <p><code>is</code> determines if two objects are the same obj...
7
2010-03-11T22:25:06Z
[ "python", "types" ]
How to determine if the given object is of given type in Python?
2,429,164
<p>I always thought operator <code>is</code> determined if the given variable is of the given type. But I just determined it was not true:</p> <pre><code>&gt;&gt;&gt; class A(): pass ... &gt;&gt;&gt; a = A() &gt;&gt;&gt; a is A False </code></pre> <p>How do I test if <code>a</code> is of type <code>class A</co...
4
2010-03-11T22:23:55Z
2,429,176
<p><a href="http://docs.python.org/library/functions.html#isinstance" rel="nofollow">isinstance(a,A)</a></p>
2
2010-03-11T22:25:16Z
[ "python", "types" ]
Difference between Python dynamic field lookup
2,429,232
<p>What's the difference (if any) between</p> <pre><code>model.__dict__['title_en'] </code></pre> <p>and</p> <pre><code>model.__getattribute__('title_en') </code></pre> <p>and what's best practice ?</p>
1
2010-03-11T22:33:41Z
2,429,242
<p>Best practice? Use <a href="http://diveintopython.net/power_of_introspection/getattr.html" rel="nofollow">getattr</a>.</p> <pre><code>getattr(model, 'title_en') </code></pre> <p>You only want <code>__getattr__</code> or <code>__getattribute__</code> when you want to <a href="http://docs.python.org/reference/datamo...
5
2010-03-11T22:35:02Z
[ "python" ]
Difference between Python dynamic field lookup
2,429,232
<p>What's the difference (if any) between</p> <pre><code>model.__dict__['title_en'] </code></pre> <p>and</p> <pre><code>model.__getattribute__('title_en') </code></pre> <p>and what's best practice ?</p>
1
2010-03-11T22:33:41Z
2,429,248
<p>The first won't work because <code>__dict__</code> is supposed to be a dictionary, not a function. And the correct way is <code>getattr(model, 'title_en')</code>.</p>
1
2010-03-11T22:35:31Z
[ "python" ]
Difference between Python dynamic field lookup
2,429,232
<p>What's the difference (if any) between</p> <pre><code>model.__dict__['title_en'] </code></pre> <p>and</p> <pre><code>model.__getattribute__('title_en') </code></pre> <p>and what's best practice ?</p>
1
2010-03-11T22:33:41Z
2,429,355
<p>As others have said, the <a href="http://docs.python.org/library/functions.html?highlight=getattr#getattr" rel="nofollow">getattr</a> built-in is the right way to get an attribute (in general you don't access Python special methods directly: you access them through built-ins and operators!).</p> <p><code>getattr</c...
5
2010-03-11T23:14:24Z
[ "python" ]
Why is Decimal('0') > 9999.0 True in Python?
2,429,475
<p>This is somehow related to my question <a href="http://stackoverflow.com/questions/2384078/why-is-0-true-in-python">Why is ''>0 True in Python?</a></p> <p>In Python 2.6.4:</p> <pre><code>&gt;&gt; Decimal('0') &gt; 9999.0 True </code></pre> <p>From the <a href="http://stackoverflow.com/questions/2384078/why-is-0-t...
5
2010-03-11T23:40:06Z
2,429,536
<p>Because the decimal module does not compare against any type except long, int, and Decimal. In all other cases, decimal silently returns the "not something it knows about object" as greater. You can see this behavior in the _convert_other() function of decimal.py</p> <p>Silly, silly Decimal class. </p> <p><em>...
12
2010-03-11T23:55:26Z
[ "python", "comparison", "types", "operators", "logic" ]
Why is Decimal('0') > 9999.0 True in Python?
2,429,475
<p>This is somehow related to my question <a href="http://stackoverflow.com/questions/2384078/why-is-0-true-in-python">Why is ''>0 True in Python?</a></p> <p>In Python 2.6.4:</p> <pre><code>&gt;&gt; Decimal('0') &gt; 9999.0 True </code></pre> <p>From the <a href="http://stackoverflow.com/questions/2384078/why-is-0-t...
5
2010-03-11T23:40:06Z
2,429,569
<pre><code>def __gt__(self, other, context=None): other = _convert_other(other) if other is NotImplemented: return other ans = self._compare_check_nans(other, context) if ans: return False return self._cmp(other) &gt; 0 def _convert_other(other, raiseit=False): """Convert other...
1
2010-03-12T00:01:53Z
[ "python", "comparison", "types", "operators", "logic" ]
Why do people write #!/usr/bin/env python on the first line of a Python script?
2,429,511
<p>It seems to me like the files run the same without that line.</p>
564
2010-03-11T23:50:54Z
2,429,515
<p>That is called the <a href="http://www.in-ulm.de/~mascheck/various/shebang/">shebang line</a>. As the <a href="http://en.wikipedia.org/wiki/Shebang_%28Unix%29">Wikipedia entry explains</a>:</p> <blockquote> <p>In computing, a shebang (also called a hashbang, hashpling, pound bang, or crunchbang) refers to the cha...
169
2010-03-11T23:52:37Z
[ "python", "shell", "shebang" ]
Why do people write #!/usr/bin/env python on the first line of a Python script?
2,429,511
<p>It seems to me like the files run the same without that line.</p>
564
2010-03-11T23:50:54Z
2,429,517
<p>If you have several versions of Python installed, <code>/usr/bin/env</code> will ensure the interpreter used is the first one on your environment's <code>$PATH</code>. The alternative would be to hardcode something like <code>#!/usr/bin/python</code>; that's ok, but less flexible.</p> <p>In Unix, an <em>executable<...
683
2010-03-11T23:52:41Z
[ "python", "shell", "shebang" ]
Why do people write #!/usr/bin/env python on the first line of a Python script?
2,429,511
<p>It seems to me like the files run the same without that line.</p>
564
2010-03-11T23:50:54Z
2,429,524
<p>This is a shell convention that tells the shell which program can execute the script.</p> <pre>#!/usr/bin/env python</pre> <p>resolves to a path to the Python binary.</p>
8
2010-03-11T23:53:22Z
[ "python", "shell", "shebang" ]
Why do people write #!/usr/bin/env python on the first line of a Python script?
2,429,511
<p>It seems to me like the files run the same without that line.</p>
564
2010-03-11T23:50:54Z
2,429,552
<p>Technically, in Python, this is just a comment line.</p> <p>This line is only used if you run the py script <em>from the shell</em> (from the command line). This is know as the <a href="https://en.wikipedia.org/wiki/Shebang_(Unix)">"<em>Shebang</em>!"</a>, and it is used in various situations, not just with Python ...
31
2010-03-11T23:58:43Z
[ "python", "shell", "shebang" ]
Why do people write #!/usr/bin/env python on the first line of a Python script?
2,429,511
<p>It seems to me like the files run the same without that line.</p>
564
2010-03-11T23:50:54Z
2,429,556
<blockquote> <p>It seems to me like the files run the same without that line.</p> </blockquote> <p>If so, then perhaps you're running the Python program on Windows? Windows doesn't use that line—instead, it uses the file-name extension to run the program associated with the file extension.</p>
3
2010-03-11T23:59:37Z
[ "python", "shell", "shebang" ]
Why do people write #!/usr/bin/env python on the first line of a Python script?
2,429,511
<p>It seems to me like the files run the same without that line.</p>
564
2010-03-11T23:50:54Z
2,429,730
<p>Expanding a bit on the other answers, here's a little example of how your command line scripts can get into trouble by incautious use of <code>/usr/bin/env</code> shebang lines:</p> <pre><code>$ /usr/local/bin/python -V Python 2.6.4 $ /usr/bin/python -V Python 2.5.1 $ cat my_script.py #!/usr/bin/env python import ...
107
2010-03-12T00:35:46Z
[ "python", "shell", "shebang" ]
Why do people write #!/usr/bin/env python on the first line of a Python script?
2,429,511
<p>It seems to me like the files run the same without that line.</p>
564
2010-03-11T23:50:54Z
6,769,343
<p>The main reason to do this is to make the script portable across operating system environments. </p> <p>For example under mingw, python scripts use :</p> <pre><code>#!/c/python3k/python </code></pre> <p>and under GNU/Linux distribution it is either:</p> <pre><code>#!/usr/local/bin/python </code></pre> <p>or ...
31
2011-07-20T22:34:10Z
[ "python", "shell", "shebang" ]
Why do people write #!/usr/bin/env python on the first line of a Python script?
2,429,511
<p>It seems to me like the files run the same without that line.</p>
564
2010-03-11T23:50:54Z
8,463,033
<p>It's recommended way, proposed in documentation:</p> <blockquote> <p>2.2.2. Executable Python Scripts</p> <p>On BSD’ish Unix systems, Python scripts can be made directly executable, like shell scripts, by putting the line</p> <pre><code>#! /usr/bin/env python3.2 </code></pre> </blockquote> <p>from <a h...
11
2011-12-11T09:34:30Z
[ "python", "shell", "shebang" ]
Why do people write #!/usr/bin/env python on the first line of a Python script?
2,429,511
<p>It seems to me like the files run the same without that line.</p>
564
2010-03-11T23:50:54Z
9,865,189
<p>In order to run the python script, we need to tell the shell three things:</p> <ol> <li>That the file is a script</li> <li>Which interpreter we want to execute the script</li> <li>The path of said interpreter</li> </ol> <p>The shebang <code>#!</code> accomplishes (1.). The shebang begins with a <code>#</code> beca...
65
2012-03-26T00:07:27Z
[ "python", "shell", "shebang" ]
Why do people write #!/usr/bin/env python on the first line of a Python script?
2,429,511
<p>It seems to me like the files run the same without that line.</p>
564
2010-03-11T23:50:54Z
13,992,280
<p>You can try this issue using virtualenv</p> <p>Here is test.py</p> <pre><code>#! /usr/bin/env python import sys print(sys.version) </code></pre> <p>Create virtual environments</p> <pre><code>virtualenv test2.6 -p /usr/bin/python2.6 virtualenv test2.7 -p /usr/bin/python2.7 </code></pre> <p>activate each environm...
8
2012-12-21T14:52:58Z
[ "python", "shell", "shebang" ]
Why do people write #!/usr/bin/env python on the first line of a Python script?
2,429,511
<p>It seems to me like the files run the same without that line.</p>
564
2010-03-11T23:50:54Z
22,475,174
<p>It probably makes sense to emphasize one thing that the most have missed, which may prevent immediate understanding. When you type <code>python</code> in terminal you don't normally provide a full path. Instead, the executable is up looked in <code>PATH</code> environment variable. In turn, when you want to execute ...
15
2014-03-18T09:31:10Z
[ "python", "shell", "shebang" ]
Why do people write #!/usr/bin/env python on the first line of a Python script?
2,429,511
<p>It seems to me like the files run the same without that line.</p>
564
2010-03-11T23:50:54Z
27,998,855
<p>Perhaps your question is in this sense:</p> <p>If you want to use: <code>$python myscript.py</code></p> <p>You don't need that line at all. The system will call python and then python interpreter will run your script.</p> <p>But if you intend to use: <code>$./myscript.py</code></p> <p>Calling it directly like a ...
23
2015-01-17T11:13:25Z
[ "python", "shell", "shebang" ]
Why do people write #!/usr/bin/env python on the first line of a Python script?
2,429,511
<p>It seems to me like the files run the same without that line.</p>
564
2010-03-11T23:50:54Z
27,998,937
<p>this tells the script where is python directory !</p> <pre><code>#! /usr/bin/env python </code></pre>
-4
2015-01-17T11:22:45Z
[ "python", "shell", "shebang" ]
Why do people write #!/usr/bin/env python on the first line of a Python script?
2,429,511
<p>It seems to me like the files run the same without that line.</p>
564
2010-03-11T23:50:54Z
36,437,905
<p>If you're running your script in a virtual environment, say <code>venv</code>, then executing <code>which python</code> while working on <code>venv</code> will display the path to the Python interpreter:</p> <p><strong><code>~/Envs/venv/bin/python</code></strong></p> <p>Note that the <strong>name of the virtual en...
3
2016-04-05T22:05:42Z
[ "python", "shell", "shebang" ]
Why do people write #!/usr/bin/env python on the first line of a Python script?
2,429,511
<p>It seems to me like the files run the same without that line.</p>
564
2010-03-11T23:50:54Z
37,304,649
<p>Considering the portability issues between <code>python2</code> and <code>python3</code>, you should always specify either version unless your program is compatible with both.</p> <p>Some distributions are shipping <code>python</code> symlinked to <code>python3</code> for a while now - do not rely on <code>python</...
1
2016-05-18T15:58:10Z
[ "python", "shell", "shebang" ]
Why do people write #!/usr/bin/env python on the first line of a Python script?
2,429,511
<p>It seems to me like the files run the same without that line.</p>
564
2010-03-11T23:50:54Z
37,794,533
<p>It tells the interpreter which version of python to run the program with when you have multiple versions of python.</p>
1
2016-06-13T16:12:49Z
[ "python", "shell", "shebang" ]
Python for loop question
2,429,560
<p>I was wondering how to achieve the following in python:</p> <pre><code>for( int i = 0; cond...; i++) if cond... i++; //to skip an run-through </code></pre> <p>I tried this with no luck.</p> <pre><code>for i in range(whatever): if cond... : i += 1 </code></pre>
14
2010-03-12T00:00:39Z
2,429,584
<p>There is a <code>continue</code> keyword which skips the current iteration and advances to the next one (and a <code>break</code> keyword which skips all loop iterations and exits the loop):</p> <pre><code>for i in range(10): if i % 2 == 0: # skip even numbers continue print i </code></pre>
8
2010-03-12T00:04:13Z
[ "python", "loops", "for-loop" ]
Python for loop question
2,429,560
<p>I was wondering how to achieve the following in python:</p> <pre><code>for( int i = 0; cond...; i++) if cond... i++; //to skip an run-through </code></pre> <p>I tried this with no luck.</p> <pre><code>for i in range(whatever): if cond... : i += 1 </code></pre>
14
2010-03-12T00:00:39Z
2,429,600
<p>Python's for loops are different. <code>i</code> gets reassigned to the next value every time through the loop.</p> <p>The following will do what you want, because it is taking the literal version of what C++ is doing:</p> <pre><code>i = 0 while i &lt; some_value: if cond...: i+=1 ...code... i...
21
2010-03-12T00:07:36Z
[ "python", "loops", "for-loop" ]
Python for loop question
2,429,560
<p>I was wondering how to achieve the following in python:</p> <pre><code>for( int i = 0; cond...; i++) if cond... i++; //to skip an run-through </code></pre> <p>I tried this with no luck.</p> <pre><code>for i in range(whatever): if cond... : i += 1 </code></pre>
14
2010-03-12T00:00:39Z
2,429,605
<p>You can't trivially "skip the next leg" (you can of course skip <em>this</em> leg with a <code>continue</code>). If you really insist you can do it with an auxiliary <code>bool</code>, e.g.</p> <pre><code>skipping = False for i in whatever: if skipping: skipping = False continue skipping = cond ... </...
0
2010-03-12T00:08:33Z
[ "python", "loops", "for-loop" ]
Python for loop question
2,429,560
<p>I was wondering how to achieve the following in python:</p> <pre><code>for( int i = 0; cond...; i++) if cond... i++; //to skip an run-through </code></pre> <p>I tried this with no luck.</p> <pre><code>for i in range(whatever): if cond... : i += 1 </code></pre>
14
2010-03-12T00:00:39Z
2,429,616
<p>Remember that you are iterating over the elements in the list, and not iterating over a number.</p> <p>For example consider the following:</p> <pre><code>for i in ["cat", "dog"]: print i </code></pre> <p>What would happen if you did i+1 there? You can see now why it doesn't skip the next element in the list.</p...
4
2010-03-12T00:10:53Z
[ "python", "loops", "for-loop" ]
Python for loop question
2,429,560
<p>I was wondering how to achieve the following in python:</p> <pre><code>for( int i = 0; cond...; i++) if cond... i++; //to skip an run-through </code></pre> <p>I tried this with no luck.</p> <pre><code>for i in range(whatever): if cond... : i += 1 </code></pre>
14
2010-03-12T00:00:39Z
2,432,290
<p>You can explicitly increment the iterator.</p> <pre><code>whatever = iter(whatever) for i in whatever: if cond: whatever.next() </code></pre> <p>You will need to catch StopIteration if cond can be True on the last element.</p>
4
2010-03-12T11:16:58Z
[ "python", "loops", "for-loop" ]
Python for loop question
2,429,560
<p>I was wondering how to achieve the following in python:</p> <pre><code>for( int i = 0; cond...; i++) if cond... i++; //to skip an run-through </code></pre> <p>I tried this with no luck.</p> <pre><code>for i in range(whatever): if cond... : i += 1 </code></pre>
14
2010-03-12T00:00:39Z
2,450,646
<pre><code>for i in filter(lambda x:x!=2,range(5)): </code></pre>
0
2010-03-15T21:31:47Z
[ "python", "loops", "for-loop" ]
Python for loop question
2,429,560
<p>I was wondering how to achieve the following in python:</p> <pre><code>for( int i = 0; cond...; i++) if cond... i++; //to skip an run-through </code></pre> <p>I tried this with no luck.</p> <pre><code>for i in range(whatever): if cond... : i += 1 </code></pre>
14
2010-03-12T00:00:39Z
2,450,740
<p>There is an alternate approach to this, depending on the task you are trying to accomplish. If <code>cond</code> is entirely a function of the input data you are looping over, you might try something like the following:</p> <pre><code>def check_cond(item): if item satisfies cond: return True return ...
2
2010-03-15T21:50:27Z
[ "python", "loops", "for-loop" ]
Add Keyboard Binding To Existing Emacs Mode
2,429,603
<p>I'm attempting my first modification of Emacs. I recorded a little keyboard macro and had Emacs spit it out as elisp, resulting in:</p> <pre><code>(setq add-docstring "\C-rdef\C-n\C-a\C-m\C-p\C-i\C-u6\"\C-u3\C-b") (global-set-key "\C-c\C-d" 'add-docstring)</code></pre> <p>Searching the Emacs reference, though...
6
2010-03-12T00:08:12Z
2,430,392
<p>Firstly, do not mess with python.el. What you want to do is to create your own custom binding for python mode. This is usually done in your <code>.emacs</code> file in your home directory.</p> <p>In that file add something like the following (I have not tested this -- so there may be some error in syntax and I do n...
1
2010-03-12T03:51:06Z
[ "python", "emacs", "keyboard-shortcuts", "elisp" ]
Add Keyboard Binding To Existing Emacs Mode
2,429,603
<p>I'm attempting my first modification of Emacs. I recorded a little keyboard macro and had Emacs spit it out as elisp, resulting in:</p> <pre><code>(setq add-docstring "\C-rdef\C-n\C-a\C-m\C-p\C-i\C-u6\"\C-u3\C-b") (global-set-key "\C-c\C-d" 'add-docstring)</code></pre> <p>Searching the Emacs reference, though...
6
2010-03-12T00:08:12Z
2,430,474
<p>It turns out, <kbd>C-c C-d</kbd> is already bound in <code>python-mode</code> (to <code>'python-pdbtrack-toggle-stack-tracking</code>), so you may want to revisit your choice of key binding.</p> <p><em>Note:</em> if you just want to cut/paste a solution, jump to the end of the answer. Read on for an explanation of...
14
2010-03-12T04:14:42Z
[ "python", "emacs", "keyboard-shortcuts", "elisp" ]
python: variable not getting defined after several conditionals
2,429,637
<p>For some reason this program is saying that 'switch' is not defined. What is going on?</p> <pre><code>#PYTHON 3.1.1 class mysrt: def __init__(self): self.DATA = open('ORDER.txt', 'r') self.collect = 0 cache1 = str(self.DATA.readlines()) cache2 = [] ...
1
2010-03-12T00:15:02Z
2,429,654
<p>If <code>CACHE_LIST_1</code> is an empty sequence then <code>switch</code> will never get bound.</p>
6
2010-03-12T00:17:20Z
[ "python", "class", "python-3.x" ]
What is the purpose of a zip function (as in Python or C# 4.0)?
2,429,692
<p>Someone asked <a href="http://stackoverflow.com/questions/2427015">How to do Python’s zip in C#?</a>...</p> <p>...which leads me to ask, what good is zip? In what scenarios do I need this? Is it really so foundational that I need this in the base class library? </p>
7
2010-03-12T00:26:32Z
2,429,712
<p>It allows you to process sequences in parallel instead of sequentially or nested. There's... so many uses for it that they currently escape me.</p>
7
2010-03-12T00:29:33Z
[ "c#", "python", "zip" ]
What is the purpose of a zip function (as in Python or C# 4.0)?
2,429,692
<p>Someone asked <a href="http://stackoverflow.com/questions/2427015">How to do Python’s zip in C#?</a>...</p> <p>...which leads me to ask, what good is zip? In what scenarios do I need this? Is it really so foundational that I need this in the base class library? </p>
7
2010-03-12T00:26:32Z
2,429,725
<p>Here's a common use case for zip:</p> <pre><code>x = [1,2,3,4,5] y = [6,7,8,9,0] for a,b in zip(x,y): print a, b </code></pre> <p>Which would output:</p> <pre><code>1 6 2 7 3 8 4 9 5 0 </code></pre>
7
2010-03-12T00:35:07Z
[ "c#", "python", "zip" ]
What is the purpose of a zip function (as in Python or C# 4.0)?
2,429,692
<p>Someone asked <a href="http://stackoverflow.com/questions/2427015">How to do Python’s zip in C#?</a>...</p> <p>...which leads me to ask, what good is zip? In what scenarios do I need this? Is it really so foundational that I need this in the base class library? </p>
7
2010-03-12T00:26:32Z
2,429,734
<p>A use case:</p> <pre><code>&gt;&gt;&gt; fields = ["id", "name", "location"] &gt;&gt;&gt; values = ["13", "bill", "redmond"] &gt;&gt;&gt; dict(zip(fields, values)) {'location': 'redmond', 'id': '13', 'name': 'bill'} </code></pre> <p>Try doing this without zip...</p>
5
2010-03-12T00:36:43Z
[ "c#", "python", "zip" ]
What is the purpose of a zip function (as in Python or C# 4.0)?
2,429,692
<p>Someone asked <a href="http://stackoverflow.com/questions/2427015">How to do Python’s zip in C#?</a>...</p> <p>...which leads me to ask, what good is zip? In what scenarios do I need this? Is it really so foundational that I need this in the base class library? </p>
7
2010-03-12T00:26:32Z
2,429,737
<p>zip is useful if you'd like to iterate over multiple iterables simultaneously, which is a reasonably common scenario in Python.</p> <p>One real-world scenario where zip has come in handy for me is if you have an M by N array, and you want to look at columns instead of rows. For example:</p> <pre><code>&gt;&gt;&gt...
11
2010-03-12T00:37:46Z
[ "c#", "python", "zip" ]
What is the purpose of a zip function (as in Python or C# 4.0)?
2,429,692
<p>Someone asked <a href="http://stackoverflow.com/questions/2427015">How to do Python’s zip in C#?</a>...</p> <p>...which leads me to ask, what good is zip? In what scenarios do I need this? Is it really so foundational that I need this in the base class library? </p>
7
2010-03-12T00:26:32Z
2,429,749
<p>Here's a case where I used <code>zip()</code> to useful effect, in a Python class for comparing version numbers:</p> <pre><code>class Version(object): # ... snip ... def get_tuple(self): return (self.major, self.minor, self.revision) def compare(self, other): def comp(a, b): ...
2
2010-03-12T00:41:51Z
[ "c#", "python", "zip" ]
What is the purpose of a zip function (as in Python or C# 4.0)?
2,429,692
<p>Someone asked <a href="http://stackoverflow.com/questions/2427015">How to do Python’s zip in C#?</a>...</p> <p>...which leads me to ask, what good is zip? In what scenarios do I need this? Is it really so foundational that I need this in the base class library? </p>
7
2010-03-12T00:26:32Z
2,429,762
<p>It's handy in different places. My favorite, from <a href="http://norvig.com/python-iaq.html" rel="nofollow">http://norvig.com/python-iaq.html</a>, is transposing a matrix:</p> <pre><code>&gt;&gt;&gt; x = [ [1,2,3,4,5],[6,7,8,9,10],[11,12,13,14,15]] &gt;&gt;&gt; zip(*x) [(1, 6, 11), (2, 7, 12), (3, 8, 13), (4, 9,...
3
2010-03-12T00:46:02Z
[ "c#", "python", "zip" ]
What is the purpose of a zip function (as in Python or C# 4.0)?
2,429,692
<p>Someone asked <a href="http://stackoverflow.com/questions/2427015">How to do Python’s zip in C#?</a>...</p> <p>...which leads me to ask, what good is zip? In what scenarios do I need this? Is it really so foundational that I need this in the base class library? </p>
7
2010-03-12T00:26:32Z
2,429,912
<p>Someone actually asked a <a href="http://stackoverflow.com/questions/2352379/can-i-get-the-delta-of-two-ienumerables-in-linq/2352450#2352450">question</a> here fairly recently that I answered with the <code>Zip</code> extension method, so it's obviously important for <em>some</em> people. ;)</p> <p>Actually, it is ...
6
2010-03-12T01:28:29Z
[ "c#", "python", "zip" ]
Need help understanding "TypeError: default __new__ takes no parameters" error in python
2,429,899
<p>For some reason I am having trouble getting my head around <code>__init__</code> and <code>__new__</code>. I have a bunch of code that runs fine from the terminal, but when I load it as a plugin for Google Quick Search Box, I get the error <code>TypeError: default __new__ takes no parameters</code>.</p> <p>I have b...
3
2010-03-12T01:24:19Z
2,429,957
<p>Simplest way to reproduce your problem:</p> <pre><code>&gt;&gt;&gt; class Bah(object): pass ... &gt;&gt;&gt; x = Bah(23) Traceback (most recent call last): File "&lt;stdin&gt;", line 1, in ? TypeError: default __new__ takes no parameters </code></pre> <p>So it looks like there's a class in your code (not when r...
7
2010-03-12T01:40:03Z
[ "python", "init", "typeerror" ]
Need help understanding "TypeError: default __new__ takes no parameters" error in python
2,429,899
<p>For some reason I am having trouble getting my head around <code>__init__</code> and <code>__new__</code>. I have a bunch of code that runs fine from the terminal, but when I load it as a plugin for Google Quick Search Box, I get the error <code>TypeError: default __new__ takes no parameters</code>.</p> <p>I have b...
3
2010-03-12T01:24:19Z
2,429,977
<p>There are a handful of basic class construction concepts that you seem to be missing. </p> <p>The <code>__init__</code> method is used when the class is first <code>init</code>ialized, and is how you set up its internals. You also want to take advantage of Python's <a href="http://stackoverflow.com/questions/5486...
2
2010-03-12T01:44:32Z
[ "python", "init", "typeerror" ]
Python help() function and the string.title function
2,430,166
<p>Why doesn't </p> <pre><code>import string;help(string.title) </code></pre> <p>seem to work but </p> <pre><code>help(string.strip) </code></pre> <p>works just fine?</p> <p>I get the error </p> <blockquote> <p>Traceback (most recent call last):<br> File "", line 1, in AttributeError: 'module' obj...
3
2010-03-12T02:39:02Z
2,430,176
<p><code>help(str.title)</code> seems to work just fine.</p>
1
2010-03-12T02:41:47Z
[ "python" ]
Python help() function and the string.title function
2,430,166
<p>Why doesn't </p> <pre><code>import string;help(string.title) </code></pre> <p>seem to work but </p> <pre><code>help(string.strip) </code></pre> <p>works just fine?</p> <p>I get the error </p> <blockquote> <p>Traceback (most recent call last):<br> File "", line 1, in AttributeError: 'module' obj...
3
2010-03-12T02:39:02Z
2,430,231
<p><code>title</code> is a method on objects of type <code>str</code>, not a function in the <code>string</code> module. That means you can do <code>"foo".title()</code> or <code>str.title("foo")</code> but not <code>string.title("foo")</code>.</p>
2
2010-03-12T02:56:17Z
[ "python" ]
Which XML library for what purposes?
2,430,423
<p>A search for "python" and "xml" returns a variety of libraries for combining the two.</p> <p>This list probably faulty:</p> <ul> <li>xml.dom</li> <li>xml.etree</li> <li>xml.sax</li> <li>xml.parsers.expat</li> <li>PyXML</li> <li>beautifulsoup?</li> <li>HTMLParser</li> <li>htmllib</li> <li>sgmllib</li> </ul> <p>Be ...
7
2010-03-12T04:02:26Z
2,430,541
<p>The DOM/SAX divide is a basic one. It applies not just to python since DOM and SAX are cross-language.</p> <p><strong>DOM</strong>: read the whole document into memory and manipulate it. Good for:</p> <ul> <li>complex relationships across tags in the markup</li> <li>small intricate XML documents</li> <li>Cautions:...
6
2010-03-12T04:40:02Z
[ "python", "xml" ]
Which XML library for what purposes?
2,430,423
<p>A search for "python" and "xml" returns a variety of libraries for combining the two.</p> <p>This list probably faulty:</p> <ul> <li>xml.dom</li> <li>xml.etree</li> <li>xml.sax</li> <li>xml.parsers.expat</li> <li>PyXML</li> <li>beautifulsoup?</li> <li>HTMLParser</li> <li>htmllib</li> <li>sgmllib</li> </ul> <p>Be ...
7
2010-03-12T04:02:26Z
2,430,545
<p>I don't do much with XML, but when I've needed to, <a href="http://lxml.de/" rel="nofollow">lxml</a> has been a joy to work with and is apparently quite fast. The element tree API is very nice in an object oriented setting.</p>
1
2010-03-12T04:40:58Z
[ "python", "xml" ]
Which XML library for what purposes?
2,430,423
<p>A search for "python" and "xml" returns a variety of libraries for combining the two.</p> <p>This list probably faulty:</p> <ul> <li>xml.dom</li> <li>xml.etree</li> <li>xml.sax</li> <li>xml.parsers.expat</li> <li>PyXML</li> <li>beautifulsoup?</li> <li>HTMLParser</li> <li>htmllib</li> <li>sgmllib</li> </ul> <p>Be ...
7
2010-03-12T04:02:26Z
2,430,575
<p>I find <code>xml.etree</code> essentially sufficient for everything, except for <code>BeautifulSoup</code> if I ever need to parse <em>broken</em> XML (not a common problem, differently from broken HTML, which BeautifulSoup also helps with and <em>is</em> everywhere): it has reasonable support for reading entire XML...
4
2010-03-12T04:51:17Z
[ "python", "xml" ]
Which XML library for what purposes?
2,430,423
<p>A search for "python" and "xml" returns a variety of libraries for combining the two.</p> <p>This list probably faulty:</p> <ul> <li>xml.dom</li> <li>xml.etree</li> <li>xml.sax</li> <li>xml.parsers.expat</li> <li>PyXML</li> <li>beautifulsoup?</li> <li>HTMLParser</li> <li>htmllib</li> <li>sgmllib</li> </ul> <p>Be ...
7
2010-03-12T04:02:26Z
2,430,695
<p>For many problems you can get by with the xml. It has the major advantage of being part of the standard library. This means that it is pre-installed on almost every system and that the interface will be static. It is not the best, or the fastest, but it is there.</p> <p>For everything else there is lxml. Specic...
1
2010-03-12T05:31:34Z
[ "python", "xml" ]
using python 'with' statement with iterators?
2,430,501
<p>I'm using Python 2.5. I'm trying to use this 'with' statement.</p> <pre><code>from __future__ import with_statement a = [] with open('exampletxt.txt','r') as f: while True: a.append(f.next().strip().split()) print a </code></pre> <p>The contents of 'exampletxt.txt' are simple:</p> <pre><code>a b </cod...
4
2010-03-12T04:24:48Z
2,430,510
<p>Raising <code>StopIteration</code> is what an iterator does when it gets to the end. Normally the <code>for</code> statement catches it silently and continues to the <code>else</code> clause, but if it's being iterated manually as in your case then the code has to be prepared to handle the exception itself.</p>
4
2010-03-12T04:27:22Z
[ "python" ]
using python 'with' statement with iterators?
2,430,501
<p>I'm using Python 2.5. I'm trying to use this 'with' statement.</p> <pre><code>from __future__ import with_statement a = [] with open('exampletxt.txt','r') as f: while True: a.append(f.next().strip().split()) print a </code></pre> <p>The contents of 'exampletxt.txt' are simple:</p> <pre><code>a b </cod...
4
2010-03-12T04:24:48Z
2,430,513
<p>Your while loop doesn't end, but the file does so it raises a StopIteration exception when there is nothing else to iterate to.</p>
1
2010-03-12T04:28:46Z
[ "python" ]
using python 'with' statement with iterators?
2,430,501
<p>I'm using Python 2.5. I'm trying to use this 'with' statement.</p> <pre><code>from __future__ import with_statement a = [] with open('exampletxt.txt','r') as f: while True: a.append(f.next().strip().split()) print a </code></pre> <p>The contents of 'exampletxt.txt' are simple:</p> <pre><code>a b </cod...
4
2010-03-12T04:24:48Z
2,430,514
<p>You don't have any terminating condition in any of your while loops, so you keep returning until you get StopIteration exception which you don't handle.</p>
1
2010-03-12T04:29:28Z
[ "python" ]
using python 'with' statement with iterators?
2,430,501
<p>I'm using Python 2.5. I'm trying to use this 'with' statement.</p> <pre><code>from __future__ import with_statement a = [] with open('exampletxt.txt','r') as f: while True: a.append(f.next().strip().split()) print a </code></pre> <p>The contents of 'exampletxt.txt' are simple:</p> <pre><code>a b </cod...
4
2010-03-12T04:24:48Z
2,432,387
<p>You can always rewrite while-with-explicit-next loops. When you have an explicit <code>next</code>, you're just looking ahead one token.</p> <p>Generally, loops of this form can be rewritten.</p> <pre><code>def g(f): while True: x = f.next() if test1(x): a = x elif test2(x)...
1
2010-03-12T11:35:27Z
[ "python" ]
How to ping an ip and get only the ms in the Tk with Python?
2,430,519
<p>I want to make a little tk app that continuous ping an ip and only show the MS, like, "10ms" </p> <p>how could I do?</p>
2
2010-03-12T04:30:56Z
2,430,531
<p>To continuously ping an IP</p> <pre><code>os.system("ping -t 192.168.1.1") </code></pre>
0
2010-03-12T04:37:21Z
[ "python", "windows", "ping" ]
How to ping an ip and get only the ms in the Tk with Python?
2,430,519
<p>I want to make a little tk app that continuous ping an ip and only show the MS, like, "10ms" </p> <p>how could I do?</p>
2
2010-03-12T04:30:56Z
2,430,550
<p>If you want to use Windows <code>ping</code>, you'll have to parse the output from the command line.</p> <p>This is very specific, but should work:</p> <pre><code>import os while(1): ping = os.popen('ping www.google.com -n 1') result = ping.readlines() msLine = result[-1].strip() print msLine.splot...
2
2010-03-12T04:43:40Z
[ "python", "windows", "ping" ]
How do I get all the keys that are stored in the Cassandra column family with pycassa?
2,430,539
<p>Is anyone having experience working with <a href="http://github.com/vomjom/pycassa">pycassa</a> I have a doubt with it. How do I get all the keys that are stored in the database?</p> <p>well in this small snippet we need to give the keys in order to get the associated columns (here the keys are 'foo' and 'bar'),tha...
6
2010-03-12T04:39:38Z
2,540,908
<p>try: </p> <pre><code> list(cf.get_range().get_keys()) </code></pre> <p>more good stuff here: <a href="http://github.com/vomjom/pycassa">http://github.com/vomjom/pycassa</a></p>
11
2010-03-29T20:08:44Z
[ "python", "cassandra", "pycassa" ]
How do I get all the keys that are stored in the Cassandra column family with pycassa?
2,430,539
<p>Is anyone having experience working with <a href="http://github.com/vomjom/pycassa">pycassa</a> I have a doubt with it. How do I get all the keys that are stored in the database?</p> <p>well in this small snippet we need to give the keys in order to get the associated columns (here the keys are 'foo' and 'bar'),tha...
6
2010-03-12T04:39:38Z
5,345,342
<p><code>get_range([start][, finish][, columns][, column_start][, column_finish][, column_reversed][, column_count][, row_count][, include_timestamp][, super_column][, read_consistency_level][, buffer_size])</code></p> <blockquote> <p>Get an iterator over rows in a specified key range.</p> </blockquote> <p><a hre...
1
2011-03-17T21:15:19Z
[ "python", "cassandra", "pycassa" ]
How do I get all the keys that are stored in the Cassandra column family with pycassa?
2,430,539
<p>Is anyone having experience working with <a href="http://github.com/vomjom/pycassa">pycassa</a> I have a doubt with it. How do I get all the keys that are stored in the database?</p> <p>well in this small snippet we need to give the keys in order to get the associated columns (here the keys are 'foo' and 'bar'),tha...
6
2010-03-12T04:39:38Z
12,896,327
<p>You can try: <code>cf.get_range(column_count=0,filter_empty=False)</code>. </p> <pre><code># Since get_range() returns a generator - print only the keys. for value in cf.get_range(column_count=0,filter_empty=False): print value[0] </code></pre>
4
2012-10-15T13:10:37Z
[ "python", "cassandra", "pycassa" ]
How do I get all the keys that are stored in the Cassandra column family with pycassa?
2,430,539
<p>Is anyone having experience working with <a href="http://github.com/vomjom/pycassa">pycassa</a> I have a doubt with it. How do I get all the keys that are stored in the database?</p> <p>well in this small snippet we need to give the keys in order to get the associated columns (here the keys are 'foo' and 'bar'),tha...
6
2010-03-12T04:39:38Z
17,861,471
<p>Minor improvement on Santhosh's solution</p> <pre><code>dict(cf.get_range(column_count=0,filter_empty=False)).keys() </code></pre> <p>If you care about order:</p> <pre><code>OrderedDict(cf.get_range(column_count=0,filter_empty=False)).keys() </code></pre> <p>get_range returns a generator. We can create a dict f...
1
2013-07-25T14:52:10Z
[ "python", "cassandra", "pycassa" ]
How do I get all the keys that are stored in the Cassandra column family with pycassa?
2,430,539
<p>Is anyone having experience working with <a href="http://github.com/vomjom/pycassa">pycassa</a> I have a doubt with it. How do I get all the keys that are stored in the database?</p> <p>well in this small snippet we need to give the keys in order to get the associated columns (here the keys are 'foo' and 'bar'),tha...
6
2010-03-12T04:39:38Z
28,487,183
<p>There's a problem with <a href="http://stackoverflow.com/a/12896327/34813">Santhosh's</a> and <a href="http://stackoverflow.com/a/17861471/34813">kzarns'</a> answers, as you're bringing in memory a potentially huge dict that you are immediately discarding. A better approach would be using list comprehensions for thi...
0
2015-02-12T20:30:24Z
[ "python", "cassandra", "pycassa" ]
Scapy install issues. Nothing seems to actually be installed?
2,430,573
<p>I have an apple computer running Leopard with python 2.6. I downloaded the latest version of scapy and ran "<code>python setup.py install</code>". All went according to plan. Now, when I try to run it in interactive mode by just typing "scapy", it throws a bunch of errors. What gives!</p> <p>Just in case, here ...
10
2010-03-12T04:50:29Z
2,949,268
<p>Follow these instructions from scapy website. There are dependencies that you must resolve before doing the install. It worked like a charm for me on a Windows machine.</p> <p><a href="http://www.secdev.org/projects/scapy/doc/installation.html#mac-os-x">http://www.secdev.org/projects/scapy/doc/installation.html#mac...
10
2010-06-01T11:19:14Z
[ "python", "installation", "scapy" ]
Scapy install issues. Nothing seems to actually be installed?
2,430,573
<p>I have an apple computer running Leopard with python 2.6. I downloaded the latest version of scapy and ran "<code>python setup.py install</code>". All went according to plan. Now, when I try to run it in interactive mode by just typing "scapy", it throws a bunch of errors. What gives!</p> <p>Just in case, here ...
10
2010-03-12T04:50:29Z
12,937,608
<p>I have collected all the libraries needed for network programming in Python for Windows and made a single integrated installer. Its on <a href="https://code.google.com/p/allinstall/" rel="nofollow"><strong>Google Code</strong></a>. Just extract and run the installer after reading the installation file, installs all ...
1
2012-10-17T15:15:35Z
[ "python", "installation", "scapy" ]
Scapy install issues. Nothing seems to actually be installed?
2,430,573
<p>I have an apple computer running Leopard with python 2.6. I downloaded the latest version of scapy and ran "<code>python setup.py install</code>". All went according to plan. Now, when I try to run it in interactive mode by just typing "scapy", it throws a bunch of errors. What gives!</p> <p>Just in case, here ...
10
2010-03-12T04:50:29Z
17,804,662
<p>Install libdnet:<a href="http://libdnet.sourceforge.net/" rel="nofollow">http://libdnet.sourceforge.net/</a> and python-libpcat: <a href="http://sourceforge.net/projects/pylibpcap/" rel="nofollow">http://sourceforge.net/projects/pylibpcap/</a></p> <p>For libdent:</p> <pre><code>CFLAGS='-arch i386 -arch x86_64' ./c...
1
2013-07-23T08:05:29Z
[ "python", "installation", "scapy" ]
Scapy install issues. Nothing seems to actually be installed?
2,430,573
<p>I have an apple computer running Leopard with python 2.6. I downloaded the latest version of scapy and ran "<code>python setup.py install</code>". All went according to plan. Now, when I try to run it in interactive mode by just typing "scapy", it throws a bunch of errors. What gives!</p> <p>Just in case, here ...
10
2010-03-12T04:50:29Z
19,050,483
<p>I was able to get this working by #commenting out the route6 import statment in all.py within the scapy mod directory.</p> <p>After that, I was able to bring up the interactive scapy prompt.</p> <p>So the real solution to this issue is to make sure you have a compatible route6 mod.</p>
0
2013-09-27T12:12:43Z
[ "python", "installation", "scapy" ]
Scapy install issues. Nothing seems to actually be installed?
2,430,573
<p>I have an apple computer running Leopard with python 2.6. I downloaded the latest version of scapy and ran "<code>python setup.py install</code>". All went according to plan. Now, when I try to run it in interactive mode by just typing "scapy", it throws a bunch of errors. What gives!</p> <p>Just in case, here ...
10
2010-03-12T04:50:29Z
20,714,575
<p>I've also had lots of issues getting Scapy and its dependencies properly installed on my Mac, finally I found Homebrew Python GitHub page <a href="https://github.com/Homebrew/homebrew-python" rel="nofollow">https://github.com/Homebrew/homebrew-python</a> it contains lots of helpful/useful brew formula including one...
7
2013-12-21T01:51:27Z
[ "python", "installation", "scapy" ]
Scapy install issues. Nothing seems to actually be installed?
2,430,573
<p>I have an apple computer running Leopard with python 2.6. I downloaded the latest version of scapy and ran "<code>python setup.py install</code>". All went according to plan. Now, when I try to run it in interactive mode by just typing "scapy", it throws a bunch of errors. What gives!</p> <p>Just in case, here ...
10
2010-03-12T04:50:29Z
33,178,399
<p>MAC install follow the instructions <a href="http://juhalaaksonen.com/blog/2013/12/11/installing-scapy-for-mac-os-x/" rel="nofollow">here</a> in case if you want to install it in a virtualenv by first going into the virtualenv and then just using python setup.py install instead of sudo.</p>
0
2015-10-16T19:41:19Z
[ "python", "installation", "scapy" ]
Problem with Tk and Ping in Python
2,430,653
<p>I'm not being able to make this line work with Tk</p> <pre><code>import os while(1): ping = os.popen('ping www.google.com -n 1') result = ping.readlines() msLine = result[-1].strip() print msLine.split(' = ')[-1] </code></pre> <p>I'm trying to create a label and text = msLine.split... but everythin...
0
2010-03-12T05:19:26Z
2,430,744
<p>There can be other issues with Tk and popen(). First:</p> <p><em><strong>Thou shalt not continously ping or fetch from google.com.</em></strong></p> <p>Add a "import time" at the top and "time.sleep(2)" at the bottom of the while loop.</p> <p>Second:</p> <p>You probably meant "ping www.google.com -c 1" instead...
0
2010-03-12T05:45:31Z
[ "python", "tkinter" ]
Problem with Tk and Ping in Python
2,430,653
<p>I'm not being able to make this line work with Tk</p> <pre><code>import os while(1): ping = os.popen('ping www.google.com -n 1') result = ping.readlines() msLine = result[-1].strip() print msLine.split(' = ')[-1] </code></pre> <p>I'm trying to create a label and text = msLine.split... but everythin...
0
2010-03-12T05:19:26Z
2,438,514
<p>Your example code shows no GUI code. It is impossible to guess why your GUI freezes without seeing the code. Though, your code is pretty buggy so even if there were GUI code in your post it likely wouldn't help.</p> <p>Is it possible that you're forgetting to call the mainloop() method on your root widget? That wou...
0
2010-03-13T13:38:39Z
[ "python", "tkinter" ]
can we display glass bar chart in python with google app engine
2,430,748
<p>i am using bar chat and i want to use glass bar chart instead of that</p> <p>tutorials are given for PHP only.</p>
0
2010-03-12T05:46:00Z
2,433,096
<p>Disclaimer: I don't know, what is "glass bar chart".</p> <p>You cannot (or at least it is not effective to) generate graphics (charts) on the AppEngine servers. However, if you want to display bar charts or any other kind of plots and charts in your AppEngine applications, you have two other solutions:</p> <p>A) U...
3
2010-03-12T13:49:18Z
[ "python" ]
Passing keyword arguments to a class method decorator
2,430,759
<p>I have a class that has an output() method which returns a matplotlib Figure instance. I have a decorator I wrote that takes that fig instance and turns it into a Django response object.</p> <p>My decorator looks like this:</p> <pre><code>class plot_svg(object): def __init__(self, view): self.view = vi...
6
2010-03-12T05:48:31Z
2,430,781
<p>Right: when you decorate with a class, instead of with a function, you have to make it a descriptor (give it a <code>__get__</code> method, at least) to get the "automatic self". Simplest is to decorate with a function instead:</p> <pre><code>def plot_svg(view): def wrapper(*args, **kwargs): print arg...
6
2010-03-12T05:52:46Z
[ "python", "decorator" ]
Passing keyword arguments to a class method decorator
2,430,759
<p>I have a class that has an output() method which returns a matplotlib Figure instance. I have a decorator I wrote that takes that fig instance and turns it into a Django response object.</p> <p>My decorator looks like this:</p> <pre><code>class plot_svg(object): def __init__(self, view): self.view = vi...
6
2010-03-12T05:48:31Z
2,430,843
<p>OK, there seem to be a couple of issues.</p> <p>First, some syntax. You are getting the "takes exactly one argument" error because your decorator, @plot_svg, is expecting one parameter (a view). There are other syntax errors as well.</p> <p>Second, and more importantly, you want to write a function instead of a ...
1
2010-03-12T06:06:10Z
[ "python", "decorator" ]
Any downsides to UPX-ing my 32-bit Python 2.6.4 development environment EXE/PYD/DLL files?
2,431,236
<p>Are there any downsides to UPX-ing my 32-bit Python 2.6.4 development environment EXE/PYD/DLL files?</p> <p>The reason I'm asking is that I frequently use a custom PY2EXE script that UPX's copies of these files on every build.</p> <p>Yes, I could get fancy and try to cache UPXed files, but I think a simpler, safer...
2
2010-03-12T07:56:36Z
2,433,251
<p>I have experienced significant increases in start up time when UPX compressed executables are run on systems with certain virus scanners. I was only compressing single executables, but I expect that each compressed dll would add to the start time.</p> <p>Is it really necessary to use UPX? I can't imagine the spac...
1
2010-03-12T14:14:23Z
[ "python", "py2exe", "upx" ]
Reverse Search Best Practices?
2,431,276
<p>I'm making an app that has a need for reverse searches. By this, I mean that users of the app will enter search parameters and save them; then, when any new objects get entered onto the system, if they match the existing search parameters that a user has saved, a notification will be sent, etc. </p> <p>I am havin...
8
2010-03-12T08:07:14Z
2,431,308
<p>At the database level, many databases offer 'triggers'.</p> <p>Another approach is to have timed jobs that periodically fetch all items from the database that have a last-modified date since the last run; then these get filtered and alerts issued. You can perhaps put some of the filtering into the query statement ...
4
2010-03-12T08:16:57Z
[ "python", "django", "search", "reverse" ]
Reverse Search Best Practices?
2,431,276
<p>I'm making an app that has a need for reverse searches. By this, I mean that users of the app will enter search parameters and save them; then, when any new objects get entered onto the system, if they match the existing search parameters that a user has saved, a notification will be sent, etc. </p> <p>I am havin...
8
2010-03-12T08:07:14Z
2,433,746
<p>The amount of effort you use to solve this problem is directly related to the number of <em>stored queries</em> you are dealing with.</p> <p>Over 20 years ago we handled <em>stored queries</em> by treating them as minidocs and indexing them based on all of the <em>must have</em> and <em>may have</em> terms. A new d...
4
2010-03-12T15:31:25Z
[ "python", "django", "search", "reverse" ]
Reverse Search Best Practices?
2,431,276
<p>I'm making an app that has a need for reverse searches. By this, I mean that users of the app will enter search parameters and save them; then, when any new objects get entered onto the system, if they match the existing search parameters that a user has saved, a notification will be sent, etc. </p> <p>I am havin...
8
2010-03-12T08:07:14Z
2,436,478
<p>If you stored the type(s) of object(s) involved in each stored search as a <a href="http://www.djangoproject.com/documentation/models/generic_relations/" rel="nofollow">generic relation</a>, you could add a post-save <a href="http://docs.djangoproject.com/en/dev/topics/signals/" rel="nofollow">signal</a> to all invo...
1
2010-03-12T23:10:14Z
[ "python", "django", "search", "reverse" ]
Text to a PNG on App Engine (Python)
2,431,345
<p><em>Note: I am cross-posting this from App Engine group because I got no answers there.</em></p> <p>As part of my site about Japan, I have a feature where the user can get a large PNG for use as desktop background that shows the user's name in Japanese. After switching my site hosting entirely to App Engine, I r...
24
2010-03-12T08:28:44Z
2,431,377
<p><strong>[Stop press: As comment suggests - this answer doesn't work in Googe App Engine.]</strong></p> <p>The Python Imaging Library (<a href="http://www.pythonware.com/products/pil/" rel="nofollow">PIL</a>) can accomplish this.</p> <p>You can load in the image, draw Unicode text on it with the ImageDraw.text() fu...
3
2010-03-12T08:37:27Z
[ "python", "image", "google-app-engine", "unicode" ]
Text to a PNG on App Engine (Python)
2,431,345
<p><em>Note: I am cross-posting this from App Engine group because I got no answers there.</em></p> <p>As part of my site about Japan, I have a feature where the user can get a large PNG for use as desktop background that shows the user's name in Japanese. After switching my site hosting entirely to App Engine, I r...
24
2010-03-12T08:28:44Z
2,432,992
<h3>Solution #1. Pure Python image library.</h3> <p>You can try to bundle <a href="http://packages.python.org/pypng/">PyPNG</a> with your application. PyPNG is a pure Python library to create PNG images. It depends on zlib module, which is allowed on AppEngine, so PyPNG should work on AppEngine. Just use StringIO obje...
29
2010-03-12T13:28:27Z
[ "python", "image", "google-app-engine", "unicode" ]
Text to a PNG on App Engine (Python)
2,431,345
<p><em>Note: I am cross-posting this from App Engine group because I got no answers there.</em></p> <p>As part of my site about Japan, I have a feature where the user can get a large PNG for use as desktop background that shows the user's name in Japanese. After switching my site hosting entirely to App Engine, I r...
24
2010-03-12T08:28:44Z
2,436,549
<p>I ran into this same problem with writing text to an image. The issue at hand is that any imaging libraries used on google app engine must be pure python, which rules out PIL.</p> <h2>PyBMP</h2> <p><a href="http://code.google.com/p/pybmp/">PyBMP</a> is a pure-python library that can do simple text rendering. Fro...
9
2010-03-12T23:28:49Z
[ "python", "image", "google-app-engine", "unicode" ]
Text to a PNG on App Engine (Python)
2,431,345
<p><em>Note: I am cross-posting this from App Engine group because I got no answers there.</em></p> <p>As part of my site about Japan, I have a feature where the user can get a large PNG for use as desktop background that shows the user's name in Japanese. After switching my site hosting entirely to App Engine, I r...
24
2010-03-12T08:28:44Z
10,110,116
<p>It's a bit too late but I was looking for the same. I managed to draw unicode string (here Devanagari) onto an image and save it as a '.png' file by doing the following:</p> <pre><code># -*- coding: utf-8 -*- import Image, ImageDraw, ImageFont img = Image.new('L', (16,16), 255) draw = ImageDraw.Draw(img) text_to_d...
3
2012-04-11T16:32:19Z
[ "python", "image", "google-app-engine", "unicode" ]
Eclipse Pydev: Supress no-self errors in python wrappers generated with swig
2,431,435
<p>when generating python wrappers with swig the python wrapper classes in the generated python file do not have an explicit self parameter, for example see below:</p> <pre><code>class PySwigIterator(_object): def value(*args): return _spatiotemporalnmf.PySwigIterator_value(*args) def incr(*args): return _spat...
1
2010-03-12T08:52:39Z
2,431,550
<p>As from the documentation, any file with the comment </p> <pre><code>#@PydevCodeAnalysisIgnore </code></pre> <p>inside will not be analyzed.</p> <p>Therefore, you just need to add it to all SWIG-generated files, and you should be OK. It is just one place to change, and you could even write a very small processor ...
1
2010-03-12T09:16:49Z
[ "python", "swig", "pydev" ]
QTableWidget signal cellChanged(): distinguish between user input and change by routines
2,431,844
<p>i am using PyQt but my question is a general Qt one:</p> <p>I have a QTableWidget that is set up by the function updateTable. It writes the data from DATASET to the table when it is called. Unfortunately this causes my QTableWidget to emit the signal cellChanged() for every cell.</p> <p>The signal cellChanged() is...
2
2010-03-12T10:02:39Z
2,432,210
<p>It seems, that this is the only signal in QTableWidget at least for 4.6. You could post a feature request, but I don't know if it is accepted and you might wait for long time ;-)</p> <p>Maybe you could try to write a subclass of QTableWidget and emit own signals, when cell is changed internally.</p> <p>Anyway, dis...
1
2010-03-12T11:02:44Z
[ "python", "qt", "pyqt", "signals", "qtablewidget" ]
QTableWidget signal cellChanged(): distinguish between user input and change by routines
2,431,844
<p>i am using PyQt but my question is a general Qt one:</p> <p>I have a QTableWidget that is set up by the function updateTable. It writes the data from DATASET to the table when it is called. Unfortunately this causes my QTableWidget to emit the signal cellChanged() for every cell.</p> <p>The signal cellChanged() is...
2
2010-03-12T10:02:39Z
2,449,334
<p>I would recommend changing from a <code>QTableWidget</code> to a <code>QTableView</code> with an appropriate model. From the sounds of it, you have a database or other data object holding and arranging the data anyway, so it would hopefully be fairly easy to do. This would then allow you to distinguish between edi...
1
2010-03-15T18:02:24Z
[ "python", "qt", "pyqt", "signals", "qtablewidget" ]
QTableWidget signal cellChanged(): distinguish between user input and change by routines
2,431,844
<p>i am using PyQt but my question is a general Qt one:</p> <p>I have a QTableWidget that is set up by the function updateTable. It writes the data from DATASET to the table when it is called. Unfortunately this causes my QTableWidget to emit the signal cellChanged() for every cell.</p> <p>The signal cellChanged() is...
2
2010-03-12T10:02:39Z
2,500,472
<p>In similar situation I've just used</p> <pre><code>bool QObject::blockSignals ( bool block ) bool QObject::signalsBlocked () const </code></pre> <p>Block signals before setting up the table, then unblock:</p> <pre><code>myTable.blockSignals(True) #blah-blah.. myTable.blockSignals(False) </code></pre>
4
2010-03-23T14:01:51Z
[ "python", "qt", "pyqt", "signals", "qtablewidget" ]
How to compile gettext translations in setup.py of a Django app
2,431,937
<p>How can I make sure <code>setup.py</code> compiles projects PO files and include them whenever an <code>sdist</code> is created. This is a Django app and manual process to generate MO files is to run following command in the app's root directory:</p> <pre><code>django-admin compilemessages </code></pre> <p>(This m...
6
2010-03-12T10:19:04Z
2,432,175
<pre><code>from django.core.management.commands.compilemessages import compile_messages </code></pre> <p>and use it in your <code>setup.py</code> script before you run <code>setup</code> and then include created files in <code>setup</code> method.</p>
3
2010-03-12T10:57:57Z
[ "python", "distribution", "packaging", "gettext", "setup.py" ]
How to compile gettext translations in setup.py of a Django app
2,431,937
<p>How can I make sure <code>setup.py</code> compiles projects PO files and include them whenever an <code>sdist</code> is created. This is a Django app and manual process to generate MO files is to run following command in the app's root directory:</p> <pre><code>django-admin compilemessages </code></pre> <p>(This m...
6
2010-03-12T10:19:04Z
15,520,651
<p>My simple solution (got some idea from Trac):</p> <pre><code>#!/usr/bin/env python from setuptools import setup, find_packages from setuptools.command.install_lib import install_lib as _install_lib from distutils.command.build import build as _build from distutils.cmd import Command class compile_translations(Com...
5
2013-03-20T10:12:54Z
[ "python", "distribution", "packaging", "gettext", "setup.py" ]
Python: Lits containg tuples and long int
2,432,402
<p>I have a list containing a tuples and long integers the list looks like this:</p> <pre><code> table = [(1L,), (1L,), (1L,), (2L,), (2L,), (2L,), (3L,), (3L,)] </code></pre> <p>How do i convert the table to look like a formal list?</p> <p>so the output would be:</p> <pre><code>table = ['1','1','1','2','2','2','...
2
2010-03-12T11:37:47Z
2,432,406
<pre><code>&gt;&gt;&gt; table = [(1L,), (1L,), (1L,), (2L,), (2L,), (2L,), (3L,), (3L,)] &gt;&gt;&gt; [int(e[0]) for e in table] [1, 1, 1, 2, 2, 2, 3, 3] &gt;&gt;&gt; [str(e[0]) for e in table] ['1', '1', '1', '2', '2', '2', '3', '3'] </code></pre>
8
2010-03-12T11:38:57Z
[ "python", "list", "tuples" ]
Python: Lits containg tuples and long int
2,432,402
<p>I have a list containing a tuples and long integers the list looks like this:</p> <pre><code> table = [(1L,), (1L,), (1L,), (2L,), (2L,), (2L,), (3L,), (3L,)] </code></pre> <p>How do i convert the table to look like a formal list?</p> <p>so the output would be:</p> <pre><code>table = ['1','1','1','2','2','2','...
2
2010-03-12T11:37:47Z
2,432,417
<p>With <a href="http://docs.python.org/library/itertools.html" rel="nofollow">itertools</a></p> <pre><code>import itertools &gt;&gt;&gt; x=[(1L,), (1L,), (1L,), (2L,), (2L,), (2L,), (3L,), (3L,)] &gt;&gt;&gt; &gt;&gt;&gt; list(itertools.chain(*x)) [1L, 1L, 1L, 2L, 2L, 2L, 3L, 3L] &gt;&gt;&gt; &gt;&gt;&gt; map(str,it...
2
2010-03-12T11:41:58Z
[ "python", "list", "tuples" ]
Python: Lits containg tuples and long int
2,432,402
<p>I have a list containing a tuples and long integers the list looks like this:</p> <pre><code> table = [(1L,), (1L,), (1L,), (2L,), (2L,), (2L,), (3L,), (3L,)] </code></pre> <p>How do i convert the table to look like a formal list?</p> <p>so the output would be:</p> <pre><code>table = ['1','1','1','2','2','2','...
2
2010-03-12T11:37:47Z
2,432,588
<p>You shouldn't worry about the differences between ints and longs. If you ever try to print a long, the L will disappear. </p> <pre><code>nums = [1L, 1L, 1L, 2L, 2L, 2L, 3L, 3L] &gt;&gt;&gt; for num in nums: ... print num, 1 1 1 2 2 2 3 3 </code></pre> <p>Also, why do you want your result list to have strings...
1
2010-03-12T12:18:04Z
[ "python", "list", "tuples" ]
Getting values from Multiple Text Entry using Pygtk and Python
2,432,468
<p>On a click of a button named "Add Textbox" it calls a function which creates a single textbox using (gtk.Entry) function. So each time i click that button it creates a textbox.<br/><br/> I have a submit button which should fetches all the values of the text boxes(say 10 textboxes) generated with the name of "entry"....
0
2010-03-12T11:55:29Z
2,432,881
<p>You could be a bit clearer, it's not obvious what you do with your GtkEntry after creating it. The easiest thing would be to just add it to a Python list, so you can iterate over all created GtkEntry widgets later.</p> <p>Or, you could "tag" the widgets with something to make them identifiable, and iterate over the...
1
2010-03-12T13:10:49Z
[ "python", "gtk", "pygtk", "glade" ]
A RAM error of big array
2,432,521
<p>I need to get the numbers of one line randomly, and put each line in other array, then get the numbers of one col.</p> <p>I have a big file, more than 400M. In that file, there are 13496*13496 number, means 13496 rows and 13496 cols. I want to read them to a array. This is my code:</p> <pre><code>_L1 = [[0 for col...
2
2010-03-12T12:05:22Z
2,432,565
<p>you might want to approach your problem in another way. Process the file line by line. I don't see a need to store the whole big file into array. Otherwise, you might want to tell us what you are actually trying to do.</p> <pre><code>for line in open("400MB_file"): # do something with line. </code></pre> <p>O...
7
2010-03-12T12:11:20Z
[ "python" ]
A RAM error of big array
2,432,521
<p>I need to get the numbers of one line randomly, and put each line in other array, then get the numbers of one col.</p> <p>I have a big file, more than 400M. In that file, there are 13496*13496 number, means 13496 rows and 13496 cols. I want to read them to a array. This is my code:</p> <pre><code>_L1 = [[0 for col...
2
2010-03-12T12:05:22Z
2,432,611
<p><a href="http://docs.python.org/library/exceptions.html#exceptions.MemoryError" rel="nofollow">MemoryError</a> exception:</p> <blockquote> <p>Raised <strong>when an operation runs out of memory</strong> but the situation may still be rescued (by deleting some objects). The associated value is a string ind...
0
2010-03-12T12:21:22Z
[ "python" ]
A RAM error of big array
2,432,521
<p>I need to get the numbers of one line randomly, and put each line in other array, then get the numbers of one col.</p> <p>I have a big file, more than 400M. In that file, there are 13496*13496 number, means 13496 rows and 13496 cols. I want to read them to a array. This is my code:</p> <pre><code>_L1 = [[0 for col...
2
2010-03-12T12:05:22Z
2,432,629
<p>This is a simple case of your program demanding more memory than is available to the computer. An array of 13496x13496 elements requires 182,142,016 'cells', where a cell is a minimum of one byte (if storing chars) and potentially several bytes (if storing floating-point numerics, for example). I'm not even taking y...
3
2010-03-12T12:24:19Z
[ "python" ]
A RAM error of big array
2,432,521
<p>I need to get the numbers of one line randomly, and put each line in other array, then get the numbers of one col.</p> <p>I have a big file, more than 400M. In that file, there are 13496*13496 number, means 13496 rows and 13496 cols. I want to read them to a array. This is my code:</p> <pre><code>_L1 = [[0 for col...
2
2010-03-12T12:05:22Z
2,433,622
<p>Short answer: the Python object overhead is killing you. In Python 2.x on a 64-bit machine, a list of strings consumes 48 bytes per list entry even before accounting for the content of the strings. That's over 8.7 Gb of overhead for the size of array you describe. On a 32-bit machine it'll be a bit better: only 28...
3
2010-03-12T15:12:11Z
[ "python" ]
A RAM error of big array
2,432,521
<p>I need to get the numbers of one line randomly, and put each line in other array, then get the numbers of one col.</p> <p>I have a big file, more than 400M. In that file, there are 13496*13496 number, means 13496 rows and 13496 cols. I want to read them to a array. This is my code:</p> <pre><code>_L1 = [[0 for col...
2
2010-03-12T12:05:22Z
2,434,667
<p>Replace this:</p> <pre><code>_strlf = _strlf[:-1] </code></pre> <p>with this:</p> <pre><code>_strlf = [float(val) for val in _strlf[:-1]] </code></pre> <p>You are making a big array of strings. I can guarantee that the string <code>"123.00123214213"</code> takes a lot less memory when you convert it to floating ...
0
2010-03-12T17:43:44Z
[ "python" ]
SQLAlchemy autocommiting?
2,432,527
<p>I have an issue with SQLAlchemy apparently committing. A rough sketch of my code:</p> <pre><code>trans = self.conn.begin() try: assert not self.conn.execute(my_obj.__table__.select(my_obj.id == id)).first() self.conn.execute(my_obj.__table__.insert().values(id=id)) assert not self.conn.exec...
1
2010-03-12T12:06:28Z
2,432,732
<p>You're right in that changes aren't get <em>commited</em> to DB. But they are auto-<em>flushed</em> by SQLAlchemy when you perform query, in your case flush is performed on lines with asserts. So if you will not explicitly call <code>commit</code> you will never see these changes in DB, within real data. However, yo...
1
2010-03-12T12:41:53Z
[ "python", "transactions", "sqlalchemy" ]
Unbuffered subprocess output (last line missing)
2,432,556
<p>I must be overlooking something terribly obvious. I need to execute a C program, display its output in real time and finally parse its last line, which should be straightforward as the last line printed is <em>always</em> the same.</p> <pre><code>process = subprocess.Popen(args, shell = True, ...
3
2010-03-12T12:10:14Z
2,432,689
<p><code>readline()</code> has to buffer the text, waiting for a new-line.</p> <p>You'll always have a race condition - no amount of un-buffered streams will handle the fact that you're handling a line, then checking for exit, then reading a line, so if the subprocess exits while you're handling a line, you won't read...
2
2010-03-12T12:34:14Z
[ "python", "subprocess", "popen" ]