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
Auto kill fastcgi process when deploying django
2,071,615
<p>Everything goes well days ago. But since today, when I run fastcgi, the process will be killed by system automatically. The worst thing is I don't know why and which process kill the fastcgi process.</p> <p>Let me give some detail.</p> <p>we use nginx to serve static files for another django app which listen to 8...
2
2010-01-15T13:06:58Z
12,880,121
<p>'lsof -w -n -i tcp:8090' or 'fuser -n tcp 8090' or 'netstat -anp|grep :8090[[:blank:]]' should show you the process ID. If there is no (init)script to use to shut down the offending service (since TCP/8090 means proxy) to kill you can by PID 'kill -9 pidnumber'.</p>
0
2012-10-14T07:20:20Z
[ "python", "django", "process", "fastcgi" ]
Python equivalent for Ruby's pack function
2,071,716
<p>I'm translating some of my old Ruby scripts into Python and I have trouble finding a function in Python that belongs to Ruby: <a href="http://www.ruby-doc.org/core/classes/Array.src/M002222.html" rel="nofollow">http://www.ruby-doc.org/core/classes/Array.src/M002222.html</a> - which keeps the array in little endian b...
2
2010-01-15T13:18:27Z
2,071,728
<p>Perhaps <a href="http://docs.python.org/library/struct.html" rel="nofollow">http://docs.python.org/library/struct.html</a> does something similar.</p>
4
2010-01-15T13:20:06Z
[ "python", "endianness" ]
Python equivalent for Ruby's pack function
2,071,716
<p>I'm translating some of my old Ruby scripts into Python and I have trouble finding a function in Python that belongs to Ruby: <a href="http://www.ruby-doc.org/core/classes/Array.src/M002222.html" rel="nofollow">http://www.ruby-doc.org/core/classes/Array.src/M002222.html</a> - which keeps the array in little endian b...
2
2010-01-15T13:18:27Z
2,073,102
<p>The <a href="http://docs.python.org/library/array.html?highlight=array#module-array" rel="nofollow">array</a> module of Python's standard library may offer somewhat-similar functionality (though it's definitely not an exact match). It does not force endianness (you can swap items' endianness with method <code>bytesw...
1
2010-01-15T16:27:52Z
[ "python", "endianness" ]
Python equivalent for Ruby's pack function
2,071,716
<p>I'm translating some of my old Ruby scripts into Python and I have trouble finding a function in Python that belongs to Ruby: <a href="http://www.ruby-doc.org/core/classes/Array.src/M002222.html" rel="nofollow">http://www.ruby-doc.org/core/classes/Array.src/M002222.html</a> - which keeps the array in little endian b...
2
2010-01-15T13:18:27Z
26,972,889
<p>The Python <a href="https://docs.python.org/3/library/stdtypes.html#memoryview" rel="nofollow">memoryview</a> built-in allows you to "cast" an array or any bytes-like object to different endianess. Se the <a href="https://docs.python.org/3/library/stdtypes.html#memoryview.cast" rel="nofollow">.cast</a> method. The g...
1
2014-11-17T12:36:47Z
[ "python", "endianness" ]
What program to write pdf including other pdf on Linux from Python?
2,071,727
<p>On an Ubuntu server, I want to create pdfs which include other static pdfs. I have tried using ReportLab with pyPdf. Ideally I would use ReportLab to do the whole thing, but in order to import the pdfs requires their PageCatcher which has a large recurring fee. </p> <p>So I use pyPdf to merge a page created with Re...
1
2010-01-15T13:19:47Z
2,071,841
<p>I have had a lot of success with the Java library <a href="http://www.lowagie.com/iText/" rel="nofollow">iText</a>. They have a great library of samples for pretty much anything you could think of doing with PDF files. This example is for concatenating PDF files and sounds like it would do what you need: <a href="ht...
1
2010-01-15T13:36:29Z
[ "python", "pdf", "pdf-generation", "reportlab", "pypdf" ]
What program to write pdf including other pdf on Linux from Python?
2,071,727
<p>On an Ubuntu server, I want to create pdfs which include other static pdfs. I have tried using ReportLab with pyPdf. Ideally I would use ReportLab to do the whole thing, but in order to import the pdfs requires their PageCatcher which has a large recurring fee. </p> <p>So I use pyPdf to merge a page created with Re...
1
2010-01-15T13:19:47Z
2,102,006
<p>Another non-Python answer. If you are just merging pages, then <a href="http://www.accesspdf.com/pdftk/" rel="nofollow">pdftk</a> does that well (along with a lot of other things).</p>
0
2010-01-20T14:28:10Z
[ "python", "pdf", "pdf-generation", "reportlab", "pypdf" ]
Python thread for pre-importing modules
2,071,786
<p>I am writing a Python application in the field of scientific computing. Currently, when the user works with the GUI and starts a new physics simulation, the interpreter immediately imports several necessary modules for this simulation, such as <code>Traits</code> and <code>Mayavi</code>. These modules are heavy and ...
2
2010-01-15T13:27:40Z
2,071,816
<p>The problem with this is that the imports must still complete before they are usable. Depending on when they're first used, the application could still have to block for 10 seconds before it could start up anyway. Much more productive would be to profile the modules and figure out <em>why</em> they take so long to i...
2
2010-01-15T13:31:46Z
[ "python", "multithreading", "import" ]
Python thread for pre-importing modules
2,071,786
<p>I am writing a Python application in the field of scientific computing. Currently, when the user works with the GUI and starts a new physics simulation, the interpreter immediately imports several necessary modules for this simulation, such as <code>Traits</code> and <code>Mayavi</code>. These modules are heavy and ...
2
2010-01-15T13:27:40Z
2,072,194
<p>"the user works with the GUI and starts a new physics simulation"</p> <p>Not really clear. Does "works with the GUI" means double click? Double click what? Some wxWidgets GUI application? Or IDLE? </p> <p>If so, what does "starts a new physics simulation" mean? Click a button somewhere else? A GUI button to ...
-1
2010-01-15T14:25:06Z
[ "python", "multithreading", "import" ]
Python thread for pre-importing modules
2,071,786
<p>I am writing a Python application in the field of scientific computing. Currently, when the user works with the GUI and starts a new physics simulation, the interpreter immediately imports several necessary modules for this simulation, such as <code>Traits</code> and <code>Mayavi</code>. These modules are heavy and ...
2
2010-01-15T13:27:40Z
2,072,350
<p>Why not just do this when the app starts?</p> <pre><code>def background_imports(): import Traits import Mayavi thread = threading.Thread(target=background_imports) thread.setDaemon(True) thread.start() </code></pre>
2
2010-01-15T14:47:49Z
[ "python", "multithreading", "import" ]
Python thread for pre-importing modules
2,071,786
<p>I am writing a Python application in the field of scientific computing. Currently, when the user works with the GUI and starts a new physics simulation, the interpreter immediately imports several necessary modules for this simulation, such as <code>Traits</code> and <code>Mayavi</code>. These modules are heavy and ...
2
2010-01-15T13:27:40Z
2,072,909
<p>The general idea is good, but the Python/GUI session might not be all that responsive while the background thread is <code>import</code>ing away; unfortunately, <code>import</code> inherently and inevitably "locks up" Python substantially (it's not just the GIL, there's specific extra locking for imports).</p> <p>S...
1
2010-01-15T16:01:11Z
[ "python", "multithreading", "import" ]
why i get this traceback?
2,071,895
<p>This is part of my code:</p> <pre><code>if ind_1&lt;&gt;0: rbrcol=[] brdod1=[] for i in range(27): if Add_Cyc_1[1,i]!=0: rbrcol.append(Add_Cyc_1[0,i]) brdod1.append(Add_Cyc_1[1,i]) Probrani_1=vstack((rbrcol,brdod1)) pok=0 for i in (rbrcol): pok+=1 broj1=0 fo...
0
2010-01-15T13:44:47Z
2,071,915
<p>just as the error says, "rbrcol" doesn't have value. check your for loop</p> <pre><code>for i in range(27): if Add_Cyc_1[1,i]!=0: &lt;----- this part doesn't get through rbrcol.append(Add_Cyc_1[0,i]) brdod1.append(Add_Cyc_1[1,i]) Probrani_1=vstack((rbrcol,brdod1)) </code></pre> <p>also,...
2
2010-01-15T13:48:57Z
[ "python" ]
why i get this traceback?
2,071,895
<p>This is part of my code:</p> <pre><code>if ind_1&lt;&gt;0: rbrcol=[] brdod1=[] for i in range(27): if Add_Cyc_1[1,i]!=0: rbrcol.append(Add_Cyc_1[0,i]) brdod1.append(Add_Cyc_1[1,i]) Probrani_1=vstack((rbrcol,brdod1)) pok=0 for i in (rbrcol): pok+=1 broj1=0 fo...
0
2010-01-15T13:44:47Z
2,071,931
<p>I think the real problem is the if at the very top. Your indenting is incorrect - the code as written won't run because the line after the <code>if</code> is not indented.</p> <p>Assuming it is indented in the original code, then <code>rbrcol</code> is not initialized if ind_1 is 0 and as ghostdog says if the <code...
4
2010-01-15T13:52:29Z
[ "python" ]
Python conversion from binary string to hexadecimal
2,072,351
<p>How can I perform a conversion of a binary string to the corresponding hex value in Python?</p> <p>I have <code>0000 0100 1000 1101</code> and I want to get <code>048D</code> I'm using Python 2.6.</p>
21
2010-01-15T14:47:57Z
2,072,366
<p>Welcome to StackOverflow!</p> <p><code>int</code> given base 2 and then <code>hex</code>:</p> <pre><code>&gt;&gt;&gt; int('010110', 2) 22 &gt;&gt;&gt; hex(int('010110', 2)) '0x16' &gt;&gt;&gt; &gt;&gt;&gt; hex(int('0000010010001101', 2)) '0x48d' </code></pre> <p>The doc of <code>int</code>:</p> <blockquote> <p...
29
2010-01-15T14:51:07Z
[ "python", "binary", "hex" ]
Python conversion from binary string to hexadecimal
2,072,351
<p>How can I perform a conversion of a binary string to the corresponding hex value in Python?</p> <p>I have <code>0000 0100 1000 1101</code> and I want to get <code>048D</code> I'm using Python 2.6.</p>
21
2010-01-15T14:47:57Z
2,072,379
<p>Assuming they are grouped by 4 and separated by whitespace. This preserves the leading 0.</p> <pre><code>b = '0000 0100 1000 1101' h = ''.join(hex(int(a, 2))[2:] for a in b.split()) </code></pre>
0
2010-01-15T14:52:45Z
[ "python", "binary", "hex" ]
Python conversion from binary string to hexadecimal
2,072,351
<p>How can I perform a conversion of a binary string to the corresponding hex value in Python?</p> <p>I have <code>0000 0100 1000 1101</code> and I want to get <code>048D</code> I'm using Python 2.6.</p>
21
2010-01-15T14:47:57Z
2,072,384
<pre><code>bstr = '0000 0100 1000 1101'.replace(' ', '') hstr = '%0*X' % ((len(bstr) + 3) // 4, int(bstr, 2)) </code></pre>
11
2010-01-15T14:53:14Z
[ "python", "binary", "hex" ]
Python conversion from binary string to hexadecimal
2,072,351
<p>How can I perform a conversion of a binary string to the corresponding hex value in Python?</p> <p>I have <code>0000 0100 1000 1101</code> and I want to get <code>048D</code> I'm using Python 2.6.</p>
21
2010-01-15T14:47:57Z
2,072,778
<pre><code>&gt;&gt;&gt; import string &gt;&gt;&gt; s="0000 0100 1000 1101" &gt;&gt;&gt; ''.join([ "%x"%string.atoi(bin,2) for bin in s.split() ] ) '048d' &gt;&gt;&gt; </code></pre> <p>or</p> <pre><code>&gt;&gt;&gt; s="0000 0100 1000 1101" &gt;&gt;&gt; hex(string.atoi(s.replace(" ",""),2)) '0x48d' </code></pre>
-4
2010-01-15T15:42:34Z
[ "python", "binary", "hex" ]
Python conversion from binary string to hexadecimal
2,072,351
<p>How can I perform a conversion of a binary string to the corresponding hex value in Python?</p> <p>I have <code>0000 0100 1000 1101</code> and I want to get <code>048D</code> I'm using Python 2.6.</p>
21
2010-01-15T14:47:57Z
2,072,790
<p>Converting Binary into hex without ignoring leading zeros:</p> <p>You could use the format() built-in function like this:</p> <pre><code>"{0:0&gt;4X}".format(int("0000010010001101", 2)) </code></pre>
4
2010-01-15T15:44:10Z
[ "python", "binary", "hex" ]
Python conversion from binary string to hexadecimal
2,072,351
<p>How can I perform a conversion of a binary string to the corresponding hex value in Python?</p> <p>I have <code>0000 0100 1000 1101</code> and I want to get <code>048D</code> I'm using Python 2.6.</p>
21
2010-01-15T14:47:57Z
17,638,061
<pre><code>format(int(bits, 2), '0' + str(len(bits) / 4) + 'x') </code></pre>
0
2013-07-14T09:15:45Z
[ "python", "binary", "hex" ]
Python conversion from binary string to hexadecimal
2,072,351
<p>How can I perform a conversion of a binary string to the corresponding hex value in Python?</p> <p>I have <code>0000 0100 1000 1101</code> and I want to get <code>048D</code> I'm using Python 2.6.</p>
21
2010-01-15T14:47:57Z
17,945,783
<p>Using no messy concatenations and padding :</p> <pre><code>'{:0{width}x}'.format(int(temp,2)), width=4) </code></pre> <p>Will give a hex representation with padding preserved</p>
1
2013-07-30T11:27:16Z
[ "python", "binary", "hex" ]
Python conversion from binary string to hexadecimal
2,072,351
<p>How can I perform a conversion of a binary string to the corresponding hex value in Python?</p> <p>I have <code>0000 0100 1000 1101</code> and I want to get <code>048D</code> I'm using Python 2.6.</p>
21
2010-01-15T14:47:57Z
29,435,365
<p>For whatever reason I have had issues with some of these answers, I've went and written a couple helper functions for myself, so if you have problems like I did, give these a try.</p> <pre><code>def bin_string_to_bin_value(input): highest_order = len(input) - 1 result = 0 for bit in input: result = r...
0
2015-04-03T15:44:37Z
[ "python", "binary", "hex" ]
Python conversion from binary string to hexadecimal
2,072,351
<p>How can I perform a conversion of a binary string to the corresponding hex value in Python?</p> <p>I have <code>0000 0100 1000 1101</code> and I want to get <code>048D</code> I'm using Python 2.6.</p>
21
2010-01-15T14:47:57Z
33,618,433
<p>Use python's binascii module</p> <pre><code>import binascii binFile = open('somebinaryfile.exe','rb') binaryData = binFile.read(8) print binascii.hexlify(binaryData) </code></pre>
4
2015-11-09T21:16:24Z
[ "python", "binary", "hex" ]
How to get list index and element simultaneously in Python?
2,072,407
<p>I find myself frequently writing code like this:</p> <pre><code>k = 0 for i in mylist: # y[k] = some function of i k += 1 </code></pre> <p>Instead, I could do</p> <pre><code>for k in range(K): # y[k] = some function of mylist[k] </code></pre> <p>but that doesn't seem "pythonic". (You know... indexing...
11
2010-01-15T14:56:29Z
2,072,427
<p>You can use <code>enumerate</code>:</p> <pre><code>for k,i in enumerate(mylist): #do something with index k #do something with element i </code></pre> <p>More information about <a href="http://docs.python.org/tutorial/datastructures.html#looping-techniques">looping techniques</a>.</p> <p><strong>Edit:</st...
31
2010-01-15T14:58:45Z
[ "python" ]
How to get list index and element simultaneously in Python?
2,072,407
<p>I find myself frequently writing code like this:</p> <pre><code>k = 0 for i in mylist: # y[k] = some function of i k += 1 </code></pre> <p>Instead, I could do</p> <pre><code>for k in range(K): # y[k] = some function of mylist[k] </code></pre> <p>but that doesn't seem "pythonic". (You know... indexing...
11
2010-01-15T14:56:29Z
2,072,431
<p><a href="http://docs.python.org/library/functions.html#enumerate"><code>enumerate</code></a> is the answer:</p> <pre><code>for index, element in enumerate(iterable): #work with index and element </code></pre>
13
2010-01-15T14:58:59Z
[ "python" ]
Python class methods
2,072,875
<p>I have a class as follows:</p> <pre><code>class X: def __init__(self): self.sum_x =0.0 self.sum_x_squared=0.0 self.var_x =0.0 self.sum_y =0.0 self.sum_y_squared=0.0 self.var_y =0.0 def update(self,data): [x,y,vx,vy]=data self.upd...
0
2010-01-15T15:57:58Z
2,072,895
<p>self.sumx, self.sum_x_squared?</p>
0
2010-01-15T16:00:07Z
[ "python", "oop" ]
Python class methods
2,072,875
<p>I have a class as follows:</p> <pre><code>class X: def __init__(self): self.sum_x =0.0 self.sum_x_squared=0.0 self.var_x =0.0 self.sum_y =0.0 self.sum_y_squared=0.0 self.var_y =0.0 def update(self,data): [x,y,vx,vy]=data self.upd...
0
2010-01-15T15:57:58Z
2,072,898
<p>No need. You have direct access to self.sumx, etc.</p> <p>Are you sure that the functions do belong to the class X? You seem to be missing semicolon and whitespace formatting.</p>
1
2010-01-15T16:00:24Z
[ "python", "oop" ]
Python class methods
2,072,875
<p>I have a class as follows:</p> <pre><code>class X: def __init__(self): self.sum_x =0.0 self.sum_x_squared=0.0 self.var_x =0.0 self.sum_y =0.0 self.sum_y_squared=0.0 self.var_y =0.0 def update(self,data): [x,y,vx,vy]=data self.upd...
0
2010-01-15T15:57:58Z
2,072,906
<p>You don't have to pass them, update_sums can access them just like update can.</p>
1
2010-01-15T16:01:05Z
[ "python", "oop" ]
Python class methods
2,072,875
<p>I have a class as follows:</p> <pre><code>class X: def __init__(self): self.sum_x =0.0 self.sum_x_squared=0.0 self.var_x =0.0 self.sum_y =0.0 self.sum_y_squared=0.0 self.var_y =0.0 def update(self,data): [x,y,vx,vy]=data self.upd...
0
2010-01-15T15:57:58Z
2,072,907
<p>you don't need to pass nothing but the <code>self</code>, which you're mandated to do anyway:</p> <pre><code>def update_sums(self, val): self.sum += val self.sum_squared += val * val ... </code></pre> <p>the call will be the following: <code>self.update_sums(x)</code></p> <p>The way you designed the c...
2
2010-01-15T16:01:08Z
[ "python", "oop" ]
Python class methods
2,072,875
<p>I have a class as follows:</p> <pre><code>class X: def __init__(self): self.sum_x =0.0 self.sum_x_squared=0.0 self.var_x =0.0 self.sum_y =0.0 self.sum_y_squared=0.0 self.var_y =0.0 def update(self,data): [x,y,vx,vy]=data self.upd...
0
2010-01-15T15:57:58Z
2,072,985
<p>First, note that your question has nothing to do with <a href="http://docs.python.org/library/functions.html?highlight=classmethod#classmethod">classmethod</a> (which makes <em>class</em> methods in Python) -- it's entirely about normal <em>instance</em> methods (you should edit your title... or your question, if yo...
5
2010-01-15T16:10:48Z
[ "python", "oop" ]
Python class methods
2,072,875
<p>I have a class as follows:</p> <pre><code>class X: def __init__(self): self.sum_x =0.0 self.sum_x_squared=0.0 self.var_x =0.0 self.sum_y =0.0 self.sum_y_squared=0.0 self.var_y =0.0 def update(self,data): [x,y,vx,vy]=data self.upd...
0
2010-01-15T15:57:58Z
2,073,081
<p>It looks to me like there is another class in there wanting to be let out. I would remove duplication by refactoring the code like this:</p> <pre><code>class SumOfSquares(object): def __init__(self): self.sum = 0.0 self.squares = 0.0 def update(self, val): self.sum += val s...
1
2010-01-15T16:25:31Z
[ "python", "oop" ]
Need help with python list manipulation
2,072,936
<p>i have two seperate lists</p> <pre><code>list1 = ["Infantry","Tanks","Jets"] list2 = [ 10, 20, 30] </code></pre> <p>so in reality, I have 10 Infantry, 20 Tanks and 30 Jets</p> <p>I want to create a class so that in the end, I can call this:</p> <pre><code>for unit in units: print unit.amount print unit.name ...
0
2010-01-15T16:04:52Z
2,072,953
<p>This should do it:</p> <pre><code>class Unit: """Very simple class to track a unit name, and an associated count.""" def __init__(self, name, amount): self.name = name self.amount = amount # Pre-existing lists of types and amounts. list1 = ["Infantry", "Tanks", "Jets"] list2 = [ 10, 20, 30] # Create...
5
2010-01-15T16:06:43Z
[ "python", "list" ]
Need help with python list manipulation
2,072,936
<p>i have two seperate lists</p> <pre><code>list1 = ["Infantry","Tanks","Jets"] list2 = [ 10, 20, 30] </code></pre> <p>so in reality, I have 10 Infantry, 20 Tanks and 30 Jets</p> <p>I want to create a class so that in the end, I can call this:</p> <pre><code>for unit in units: print unit.amount print unit.name ...
0
2010-01-15T16:04:52Z
2,072,958
<pre><code>class Unit(object): def __init__(self, amount, name): self.amount = amount self.name = name units = [Unit(a, n) for (a, n) in zip(list2, list1)] </code></pre>
18
2010-01-15T16:07:14Z
[ "python", "list" ]
Need help with python list manipulation
2,072,936
<p>i have two seperate lists</p> <pre><code>list1 = ["Infantry","Tanks","Jets"] list2 = [ 10, 20, 30] </code></pre> <p>so in reality, I have 10 Infantry, 20 Tanks and 30 Jets</p> <p>I want to create a class so that in the end, I can call this:</p> <pre><code>for unit in units: print unit.amount print unit.name ...
0
2010-01-15T16:04:52Z
2,073,013
<pre><code>from collections import namedtuple Unit = namedtuple("Unit", "name, amount") units = [Unit(*v) for v in zip(list1, list2)] for unit in units: print "%4d %s" % (unit.amount, unit.name) </code></pre> <p><a href="http://stackoverflow.com/questions/2072936/need-help-with-python-list-manipulation/2073030#207...
8
2010-01-15T16:15:07Z
[ "python", "list" ]
Need help with python list manipulation
2,072,936
<p>i have two seperate lists</p> <pre><code>list1 = ["Infantry","Tanks","Jets"] list2 = [ 10, 20, 30] </code></pre> <p>so in reality, I have 10 Infantry, 20 Tanks and 30 Jets</p> <p>I want to create a class so that in the end, I can call this:</p> <pre><code>for unit in units: print unit.amount print unit.name ...
0
2010-01-15T16:04:52Z
2,073,030
<p>In Python 2.6, I'd recommend a <a href="http://docs.python.org/library/collections.html?highlight=namedtuple#collections.namedtuple">named tuple</a> -- less code than writing the simple class out and very frugal in memory use too:</p> <pre><code>import collections Unit = collections.namedtuple('Unit', 'amount name...
5
2010-01-15T16:18:36Z
[ "python", "list" ]
Need help with python list manipulation
2,072,936
<p>i have two seperate lists</p> <pre><code>list1 = ["Infantry","Tanks","Jets"] list2 = [ 10, 20, 30] </code></pre> <p>so in reality, I have 10 Infantry, 20 Tanks and 30 Jets</p> <p>I want to create a class so that in the end, I can call this:</p> <pre><code>for unit in units: print unit.amount print unit.name ...
0
2010-01-15T16:04:52Z
2,073,064
<p>How about a dictionary:</p> <pre><code>units = dict(zip(list1,list2)) for type,amount in units.iteritems(): print amount,type </code></pre> <p>Endlessly expandable for additional information, and easily manipulated. If a basic type will do the job, think carefully about not using it.</p>
2
2010-01-15T16:23:19Z
[ "python", "list" ]
Django Views Join Models Using Foreign Key
2,072,966
<p>I have the following models defined:</p> <pre><code>class Player(models.Model): Team = models.ForeignKey(Team) Name = models.CharField(max_length=200) Position = models.CharField(max_length=3) ... snip ... </code></pre> <p>What I would like to output in a view is a list of players who are in the te...
1
2010-01-15T16:08:38Z
2,073,003
<p>You need a view that looks something like this:</p> <pre><code>def players(request): players_in_team_one = Player.objects.filter(Team__pk = 1) return render_to_response('players.html', {'players': players_in_team_one}) </code></pre> <p>and you can loop through it like this in <code>players.html</code>:</p>...
2
2010-01-15T16:13:00Z
[ "python", "django" ]
Access to widget in GTK+
2,072,976
<p>Building a GTK+ widget dynamically from code allows for easy access to the child widgets directly.</p> <p>Now, how do I access to the child widgets when building a GTK+ Dialog (as example) from a <code>.glade</code> file?</p> <pre><code>class ConfigDialog(object): def __init__(self, glade_file, testing=False):...
1
2010-01-15T16:10:05Z
2,073,145
<p>Already you are making the call</p> <pre><code>self.dialog = builder.get_object("config_dialog") </code></pre> <p>You should also be able to do</p> <pre><code>self.nameEntry = builder.get_object("name_entry") </code></pre> <p>This is at least how python-glade works and I assume GtkBuilder is the same.</p>
7
2010-01-15T16:33:50Z
[ "python", "gtk" ]
Access to widget in GTK+
2,072,976
<p>Building a GTK+ widget dynamically from code allows for easy access to the child widgets directly.</p> <p>Now, how do I access to the child widgets when building a GTK+ Dialog (as example) from a <code>.glade</code> file?</p> <pre><code>class ConfigDialog(object): def __init__(self, glade_file, testing=False):...
1
2010-01-15T16:10:05Z
2,073,615
<p>In addition, if you want to search for a named widget and the Builder instance isn't available, you could try using the following utility function:</p> <pre><code>def get_child_by_name(parent, name): """ Iterate through a gtk container, `parent`, and return the widget with the name `name`. """ ...
4
2010-01-15T17:40:32Z
[ "python", "gtk" ]
Random weighted choice
2,073,235
<p>I have data like this:</p> <pre><code>d = ( (701, 1, 0.2), (701, 2, 0.3), (701, 3, 0.5), (702, 1, 0.2), (702, 2, 0.3), (703, 3, 0.5) ) </code></pre> <p>Where (701, 1, 0.2) = (id1, id2, priority)</p> <p>Is there a pretty way to choose id2 if I know id1, using priority?</p> <p>Func(701) should return: ...
13
2010-01-15T16:43:41Z
2,073,254
<p>Use a discrete uniform distribution from the <a href="http://docs.python.org/library/random.html" rel="nofollow">random module</a> over a sufficient number of values, then partition it:</p> <p>For example, for case 701 use a distribution over 10 values, for 2 values return 1, for another 3, return 2, and for the ot...
2
2010-01-15T16:46:34Z
[ "python" ]
Random weighted choice
2,073,235
<p>I have data like this:</p> <pre><code>d = ( (701, 1, 0.2), (701, 2, 0.3), (701, 3, 0.5), (702, 1, 0.2), (702, 2, 0.3), (703, 3, 0.5) ) </code></pre> <p>Where (701, 1, 0.2) = (id1, id2, priority)</p> <p>Is there a pretty way to choose id2 if I know id1, using priority?</p> <p>Func(701) should return: ...
13
2010-01-15T16:43:41Z
2,073,336
<p>If your percent values will not be more precise than whole percent values, use a random number generator to generate a number 0-99.</p> <p>Then in your function, use (programmatic) cases to choose the correct number. For example (clean this up):</p> <pre> if 701 if random_num &lt; 20 return 1 else if rando...
1
2010-01-15T16:59:00Z
[ "python" ]
Random weighted choice
2,073,235
<p>I have data like this:</p> <pre><code>d = ( (701, 1, 0.2), (701, 2, 0.3), (701, 3, 0.5), (702, 1, 0.2), (702, 2, 0.3), (703, 3, 0.5) ) </code></pre> <p>Where (701, 1, 0.2) = (id1, id2, priority)</p> <p>Is there a pretty way to choose id2 if I know id1, using priority?</p> <p>Func(701) should return: ...
13
2010-01-15T16:43:41Z
2,073,355
<p>Generate a Cumulative Distribution Function for each ID1 thus:</p> <pre><code>cdfs = defaultdict() for id1,id2,val in d: prevtotal = cdfs[id1][-1][0] newtotal = prevtotal + val cdfs[id1].append( (newtotal,id2) ) </code></pre> <p>So you will have</p> <pre><code>cdfs = { 701 : [ (0.2,1), (0.5,2), (1.0,3...
6
2010-01-15T17:01:33Z
[ "python" ]
Random weighted choice
2,073,235
<p>I have data like this:</p> <pre><code>d = ( (701, 1, 0.2), (701, 2, 0.3), (701, 3, 0.5), (702, 1, 0.2), (702, 2, 0.3), (703, 3, 0.5) ) </code></pre> <p>Where (701, 1, 0.2) = (id1, id2, priority)</p> <p>Is there a pretty way to choose id2 if I know id1, using priority?</p> <p>Func(701) should return: ...
13
2010-01-15T16:43:41Z
2,073,444
<p>A very quick hack:</p> <pre><code>import random d = { 701: [(1,0.2),(2,0.3),(3,0.5)], 702: [(1,0.2),(2,0.3),(3,0.5)] } def func(value): possible_values=d[value] total=sum(p[-1] for p in possible_values) random_value=random.random() prob=possible_values[0][-1]/total index=1 while in...
1
2010-01-15T17:14:41Z
[ "python" ]
Random weighted choice
2,073,235
<p>I have data like this:</p> <pre><code>d = ( (701, 1, 0.2), (701, 2, 0.3), (701, 3, 0.5), (702, 1, 0.2), (702, 2, 0.3), (703, 3, 0.5) ) </code></pre> <p>Where (701, 1, 0.2) = (id1, id2, priority)</p> <p>Is there a pretty way to choose id2 if I know id1, using priority?</p> <p>Func(701) should return: ...
13
2010-01-15T16:43:41Z
2,073,505
<p>Two ideas (allow me to illustrate it with separated options and ratios for the sake of clarity in the argument names, if they're packed in a tuple you can save the "zip"):</p> <p>a) Denormalize the weights to get integer ratios, then put in a list as many copies as the ratio and use <code>random.choice</code>.</p> ...
0
2010-01-15T17:23:25Z
[ "python" ]
Random weighted choice
2,073,235
<p>I have data like this:</p> <pre><code>d = ( (701, 1, 0.2), (701, 2, 0.3), (701, 3, 0.5), (702, 1, 0.2), (702, 2, 0.3), (703, 3, 0.5) ) </code></pre> <p>Where (701, 1, 0.2) = (id1, id2, priority)</p> <p>Is there a pretty way to choose id2 if I know id1, using priority?</p> <p>Func(701) should return: ...
13
2010-01-15T16:43:41Z
2,073,525
<p>Realizing that my first answer was quite buggy in its math, I have produced a new idea. I believe the algorithm here is similar to that of several of the other answers, but this implementation seems to qualify for the "pretty" (if that equals simple) requirement of the question:</p> <pre><code>def func(id): rnd...
3
2010-01-15T17:26:16Z
[ "python" ]
Random weighted choice
2,073,235
<p>I have data like this:</p> <pre><code>d = ( (701, 1, 0.2), (701, 2, 0.3), (701, 3, 0.5), (702, 1, 0.2), (702, 2, 0.3), (703, 3, 0.5) ) </code></pre> <p>Where (701, 1, 0.2) = (id1, id2, priority)</p> <p>Is there a pretty way to choose id2 if I know id1, using priority?</p> <p>Func(701) should return: ...
13
2010-01-15T16:43:41Z
2,075,137
<p>You can also create a 100-element list for each value, and then let random.choice do the selecting from a seeded list whose members are loaded in the weighting that you want:</p> <pre><code>import random from collections import defaultdict d = ( (701, 1, 0.2), (701, 2, 0.3), (701, 3, 0.5), (702, 1, 0.2...
0
2010-01-15T22:17:24Z
[ "python" ]
Search and Replace in HTML with BeautifulSoup
2,073,541
<p>I want to use BeautfulSoup to search and replace <code>&lt;\a&gt;</code> with <code>&lt;\a&gt;&lt;br&gt;</code>. I know how to open with <code>urllib2</code> and then parse to extract all the <code>&lt;a&gt;</code> tags. What I want to do is search and replace the closing tag with the closing tag plus the break. Any...
7
2010-01-15T17:29:56Z
2,073,697
<p>This will insert a <code>&lt;br&gt;</code> tag after the end of each <code>&lt;a&gt;...&lt;/a&gt;</code> element:</p> <pre><code>from BeautifulSoup import BeautifulSoup, Tag # .... soup = BeautifulSoup(data) for a in soup.findAll('a'): a.parent.insert(a.parent.index(a)+1, Tag(soup, 'br')) </code></pre> <p>Yo...
13
2010-01-15T17:56:09Z
[ "python", "beautifulsoup" ]
Search and Replace in HTML with BeautifulSoup
2,073,541
<p>I want to use BeautfulSoup to search and replace <code>&lt;\a&gt;</code> with <code>&lt;\a&gt;&lt;br&gt;</code>. I know how to open with <code>urllib2</code> and then parse to extract all the <code>&lt;a&gt;</code> tags. What I want to do is search and replace the closing tag with the closing tag plus the break. Any...
7
2010-01-15T17:29:56Z
2,073,704
<p>You don't replace an end-tag; in BeautifulSoup you are dealing with a document object model like in a browser, not a string full of HTML. So you couldn't ‘replace’ an end-tag without also replacing the start-tag.</p> <p>What you want to do is insert a new <code>&lt;br&gt;</code> element immediately after the <c...
3
2010-01-15T17:57:23Z
[ "python", "beautifulsoup" ]
Search and Replace in HTML with BeautifulSoup
2,073,541
<p>I want to use BeautfulSoup to search and replace <code>&lt;\a&gt;</code> with <code>&lt;\a&gt;&lt;br&gt;</code>. I know how to open with <code>urllib2</code> and then parse to extract all the <code>&lt;a&gt;</code> tags. What I want to do is search and replace the closing tag with the closing tag plus the break. Any...
7
2010-01-15T17:29:56Z
31,263,244
<p>suppose you have an element which you know contains the "br" markup tags, one way to remove &amp; replace the "br" tags with a different string is like this:</p> <pre><code>originalSoup = BeautifulSoup("your_html_file.html") replaceString = ", " # replace each &lt;br/&gt; tag with ", " # Ex. &lt;p&gt;Hello&lt;br/&g...
1
2015-07-07T08:17:11Z
[ "python", "beautifulsoup" ]
How get get more search results than the server's sizelimit with Python LDAP?
2,073,574
<p>I am using the <a href="http://www.python-ldap.org/">python LDAP</a> module to (amongst other things) search for groups, and am running into the server's size limit and getting a SIZELIMIT_EXCEEDED exception. I have tried both synchronous and asynchronous searches and hit the problem both ways.</p> <p>You are supp...
9
2010-01-15T17:34:52Z
2,086,982
<p>Here are some links related to paging in python-ldap.</p> <ul> <li>Documentation: <a href="http://www.python-ldap.org/doc/html/ldap-controls.html#ldap.controls.SimplePagedResultsControl">http://www.python-ldap.org/doc/html/ldap-controls.html#ldap.controls.SimplePagedResultsControl</a></li> <li>Example code using pa...
12
2010-01-18T15:19:12Z
[ "python", "ldap" ]
How get get more search results than the server's sizelimit with Python LDAP?
2,073,574
<p>I am using the <a href="http://www.python-ldap.org/">python LDAP</a> module to (amongst other things) search for groups, and am running into the server's size limit and getting a SIZELIMIT_EXCEEDED exception. I have tried both synchronous and asynchronous searches and hit the problem both ways.</p> <p>You are supp...
9
2010-01-15T17:34:52Z
2,089,344
<p>After some discussion on the python-ldap-dev mailing list, I can answer my own question. </p> <p>Page controls ARE supported by the Python lDAP module, but the docs had not been updated for search_ext to show that. The <a href="http://www.novell.com/coolsolutions/tip/18274.html">example linked by Gorgapor</a> sho...
5
2010-01-18T21:28:09Z
[ "python", "ldap" ]
multiprocessing problem [pyqt, py2exe]
2,073,942
<p>I am writing a GUI program using PyQt4. There is a button in my main window and by clicking this button. I hope to launch a background process which is an instance of a class derived from processing.Process.</p> <pre><code>class BackgroundTask(processing.Process): def __init__(self, input): processin...
14
2010-01-15T18:49:23Z
2,160,064
<p>"Functionality within this package requires that the main method be importable by the children."</p> <p>I think this means you have to have main() function defined somewhere.</p>
0
2010-01-29T05:27:39Z
[ "python", "pyqt", "multiprocessing", "py2exe" ]
multiprocessing problem [pyqt, py2exe]
2,073,942
<p>I am writing a GUI program using PyQt4. There is a button in my main window and by clicking this button. I hope to launch a background process which is an instance of a class derived from processing.Process.</p> <pre><code>class BackgroundTask(processing.Process): def __init__(self, input): processin...
14
2010-01-15T18:49:23Z
2,196,650
<p>I think your actual problem has to do with this:</p> <blockquote> <p>The program works as expected under the python intepreter, i.e. if it is started from the command line "python myapp.py".</p> <p>However, after I package the program using py2exe, every time when I click that button, > instead of starting t...
24
2010-02-04T00:52:34Z
[ "python", "pyqt", "multiprocessing", "py2exe" ]
django logging local javascript events
2,073,962
<p>All..</p> <p>Say there exists a template x.html in Django templates section.</p> <p>The contents of this page are </p> <pre><code>&lt;html&gt; &lt;a href="#" onclick="noserverrequest"&gt; &lt;input type="button onclick="noserverrequest"/&gt; .............. &lt;/html&gt; </code></pre> <p>I have n number of button...
0
2010-01-15T18:52:38Z
2,075,381
<p>you should better trigger an image load in javascript : </p> <pre><code>function log(info) { document.getElementById('pixel').src = '/tracker?'+info; } </code></pre> <p>somewhere on your page :</p> <pre><code>&lt;img id='pixel' src='pixel.gif' style='display:none'/&gt; </code></pre> <p>then call it this way in...
0
2010-01-15T23:14:59Z
[ "javascript", "jquery", "python", "django" ]
Use function from Python script in OS path
2,074,071
<p>I have a third-party Python script (foo.py) in a folder that is in my system path (but not the Python sys.path). foo.py is not part of any Python module.</p> <p>I am writing another script (bar.py) in which I'd like to call a function located in foo.py. Is this possible? Can it be done without explicitly naming the...
0
2010-01-15T19:07:47Z
2,074,086
<p>You can include the path of foo.py in the PYTHONPATH environment variable. The interpreter will look also the directories contained there, so you can make the import just like it was on the same directory.</p>
2
2010-01-15T19:11:54Z
[ "python", "import" ]
Use function from Python script in OS path
2,074,071
<p>I have a third-party Python script (foo.py) in a folder that is in my system path (but not the Python sys.path). foo.py is not part of any Python module.</p> <p>I am writing another script (bar.py) in which I'd like to call a function located in foo.py. Is this possible? Can it be done without explicitly naming the...
0
2010-01-15T19:07:47Z
2,074,089
<p>If Python does not find the module, I don't think there's another way then to specify where it can be found, with one easy way being:</p> <pre><code>import sys sys.path.append('/myfolder/itsinthisfolder/') import foo </code></pre>
2
2010-01-15T19:12:10Z
[ "python", "import" ]
How to speedup python unittest on muticore machines?
2,074,074
<p>I'm using python unittest in order to test some other external application but it takes too much time to run the test one by one.</p> <p>I would like to know how can I speedup this process by using the power of multi-cores. Can I tweak unittest to execute tests in parallel? How?</p> <p>This question is not able p...
10
2010-01-15T19:08:22Z
2,074,123
<p>If your tests are not too involved, you may be able to run them using <a href="http://pytest.org/" rel="nofollow">py.test</a> which has <a href="https://pypi.python.org/pypi/pytest-xdist" rel="nofollow">support for distributed testing</a>. If you are not running on Windows, then <a href="http://nose.readthedocs.org/...
6
2010-01-15T19:16:51Z
[ "python", "multithreading", "unit-testing", "performance", "multicore" ]
How to speedup python unittest on muticore machines?
2,074,074
<p>I'm using python unittest in order to test some other external application but it takes too much time to run the test one by one.</p> <p>I would like to know how can I speedup this process by using the power of multi-cores. Can I tweak unittest to execute tests in parallel? How?</p> <p>This question is not able p...
10
2010-01-15T19:08:22Z
2,074,152
<p>Maybe you can run each test on a different process using the <code>multiprocessing</code> library. This implies that each unit test (or group of unit tests) should be independent and doesn't need to share the state. It will open other processes, and will make use of other cores.</p> <p>Check specifically the 'Using...
0
2010-01-15T19:20:23Z
[ "python", "multithreading", "unit-testing", "performance", "multicore" ]
How to speedup python unittest on muticore machines?
2,074,074
<p>I'm using python unittest in order to test some other external application but it takes too much time to run the test one by one.</p> <p>I would like to know how can I speedup this process by using the power of multi-cores. Can I tweak unittest to execute tests in parallel? How?</p> <p>This question is not able p...
10
2010-01-15T19:08:22Z
17,142,515
<p>The <a href="http://pypi.python.org/pypi/testtools" rel="nofollow">testtools</a> package is an extension of unittest which supports running tests concurrently. It can be used with your old test classes that inherit <code>unittest.TestCase</code>.</p> <p>For example:</p> <pre><code>import unittest import testtools ...
3
2013-06-17T07:37:11Z
[ "python", "multithreading", "unit-testing", "performance", "multicore" ]
How to speedup python unittest on muticore machines?
2,074,074
<p>I'm using python unittest in order to test some other external application but it takes too much time to run the test one by one.</p> <p>I would like to know how can I speedup this process by using the power of multi-cores. Can I tweak unittest to execute tests in parallel? How?</p> <p>This question is not able p...
10
2010-01-15T19:08:22Z
35,182,727
<p>As the @vinay-sajip suggested, a few non-core python packages like <code>py.test</code> and <code>nose</code> provided parallel execution of unit tests via <code>multiprocessing</code> lib right out of the box. </p> <p>However, one thing to consider is that if you are testing a web app with database backend and maj...
0
2016-02-03T16:40:18Z
[ "python", "multithreading", "unit-testing", "performance", "multicore" ]
max size in BlobProperty (appengine)
2,074,154
<p>What is the maximum size of one BlobProperty in appengine? I'm not talking about of the Blobstore API, i'm referring to the property class <a href="http://code.google.com/appengine/docs/python/datastore/typesandpropertyclasses.html#BlobProperty">BlobProperty</a></p> <p>Please add a link who support your answers </...
7
2010-01-15T19:20:42Z
2,074,245
<p>The limit is 1 megabyte. <a href="http://code.google.com/appengine/docs/python/datastore/entitiesandmodels.html#Properties_and_Types">Docs here</a>.</p> <blockquote> <p>Like db.Text, a db.Blob value can be as large as 1 megabyte, but is not indexed, and cannot be used in query filters or sort orders. The db...
10
2010-01-15T19:33:21Z
[ "python", "google-app-engine" ]
Performance of python library keyczar in Windows
2,074,195
<p>I am running this code to see the performance impact of the <a href="http://www.keyczar.org/" rel="nofollow">keyczar encryption library</a> from google:</p> <pre><code>from keyczar import keyczar, keys def main(iters): key = keys.RsaPrivateKey.Generate() msg = "ciao" crypt = None for i in range(ite...
2
2010-01-15T19:26:51Z
2,074,879
<p>For that kind of difference, I would suspect that linux is using a c-module to to the work. Perhaps the Windows version failed to install a dll somewhere, so is falling back to Python code</p> <p>Are you running the same version of Python on both platforms?</p>
0
2010-01-15T21:21:06Z
[ "python", "profiling", "keyczar" ]
Performance of python library keyczar in Windows
2,074,195
<p>I am running this code to see the performance impact of the <a href="http://www.keyczar.org/" rel="nofollow">keyczar encryption library</a> from google:</p> <pre><code>from keyczar import keyczar, keys def main(iters): key = keys.RsaPrivateKey.Generate() msg = "ciao" crypt = None for i in range(ite...
2
2010-01-15T19:26:51Z
2,109,895
<p>PyCrypto has a C module called _fastmath which uses GNU MP for the public key operations. If it is not available, it instead uses Python's native long integers, which are much much slower.</p> <p>The two files are src/_fastmath.c and lib/Crypto/PublicKey/_slowmath.py</p> <p>It's likely that Python on Windows does ...
1
2010-01-21T14:27:25Z
[ "python", "profiling", "keyczar" ]
Connecting signals in GTK+: anonymous way?
2,074,372
<p>After reading <a href="http://www.pygtk.org/articles/subclassing-gobject/sub-classing-gobject-in-python.htm" rel="nofollow">"Using your signals"</a> I am wondering if it is possible to connect the signals to "sinks" in an "anonymous" way?</p> <p>In order words, if the example following (snippet from reference above...
0
2010-01-15T19:55:20Z
2,075,914
<p>Yes, you can use <a href="http://www.pygtk.org/docs/pygobject/gobject-functions.html#function-gobject--add-emission-hook" rel="nofollow">gobject.add_emission_hook</a> (<a href="http://library.gnome.org/devel/gobject/unstable/gobject-Signals.html#g-signal-add-emission-hook" rel="nofollow">g_signal_add_emission_hook</...
1
2010-01-16T01:57:25Z
[ "python", "gtk" ]
Django Query That Get Most Recent Objects From Different Categories
2,074,514
<p>I have two models <code>A</code> and <code>B</code>. All <code>B</code> objects have a foreign key to an <code>A</code> object. Given a set of <code>A</code> objects, is there anyway to use the ORM to get a set of <code>B</code> objects containing the most recent object created for each <code>A</code> object</p> <p...
41
2010-01-15T20:21:01Z
2,074,595
<p>This should do the job:</p> <pre><code>from django.db.models import Max Bakery.objects.annotate(Max('cake__baked_at')) </code></pre>
5
2010-01-15T20:34:44Z
[ "python", "django", "django-queryset", "greatest-n-per-group" ]
Django Query That Get Most Recent Objects From Different Categories
2,074,514
<p>I have two models <code>A</code> and <code>B</code>. All <code>B</code> objects have a foreign key to an <code>A</code> object. Given a set of <code>A</code> objects, is there anyway to use the ORM to get a set of <code>B</code> objects containing the most recent object created for each <code>A</code> object</p> <p...
41
2010-01-15T20:21:01Z
2,076,665
<p>As far as I know, there is no one-step way of doing this in Django ORM.</p> <p>But you can split it in two queries:</p> <pre><code>bakeries = Bakery.objects.annotate(hottest_cake_baked_at=Max('cake__baked_at')) hottest_cakes = Cake.objects.filter(baked_at__in=[b.hottest_cake_baked_at for b in bakeries]) </code></...
24
2010-01-16T08:12:43Z
[ "python", "django", "django-queryset", "greatest-n-per-group" ]
Django Query That Get Most Recent Objects From Different Categories
2,074,514
<p>I have two models <code>A</code> and <code>B</code>. All <code>B</code> objects have a foreign key to an <code>A</code> object. Given a set of <code>A</code> objects, is there anyway to use the ORM to get a set of <code>B</code> objects containing the most recent object created for each <code>A</code> object</p> <p...
41
2010-01-15T20:21:01Z
20,129,229
<p>If you happen to be using PostGreSQL, you can use <a href="https://docs.djangoproject.com/en/dev/ref/models/querysets/#django.db.models.query.QuerySet.distinct">Django's interface to DISTINCT ON</a>:</p> <pre><code>recent_cakes = Cake.objects.order_by('bakery__id', '-baked_at').distinct('bakery__id') </code></pre> ...
12
2013-11-21T18:35:42Z
[ "python", "django", "django-queryset", "greatest-n-per-group" ]
Django Query That Get Most Recent Objects From Different Categories
2,074,514
<p>I have two models <code>A</code> and <code>B</code>. All <code>B</code> objects have a foreign key to an <code>A</code> object. Given a set of <code>A</code> objects, is there anyway to use the ORM to get a set of <code>B</code> objects containing the most recent object created for each <code>A</code> object</p> <p...
41
2010-01-15T20:21:01Z
29,390,389
<p>I was fighting with similar problem and finally come to following solution. It does not rely on <code>order_by</code> and <code>distinct</code> so can be sorted as desired on db-side and also can be used as nested query for filtering. I also believe this implementation is db engine independent, because it's based on...
0
2015-04-01T12:07:08Z
[ "python", "django", "django-queryset", "greatest-n-per-group" ]
Euler Project No. 2 with Python
2,074,573
<p>Can somebody tell me why this should be wrong?</p> <pre><code>#Each new term in the Fibonacci sequence is generated #by adding the previous two terms. By starting with 1 and 2, #the first 10 terms will be: #1, 2, 3, 5, 8, 13, 21, 34, 55, 89, ... #Find the sum of all the even-valued terms in the sequence #which do n...
0
2010-01-15T20:31:37Z
2,074,615
<p>replace </p> <pre><code> sum += a print('sum', sum) if sum &gt;= 4000000: break </code></pre> <p>with </p> <pre><code> if a &gt; 4000000: break sum += a print('sum', sum) </code></pre> <p>You should compare "a" with 4000000, not "sum", like Daniel Roseman said.</p>
6
2010-01-15T20:37:22Z
[ "python" ]
Euler Project No. 2 with Python
2,074,573
<p>Can somebody tell me why this should be wrong?</p> <pre><code>#Each new term in the Fibonacci sequence is generated #by adding the previous two terms. By starting with 1 and 2, #the first 10 terms will be: #1, 2, 3, 5, 8, 13, 21, 34, 55, 89, ... #Find the sum of all the even-valued terms in the sequence #which do n...
0
2010-01-15T20:31:37Z
2,074,618
<p>The question asked for the sum of even <em>terms</em> which do not exceed four million. You're checking if the <em>sum</em> doesn't exceed 4m.</p>
2
2010-01-15T20:38:04Z
[ "python" ]
Euler Project No. 2 with Python
2,074,573
<p>Can somebody tell me why this should be wrong?</p> <pre><code>#Each new term in the Fibonacci sequence is generated #by adding the previous two terms. By starting with 1 and 2, #the first 10 terms will be: #1, 2, 3, 5, 8, 13, 21, 34, 55, 89, ... #Find the sum of all the even-valued terms in the sequence #which do n...
0
2010-01-15T20:31:37Z
2,074,671
<p>Here's a completely different way to solve the problem using a generator and itertools:</p> <pre><code>def fib(): a = b = 1 while 1: yield a a, b = b, a + b import itertools print sum(n for n in itertools.takewhile( lambda x: x &lt;= 4000000, fib()) if n % 2 == 0) </code></pre> <p>Outp...
7
2010-01-15T20:47:01Z
[ "python" ]
Euler Project No. 2 with Python
2,074,573
<p>Can somebody tell me why this should be wrong?</p> <pre><code>#Each new term in the Fibonacci sequence is generated #by adding the previous two terms. By starting with 1 and 2, #the first 10 terms will be: #1, 2, 3, 5, 8, 13, 21, 34, 55, 89, ... #Find the sum of all the even-valued terms in the sequence #which do n...
0
2010-01-15T20:31:37Z
3,677,893
<p>I'm trying to solve the same problem - although I understand the logic to do it, I don't understand why this works (outputs the right sum)</p> <pre><code>limit = 4000000 s = 0 l = [1,2] while l[-1]&lt;limit: n = l[-1]+l[-2] l.append(n) print n </code></pre> <p>And then then moment I put in the modulo ...
0
2010-09-09T15:10:42Z
[ "python" ]
Euler Project No. 2 with Python
2,074,573
<p>Can somebody tell me why this should be wrong?</p> <pre><code>#Each new term in the Fibonacci sequence is generated #by adding the previous two terms. By starting with 1 and 2, #the first 10 terms will be: #1, 2, 3, 5, 8, 13, 21, 34, 55, 89, ... #Find the sum of all the even-valued terms in the sequence #which do n...
0
2010-01-15T20:31:37Z
15,170,242
<p>This is the code I used. It is very helpful and teaches you about generators.</p> <pre><code>def fib(): x,y = 0,1 while True: yield x x,y = y, x+y def even(seq): for number in seq: if not number % 2: yield number def under_a_million(seq): for num...
0
2013-03-02T03:06:01Z
[ "python" ]
Euler Project No. 2 with Python
2,074,573
<p>Can somebody tell me why this should be wrong?</p> <pre><code>#Each new term in the Fibonacci sequence is generated #by adding the previous two terms. By starting with 1 and 2, #the first 10 terms will be: #1, 2, 3, 5, 8, 13, 21, 34, 55, 89, ... #Find the sum of all the even-valued terms in the sequence #which do n...
0
2010-01-15T20:31:37Z
22,643,554
<p>Keep it simple and it should take you less than 0.1 seconds. </p> <pre><code>from datetime import datetime x, y = 1, 1 total = 0 for i in xrange (1, 100): x = x + y if x % 2 == 0 and x &lt;= 4000000: total += x y = y + x if y % 2 == 0 and x &lt;= 4000000: total += y print total sta...
0
2014-03-25T18:42:05Z
[ "python" ]
Django ManyToManyField Creation Problems
2,074,900
<p>I currently have these models:</p> <pre><code>class Category(models.Model): name = models.CharField(max_length=200) parent = models.ForeignKey('self', blank=True, null=True, related_name='child') description = models.TextField(blank=True,null=True) class Item(models.Model): name = models.CharField(...
1
2010-01-15T21:26:27Z
2,074,958
<p>Have a look at some examples <a href="http://www.djangoproject.com/documentation/models/many_to_many/" rel="nofollow">here</a>.</p> <p>Basically, you should do:</p> <pre><code>class Item(models.Model): name = models.CharField(max_length=500) ... tags = models.ManyToManyField(Category, blank=True) </cod...
4
2010-01-15T21:38:48Z
[ "python", "django", "django-models", "many-to-many" ]
Python, print all floats to 2 decimal places in output
2,075,128
<p>I need to output 4 different floats to two decimal places.</p> <p>This is what I have:</p> <pre><code>print '%.2f' % var1,'kg =','%.2f' % var2,'lb =','%.2f' % var3,'gal =','%.2f' % var4,'l' </code></pre> <p>Which is very unclean, and looks bad. Is there a way to make any float in that out put '%.2f'? </p> <p>Not...
25
2010-01-15T22:15:31Z
2,075,141
<p>Well I would atleast clean it up as follows:</p> <pre><code>print "%.2f kg = %.2f lb = %.2f gal = %.2f l" % (var1, var2, var3, var4) </code></pre>
32
2010-01-15T22:18:30Z
[ "python", "floating-point", "string-formatting" ]
Python, print all floats to 2 decimal places in output
2,075,128
<p>I need to output 4 different floats to two decimal places.</p> <p>This is what I have:</p> <pre><code>print '%.2f' % var1,'kg =','%.2f' % var2,'lb =','%.2f' % var3,'gal =','%.2f' % var4,'l' </code></pre> <p>Which is very unclean, and looks bad. Is there a way to make any float in that out put '%.2f'? </p> <p>Not...
25
2010-01-15T22:15:31Z
2,075,149
<p>Not directly in the way you want to write that, no. One of the design tenets of Python is "Explicit is better than implicit" (see <code>import this</code>). This means that it's better to describe what you want rather than having the output format depend on some global formatting setting or something. You could of ...
0
2010-01-15T22:20:59Z
[ "python", "floating-point", "string-formatting" ]
Python, print all floats to 2 decimal places in output
2,075,128
<p>I need to output 4 different floats to two decimal places.</p> <p>This is what I have:</p> <pre><code>print '%.2f' % var1,'kg =','%.2f' % var2,'lb =','%.2f' % var3,'gal =','%.2f' % var4,'l' </code></pre> <p>Which is very unclean, and looks bad. Is there a way to make any float in that out put '%.2f'? </p> <p>Not...
25
2010-01-15T22:15:31Z
2,075,633
<p>If you just want to convert the values to nice looking strings do the following: </p> <pre><code>twodecimals = ["%.2f" % v for v in vars] </code></pre> <p>Alternatively, you could also print out the units like you have in your question:</p> <pre><code>vars = [0, 1, 2, 3] # just some example values units = ['kg', ...
13
2010-01-16T00:25:12Z
[ "python", "floating-point", "string-formatting" ]
Python, print all floats to 2 decimal places in output
2,075,128
<p>I need to output 4 different floats to two decimal places.</p> <p>This is what I have:</p> <pre><code>print '%.2f' % var1,'kg =','%.2f' % var2,'lb =','%.2f' % var3,'gal =','%.2f' % var4,'l' </code></pre> <p>Which is very unclean, and looks bad. Is there a way to make any float in that out put '%.2f'? </p> <p>Not...
25
2010-01-15T22:15:31Z
2,075,953
<p>If you are looking for readability, I believe that this is that code:</p> <pre><code>print '%(kg).2f kg = %(lb).2f lb = %(gal).2f gal = %(l).2f l' % { 'kg': var1, 'lb': var2, 'gal': var3, 'l': var4, } </code></pre>
4
2010-01-16T02:10:54Z
[ "python", "floating-point", "string-formatting" ]
Python, print all floats to 2 decimal places in output
2,075,128
<p>I need to output 4 different floats to two decimal places.</p> <p>This is what I have:</p> <pre><code>print '%.2f' % var1,'kg =','%.2f' % var2,'lb =','%.2f' % var3,'gal =','%.2f' % var4,'l' </code></pre> <p>Which is very unclean, and looks bad. Is there a way to make any float in that out put '%.2f'? </p> <p>Not...
25
2010-01-15T22:15:31Z
11,039,231
<p>I have just discovered the round function - it is in Python 2.7, not sure about 2.6. It takes a float and the number of dps as arguments, so round(22.55555, 2) gives the result 22.56. </p>
2
2012-06-14T18:31:54Z
[ "python", "floating-point", "string-formatting" ]
Python, print all floats to 2 decimal places in output
2,075,128
<p>I need to output 4 different floats to two decimal places.</p> <p>This is what I have:</p> <pre><code>print '%.2f' % var1,'kg =','%.2f' % var2,'lb =','%.2f' % var3,'gal =','%.2f' % var4,'l' </code></pre> <p>Which is very unclean, and looks bad. Is there a way to make any float in that out put '%.2f'? </p> <p>Not...
25
2010-01-15T22:15:31Z
36,204,273
<p>Format String Syntax.</p> <p><a href="https://docs.python.org/3/library/string.html#formatstrings" rel="nofollow">https://docs.python.org/3/library/string.html#formatstrings</a></p> <pre><code>from math import pi var1, var2, var3, var4 = pi, pi*2, pi*3, pi*4 '{:0.2f}, kg={:0.2f}, lb={:0.2f}, gal={:0.2f}'.format(va...
1
2016-03-24T15:41:57Z
[ "python", "floating-point", "string-formatting" ]
Split list in python
2,075,199
<p>I have following list:</p> <pre><code>mylist = ['Hello,\r', 'Whats going on.\r', 'some text'] </code></pre> <p>When I write "mylist" to a file called file.txt</p> <pre><code>open('file.txt', 'w').writelines(mylist) </code></pre> <p>I get for every line a little bit text because of the \r:</p> <pre><code>Hello, ...
0
2010-01-15T22:29:15Z
2,075,209
<p>Iterate through the list to a match with a regular expression to replace /r with a space.</p>
0
2010-01-15T22:30:48Z
[ "python" ]
Split list in python
2,075,199
<p>I have following list:</p> <pre><code>mylist = ['Hello,\r', 'Whats going on.\r', 'some text'] </code></pre> <p>When I write "mylist" to a file called file.txt</p> <pre><code>open('file.txt', 'w').writelines(mylist) </code></pre> <p>I get for every line a little bit text because of the \r:</p> <pre><code>Hello, ...
0
2010-01-15T22:29:15Z
2,075,210
<pre><code>mylist = [s.replace("\r", " ") for s in mylist] </code></pre> <p>This loops through your list, and does a string replace on each element in it.</p>
5
2010-01-15T22:31:53Z
[ "python" ]
Split list in python
2,075,199
<p>I have following list:</p> <pre><code>mylist = ['Hello,\r', 'Whats going on.\r', 'some text'] </code></pre> <p>When I write "mylist" to a file called file.txt</p> <pre><code>open('file.txt', 'w').writelines(mylist) </code></pre> <p>I get for every line a little bit text because of the \r:</p> <pre><code>Hello, ...
0
2010-01-15T22:29:15Z
2,075,232
<pre><code>open('file.txt', 'w').writelines(map(lambda x: x.replace('\r',' '),mylist)) </code></pre>
1
2010-01-15T22:36:01Z
[ "python" ]
Split list in python
2,075,199
<p>I have following list:</p> <pre><code>mylist = ['Hello,\r', 'Whats going on.\r', 'some text'] </code></pre> <p>When I write "mylist" to a file called file.txt</p> <pre><code>open('file.txt', 'w').writelines(mylist) </code></pre> <p>I get for every line a little bit text because of the \r:</p> <pre><code>Hello, ...
0
2010-01-15T22:29:15Z
2,075,630
<p>I don't know if you have this luxury, but I actually like to keep my lists of strings without newlines at the end. That way, I can manipulate them, doing things like dumping them out in debug mode, without having to do an "rstrip()" on them.</p> <p>For example, if your strings were saved like:</p> <pre><code>mylis...
0
2010-01-16T00:24:50Z
[ "python" ]
Split list in python
2,075,199
<p>I have following list:</p> <pre><code>mylist = ['Hello,\r', 'Whats going on.\r', 'some text'] </code></pre> <p>When I write "mylist" to a file called file.txt</p> <pre><code>open('file.txt', 'w').writelines(mylist) </code></pre> <p>I get for every line a little bit text because of the \r:</p> <pre><code>Hello, ...
0
2010-01-15T22:29:15Z
2,076,491
<p>Use <code>.rstrip()</code>: </p> <pre><code>&gt;&gt;&gt; mylist = ['Hello,\r', 'Whats going on.\r', 'some text'] &gt;&gt;&gt; ' '.join(map(str.rstrip,mylist)) 'Hello, Whats going on. some text' &gt;&gt;&gt; </code></pre>
0
2010-01-16T07:00:35Z
[ "python" ]
wxpython GetStatusText()
2,075,378
<p>Hey, I have a wxpython frame object with a status bar. I can do self.SetStatusText() without any trouble, but when I do self.GetStatusText() I get this error:</p> <pre><code> Traceback (most recent call last): File "D:\python\code\test.pyw", line 87, in &lt;module&gt; frame = mainframe() File "D:\python...
1
2010-01-15T23:13:43Z
2,075,458
<p>Because there is no such function. See <a href="http://www.wxpython.org/docs/api/wx.Frame-class.html" rel="nofollow">the documentation</a>. Try <code>self.GetStatusBar().GetStatusText()</code>, as defined <a href="http://www.wxpython.org/docs/api/wx.StatusBar-class.html" rel="nofollow">here</a>.</p>
3
2010-01-15T23:35:31Z
[ "python", "wxpython" ]
Python 2 and IPv6
2,075,383
<p>I'm trying to enable IPv6 in a Python 2 application and am running into trouble. Whenever I try to bind to an IPv6 socket, a <code>socket.error: getsockaddrarg: bad family</code> exception is thrown. I can reproduce the error simply by doing:</p> <pre><code>import socket s = socket.socket(socket.AF_INET6, socket...
3
2010-01-15T23:15:29Z
2,075,438
<p>Works fine with 2.6.4 on my Mac (Mac OS X 10.5.8) -- and unfortunately I can't downgrade to 2.6.2 nor do I have any openSUSE around to check where the bug specifically comes from you. Could you try getting 2.6.4 and building from sources to see if the bug goes away, or check some openSUSE-specific bug tracker...? A...
2
2010-01-15T23:29:39Z
[ "python", "ipv6" ]
Python 2 and IPv6
2,075,383
<p>I'm trying to enable IPv6 in a Python 2 application and am running into trouble. Whenever I try to bind to an IPv6 socket, a <code>socket.error: getsockaddrarg: bad family</code> exception is thrown. I can reproduce the error simply by doing:</p> <pre><code>import socket s = socket.socket(socket.AF_INET6, socket...
3
2010-01-15T23:15:29Z
2,075,496
<p>Sounds like that particular Python was not compiled with IPv6 support.</p> <p>In which case, you can download the source for that version and build yourself a compatible Python that will work. You may even be able to do some editing in the Debian package and upgrade the system python.</p>
3
2010-01-15T23:48:00Z
[ "python", "ipv6" ]
Python 2 and IPv6
2,075,383
<p>I'm trying to enable IPv6 in a Python 2 application and am running into trouble. Whenever I try to bind to an IPv6 socket, a <code>socket.error: getsockaddrarg: bad family</code> exception is thrown. I can reproduce the error simply by doing:</p> <pre><code>import socket s = socket.socket(socket.AF_INET6, socket...
3
2010-01-15T23:15:29Z
2,075,562
<p>Okay here's the answer from the comments:</p> <p>Seems like Python wasn't configured with <code>--enable-ipv6</code>.</p> <p>It shouldn't be a OS problem because Python 3 works. Even if the OS doesn't have IPv6 support, it seems that <code>socket.AF_INET6</code> is always available (if it is defined in the OS head...
4
2010-01-16T00:05:50Z
[ "python", "ipv6" ]
Can you/should you modify objects in the database in the model of other classes
2,075,411
<p>I want to perform some <code>delete()</code> and some <code>save()</code> methods on some objects that are not an instance of the current class I'm in. I'm trying to do this in an overloaded <code>save()</code> method of a class. Here is the scenerio:</p> <pre><code>class Item(models.Model): name = models.Cha...
1
2010-01-15T23:21:24Z
2,075,470
<p>I notice you are trying to update a ManyToMany in your save(). You might take a look at my answer to <a href="http://stackoverflow.com/questions/1925383/issue-with-manytomany-relationships-not-updating-inmediatly-after-save/1925784#1925784">this thread</a> and see if it applies to your situation. If you are using th...
0
2010-01-15T23:38:37Z
[ "python", "django", "model-view-controller", "django-models" ]
Can you/should you modify objects in the database in the model of other classes
2,075,411
<p>I want to perform some <code>delete()</code> and some <code>save()</code> methods on some objects that are not an instance of the current class I'm in. I'm trying to do this in an overloaded <code>save()</code> method of a class. Here is the scenerio:</p> <pre><code>class Item(models.Model): name = models.Cha...
1
2010-01-15T23:21:24Z
2,081,545
<p>I ended up resolving this issue. You can in fact accomplish what I was trying to do. The issue was that I was using the managers completely wrong. <code>a_tag</code> above was actually a reference to a Category object, so calling <code>delete()</code> on that was actually deleting my Categories, which is why I wa...
0
2010-01-17T15:55:36Z
[ "python", "django", "model-view-controller", "django-models" ]
How do you create flash images on the fly at the server side?
2,075,432
<p>The question just came up!</p> <p>I have seen in web apps we get flash images generated on the fly how is it achieved? Any api for programming languages (Java Python)?</p> <p>PS: It's adobe flash movie / image or swf</p>
0
2010-01-15T23:28:25Z
2,075,474
<p>If by Flash images you mean JPG, PNG and GIF files then you use any of the standard server side software packages or language specific libraries that utilize these packages.</p> <p>Here are the two most popular:</p> <p><a href="http://www.imagemagick.org/script/index.php" rel="nofollow">ImageMagick</a></p> <p><a ...
1
2010-01-15T23:40:16Z
[ "java", "python", "flash" ]
How do you create flash images on the fly at the server side?
2,075,432
<p>The question just came up!</p> <p>I have seen in web apps we get flash images generated on the fly how is it achieved? Any api for programming languages (Java Python)?</p> <p>PS: It's adobe flash movie / image or swf</p>
0
2010-01-15T23:28:25Z
2,151,263
<p><a href="http://teethgrinder.co.uk/open-flash-chart/" rel="nofollow">Open Flash Chart</a></p> <p><a href="http://www.adobe.com/products/flex/" rel="nofollow">Flex</a></p>
0
2010-01-27T23:49:07Z
[ "java", "python", "flash" ]
Is it possible to edit the inline code in with BeautifulSoup?
2,075,454
<p>I am aware of the ability to edit text with beautifulsoup, is it possible to edit the href links? I would like to be able to take say <code>&lt;a href="/foo/bar/"&gt;</code> and use beautifulsoup to change it to <code>&lt;a href="http://www.foobarinc.com/foo/bar/"&gt;</code>. I am not sure how I would use beautifuls...
1
2010-01-15T23:33:36Z
2,075,481
<p>As in your other question: with BeautifulSoup you're parsing in the content to a set of hierarchically nested objects representing the document, then changing those objects before serialising them back to different text. You're not editing the text directly.</p> <p>The <code>href="..."</code> part of the markup rep...
6
2010-01-15T23:42:27Z
[ "python", "beautifulsoup" ]
Is it possible to edit the inline code in with BeautifulSoup?
2,075,454
<p>I am aware of the ability to edit text with beautifulsoup, is it possible to edit the href links? I would like to be able to take say <code>&lt;a href="/foo/bar/"&gt;</code> and use beautifulsoup to change it to <code>&lt;a href="http://www.foobarinc.com/foo/bar/"&gt;</code>. I am not sure how I would use beautifuls...
1
2010-01-15T23:33:36Z
2,076,036
<p>Despite what the OP says in a comment to bobince, the following code works just fine:</p> <pre><code>from BeautifulSoup import BeautifulSoup ht = ''' &lt;a href="/foo/bar/"&gt;Hello world&lt;/a&gt; ''' soup = BeautifulSoup(ht) for link in soup.findAll('a'): if link['href'].startswith('/'): link['hre...
3
2010-01-16T03:02:29Z
[ "python", "beautifulsoup" ]
Python fails Tor check using urllib2 to initiate requests
2,075,469
<p>After reading through the <a href="http://stackoverflow.com/questions/1096379/tor-with-python">other</a> <a href="http://stackoverflow.com/questions/711351/using-urllib-with-tor">questions</a> on StackOverflow, I got a snippet of Python code that is able to make requests through a Tor proxy:</p> <pre><code>import u...
4
2010-01-15T23:38:03Z
2,075,479
<p>You've set up a proxy to your local Tor instance for the <code>http</code> protocol, but you're using <code>https</code> to talk to "check.torproject.org". Try:</p> <pre><code>print opener.open('http://check.torproject.org/').read() </code></pre>
5
2010-01-15T23:41:46Z
[ "python", "security", "urllib2", "tor" ]
Python: Help Me optimize this code.
2,075,573
<p>I am looking to see if this code can be optimized.</p> <pre><code>def gB(a,b,c): x=len(b) d=a.find(b)+x e=a.find(c,d) return a[d:e] print gB("abc","a","c") </code></pre>
0
2010-01-16T00:08:24Z
2,075,661
<p>There's a couple of problems with your code that you probably should fix before trying to optimize it.</p> <p>Firstly, it's undocumented and the naming is not helpful. I assume it is trying to extract a string between start and end markers.</p> <p>Secondly, it gives an apparent match even if the start and/or end m...
4
2010-01-16T00:31:28Z
[ "python" ]
Python: Help Me optimize this code.
2,075,573
<p>I am looking to see if this code can be optimized.</p> <pre><code>def gB(a,b,c): x=len(b) d=a.find(b)+x e=a.find(c,d) return a[d:e] print gB("abc","a","c") </code></pre>
0
2010-01-16T00:08:24Z
2,075,918
<p>What about this?</p> <pre><code>import re def gB(a, b, c): return (re.findall('%s(.*?)%s' % (b, c), a) or [''])[0] </code></pre> <p>If you are talking about smaller code, I think the re module can help you.</p>
1
2010-01-16T01:58:35Z
[ "python" ]
Why should I make multiple wx.Panel's?
2,075,638
<p>Following <a href="http://zetcode.com/wxpython/layout/" rel="nofollow">this tutorial</a> on WxPython, I've noticed that in the Find/Replace Dialog example there are extra panels where it doesn't seem like they're actually doing anything. In fact, they seem to mess up even more the layout (though that is probably som...
1
2010-01-16T00:26:32Z
2,077,637
<p>I'm not sure. I've re-written the example into less code, although it's a bit hard to follow. I may e-mail this suggestions to her.</p> <pre><code>import wx class FindReplace(wx.Dialog): def __init__(self, parent, id, title): wx.Dialog.__init__(self, parent, id, title, size=(255, 365)) vbox_to...
1
2010-01-16T14:37:24Z
[ "python", "wxpython" ]
Accessing related object key without fetching object in App Engine
2,075,951
<p>In general, it's better to do a single query vs. many queries for a given object. Let's say I have a bunch of 'son' objects each with a 'father'. I get all the 'son' objects:</p> <pre><code>sons = Son.all() </code></pre> <p>Then, I'd like to get all the fathers for that group of sons. I do:</p> <pre><code>father_...
7
2010-01-16T02:10:19Z
2,076,012
<p>You can find the answer by studying the sources of <a href="http://google_appengine/google/appengine/ext/db/__init__.py">appengine.ext.db</a> in your download of the App Engine SDK sources -- and the answer is, no, there's no special-casing as you require: the <code>__get__</code> method (line 2887 in the sources fo...
9
2010-01-16T02:48:12Z
[ "python", "google-app-engine", "gae-datastore" ]
Accessing related object key without fetching object in App Engine
2,075,951
<p>In general, it's better to do a single query vs. many queries for a given object. Let's say I have a bunch of 'son' objects each with a 'father'. I get all the 'son' objects:</p> <pre><code>sons = Son.all() </code></pre> <p>Then, I'd like to get all the fathers for that group of sons. I do:</p> <pre><code>father_...
7
2010-01-16T02:10:19Z
2,076,099
<p>I'd rather loop through the sons and get parent's keys using <a href="http://code.google.com/appengine/docs/python/datastore/modelclass.html#Model_parent_key" rel="nofollow"><code>son.parent_key()</code></a>.</p> <blockquote> <p><strong>parent_key()</strong></p> <p>Returns the Key of the parent entity of thi...
1
2010-01-16T03:37:25Z
[ "python", "google-app-engine", "gae-datastore" ]