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 |
|---|---|---|---|---|---|---|---|---|---|
Quitting matplotlib.pyplot animation gracefully | 1,735,370 | <p>I have a script that plots data of some photometry apertures, and I want to plot them in an xy plot. I am using matplotlib.pyplot with python 2.5.</p>
<p>The input data is stored in around 500 files and read. I am aware that this is not the most efficient way of inputting the data but that's another issue...</p>
<... | 2 | 2009-11-14T19:42:53Z | 1,736,564 | <p>If you update the data and do the draw in a loop, you should be able to interrupt it. Here's an example (that draws a stationary circle and then moves a line around the perimeter):</p>
<pre><code>from pylab import *
import time
data = [] # make the data
for i in range(1000):
a = .01*pi*i+.0007
m = -1./t... | 2 | 2009-11-15T04:31:04Z | [
"python",
"animation",
"quit",
"matplotlib"
] |
passing value to other module python | 1,735,395 | <p>i have two script name is A.py and B.py</p>
<p>i want to know how to send value from A.py to B.py.</p>
<p>for more detail,when run finished A.py script at the end of script ,A.py call B.py.</p>
<p>my question is i have to send some value from A.py to B.py.</p>
<p>anybody some help me how to send value A.py to B... | 0 | 2009-11-14T19:50:48Z | 1,735,406 | <p>Your question isn't quite clear.</p>
<pre><code>import B
B.methodToExecute(argument)
</code></pre>
| 2 | 2009-11-14T19:53:32Z | [
"python"
] |
passing value to other module python | 1,735,395 | <p>i have two script name is A.py and B.py</p>
<p>i want to know how to send value from A.py to B.py.</p>
<p>for more detail,when run finished A.py script at the end of script ,A.py call B.py.</p>
<p>my question is i have to send some value from A.py to B.py.</p>
<p>anybody some help me how to send value A.py to B... | 0 | 2009-11-14T19:50:48Z | 1,735,424 | <p>Do I assume correctly that you want to have B.py to use all the variables with values that exist when A.py finishes?</p>
<p>[edit]</p>
<p>Ok, the problem is you cannot easily do this without any variable assignments. What you'd like to achieve is an import statement done backwards. Normally, if you import a module... | 1 | 2009-11-14T19:59:10Z | [
"python"
] |
passing value to other module python | 1,735,395 | <p>i have two script name is A.py and B.py</p>
<p>i want to know how to send value from A.py to B.py.</p>
<p>for more detail,when run finished A.py script at the end of script ,A.py call B.py.</p>
<p>my question is i have to send some value from A.py to B.py.</p>
<p>anybody some help me how to send value A.py to B... | 0 | 2009-11-14T19:50:48Z | 1,735,961 | <p>Your question might have been phrased too abstractly for me to really know what you need.</p>
<p>Generally, what you would do is after you've done everything in A and are read for B, you will have <code>import A</code> at the top of your module and call a function in A that you what taking in all the values you wan... | 0 | 2009-11-14T23:22:23Z | [
"python"
] |
Class-level read-only properties in Python | 1,735,434 | <p>Is there some way to make a class-level read-only property in <a href="http://en.wikipedia.org/wiki/Python%5F%28programming%5Flanguage%29">Python</a>? For instance, if I have a class <code>Foo</code>, I want to say:</p>
<pre><code>x = Foo.CLASS_PROPERTY
</code></pre>
<p>but prevent anyone from saying:</p>
<pre><... | 24 | 2009-11-14T20:06:05Z | 1,735,438 | <p>Found this on <a href="http://code.activestate.com/recipes/197965/" rel="nofollow">ActiveState</a>:</p>
<pre><code># simple read only attributes with meta-class programming
# method factory for an attribute get method
def getmethod(attrname):
def _getmethod(self):
return self.__readonly__[attrname]
... | 1 | 2009-11-14T20:08:33Z | [
"python"
] |
Class-level read-only properties in Python | 1,735,434 | <p>Is there some way to make a class-level read-only property in <a href="http://en.wikipedia.org/wiki/Python%5F%28programming%5Flanguage%29">Python</a>? For instance, if I have a class <code>Foo</code>, I want to say:</p>
<pre><code>x = Foo.CLASS_PROPERTY
</code></pre>
<p>but prevent anyone from saying:</p>
<pre><... | 24 | 2009-11-14T20:06:05Z | 1,735,615 | <p>The <a href="http://code.activestate.com/recipes/197965/" rel="nofollow">ActiveState solution</a> that Pynt references makes instances of ROClass have read-only attributes. Your question seems to ask if the class itself can have read-only attributes.</p>
<p>Here is one way, based on <a href="http://code.activestate... | 4 | 2009-11-14T21:13:16Z | [
"python"
] |
Class-level read-only properties in Python | 1,735,434 | <p>Is there some way to make a class-level read-only property in <a href="http://en.wikipedia.org/wiki/Python%5F%28programming%5Flanguage%29">Python</a>? For instance, if I have a class <code>Foo</code>, I want to say:</p>
<pre><code>x = Foo.CLASS_PROPERTY
</code></pre>
<p>but prevent anyone from saying:</p>
<pre><... | 24 | 2009-11-14T20:06:05Z | 1,735,726 | <p>The existing solutions are a bit complex -- what about just ensuring that each class in a certain group has a unique metaclass, then setting a normal read-only property on the custom metaclass. Namely:</p>
<pre><code>>>> class Meta(type):
... def __new__(mcl, *a, **k):
... uniquemcl = type('Uniq', (... | 8 | 2009-11-14T21:50:56Z | [
"python"
] |
oneliner scramble program | 1,735,561 | <p>It's that time of year again that programmers want to shuffle a list such that no element resides on its original position (at least in the Netherlands, we celebrate <em>Sinterklaas</em> and pick straws for deciding who writes who a poem). Does anyone have a nice Python <strong>single statement</strong> for that?</p... | 2 | 2009-11-14T20:52:27Z | 1,735,583 | <p>Sorry this isn't a one-liner, but this works</p>
<pre><code>import random
def sinterklaas(n):
l=[]
for a in range(n):
l.append(-1)
i = 0
while i < 10:
index = random.randint(0,n-1)
if l[index] == -1 and index != i:
l[index] = i
i += 1
</code></pre>
<p... | 0 | 2009-11-14T21:02:33Z | [
"python",
"code-golf",
"shuffle"
] |
oneliner scramble program | 1,735,561 | <p>It's that time of year again that programmers want to shuffle a list such that no element resides on its original position (at least in the Netherlands, we celebrate <em>Sinterklaas</em> and pick straws for deciding who writes who a poem). Does anyone have a nice Python <strong>single statement</strong> for that?</p... | 2 | 2009-11-14T20:52:27Z | 1,735,584 | <p>After shuffling the list of numbers, let the <code>[i]</code>th person write a poem (and buy a present!) for the <code>[i+1]</code>th person in the list: that way, there can never be someone who draws him- or herself. Of course, the last one should point to the first...</p>
| 5 | 2009-11-14T21:02:42Z | [
"python",
"code-golf",
"shuffle"
] |
oneliner scramble program | 1,735,561 | <p>It's that time of year again that programmers want to shuffle a list such that no element resides on its original position (at least in the Netherlands, we celebrate <em>Sinterklaas</em> and pick straws for deciding who writes who a poem). Does anyone have a nice Python <strong>single statement</strong> for that?</p... | 2 | 2009-11-14T20:52:27Z | 1,735,592 | <p>Shifting every element in the list by one in a circular manner, <a href="http://stackoverflow.com/questions/1735561/oneliner-scramble-program/1735584#1735584">as suggested by Bart</a>, is easy:</p>
<pre><code>>>> def shift(seq):
... return seq[-1:] + seq[:-1]
...
>>> shift(range(10))
[9, 0, 1... | 3 | 2009-11-14T21:05:17Z | [
"python",
"code-golf",
"shuffle"
] |
oneliner scramble program | 1,735,561 | <p>It's that time of year again that programmers want to shuffle a list such that no element resides on its original position (at least in the Netherlands, we celebrate <em>Sinterklaas</em> and pick straws for deciding who writes who a poem). Does anyone have a nice Python <strong>single statement</strong> for that?</p... | 2 | 2009-11-14T20:52:27Z | 1,735,595 | <pre><code>import random; u = range(10)
while sum(u[i]==i for i in range(10)): random.shuffle(u)
</code></pre>
<p>(Ok, I have a line 0 in there too...)</p>
| 0 | 2009-11-14T21:05:28Z | [
"python",
"code-golf",
"shuffle"
] |
oneliner scramble program | 1,735,561 | <p>It's that time of year again that programmers want to shuffle a list such that no element resides on its original position (at least in the Netherlands, we celebrate <em>Sinterklaas</em> and pick straws for deciding who writes who a poem). Does anyone have a nice Python <strong>single statement</strong> for that?</p... | 2 | 2009-11-14T20:52:27Z | 1,735,637 | <p>For one in O(n):</p>
<pre><code>u=range(10); random.shuffle(u); v=[ u[u[i]] for i in range(10) ]; return [ v[(u[i]+1)%10] for i in u ]
</code></pre>
<p><code>u</code> is the inverse of function <code>v</code>, so <code>v[u[i]+1]</code> is effectively the element following i in array <code>v</code>.</p>
| 0 | 2009-11-14T21:18:21Z | [
"python",
"code-golf",
"shuffle"
] |
oneliner scramble program | 1,735,561 | <p>It's that time of year again that programmers want to shuffle a list such that no element resides on its original position (at least in the Netherlands, we celebrate <em>Sinterklaas</em> and pick straws for deciding who writes who a poem). Does anyone have a nice Python <strong>single statement</strong> for that?</p... | 2 | 2009-11-14T20:52:27Z | 1,735,699 | <p>My first Python program in a long while. Unlike many of the above programs, this one takes O(n) time.</p>
<pre><code>s = set(range(10))
r = list()
for i in range(10):
s2 = s - set([i])
val = s2.pop()
r.append(val)
s.discard(val)
print r
</code></pre>
<p><em>UPDATE</em>: Paul showed that the above... | 1 | 2009-11-14T21:36:16Z | [
"python",
"code-golf",
"shuffle"
] |
oneliner scramble program | 1,735,561 | <p>It's that time of year again that programmers want to shuffle a list such that no element resides on its original position (at least in the Netherlands, we celebrate <em>Sinterklaas</em> and pick straws for deciding who writes who a poem). Does anyone have a nice Python <strong>single statement</strong> for that?</p... | 2 | 2009-11-14T20:52:27Z | 1,735,822 | <p>Here's Stephan202's circular shift implemented as a one-liner with a randomly-chosen shift increment:</p>
<pre><code>from random import randrange; s = range(10); r = randrange(1,len(s)-1); print s[-r:] + s[:-r]
</code></pre>
| 0 | 2009-11-14T22:28:13Z | [
"python",
"code-golf",
"shuffle"
] |
oneliner scramble program | 1,735,561 | <p>It's that time of year again that programmers want to shuffle a list such that no element resides on its original position (at least in the Netherlands, we celebrate <em>Sinterklaas</em> and pick straws for deciding who writes who a poem). Does anyone have a nice Python <strong>single statement</strong> for that?</p... | 2 | 2009-11-14T20:52:27Z | 1,735,849 | <p>Here is how you do it with O(n) time and O(1) extra memory:</p>
<p>Comprehensible code:</p>
<pre><code>def shuffle(a)
n = a.length
(0..n - 2).each do |i|
r = rand(n - i - 1) + i + 1
a[r], a[i] = a[i], a[r]
end
a
end
</code></pre>
<p>A one-liner (assumes "a" is the array):</p>
<pre><code>n = a.len... | 1 | 2009-11-14T22:35:29Z | [
"python",
"code-golf",
"shuffle"
] |
oneliner scramble program | 1,735,561 | <p>It's that time of year again that programmers want to shuffle a list such that no element resides on its original position (at least in the Netherlands, we celebrate <em>Sinterklaas</em> and pick straws for deciding who writes who a poem). Does anyone have a nice Python <strong>single statement</strong> for that?</p... | 2 | 2009-11-14T20:52:27Z | 1,737,036 | <p>"One-liner" in fixed O(n) time:</p>
<pre><code>import random; a=range(10) # setup (could read in names instead)
for i in range(len(a)-1,0,-1): j=random.randint(0,i-1); a[j],a[i]=a[i],a[j]
print a # output
</code></pre>
<p>The loop picks elements from the maximum index (len(a)-1) down to the next-smallest (1). T... | 1 | 2009-11-15T08:59:51Z | [
"python",
"code-golf",
"shuffle"
] |
oneliner scramble program | 1,735,561 | <p>It's that time of year again that programmers want to shuffle a list such that no element resides on its original position (at least in the Netherlands, we celebrate <em>Sinterklaas</em> and pick straws for deciding who writes who a poem). Does anyone have a nice Python <strong>single statement</strong> for that?</p... | 2 | 2009-11-14T20:52:27Z | 1,737,041 | <p>This one is O(N). Having the import in the loops is a bit silly, but you wanted a one liner</p>
<pre><code>L=range(10)
for i in range(1,len(L)):import random;r=random.randint(0,i-1);L[i],L[r]=L[r],L[i]
print L
</code></pre>
<p>Here is the output distribution when L=range(5) for 100000 samples</p>
<pre><code>((1, ... | 1 | 2009-11-15T09:03:43Z | [
"python",
"code-golf",
"shuffle"
] |
oneliner scramble program | 1,735,561 | <p>It's that time of year again that programmers want to shuffle a list such that no element resides on its original position (at least in the Netherlands, we celebrate <em>Sinterklaas</em> and pick straws for deciding who writes who a poem). Does anyone have a nice Python <strong>single statement</strong> for that?</p... | 2 | 2009-11-14T20:52:27Z | 1,740,011 | <p>I found shuffle can be abused into solving this</p>
<pre><code>from random import shuffle
L = ["Anne", "Beth", "Cath", "Dave", "Emma"]
shuffle(L, int=lambda n: int(n - 1))
print L
</code></pre>
<p>The distribution is not uniform however this was not a requirement.</p>
<pre><code>#For 100,000 samples
(('Beth', 'C... | 6 | 2009-11-16T04:14:35Z | [
"python",
"code-golf",
"shuffle"
] |
Using pyparsing to parse a word escape-split over multiple lines | 1,735,722 | <p>I'm trying to parse words which can be broken up over multiple lines with a backslash-newline combination ("<code>\\n</code>") using <a href="http://pyparsing.wikispaces.com/" rel="nofollow">pyparsing</a>. Here's what I have done:</p>
<pre><code>from pyparsing import *
continued_ending = Literal('\\') + lineEnd
wo... | 5 | 2009-11-14T21:49:15Z | 1,736,536 | <p>After poking around for a bit more, I came upon <a href="http://pyparsing.wikispaces.com/message/view/home/11262229" rel="nofollow">this help thread</a> where there was this notable bit</p>
<blockquote>
<p>I often see inefficient grammars when
someone implements a pyparsing grammar
directly from a BNF definit... | 5 | 2009-11-15T04:10:18Z | [
"python",
"parsing",
"pyparsing"
] |
Using pyparsing to parse a word escape-split over multiple lines | 1,735,722 | <p>I'm trying to parse words which can be broken up over multiple lines with a backslash-newline combination ("<code>\\n</code>") using <a href="http://pyparsing.wikispaces.com/" rel="nofollow">pyparsing</a>. Here's what I have done:</p>
<pre><code>from pyparsing import *
continued_ending = Literal('\\') + lineEnd
wo... | 5 | 2009-11-14T21:49:15Z | 1,738,069 | <p>You are pretty close with your code. Any of these mods would work:</p>
<pre><code># '|' means MatchFirst, so you had a left-recursive expression
# reversing the order of the alternatives makes this work
multi_line_word << ((split_word + multi_line_word) | word)
# '^' means Or/MatchLongest, but beware using ... | 5 | 2009-11-15T16:51:08Z | [
"python",
"parsing",
"pyparsing"
] |
I set a proxy server on urllib2, and then I can't change it | 1,735,852 | <p>Like the title says, my code basically does this:</p>
<p>set proxy, test proxy, do some cool stuff</p>
<p>But after the proxy is set the first time, it sticks that way, never changing. This is the failing code:</p>
<pre><code> # Pick proxy
r = random.randint(0, len(proxies) - 1)
proxy = proxies[r]
... | 0 | 2009-11-14T22:36:53Z | 1,735,908 | <p>That does seem strange. I've always found the <a href="http://code.google.com/p/httplib2" rel="nofollow">httplib2</a> module to be the easiest Python HTTP client to work with. There is an example of using <a href="http://code.google.com/p/httplib2/wiki/Examples" rel="nofollow">httplib2 with the socks module</a>.</p... | 1 | 2009-11-14T22:58:33Z | [
"python",
"proxy",
"urllib2"
] |
Debugging a pyQT4 app? | 1,736,015 | <p>I have a fairly simple app built with pyqt4. I wanted to debug one of the functions connected to one of the buttons in my app. However, when I do the following</p>
<pre><code>python -m pdb app.pyw
> break app.pyw:55 # This is where the signal handling function starts.
</code></pre>
<p>things don't quite work l... | 31 | 2009-11-14T23:46:58Z | 1,745,965 | <p>You need to call <a href="http://www.mail-archive.com/pyqt@riverbankcomputing.com/msg13112.html">QtCore.pyqtRemoveInputHook</a>. I wrap it in my own version of <code>set_trace</code>:</p>
<pre><code>def debug_trace():
'''Set a tracepoint in the Python debugger that works with Qt'''
from PyQt4.QtCore import pyq... | 63 | 2009-11-17T01:03:06Z | [
"python",
"qt",
"pyqt4"
] |
Debugging a pyQT4 app? | 1,736,015 | <p>I have a fairly simple app built with pyqt4. I wanted to debug one of the functions connected to one of the buttons in my app. However, when I do the following</p>
<pre><code>python -m pdb app.pyw
> break app.pyw:55 # This is where the signal handling function starts.
</code></pre>
<p>things don't quite work l... | 31 | 2009-11-14T23:46:58Z | 22,485,438 | <p>I had to use a "next" command at the trace point to get outside of that function first. For that I made a modification of the code from mgrandi:</p>
<pre><code>def pyqt_set_trace():
'''Set a tracepoint in the Python debugger that works with Qt'''
from PyQt4.QtCore import pyqtRemoveInputHook
import pdb
... | 1 | 2014-03-18T16:32:06Z | [
"python",
"qt",
"pyqt4"
] |
computer algebra soft to minimize the number of operations in a set of polynomials | 1,736,034 | <p>I have systems of polynomials, fairly simple polynomial expressions but rather long
to optimize my hand. Expressions are grouped in sets, and in a given set there are common terms in several variables.</p>
<p>I would like to know if there is a computer algebra system, such as Mathematica, Matlab, or sympy, which c... | 1 | 2009-11-14T23:56:17Z | 1,736,081 | <p>Is <a href="http://code.google.com/p/sympy/" rel="nofollow">sympy</a> what you're looking for? I do believe it has support for polynomials although I don't know if it supports all the features you may desire (still, tweaking it to add what you think it might be missing has to be easier than writing your own from sc... | 1 | 2009-11-15T00:15:04Z | [
"python",
"algorithm",
"symbolic-math",
"sympy",
"computer-algebra-systems"
] |
computer algebra soft to minimize the number of operations in a set of polynomials | 1,736,034 | <p>I have systems of polynomials, fairly simple polynomial expressions but rather long
to optimize my hand. Expressions are grouped in sets, and in a given set there are common terms in several variables.</p>
<p>I would like to know if there is a computer algebra system, such as Mathematica, Matlab, or sympy, which c... | 1 | 2009-11-14T23:56:17Z | 2,333,327 | <p>Have you considered <a href="http://mathscitech.org/articles/maxima" rel="nofollow">Maxima</a>?</p>
<p>It is an impressive symbolical computation package that is free, open source, and has a strong and active community that provides valuable assistance when dealing with non-obvious formulations. It is readily avai... | 1 | 2010-02-25T10:44:44Z | [
"python",
"algorithm",
"symbolic-math",
"sympy",
"computer-algebra-systems"
] |
computer algebra soft to minimize the number of operations in a set of polynomials | 1,736,034 | <p>I have systems of polynomials, fairly simple polynomial expressions but rather long
to optimize my hand. Expressions are grouped in sets, and in a given set there are common terms in several variables.</p>
<p>I would like to know if there is a computer algebra system, such as Mathematica, Matlab, or sympy, which c... | 1 | 2009-11-14T23:56:17Z | 2,333,385 | <p>Well Mathematica can certainly do all sorts of transformations on sets of polynomial equations such as yours, and some of those transformations could be to reduce the number of terms. Whether that is the right answer for you is open to question, as you don't seem to have a copy available. I expect that the same is... | 0 | 2010-02-25T10:53:14Z | [
"python",
"algorithm",
"symbolic-math",
"sympy",
"computer-algebra-systems"
] |
computer algebra soft to minimize the number of operations in a set of polynomials | 1,736,034 | <p>I have systems of polynomials, fairly simple polynomial expressions but rather long
to optimize my hand. Expressions are grouped in sets, and in a given set there are common terms in several variables.</p>
<p>I would like to know if there is a computer algebra system, such as Mathematica, Matlab, or sympy, which c... | 1 | 2009-11-14T23:56:17Z | 4,542,016 | <p>Mathomatic may be the lightweight solution you are looking for. Have a look: <a href="http://www.mathomatic.org" rel="nofollow">http:www.mathomatic.org</a>.</p>
<p>It does simple algebra with all the usual operators, is able to simplify symbolic expressions, solve for variables and sets of eqns. </p>
<p>It has no... | 1 | 2010-12-27T21:38:20Z | [
"python",
"algorithm",
"symbolic-math",
"sympy",
"computer-algebra-systems"
] |
Python: data vs. text? | 1,736,228 | <p>Guido van Rossum's presentation about <a href="http://www.python.org/doc/essays/ppt/euro2008/Py3kEuro08.pdf">Python 3000</a> mentions several things to make a transition from Python 2 to Python 3 easier eventually. He is specifically talking about text handling since the move to Unicode as the only representation of... | 11 | 2009-11-15T01:13:19Z | 1,736,279 | <p>In a nutshell, the way text and data is handled in Py3k may arguably be the most "breaking" change in the language. By knowing and avoiding,when possible, the situations where some Python 2.6 logic will work differently than in 3.x, we can facilitate the migration when it happens. Yet we should expect that some par... | 17 | 2009-11-15T01:35:09Z | [
"python",
"unicode",
"python-3.x"
] |
Python: data vs. text? | 1,736,228 | <p>Guido van Rossum's presentation about <a href="http://www.python.org/doc/essays/ppt/euro2008/Py3kEuro08.pdf">Python 3000</a> mentions several things to make a transition from Python 2 to Python 3 easier eventually. He is specifically talking about text handling since the move to Unicode as the only representation of... | 11 | 2009-11-15T01:13:19Z | 1,736,539 | <p>The answer to your first question is simple: In Python 2.6 you can do has you used to. But, if you like, you can switch to Py3k standards by typing:</p>
<pre><code>from __future__ import unicode_literals
</code></pre>
<p>Your second question needs more clarification:</p>
<p>Strings are data that prints as human c... | 2 | 2009-11-15T04:12:26Z | [
"python",
"unicode",
"python-3.x"
] |
Python binary diff | 1,736,348 | <p>I'm trying to use bsdiff (or any binary diff implementation you come up with) to compute and apply diff onto random binary data. I would like to use it on data from a database, so it would be better not to have to write those onto disk and pass them to bsdiff.exe.</p>
<p>Is there any wrapper library or way in pytho... | 3 | 2009-11-15T02:20:37Z | 1,736,358 | <p>You can use <a href="http://docs.python.org/library/difflib.html" rel="nofollow">difflib</a> that is part of Python standard library. You can send any arbitrary data into a <code>difflib.SequenceMatcher</code>.</p>
| 2 | 2009-11-15T02:25:09Z | [
"python",
"diff"
] |
Python binary diff | 1,736,348 | <p>I'm trying to use bsdiff (or any binary diff implementation you come up with) to compute and apply diff onto random binary data. I would like to use it on data from a database, so it would be better not to have to write those onto disk and pass them to bsdiff.exe.</p>
<p>Is there any wrapper library or way in pytho... | 3 | 2009-11-15T02:20:37Z | 1,736,360 | <p>From the <a href="http://www.daemonology.net/bsdiff/">bsdiff</a> website:</p>
<blockquote>
<p>It has also been made into a <a href="http://starship.python.net/crew/atuining/cx%5Fbsdiff/index.html">Python extension module</a>, and there is a Windows port available.</p>
</blockquote>
<p>Following the link brings y... | 5 | 2009-11-15T02:26:03Z | [
"python",
"diff"
] |
Python binary diff | 1,736,348 | <p>I'm trying to use bsdiff (or any binary diff implementation you come up with) to compute and apply diff onto random binary data. I would like to use it on data from a database, so it would be better not to have to write those onto disk and pass them to bsdiff.exe.</p>
<p>Is there any wrapper library or way in pytho... | 3 | 2009-11-15T02:20:37Z | 1,736,587 | <p>Also, the <code>SequenceMatcher</code> class (from the Python standard library) can be helpful.</p>
<p>Check out the other contents of the <code>difflib</code> module as well.</p>
| 1 | 2009-11-15T04:46:45Z | [
"python",
"diff"
] |
Using Windows 7 taskbar features in PyQt | 1,736,394 | <p>I am looking for information on the integration of some of the new Windows 7 taskbar features into my PyQt applications.</p>
<p>Specifically if there already exists the possibility to use the new progress indicator (<a href="http://www.petri.co.il/wp-content/uploads/new%5Fwin7%5Ftaskbar%5Ffeatures%5F10.gif">see her... | 12 | 2009-11-15T02:45:40Z | 1,736,425 | <p>Not implemented in Qt 4.5, but <a href="http://arstechnica.com/open-source/news/2009/10/qt-46-promises-to-deliver-windows-7-maemo-and-s60-support.ars" rel="nofollow">in the works for Qt 4.6</a> it appears. PyQt won't wrap 4.6 until Qt 4.6 is officially released, but you can play with the <a href="http://doc.trollte... | 3 | 2009-11-15T03:04:59Z | [
"python",
"windows-7",
"pyqt",
"pyqt4",
"taskbar"
] |
Using Windows 7 taskbar features in PyQt | 1,736,394 | <p>I am looking for information on the integration of some of the new Windows 7 taskbar features into my PyQt applications.</p>
<p>Specifically if there already exists the possibility to use the new progress indicator (<a href="http://www.petri.co.il/wp-content/uploads/new%5Fwin7%5Ftaskbar%5Ffeatures%5F10.gif">see her... | 12 | 2009-11-15T02:45:40Z | 1,744,503 | <p>As quark said, the functionality is not in Qt 4.5, but you can call the windows API directly from Qt. Its a little bit of work though.</p>
<ol>
<li><p>The new taskbar API is exposed through COM, so you can't use ctypes.windll . You need to create a .tlb file to access the functions. Get the interface definition for... | 23 | 2009-11-16T20:00:05Z | [
"python",
"windows-7",
"pyqt",
"pyqt4",
"taskbar"
] |
Using Windows 7 taskbar features in PyQt | 1,736,394 | <p>I am looking for information on the integration of some of the new Windows 7 taskbar features into my PyQt applications.</p>
<p>Specifically if there already exists the possibility to use the new progress indicator (<a href="http://www.petri.co.il/wp-content/uploads/new%5Fwin7%5Ftaskbar%5Ffeatures%5F10.gif">see her... | 12 | 2009-11-15T02:45:40Z | 3,670,581 | <p>There is a Qt add-on that implements all the Windows 7 taskbar extensions. It is called <a href="http://www.strixcode.com/q7goodies/">Q7Goodies</a>. It comes with a PyQt bindings, so this is probably the easiest way to take advantage of Windows 7 features in PyQt.</p>
| 5 | 2010-09-08T17:55:47Z | [
"python",
"windows-7",
"pyqt",
"pyqt4",
"taskbar"
] |
Read version info from .ABR file (Photoshop brush set) | 1,736,396 | <p>Is it possible to detect which Photoshop version a brush set (.abr) file is compatible with from its binary data?</p>
<p>There is a open source C# programm called <a href="http://abrviewer.sourceforge.net/" rel="nofollow" >ABRViewer</a> but it doesn't read version info.</p>
<p>Sample brushes:</p>
<p><a href="http... | 1 | 2009-11-15T02:45:49Z | 1,736,534 | <p>If you are on Windows, you may have some luck using Python's <a href="http://python.net/crew/skippy/win32/Downloads.html" rel="nofollow">win32com</a> to interact with Photoshop programatically (a <a href="http://techarttiki.blogspot.com/2008/08/photoshop-scripting-with-python.html" rel="nofollow">nice example</a>). ... | 4 | 2009-11-15T04:08:59Z | [
"python",
"binary",
"hex",
"photoshop"
] |
Native Python Editor for Mac? | 1,736,451 | <p>I'm currently using IDLE, its decent, but I'd like to know if there're better lightweight IDEs built especially for Mac â free or commercial. </p>
| 2 | 2009-11-15T03:19:14Z | 1,736,457 | <p><a href="http://macromates.com/" rel="nofollow">TextMate</a> is a great general-purpose editor for mac. Used by the Rails community a lot, but it's great with python too.</p>
| 6 | 2009-11-15T03:22:00Z | [
"python",
"osx",
"ide",
"editor",
"python-idle"
] |
Native Python Editor for Mac? | 1,736,451 | <p>I'm currently using IDLE, its decent, but I'd like to know if there're better lightweight IDEs built especially for Mac â free or commercial. </p>
| 2 | 2009-11-15T03:19:14Z | 1,736,463 | <p>Purpose built for Mac? <a href="http://en.wikipedia.org/wiki/Xcode" rel="nofollow">Xcode</a> supports python. <a href="http://en.wikipedia.org/wiki/Textmate" rel="nofollow">Textmate</a> and <a href="http://en.wikipedia.org/wiki/BBedit" rel="nofollow">BBEdit</a> are also great editors.</p>
<p>If you're fine with gen... | 2 | 2009-11-15T03:24:18Z | [
"python",
"osx",
"ide",
"editor",
"python-idle"
] |
Native Python Editor for Mac? | 1,736,451 | <p>I'm currently using IDLE, its decent, but I'd like to know if there're better lightweight IDEs built especially for Mac â free or commercial. </p>
| 2 | 2009-11-15T03:19:14Z | 1,736,465 | <p>There is a commercial one - Textmate.
Most of the good free editors are cross-platform (if you are ok with it, I'd recommend EditRa - but it doesn't work properly under 10.6 yet, because of some bugs in wxPython).</p>
| 1 | 2009-11-15T03:25:10Z | [
"python",
"osx",
"ide",
"editor",
"python-idle"
] |
Native Python Editor for Mac? | 1,736,451 | <p>I'm currently using IDLE, its decent, but I'd like to know if there're better lightweight IDEs built especially for Mac â free or commercial. </p>
| 2 | 2009-11-15T03:19:14Z | 1,736,509 | <p>Allow me to suggest the GUI version of <a href="http://www.vim.org/" rel="nofollow">Vim</a> for Mac OS X, aptly named <a href="http://code.google.com/p/macvim/" rel="nofollow">MacVim</a>. It is superb.</p>
| 3 | 2009-11-15T03:49:15Z | [
"python",
"osx",
"ide",
"editor",
"python-idle"
] |
Native Python Editor for Mac? | 1,736,451 | <p>I'm currently using IDLE, its decent, but I'd like to know if there're better lightweight IDEs built especially for Mac â free or commercial. </p>
| 2 | 2009-11-15T03:19:14Z | 1,736,518 | <p>There're aren't any Mac-specific Python IDEs, though <a href="http://www.activestate.com/komodo/" rel="nofollow">Komodo's</a> IDE, <a href="http://www.netbeans.org/features/python/index.html" rel="nofollow">NetBeans</a> and Eclipse (with the excellent <a href="http://pydev.sourceforge.net/" rel="nofollow">PyDev</a> ... | 1 | 2009-11-15T04:00:46Z | [
"python",
"osx",
"ide",
"editor",
"python-idle"
] |
Native Python Editor for Mac? | 1,736,451 | <p>I'm currently using IDLE, its decent, but I'd like to know if there're better lightweight IDEs built especially for Mac â free or commercial. </p>
| 2 | 2009-11-15T03:19:14Z | 1,736,831 | <p>vim, emacs, BBEdit, WingIDE, or my favorite - eclipse (although, I don't think this is very lightweight)</p>
| 0 | 2009-11-15T06:56:19Z | [
"python",
"osx",
"ide",
"editor",
"python-idle"
] |
Native Python Editor for Mac? | 1,736,451 | <p>I'm currently using IDLE, its decent, but I'd like to know if there're better lightweight IDEs built especially for Mac â free or commercial. </p>
| 2 | 2009-11-15T03:19:14Z | 2,854,788 | <p>I would recommend you to look at <strong>Aptana</strong>(it's more attractive then Eclipse for me)<strong>+PyDev</strong> or <strong>PyCarm</strong>. I use <strong>TextMate</strong> too, but those are easy for debug.</p>
| 0 | 2010-05-18T05:43:45Z | [
"python",
"osx",
"ide",
"editor",
"python-idle"
] |
Native Python Editor for Mac? | 1,736,451 | <p>I'm currently using IDLE, its decent, but I'd like to know if there're better lightweight IDEs built especially for Mac â free or commercial. </p>
| 2 | 2009-11-15T03:19:14Z | 3,432,322 | <p>I use <strong>FRAISE</strong> (free) it is <em>simple</em> and useful, auto indentation, colorize, auto completion, shell.</p>
| 0 | 2010-08-07T22:39:17Z | [
"python",
"osx",
"ide",
"editor",
"python-idle"
] |
Native Python Editor for Mac? | 1,736,451 | <p>I'm currently using IDLE, its decent, but I'd like to know if there're better lightweight IDEs built especially for Mac â free or commercial. </p>
| 2 | 2009-11-15T03:19:14Z | 4,642,775 | <p>going to vote for Fraise. handles almost anything, has indentations, and uses color! its free too.</p>
| 0 | 2011-01-10T00:25:49Z | [
"python",
"osx",
"ide",
"editor",
"python-idle"
] |
Native Python Editor for Mac? | 1,736,451 | <p>I'm currently using IDLE, its decent, but I'd like to know if there're better lightweight IDEs built especially for Mac â free or commercial. </p>
| 2 | 2009-11-15T03:19:14Z | 7,764,682 | <p>check out Sublime Text 2 Alpha. seriously awesome.</p>
| 0 | 2011-10-14T07:57:57Z | [
"python",
"osx",
"ide",
"editor",
"python-idle"
] |
Native Python Editor for Mac? | 1,736,451 | <p>I'm currently using IDLE, its decent, but I'd like to know if there're better lightweight IDEs built especially for Mac â free or commercial. </p>
| 2 | 2009-11-15T03:19:14Z | 14,326,756 | <p>So, I was using <strong>TextMate</strong> for a while for python. It is good for writing small programs but not for managing big projects. I ran into problems, especially sometimes it caused mismatched indentations. For the life of me, I was not able to figure out what was going on. Then I switched to <strong>BBEdit... | 2 | 2013-01-14T21:12:49Z | [
"python",
"osx",
"ide",
"editor",
"python-idle"
] |
Programatically saving an image to a Django ImageField is creating an infinite loop of images | 1,736,550 | <p>I've got a <code>save</code> method on a model that looks like so:</p>
<pre><code>def save(self, force_insert=False, force_update=False):
img_url = "http://example.com/%s.jpg" % (self.title)
name = urlparse(img_url).path.split('/')[-1]
content = urllib.urlretrieve(img_url)
self.image.save(name, File... | 1 | 2009-11-15T04:19:27Z | 1,736,557 | <p>I'm not 100% certain, but it could be that when <code>self.image.save</code> is called, it calls the save method of the model, by default, as well - Thus creating your infinite loop. I haven't tested it but I could see that happening.</p>
<p>My suggestion if that is the issue: Send a <a href="http://docs.djangoproj... | 0 | 2009-11-15T04:25:49Z | [
"python",
"django"
] |
Programatically saving an image to a Django ImageField is creating an infinite loop of images | 1,736,550 | <p>I've got a <code>save</code> method on a model that looks like so:</p>
<pre><code>def save(self, force_insert=False, force_update=False):
img_url = "http://example.com/%s.jpg" % (self.title)
name = urlparse(img_url).path.split('/')[-1]
content = urllib.urlretrieve(img_url)
self.image.save(name, File... | 1 | 2009-11-15T04:19:27Z | 1,737,030 | <p>I think from a browse through the source code that calling <code>ImageFileField.save()</code> (actually <code>FileField.save()</code> due to inheritance) causes the instance (namely the db row) that the file name is stored in to be updated.</p>
<p>This means that in your <code>save</code> method you call <code>Imag... | 1 | 2009-11-15T08:56:20Z | [
"python",
"django"
] |
How to bundle tkinter? | 1,736,742 | <p>I am distributing an app that uses the Python/C API. I have all standard python modules in python31.zip which is basically an archive of the Lib folder in the python install directory. Here is the problem - most common modules like sys and io work fine. BUT tkinter does not. I get an error "cannot find module _tkint... | 2 | 2009-11-15T06:02:55Z | 1,736,766 | <p>why don't you use <a href="http://www.py2exe.org/" rel="nofollow">py2exe</a> to bundle your application as an executable? It should take care of all the dependencies, and will include whatever you need.</p>
| 1 | 2009-11-15T06:16:03Z | [
"python",
"tkinter"
] |
How to bundle tkinter? | 1,736,742 | <p>I am distributing an app that uses the Python/C API. I have all standard python modules in python31.zip which is basically an archive of the Lib folder in the python install directory. Here is the problem - most common modules like sys and io work fine. BUT tkinter does not. I get an error "cannot find module _tkint... | 2 | 2009-11-15T06:02:55Z | 1,736,834 | <p>I don't the best way to bundle tkinter with your app, but I do know why you're getting the error you are. The relevant section of the <a href="http://docs.python.org/library/zipimport.html" rel="nofollow">zipimport</a> module documentation:</p>
<blockquote>
<p>Any files may be present in the ZIP archive, but only... | 1 | 2009-11-15T06:57:20Z | [
"python",
"tkinter"
] |
Tree view GUI widget/gui library that can do multiple icons? | 1,736,917 | <p><a href="http://imgur.com/fcTZ2.png" rel="nofollow">Screenshot</a></p>
<p>I'm looking to recreate this in Python; I can't find a library that seems to have what I need. Are there any GUI libraries that might possibly have this? - I have scoured wxWidgets (which is my preferred gui library) but they have nothing si... | 1 | 2009-11-15T07:48:46Z | 1,736,988 | <p>you have few options</p>
<ol>
<li><p>Use wx.lib.customtreectrl.CustomTreeCtrl<br>
AppendItem of CustomTreeCtrl can take any wx widget, which is shown at end, so you can use that to affect e.g. tree.AppendItem(root, "item1", wnd=yourImageControl)</p></li>
<li><p>Use wx.gizmos.TreeListCtrl, you can have icons in sepa... | 2 | 2009-11-15T08:28:06Z | [
"python",
"user-interface",
"wxpython"
] |
Tree view GUI widget/gui library that can do multiple icons? | 1,736,917 | <p><a href="http://imgur.com/fcTZ2.png" rel="nofollow">Screenshot</a></p>
<p>I'm looking to recreate this in Python; I can't find a library that seems to have what I need. Are there any GUI libraries that might possibly have this? - I have scoured wxWidgets (which is my preferred gui library) but they have nothing si... | 1 | 2009-11-15T07:48:46Z | 1,737,311 | <p>Instead of CustomTreeCtrl, I'd look into HyperTreeList. It is based on CustomTreeCtrl, but adds support for multiple columns. I'm not sure if it supports multiple icons in one column out of the box though.</p>
| 0 | 2009-11-15T11:36:32Z | [
"python",
"user-interface",
"wxpython"
] |
How Can I Make This Python Code More Usable And Readable? | 1,737,013 | <p>Beginner in python, but been programming for about 5 years now. I suspect I have a lot to learn about doing things the object oriented way, but I know the basics. I planned on programming a calculator that shows it's work for the challenge and knowledge i'll gain from it. I just started and this is what i've got, an... | 1 | 2009-11-15T08:43:10Z | 1,737,052 | <p>If you want to make a simple calculator you could try implementing <a href="http://en.wikipedia.org/wiki/Shunting-yard%5Falgorithm" rel="nofollow">Shunting-yard algorithm</a>.</p>
<p>But if you want to go with regex approach I'd still do it a little differently:</p>
<pre><code>import re
#In python functions/metho... | 2 | 2009-11-15T09:09:51Z | [
"python",
"oop",
"usability",
"readability"
] |
How Can I Make This Python Code More Usable And Readable? | 1,737,013 | <p>Beginner in python, but been programming for about 5 years now. I suspect I have a lot to learn about doing things the object oriented way, but I know the basics. I planned on programming a calculator that shows it's work for the challenge and knowledge i'll gain from it. I just started and this is what i've got, an... | 1 | 2009-11-15T08:43:10Z | 1,737,060 | <p>Some problems:</p>
<pre><code>contents = re.match("(\(.*\))", problem)
</code></pre>
<p>When it's given the input <code>(1+2)/(3+4)</code>, it's going to try to evaluate <code>1+2)/(3+4</code>.</p>
<p>It also doesn't go all the way into nested parentheses, for this you would need to use recursion.</p>
<p>I think... | 5 | 2009-11-15T09:18:04Z | [
"python",
"oop",
"usability",
"readability"
] |
How Can I Make This Python Code More Usable And Readable? | 1,737,013 | <p>Beginner in python, but been programming for about 5 years now. I suspect I have a lot to learn about doing things the object oriented way, but I know the basics. I planned on programming a calculator that shows it's work for the challenge and knowledge i'll gain from it. I just started and this is what i've got, an... | 1 | 2009-11-15T08:43:10Z | 1,737,061 | <p>Why don't you match only for the double and matching parentheses? The first match for a single <code>(</code> is not really necessary because if the match for the doubles fail, this means there are no expression for you to evaluate.</p>
<pre><code>import re
def eval_parentheses(problem):
contents = re.match("(... | 0 | 2009-11-15T09:18:10Z | [
"python",
"oop",
"usability",
"readability"
] |
How Can I Make This Python Code More Usable And Readable? | 1,737,013 | <p>Beginner in python, but been programming for about 5 years now. I suspect I have a lot to learn about doing things the object oriented way, but I know the basics. I planned on programming a calculator that shows it's work for the challenge and knowledge i'll gain from it. I just started and this is what i've got, an... | 1 | 2009-11-15T08:43:10Z | 1,737,064 | <p>I'd probably replace occurrences of</p>
<pre><code>re.match( "\(", problem)
</code></pre>
<p>with</p>
<pre><code>problem.startswith("(")
</code></pre>
<p>In</p>
<pre><code>contents = re.match("(\(.*\))", problem)
parenthsAnswer = contents.group(0)
</code></pre>
<p>you don't check to see whether contents matche... | 2 | 2009-11-15T09:19:20Z | [
"python",
"oop",
"usability",
"readability"
] |
Django auto_now and auto_now_add | 1,737,017 | <p>For Django 1.1.</p>
<p>I have this in my models.py:</p>
<pre><code>class User(models.Model):
created = models.DateTimeField(auto_now_add=True)
modified = models.DateTimeField(auto_now=True)
</code></pre>
<p>When updating a row I get:</p>
<pre><code>[Sun Nov 15 02:18:12 2009] [error] /home/ptarjan/project... | 136 | 2009-11-15T08:47:56Z | 1,737,078 | <p>Any field with the <code>auto_now</code> attribute set will also inherit <code>editable=False</code> and therefore will not show up in the admin panel. There has been talk in the past about making the <code>auto_now</code> and <code>auto_now_add</code> arguments go away, and although they still exist, I feel you're... | 194 | 2009-11-15T09:26:31Z | [
"python",
"django",
"datetime",
"django-models",
"django-admin"
] |
Django auto_now and auto_now_add | 1,737,017 | <p>For Django 1.1.</p>
<p>I have this in my models.py:</p>
<pre><code>class User(models.Model):
created = models.DateTimeField(auto_now_add=True)
modified = models.DateTimeField(auto_now=True)
</code></pre>
<p>When updating a row I get:</p>
<pre><code>[Sun Nov 15 02:18:12 2009] [error] /home/ptarjan/project... | 136 | 2009-11-15T08:47:56Z | 1,737,488 | <blockquote>
<p>Is this cause for concern?</p>
</blockquote>
<p>No, Django automatically adds it for you while saving the models, so, it is expected.</p>
<blockquote>
<p>Side question: in my admin tool, those 2 fields aren't showing up. Is that expected?</p>
</blockquote>
<p>Since these fields are auto added, th... | 1 | 2009-11-15T13:09:26Z | [
"python",
"django",
"datetime",
"django-models",
"django-admin"
] |
Django auto_now and auto_now_add | 1,737,017 | <p>For Django 1.1.</p>
<p>I have this in my models.py:</p>
<pre><code>class User(models.Model):
created = models.DateTimeField(auto_now_add=True)
modified = models.DateTimeField(auto_now=True)
</code></pre>
<p>When updating a row I get:</p>
<pre><code>[Sun Nov 15 02:18:12 2009] [error] /home/ptarjan/project... | 136 | 2009-11-15T08:47:56Z | 3,330,128 | <p>Bah... Not enough reputation to comment... But I wanted to point out that the opinion expressed in the accepted answer is somewhat outdated. According to more recent discussions (django bugs <a href="https://code.djangoproject.com/ticket/7634">#7634</a> and <a href="https://code.djangoproject.com/ticket/12785">#1278... | 96 | 2010-07-25T17:01:35Z | [
"python",
"django",
"datetime",
"django-models",
"django-admin"
] |
Django auto_now and auto_now_add | 1,737,017 | <p>For Django 1.1.</p>
<p>I have this in my models.py:</p>
<pre><code>class User(models.Model):
created = models.DateTimeField(auto_now_add=True)
modified = models.DateTimeField(auto_now=True)
</code></pre>
<p>When updating a row I get:</p>
<pre><code>[Sun Nov 15 02:18:12 2009] [error] /home/ptarjan/project... | 136 | 2009-11-15T08:47:56Z | 11,646,630 | <p>Talking about a side question: if you want to see this fields in admin (though, you won't be able to edit it), you can add <code>readonly_fields</code> to your admin class.</p>
<pre><code>class SomeAdmin(ModelAdmin):
readonly_fields = ("created","modified",)
</code></pre>
<p>Well, this applies only to latest D... | 20 | 2012-07-25T09:25:41Z | [
"python",
"django",
"datetime",
"django-models",
"django-admin"
] |
Django auto_now and auto_now_add | 1,737,017 | <p>For Django 1.1.</p>
<p>I have this in my models.py:</p>
<pre><code>class User(models.Model):
created = models.DateTimeField(auto_now_add=True)
modified = models.DateTimeField(auto_now=True)
</code></pre>
<p>When updating a row I get:</p>
<pre><code>[Sun Nov 15 02:18:12 2009] [error] /home/ptarjan/project... | 136 | 2009-11-15T08:47:56Z | 14,832,661 | <p>As for your Admin display, see <a href="http://stackoverflow.com/a/3967891/1536539">this answer</a>.</p>
<p>Note: auto_now and auto_now_add are set to editable=False by default, which is why this applies.</p>
| 2 | 2013-02-12T12:32:59Z | [
"python",
"django",
"datetime",
"django-models",
"django-admin"
] |
Django auto_now and auto_now_add | 1,737,017 | <p>For Django 1.1.</p>
<p>I have this in my models.py:</p>
<pre><code>class User(models.Model):
created = models.DateTimeField(auto_now_add=True)
modified = models.DateTimeField(auto_now=True)
</code></pre>
<p>When updating a row I get:</p>
<pre><code>[Sun Nov 15 02:18:12 2009] [error] /home/ptarjan/project... | 136 | 2009-11-15T08:47:56Z | 16,672,915 | <p>Here's the answer if you're using south and you want to default to the date you add the field to the database:</p>
<p>Choose option <strong>2</strong>
then: <strong>datetime.datetime.now()</strong></p>
<p>Looks like this:</p>
<pre><code>$ ./manage.py schemamigration myapp --auto
? The field 'User.created_date' d... | 0 | 2013-05-21T14:46:11Z | [
"python",
"django",
"datetime",
"django-models",
"django-admin"
] |
Django auto_now and auto_now_add | 1,737,017 | <p>For Django 1.1.</p>
<p>I have this in my models.py:</p>
<pre><code>class User(models.Model):
created = models.DateTimeField(auto_now_add=True)
modified = models.DateTimeField(auto_now=True)
</code></pre>
<p>When updating a row I get:</p>
<pre><code>[Sun Nov 15 02:18:12 2009] [error] /home/ptarjan/project... | 136 | 2009-11-15T08:47:56Z | 18,752,680 | <p>I think the easiest (and maybe most elegant) solution here is to leverage the fact that you can set <code>default</code> to a callable. So, to get around admin's special handling of auto_now, you can just declare the field like so:</p>
<pre><code>from django.utils import timezone
date_filed = models.DateField(defau... | 9 | 2013-09-11T22:58:15Z | [
"python",
"django",
"datetime",
"django-models",
"django-admin"
] |
Django auto_now and auto_now_add | 1,737,017 | <p>For Django 1.1.</p>
<p>I have this in my models.py:</p>
<pre><code>class User(models.Model):
created = models.DateTimeField(auto_now_add=True)
modified = models.DateTimeField(auto_now=True)
</code></pre>
<p>When updating a row I get:</p>
<pre><code>[Sun Nov 15 02:18:12 2009] [error] /home/ptarjan/project... | 136 | 2009-11-15T08:47:56Z | 22,015,427 | <p>I have find a solution</p>
<p>if i have a model class like:</p>
<pre><code>class MyModel(models.Model):
time = models.DatetimeField(auto_now_add=True)
time.editable = True
</code></pre>
<p>Then this field will show up in my admin change page</p>
| 9 | 2014-02-25T13:18:16Z | [
"python",
"django",
"datetime",
"django-models",
"django-admin"
] |
Django auto_now and auto_now_add | 1,737,017 | <p>For Django 1.1.</p>
<p>I have this in my models.py:</p>
<pre><code>class User(models.Model):
created = models.DateTimeField(auto_now_add=True)
modified = models.DateTimeField(auto_now=True)
</code></pre>
<p>When updating a row I get:</p>
<pre><code>[Sun Nov 15 02:18:12 2009] [error] /home/ptarjan/project... | 136 | 2009-11-15T08:47:56Z | 22,099,287 | <p><code>auto_now=True</code> didn't work for me in Django 1.4.1, but the below code saved me. It's for timezone aware datetime.</p>
<pre><code>from django.utils.timezone import get_current_timezone
from datetime import datetime
class EntryVote(models.Model):
voted_on = models.DateTimeField(auto_now=True)
de... | 1 | 2014-02-28T15:31:45Z | [
"python",
"django",
"datetime",
"django-models",
"django-admin"
] |
Django auto_now and auto_now_add | 1,737,017 | <p>For Django 1.1.</p>
<p>I have this in my models.py:</p>
<pre><code>class User(models.Model):
created = models.DateTimeField(auto_now_add=True)
modified = models.DateTimeField(auto_now=True)
</code></pre>
<p>When updating a row I get:</p>
<pre><code>[Sun Nov 15 02:18:12 2009] [error] /home/ptarjan/project... | 136 | 2009-11-15T08:47:56Z | 24,276,495 | <p>You can use <code>timezone.now()</code> for created and <code>auto_now</code> for modified:</p>
<pre><code>from django.utils import timezone
class User(models.Model):
created = models.DateTimeField(default=timezone.now())
modified = models.DateTimeField(auto_now=True)
</code></pre>
<p>If you are using a cu... | 5 | 2014-06-18T03:14:59Z | [
"python",
"django",
"datetime",
"django-models",
"django-admin"
] |
Django auto_now and auto_now_add | 1,737,017 | <p>For Django 1.1.</p>
<p>I have this in my models.py:</p>
<pre><code>class User(models.Model):
created = models.DateTimeField(auto_now_add=True)
modified = models.DateTimeField(auto_now=True)
</code></pre>
<p>When updating a row I get:</p>
<pre><code>[Sun Nov 15 02:18:12 2009] [error] /home/ptarjan/project... | 136 | 2009-11-15T08:47:56Z | 24,663,093 | <p>Based on what I've read and my experience with Django so far, auto_now_add is buggy. I agree with jthanism --- override the normal save method it's clean and you know what's hapenning. Now, to make it dry, create an abstract model called TimeStamped:</p>
<pre><code>from django.utils import timezone
class TimeSta... | 6 | 2014-07-09T20:18:05Z | [
"python",
"django",
"datetime",
"django-models",
"django-admin"
] |
Django auto_now and auto_now_add | 1,737,017 | <p>For Django 1.1.</p>
<p>I have this in my models.py:</p>
<pre><code>class User(models.Model):
created = models.DateTimeField(auto_now_add=True)
modified = models.DateTimeField(auto_now=True)
</code></pre>
<p>When updating a row I get:</p>
<pre><code>[Sun Nov 15 02:18:12 2009] [error] /home/ptarjan/project... | 136 | 2009-11-15T08:47:56Z | 36,869,051 | <p>I needed something similar today at work. Default value to be timezone.now(), but editable both in admin and class views inheriting from FormMixin, so for created in my models.py the following code fulfilled those requirements:</p>
<pre><code>from __future__ import unicode_literals
import datetime
from django.db i... | 0 | 2016-04-26T15:15:12Z | [
"python",
"django",
"datetime",
"django-models",
"django-admin"
] |
What's wrong with this program? | 1,737,072 | <pre><code>def short_distance(origins,(x,y),gap):
for (i,j) in origins.spilt(â â):
h=[]
h.append(float(math.sqrt ((i-x)*(i-x)+(j-y)*(j-y))))
for n in h:
if not gap < n:
print 0
if gap < n :
print n
</code></pre>
| -4 | 2009-11-15T09:24:02Z | 1,737,081 | <ul>
<li>the indentation is wrong; the <code>for</code> loops should be indented more than the <code>def</code></li>
<li>typo: <code>origins.spilt(" ")</code> should probably be <code>origins.split(" ")</code></li>
</ul>
| 2 | 2009-11-15T09:29:01Z | [
"python"
] |
What's wrong with this program? | 1,737,072 | <pre><code>def short_distance(origins,(x,y),gap):
for (i,j) in origins.spilt(â â):
h=[]
h.append(float(math.sqrt ((i-x)*(i-x)+(j-y)*(j-y))))
for n in h:
if not gap < n:
print 0
if gap < n :
print n
</code></pre>
| -4 | 2009-11-15T09:24:02Z | 1,737,271 | <p>Your code is perhaps for finding points from <code>origins</code> that are close to <code>(x, y)</code>. There is a lot of errors in it:</p>
<ol>
<li>Indention is wrong.</li>
<li><code>split()</code> method is spelled wrong.</li>
<li><code>split()</code> method returns flat list while you are expecting a list of pa... | 2 | 2009-11-15T11:19:47Z | [
"python"
] |
What's wrong with this program? | 1,737,072 | <pre><code>def short_distance(origins,(x,y),gap):
for (i,j) in origins.spilt(â â):
h=[]
h.append(float(math.sqrt ((i-x)*(i-x)+(j-y)*(j-y))))
for n in h:
if not gap < n:
print 0
if gap < n :
print n
</code></pre>
| -4 | 2009-11-15T09:24:02Z | 1,737,340 | <ol>
<li>You'll need to import math</li>
<li>The indentation is wrong</li>
<li>If Origins is a string like <code>'1,1 2,2 3,3'</code>, <code>Origins.split(" ")</code> will give you a list of strings <code>["1,1", "2,2", "3,3"]</code>. You will need to do some extra work to be able to use it with the for loop <code>for... | 0 | 2009-11-15T11:50:23Z | [
"python"
] |
What's wrong with this program? | 1,737,072 | <pre><code>def short_distance(origins,(x,y),gap):
for (i,j) in origins.spilt(â â):
h=[]
h.append(float(math.sqrt ((i-x)*(i-x)+(j-y)*(j-y))))
for n in h:
if not gap < n:
print 0
if gap < n :
print n
</code></pre>
| -4 | 2009-11-15T09:24:02Z | 1,737,432 | <p>I would write the code more like this. If you run the code, it will report any failing tests (of which there are none).</p>
<pre><code>import math
def short_distance(origins, point, gap):
"""
Describe origins, point, and gap are and what the
expected outcome is.
Then provide an example that tests the code
&... | 4 | 2009-11-15T12:33:41Z | [
"python"
] |
What's wrong with this program? | 1,737,072 | <pre><code>def short_distance(origins,(x,y),gap):
for (i,j) in origins.spilt(â â):
h=[]
h.append(float(math.sqrt ((i-x)*(i-x)+(j-y)*(j-y))))
for n in h:
if not gap < n:
print 0
if gap < n :
print n
</code></pre>
| -4 | 2009-11-15T09:24:02Z | 1,737,930 | <p>Here's the code:</p>
<pre><code>from math import sqrt
def short_distance(origins,(x,y),gap):
def distance(i, j):
ix, iy = i - x, j - y
return sqrt (ix*ix + iy*iy)
all_distances = (distance(float(i), float(j)) for (i,j) in origins)
for n in all_distances:
print (0 if gap >= n e... | 0 | 2009-11-15T16:02:21Z | [
"python"
] |
How do I enforce a UTF8 encoding on a generated CSV report? | 1,737,178 | <p>How do I enforce a UTF8 encoding on a generated CSV report in web2py?</p>
| 2 | 2009-11-15T10:22:24Z | 1,738,232 | <p>Use the <code>str.encode</code> function together with the csv module, there is a complete example that will show you that <a href="http://docs.python.org/library/csv.html?highlight=csv#module-csv" rel="nofollow">in the Python documentation</a> (or in the link given in comment to your question). Quick example:</p>
... | 2 | 2009-11-15T17:44:17Z | [
"python",
"web2py"
] |
SQLAlchemy 0.5.5 - defining table schema | 1,737,351 | <p>I used <code>sqlautocode</code> to generate a model.py for an existing MySQL database and here's a table example:</p>
<pre><code>fusion_articles = Table('fusion_articles', metadata,
Column(u'article_id', Integer(), primary_key=True, nullable=False),
Column(u'article_cat', Integer(), primary_key=Fal... | 0 | 2009-11-15T11:56:24Z | 1,737,382 | <p>It's largely a style preference, but also depends on how complex your code is.</p>
<p>If you're writing a short, isolated script that will likely not be imported elsewhere, bringing lots of names into your namespace (i.e. Table, Column) isn't a problem and makes the code easier to read.</p>
<p>If, on the other han... | 1 | 2009-11-15T12:08:28Z | [
"python",
"sqlalchemy"
] |
File open error by using codec utf-8 in python | 1,737,410 | <p>I execute following code on windows xp and python 2.6.4</p>
<p>But it show IOError.</p>
<p>How to open file whose name has utf-8 codec.</p>
<pre><code>>>> open( unicode('íê¸.txt', 'euc-kr').encode('utf-8') )
Traceback (most recent call last):
File "<pyshell#0>", line 1, in <module>
... | 3 | 2009-11-15T12:20:50Z | 1,737,476 | <p>The C runtime interface that Windows exposes to Python uses the system code page to encode filenames. Unlike on OS X and modern Linux versions, on Windows the system code page is never UTF-8. So the UTF-8 byte string won't be any good.</p>
<p>You could encode the filename to the current code page using <code>.encod... | 15 | 2009-11-15T12:59:46Z | [
"python",
"unicode",
"utf-8"
] |
Django: debugging entries just disapearing | 1,737,424 | <p>So, I'm pulling my hair out here, and maybe someone has an insight.</p>
<p>I have a cronjob that loops over all my <code>Link</code> objects, does some stuff, might change properties on the object and does a <code>save()</code>. That's it.</p>
<p>Every so often (around once an hour), one of my rows just disappears... | 1 | 2009-11-15T12:29:22Z | 1,737,971 | <p>You could use <a href="http://code.google.com/p/django-logging/wiki/Overview" rel="nofollow">django-logging</a> with <code>LOGGING_LOG_SQL = True</code> to log all the SQL, so you can see if any DELETE's are occurring.</p>
| 1 | 2009-11-15T16:14:26Z | [
"python",
"django",
"debugging"
] |
Django: debugging entries just disapearing | 1,737,424 | <p>So, I'm pulling my hair out here, and maybe someone has an insight.</p>
<p>I have a cronjob that loops over all my <code>Link</code> objects, does some stuff, might change properties on the object and does a <code>save()</code>. That's it.</p>
<p>Every so often (around once an hour), one of my rows just disappears... | 1 | 2009-11-15T12:29:22Z | 1,738,021 | <p>You could override the delete method on your Link class and dump a stack trace or log a message to see if it's indeed happening from within your Django application.</p>
<pre><code>import sys, traceback
def delete(self):
super(Link, self).delete()
try:
assert False
except AssertionError, e
tra... | 2 | 2009-11-15T16:32:48Z | [
"python",
"django",
"debugging"
] |
The Matlab equivalent of Python's "None" | 1,737,523 | <p>Is there a keyword in Matlab that is roughly equivalent to <code>None</code> in python?</p>
<p>I am trying to use it to mark an optional argument to a function. I am translating the following Python code</p>
<pre><code>def f(x,y=None):
if y == None:
return g(x)
else:
return h(x,y)
</code></pre>
... | 6 | 2009-11-15T13:23:18Z | 1,737,544 | <p><code>NaN</code> while not equivalent, often serves the similar purpose. </p>
| 4 | 2009-11-15T13:33:27Z | [
"python",
"matlab"
] |
The Matlab equivalent of Python's "None" | 1,737,523 | <p>Is there a keyword in Matlab that is roughly equivalent to <code>None</code> in python?</p>
<p>I am trying to use it to mark an optional argument to a function. I am translating the following Python code</p>
<pre><code>def f(x,y=None):
if y == None:
return g(x)
else:
return h(x,y)
</code></pre>
... | 6 | 2009-11-15T13:23:18Z | 1,737,565 | <p>in your specific case. you may use <code>nargin</code> to determine how many input arguments here provided when calling the function. </p>
<p>from the <a href="http://www.mathworks.com/access/helpdesk/help/techdoc/matlab%5Fprog/bresuxt-1.html#br67di7-1" rel="nofollow">MATLAB documentation</a>:</p>
<blockquote>
<... | 10 | 2009-11-15T13:46:38Z | [
"python",
"matlab"
] |
The Matlab equivalent of Python's "None" | 1,737,523 | <p>Is there a keyword in Matlab that is roughly equivalent to <code>None</code> in python?</p>
<p>I am trying to use it to mark an optional argument to a function. I am translating the following Python code</p>
<pre><code>def f(x,y=None):
if y == None:
return g(x)
else:
return h(x,y)
</code></pre>
... | 6 | 2009-11-15T13:23:18Z | 1,738,271 | <p><code>nargin</code> is definitely the easiest way of doing it. Also it is usually good practise to validate the number of input argument using <strong><a href="http://www.mathworks.com/access/helpdesk/help/techdoc/ref/nargchk.html">nargchk</a></strong>:</p>
<pre><code>function e = testFunc(a,b,c,d)
error( nargc... | 5 | 2009-11-15T18:00:46Z | [
"python",
"matlab"
] |
Safely executing user-submitted python code on the server | 1,737,524 | <p>I am looking into starting a project which involves executing python code that the user enters via a HTML form. I know this can be potentially lethal (<code>exec</code>), but I have seen it done successfully in at least <a href="http://challenge.ncss.edu.au/">one instance</a>. </p>
<p>I sent an email off to the dev... | 6 | 2009-11-15T13:23:32Z | 1,737,538 | <p>Using <a href="http://linux.die.net/man/1/chroot" rel="nofollow"><code>chroot</code></a> (<a href="http://en.wikipedia.org/wiki/Chroot" rel="nofollow">Wikipedia</a>) may be part of the solution, e.g. combined with <a href="http://linux.die.net/man/1/ulimit" rel="nofollow"><code>ulimit</code></a> and some other commo... | 0 | 2009-11-15T13:31:22Z | [
"python",
"user-input"
] |
Safely executing user-submitted python code on the server | 1,737,524 | <p>I am looking into starting a project which involves executing python code that the user enters via a HTML form. I know this can be potentially lethal (<code>exec</code>), but I have seen it done successfully in at least <a href="http://challenge.ncss.edu.au/">one instance</a>. </p>
<p>I sent an email off to the dev... | 6 | 2009-11-15T13:23:32Z | 1,737,539 | <p>If you run the script as user <code>nobody</code> (on Linux), it can write practically nowhere and read no data that has its permissions set up properly. But it could still cause a DoS attack by, for example:</p>
<ul>
<li>filling up <code>/tmp</code></li>
<li>eating all RAM</li>
<li>eating all CPU</li>
</ul>
<p>Fu... | 2 | 2009-11-15T13:31:27Z | [
"python",
"user-input"
] |
Safely executing user-submitted python code on the server | 1,737,524 | <p>I am looking into starting a project which involves executing python code that the user enters via a HTML form. I know this can be potentially lethal (<code>exec</code>), but I have seen it done successfully in at least <a href="http://challenge.ncss.edu.au/">one instance</a>. </p>
<p>I sent an email off to the dev... | 6 | 2009-11-15T13:23:32Z | 1,737,600 | <p>On a modern Linux in addition to chroot(2) you can restrict process further by using clone(2) instead of fork(2). There are several interesting clone(2) flags:</p>
<pre><code>CLONE_NEWIPC (new namespace for semaphores, shared memory, message queues)
CLONE_NEWNET (new network namespace - nice one)
CLONE_NEWNS (new s... | 3 | 2009-11-15T14:07:27Z | [
"python",
"user-input"
] |
Safely executing user-submitted python code on the server | 1,737,524 | <p>I am looking into starting a project which involves executing python code that the user enters via a HTML form. I know this can be potentially lethal (<code>exec</code>), but I have seen it done successfully in at least <a href="http://challenge.ncss.edu.au/">one instance</a>. </p>
<p>I sent an email off to the dev... | 6 | 2009-11-15T13:23:32Z | 2,052,326 | <p><a href="http://codepad.org/about" rel="nofollow">http://codepad.org/about</a> has implemented such a system successfully (as a public code pasting/running service!)</p>
<blockquote>
<p>codepad.org is an online compiler/interpreter, and a simple collaboration tool. It's a pastebin that executes code for you. [...... | 1 | 2010-01-12T20:59:08Z | [
"python",
"user-input"
] |
QGraphicsScene and positioning | 1,737,624 | <p>How to put QGraphicsScene's (0,0) to top-left corner of QGraphicsView?</p>
| 2 | 2009-11-15T14:17:13Z | 1,741,125 | <p><code>QGraphicsScene</code> will be filled in the whole <code>QGraphicsView</code> but You have the <a href="http://doc.trolltech.com/4.2/qgraphicsview.html#sceneRect-prop" rel="nofollow"><code>setSceneRect</code></a> function to choose the <code>QGraphicsScene</code> part you want to see in the <code>QGraphicsView<... | 0 | 2009-11-16T09:46:37Z | [
"python",
"qt",
"pyqt"
] |
QGraphicsScene and positioning | 1,737,624 | <p>How to put QGraphicsScene's (0,0) to top-left corner of QGraphicsView?</p>
| 2 | 2009-11-15T14:17:13Z | 4,600,372 | <p>Try doing <code>setCenterOn(0,0)</code> on the <code>QGraphicsView</code>?</p>
| 1 | 2011-01-05T02:38:09Z | [
"python",
"qt",
"pyqt"
] |
Dict has key from list | 1,737,778 | <p>How can I determine if any of the list elements are a key to a dict?
The straight forward way is,</p>
<pre><code>for i in myList:
if i in myDict:
return True
return False
</code></pre>
<p>but is there a faster / more concise way?</p>
| 7 | 2009-11-15T15:13:00Z | 1,737,790 | <pre><code>#!python
any(x in MyDict for x in MyList)
set(MyList).intersection(MyDict)
</code></pre>
| 20 | 2009-11-15T15:17:10Z | [
"python",
"list",
"dictionary"
] |
Dict has key from list | 1,737,778 | <p>How can I determine if any of the list elements are a key to a dict?
The straight forward way is,</p>
<pre><code>for i in myList:
if i in myDict:
return True
return False
</code></pre>
<p>but is there a faster / more concise way?</p>
| 7 | 2009-11-15T15:13:00Z | 1,737,824 | <p>Assuming you are talking about python, an alternate method of doing this would be:</p>
<pre><code>return len([x for x in myList if x in myDict]) > 0
</code></pre>
| 1 | 2009-11-15T15:26:41Z | [
"python",
"list",
"dictionary"
] |
Dict has key from list | 1,737,778 | <p>How can I determine if any of the list elements are a key to a dict?
The straight forward way is,</p>
<pre><code>for i in myList:
if i in myDict:
return True
return False
</code></pre>
<p>but is there a faster / more concise way?</p>
| 7 | 2009-11-15T15:13:00Z | 1,737,862 | <p>In addition to <code>any(item in my_dict for item in my_list)</code> from <a href="http://stackoverflow.com/questions/1737778/dict-has-key-from-list/1737790#1737790">@Ronny's answer</a>:</p>
<pre><code>any(map(my_dict.__contains__, my_list)) # Python 3.x
</code></pre>
<p>Or:</p>
<pre><code>from itertools import i... | 6 | 2009-11-15T15:39:14Z | [
"python",
"list",
"dictionary"
] |
Dict has key from list | 1,737,778 | <p>How can I determine if any of the list elements are a key to a dict?
The straight forward way is,</p>
<pre><code>for i in myList:
if i in myDict:
return True
return False
</code></pre>
<p>but is there a faster / more concise way?</p>
| 7 | 2009-11-15T15:13:00Z | 1,737,886 | <p><a href="http://stackoverflow.com/questions/1285911/python-how-do-i-check-that-multiple-keys-are-in-a-dict-in-one-go/1285920#1285920">This was a popular answer</a> to a related question:</p>
<pre><code>>>> if all (k in foo for k in ("foo","bar")):
... print "They're there!"
...
They're there!
</code></... | 1 | 2009-11-15T15:47:17Z | [
"python",
"list",
"dictionary"
] |
Dict has key from list | 1,737,778 | <p>How can I determine if any of the list elements are a key to a dict?
The straight forward way is,</p>
<pre><code>for i in myList:
if i in myDict:
return True
return False
</code></pre>
<p>but is there a faster / more concise way?</p>
| 7 | 2009-11-15T15:13:00Z | 1,737,902 | <p>Thank you all so much. I tested the performance of all the answers and the fastest was </p>
<pre><code>return len([x for x in myList if x in myDict]) > 0
</code></pre>
<p>but I didn't try the "set" answer because I didn't see how to turn it into one line.</p>
| 0 | 2009-11-15T15:51:02Z | [
"python",
"list",
"dictionary"
] |
change 2 byte in a string | 1,737,782 | <p>I'd like to change 2 byte in a string like this:</p>
<pre><code>"ABCDEFGHIJKLMNOPQRSTUVWXYZ"
</code></pre>
<p>Let's imagine I want to replace <code>'RS'</code> by 11, I know how to do it with one byte like [:], but for 2 or more in the middle of the string ?</p>
<p>Thanks !</p>
| 0 | 2009-11-15T15:14:20Z | 1,737,801 | <p>Strings are immutable, you can't change them. You have to make a new string from parts of the old one:</p>
<pre><code>>>> az= 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
>>> az= az[:17]+'11'+az[19:]
>>> az
'ABCDEFGHIJKLMNOPQ11TUVWXYZ'
</code></pre>
<p>although depending one what you're doing there may ... | 4 | 2009-11-15T15:20:59Z | [
"python",
"string"
] |
change 2 byte in a string | 1,737,782 | <p>I'd like to change 2 byte in a string like this:</p>
<pre><code>"ABCDEFGHIJKLMNOPQRSTUVWXYZ"
</code></pre>
<p>Let's imagine I want to replace <code>'RS'</code> by 11, I know how to do it with one byte like [:], but for 2 or more in the middle of the string ?</p>
<p>Thanks !</p>
| 0 | 2009-11-15T15:14:20Z | 1,737,872 | <p>I would use <a href="http://docs.python.org/library/stdtypes.html#string-methods" rel="nofollow">string.replace()</a>:</p>
<pre><code>>>> import string
>>> az = string.lowercase
>>> az = az.replace('rs', '11')
>>> az
'abcdefghijklmnopq11tuvwxyz'
</code></pre>
| 1 | 2009-11-15T15:41:38Z | [
"python",
"string"
] |
change 2 byte in a string | 1,737,782 | <p>I'd like to change 2 byte in a string like this:</p>
<pre><code>"ABCDEFGHIJKLMNOPQRSTUVWXYZ"
</code></pre>
<p>Let's imagine I want to replace <code>'RS'</code> by 11, I know how to do it with one byte like [:], but for 2 or more in the middle of the string ?</p>
<p>Thanks !</p>
| 0 | 2009-11-15T15:14:20Z | 1,738,455 | <p>I think it's a trick question, see <strong>"how to do it with one byte"</strong>:</p>
<pre><code>>>> st="ABCDEFGHIJKLMNOPQRSTUVWXYZ"
>>> st="ABCDEFGHIJKLMNOPQRSTUVWXYZ".replace("R","1").replace("S","1")
>>> print st
ABCDEFGHIJKLMNOPQ11TUVWXYZ
</code></pre>
| 0 | 2009-11-15T18:59:04Z | [
"python",
"string"
] |
How does the Python's range function work? | 1,738,109 | <p>all,I am not really understand for loop in the following,can anyone give some tips?thanks in advance</p>
<pre><code>for i in range(5):
print i
</code></pre>
<p>then it gives 0,1,2,3,4 is that python assign 0,1,2,3,4 to i at the same time? however if i wrote:</p>
<pre><code>for i in range(5):
a=i+1
</c... | 8 | 2009-11-15T17:06:38Z | 1,738,118 | <p>A "for loop" in most, if not all, programming languages is a mechanism to run a piece of code more than once.</p>
<p>This code:</p>
<pre><code>for i in range(5):
print i
</code></pre>
<p>can be thought of working like this:</p>
<pre><code>i = 0
print i
i = 1
print i
i = 2
print i
i = 3
print i
i = 4
print i
... | 27 | 2009-11-15T17:11:13Z | [
"python",
"for-loop",
"range"
] |
How does the Python's range function work? | 1,738,109 | <p>all,I am not really understand for loop in the following,can anyone give some tips?thanks in advance</p>
<pre><code>for i in range(5):
print i
</code></pre>
<p>then it gives 0,1,2,3,4 is that python assign 0,1,2,3,4 to i at the same time? however if i wrote:</p>
<pre><code>for i in range(5):
a=i+1
</c... | 8 | 2009-11-15T17:06:38Z | 1,738,119 | <p>The <code>range</code> function wil give you a list of numbers, while the <code>for</code> loop will iterate through the list and execute the given code for each of its items.</p>
<pre><code>for i in range(5):
print i
</code></pre>
<p>This simply executes <code>print i</code> five times, for i ranging from 0... | 0 | 2009-11-15T17:11:34Z | [
"python",
"for-loop",
"range"
] |
How does the Python's range function work? | 1,738,109 | <p>all,I am not really understand for loop in the following,can anyone give some tips?thanks in advance</p>
<pre><code>for i in range(5):
print i
</code></pre>
<p>then it gives 0,1,2,3,4 is that python assign 0,1,2,3,4 to i at the same time? however if i wrote:</p>
<pre><code>for i in range(5):
a=i+1
</c... | 8 | 2009-11-15T17:06:38Z | 1,738,122 | <pre><code>for i in range(5):
</code></pre>
<p>is the same as</p>
<pre><code>for i in [0,1,2,3,4]:
</code></pre>
| 0 | 2009-11-15T17:12:35Z | [
"python",
"for-loop",
"range"
] |
How does the Python's range function work? | 1,738,109 | <p>all,I am not really understand for loop in the following,can anyone give some tips?thanks in advance</p>
<pre><code>for i in range(5):
print i
</code></pre>
<p>then it gives 0,1,2,3,4 is that python assign 0,1,2,3,4 to i at the same time? however if i wrote:</p>
<pre><code>for i in range(5):
a=i+1
</c... | 8 | 2009-11-15T17:06:38Z | 1,738,130 | <p>It is looping, probably the problem is in the part of the print...</p>
<p>If you can't find the logic where the system prints, just add the folling where you want the content out:</p>
<pre><code>for i in range(len(vs)):
print vs[i]
print fs[i]
print rs[i]
</code></pre>
| 0 | 2009-11-15T17:15:21Z | [
"python",
"for-loop",
"range"
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.