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 |
|---|---|---|---|---|---|---|---|---|---|
Are Python docstrings and comments stored in memory when module is loaded? | 1,983,177 | <blockquote>
<p>Are Python docstrings and comments stored in memory when module is loaded?</p>
</blockquote>
<p>I've wondered if this is true, because I usually document my code well; may this affect memory usage?</p>
<p><strong>Usually every Python object has a <code>__doc__</code> method. Are those docstrings rea... | 6 | 2009-12-30T23:55:57Z | 1,983,288 | <blockquote>
<p>Do Python docstrings and comments are
stored in memory when module is
loaded?</p>
</blockquote>
<p>Docstrings are compiled into the .pyc file, and are loaded into memory. Comments are discarded during compilation and have no impact on anything except the insignificant extra time taken to ignore ... | 1 | 2009-12-31T00:23:11Z | [
"python",
"comments",
"memory-management",
"docstring"
] |
who can tell me what can call the built-in functions in next code | 1,983,199 | <p>i know some of this,ex.</p>
<p><code>__mod__</code> will be call /</p>
<p><code>__eq__</code>will be call == > and <</p>
<p>but i don't know all.</p>
<pre><code> def __nonzero__(self):
# an image is "true" if it contains at least one non-zero pixel
return self.im.getbbox() is not None
... | 0 | 2009-12-31T00:01:04Z | 1,983,216 | <p><a href="http://docs.python.org/reference/datamodel.html#special-method-names" rel="nofollow">Section 3.4</a> of the Python Language Reference covers the magic methods.</p>
| 3 | 2009-12-31T00:05:01Z | [
"python"
] |
who can tell me what can call the built-in functions in next code | 1,983,199 | <p>i know some of this,ex.</p>
<p><code>__mod__</code> will be call /</p>
<p><code>__eq__</code>will be call == > and <</p>
<p>but i don't know all.</p>
<pre><code> def __nonzero__(self):
# an image is "true" if it contains at least one non-zero pixel
return self.im.getbbox() is not None
... | 0 | 2009-12-31T00:01:04Z | 1,983,232 | <p>See the <a href="http://docs.python.org/reference/datamodel.html#special-method-names" rel="nofollow">Special Method Names</a> section in the reference manual, including <a href="http://docs.python.org/reference/datamodel.html#basic-customization" rel="nofollow">Basic Customization</a> and <a href="http://docs.pytho... | 2 | 2009-12-31T00:07:40Z | [
"python"
] |
who can tell me what can call the built-in functions in next code | 1,983,199 | <p>i know some of this,ex.</p>
<p><code>__mod__</code> will be call /</p>
<p><code>__eq__</code>will be call == > and <</p>
<p>but i don't know all.</p>
<pre><code> def __nonzero__(self):
# an image is "true" if it contains at least one non-zero pixel
return self.im.getbbox() is not None
... | 0 | 2009-12-31T00:01:04Z | 1,983,296 | <p><code>__mod__</code> is called for <code>%</code>, <strong>not</strong> for <code>/</code> as you state:</p>
<pre><code>>>> class x(int):
... def __mod__(self, y):
... print '__mod__(%s, %s)' % (self, y)
... return int.__mod__(self, y)
...
>>> a = x(23)
>>> a / 4
5
>>>... | 1 | 2009-12-31T00:26:04Z | [
"python"
] |
Please discuss what are and why use portlets | 1,983,282 | <p>Why would I want to use java portlets above tomcat and gwt?
Would portlets make it less- or un- necessary for me to use jsp and jsf?
Has Jboss been part of the portlet evolution culture? Does Jboss satisfy the portlet jsrs?</p>
<p>What portlet implementation/brand would run on gae java and gae python?
Are portlet s... | 2 | 2009-12-31T00:21:37Z | 1,983,323 | <p>Portlets were a well-meaning but mis-guided attempt at a reusable widget API for web applications. Think of the personalised google home page, with the portlets like weather, news, mail, etc.</p>
<p>Unfortunately, they made a bit of a mess of it. The Portlet API is a bit of a pig, a real barrel of not-fun, and ther... | 6 | 2009-12-31T00:34:11Z | [
"java",
".net",
"python",
"portlet"
] |
Please discuss what are and why use portlets | 1,983,282 | <p>Why would I want to use java portlets above tomcat and gwt?
Would portlets make it less- or un- necessary for me to use jsp and jsf?
Has Jboss been part of the portlet evolution culture? Does Jboss satisfy the portlet jsrs?</p>
<p>What portlet implementation/brand would run on gae java and gae python?
Are portlet s... | 2 | 2009-12-31T00:21:37Z | 1,983,356 | <p>If you happen to have a framework that you need to use, and it supports portlets, you may find then that portlets are going to be useful, since the application is built with the idea, but, as others have mentioned, if you are starting on a project, there are many other technologies that will do what you want with le... | 2 | 2009-12-31T00:42:10Z | [
"java",
".net",
"python",
"portlet"
] |
Please discuss what are and why use portlets | 1,983,282 | <p>Why would I want to use java portlets above tomcat and gwt?
Would portlets make it less- or un- necessary for me to use jsp and jsf?
Has Jboss been part of the portlet evolution culture? Does Jboss satisfy the portlet jsrs?</p>
<p>What portlet implementation/brand would run on gae java and gae python?
Are portlet s... | 2 | 2009-12-31T00:21:37Z | 1,985,241 | <blockquote>
<p>Why would I want to use java portlets above tomcat and gwt?</p>
</blockquote>
<p>These technologies are not directly comparable. Coming from regular web page development, Portlets seem like a very restrictive technology. But then the value of Portal servers is largely the control they give to adminis... | 1 | 2009-12-31T12:33:50Z | [
"java",
".net",
"python",
"portlet"
] |
i can't found '_weakref.py',where is '_weakref.py' | 1,983,332 | <pre><code>from _weakref import (
getweakrefcount,
getweakrefs,
ref,
proxy,
CallableProxyType,
ProxyType,
ReferenceType)
</code></pre>
| 0 | 2009-12-31T00:36:53Z | 1,983,367 | <p>It's not a Python-coded module, it's a C-coded Python-extension module.</p>
<p>You can read the extension module's C source code <a href="http://svn.python.org/view/python/trunk/Modules/%5Fweakref.c?revision=59564&view=markup" rel="nofollow">here</a>.</p>
| 2 | 2009-12-31T00:45:14Z | [
"python"
] |
i can't found '_weakref.py',where is '_weakref.py' | 1,983,332 | <pre><code>from _weakref import (
getweakrefcount,
getweakrefs,
ref,
proxy,
CallableProxyType,
ProxyType,
ReferenceType)
</code></pre>
| 0 | 2009-12-31T00:36:53Z | 1,983,378 | <p><code>_weakref</code> is a C module that comes with Python. Having said that, you should never import a module starting with an underscore directly; import the Python module and let it deal with the C module as needed, in this case <code>weakref</code>.</p>
| 3 | 2009-12-31T00:48:17Z | [
"python"
] |
Python Encapsulate a function to Print to a variable | 1,983,401 | <p>If I have a function that contains a lot of print statements:</p>
<p>ie.</p>
<pre><code>def funA():
print "Hi"
print "There"
print "Friend"
print "!"
</code></pre>
<p>What I want to do is something like this</p>
<pre><code>def main():
##funA() does not print to screen here
a = getPrint(funA()) ##wher... | 3 | 2009-12-31T00:56:12Z | 1,983,411 | <p>Replace <code>sys.stdout</code> with a <a href="http://docs.python.org/library/stdtypes.html#file-objects" rel="nofollow">file-like object</a>.</p>
| 1 | 2009-12-31T00:58:08Z | [
"python"
] |
Python Encapsulate a function to Print to a variable | 1,983,401 | <p>If I have a function that contains a lot of print statements:</p>
<p>ie.</p>
<pre><code>def funA():
print "Hi"
print "There"
print "Friend"
print "!"
</code></pre>
<p>What I want to do is something like this</p>
<pre><code>def main():
##funA() does not print to screen here
a = getPrint(funA()) ##wher... | 3 | 2009-12-31T00:56:12Z | 1,983,418 | <p>Use cStringIO ( see <a href="http://docs.python.org/library/stringio.html" rel="nofollow">doc</a> ).</p>
<pre><code>from cStringIO import StringIO
old_stdout = sys.stdout
sys.stdout = mystdout = StringIO()
getPrint( funA() )
# use mystdout to get string
</code></pre>
| 1 | 2009-12-31T01:00:13Z | [
"python"
] |
Python Encapsulate a function to Print to a variable | 1,983,401 | <p>If I have a function that contains a lot of print statements:</p>
<p>ie.</p>
<pre><code>def funA():
print "Hi"
print "There"
print "Friend"
print "!"
</code></pre>
<p>What I want to do is something like this</p>
<pre><code>def main():
##funA() does not print to screen here
a = getPrint(funA()) ##wher... | 3 | 2009-12-31T00:56:12Z | 1,983,450 | <p>You can do <em>almost</em> exactly what you want, as long as you don't mind a tiny syntax difference:</p>
<pre><code>import cStringIO
import sys
def getPrint(thefun, *a, **k):
savstdout = sys.stdout
sys.stdout = cStringIO.StringIO()
try:
thefun(*a, **k)
finally:
v = sys.stdout.getvalue()
sys.st... | 7 | 2009-12-31T01:10:43Z | [
"python"
] |
Python Encapsulate a function to Print to a variable | 1,983,401 | <p>If I have a function that contains a lot of print statements:</p>
<p>ie.</p>
<pre><code>def funA():
print "Hi"
print "There"
print "Friend"
print "!"
</code></pre>
<p>What I want to do is something like this</p>
<pre><code>def main():
##funA() does not print to screen here
a = getPrint(funA()) ##wher... | 3 | 2009-12-31T00:56:12Z | 1,983,456 | <pre><code>from cStringIO import StringIO
def getPrint(func, *args, **kwds):
old_stdout = sys.stdout
sys.stdout = StringIO()
try:
func(*args, **kwds)
except:
raise
else:
return sys.stdout.getvalue()
finally:
sys.stdout = old_stdout
#...
a = getPrint(funA) # notice no (), it is called by ge... | 3 | 2009-12-31T01:12:51Z | [
"python"
] |
Python Encapsulate a function to Print to a variable | 1,983,401 | <p>If I have a function that contains a lot of print statements:</p>
<p>ie.</p>
<pre><code>def funA():
print "Hi"
print "There"
print "Friend"
print "!"
</code></pre>
<p>What I want to do is something like this</p>
<pre><code>def main():
##funA() does not print to screen here
a = getPrint(funA()) ##wher... | 3 | 2009-12-31T00:56:12Z | 1,983,583 | <p>Best way is to do a context manager</p>
<pre><code>from contextlib import contextmanager
import StringIO
import sys
@contextmanager
def capture():
old_stdout = sys.stdout
sys.stdout = StringIO.StringIO()
try:
yield sys.stdout
finally:
sys.stdout = old_stdout
</code></pre>
<p>Now yo... | 2 | 2009-12-31T01:56:10Z | [
"python"
] |
Python Encapsulate a function to Print to a variable | 1,983,401 | <p>If I have a function that contains a lot of print statements:</p>
<p>ie.</p>
<pre><code>def funA():
print "Hi"
print "There"
print "Friend"
print "!"
</code></pre>
<p>What I want to do is something like this</p>
<pre><code>def main():
##funA() does not print to screen here
a = getPrint(funA()) ##wher... | 3 | 2009-12-31T00:56:12Z | 1,983,619 | <p>The simplest thing is to change your <code>funA()</code> to not print anything, but simply to return the string values.</p>
<p>Like so:</p>
<pre><code>def funA():
return "Hi\n" + "There\n" + "Friend\n" + "!\n"
# later:
print(funA())
</code></pre>
<p>It's always easy to collect strings and print them; it's tr... | 0 | 2009-12-31T02:19:28Z | [
"python"
] |
Why Unexpected Indent? | 1,983,405 | <p>Why does this happen?</p>
<pre><code>def LoadPackageList():
try:
#Attempts to load package list... Adds each neccessary attribute into array
print("Loading Package List... please wait")
packages = []
packagelisturl = os.getcwd() + "packages.list"
dom = minidom.parse(urlli... | 1 | 2009-12-31T00:57:08Z | 1,983,413 | <p>The code you posted works just fine. Therefore, check the lines immediately above the part you posted. If that does not help, please post the exact error message and a little more of the code.</p>
<p><strong>Edit</strong>: Also check that you do not have a mixture of tabs and spaces.</p>
<p><strong>Edit 2:</strong... | 4 | 2009-12-31T00:59:32Z | [
"python",
"indentation"
] |
Why Unexpected Indent? | 1,983,405 | <p>Why does this happen?</p>
<pre><code>def LoadPackageList():
try:
#Attempts to load package list... Adds each neccessary attribute into array
print("Loading Package List... please wait")
packages = []
packagelisturl = os.getcwd() + "packages.list"
dom = minidom.parse(urlli... | 1 | 2009-12-31T00:57:08Z | 1,983,417 | <p>Try running it through <code>python -t</code> and see if there is a mixture of tabs and spaces somewhere in there.</p>
<p>As a side note: use <a href="http://docs.python.org/library/optparse.html#module-optparse" rel="nofollow"><code>optparse</code></a> to process command line parameters. It will make your life muc... | 7 | 2009-12-31T01:00:06Z | [
"python",
"indentation"
] |
Why Unexpected Indent? | 1,983,405 | <p>Why does this happen?</p>
<pre><code>def LoadPackageList():
try:
#Attempts to load package list... Adds each neccessary attribute into array
print("Loading Package List... please wait")
packages = []
packagelisturl = os.getcwd() + "packages.list"
dom = minidom.parse(urlli... | 1 | 2009-12-31T00:57:08Z | 1,986,860 | <p>Shouldn't the try on line 2 have an except, finally or else associated with it? Or is this some new Python idiom I haven't seen before?</p>
| 3 | 2009-12-31T19:46:08Z | [
"python",
"indentation"
] |
why my code make dead-loop,it is about 'iter(c,a)' | 1,983,543 | <pre><code>def c():
yield 222
yield 333
a=[1,2,3,4]
b=iter(c,333)
print a,b
for i in b:
print i
</code></pre>
<p>how can i get it.</p>
| 1 | 2009-12-31T01:41:09Z | 1,983,558 | <p>You didn't call c().</p>
<p>Your question is cryptic. I don't know what you expect.</p>
<p>Please, edit the question and add information about what you thought that would do, and what you've observed instead.</p>
| 1 | 2009-12-31T01:45:49Z | [
"python"
] |
why my code make dead-loop,it is about 'iter(c,a)' | 1,983,543 | <pre><code>def c():
yield 222
yield 333
a=[1,2,3,4]
b=iter(c,333)
print a,b
for i in b:
print i
</code></pre>
<p>how can i get it.</p>
| 1 | 2009-12-31T01:41:09Z | 1,983,567 | <p>You need to provide the function (which will return the next value) to your <code>iter()</code> call. In your case, that's <code>c().next</code> rather than <code>c</code>.</p>
<p>This snippet below works as expected by producing all the yielded values up to, but exclusive of, the terminating value.</p>
<pre><code... | 2 | 2009-12-31T01:49:54Z | [
"python"
] |
why my code make dead-loop,it is about 'iter(c,a)' | 1,983,543 | <pre><code>def c():
yield 222
yield 333
a=[1,2,3,4]
b=iter(c,333)
print a,b
for i in b:
print i
</code></pre>
<p>how can i get it.</p>
| 1 | 2009-12-31T01:41:09Z | 1,983,579 | <p>iter takes a callable and a sentinel and calls the callable repeatedly. Calling c repeatedly creates new generators which is not what you want. You want to call c once and then repeatedly call the next function, so try this instead:</p>
<pre><code>def c():
yield 222
yield 333
a=[1,2,3,4]
b=iter(c().next, 3... | 1 | 2009-12-31T01:54:54Z | [
"python"
] |
why my code make dead-loop,it is about 'iter(c,a)' | 1,983,543 | <pre><code>def c():
yield 222
yield 333
a=[1,2,3,4]
b=iter(c,333)
print a,b
for i in b:
print i
</code></pre>
<p>how can i get it.</p>
| 1 | 2009-12-31T01:41:09Z | 1,983,585 | <p>Because <code>c</code> never <em>returns</em> 333. </p>
<p>When using a <em>sentinel</em> in <code>iter</code> the first argument <strong>must</strong> be a callable, and <code>iter</code> will <em>yield</em> the returning value of the first argument until this value is equal to the sentinel.</p>
<p>What you'd li... | 0 | 2009-12-31T01:56:56Z | [
"python"
] |
How can I have Google App Engine clear memcache every time a site is deployed? | 1,983,556 | <p>The title asks it all. The content on the site I'm building wont change very quickly at all and so Memcache could potentially store data for months except for when I put up an update. Is there a way to make it clear the cache every time I deploy the site? I'm using the Python runtime.</p>
<h3>Update 1</h3>
<p><del... | 25 | 2009-12-31T01:45:30Z | 1,983,573 | <p>Have you tried <code>flush_all()</code> function? <a href="http://code.google.com/appengine/docs/python/memcache/functions.html">Docs here</a>. You'll need a bit of logic & state to detect a new deployment or have a special script to perform the flushing.</p>
<p><strong>Updated</strong>: look at the absolute pa... | 21 | 2009-12-31T01:52:13Z | [
"python",
"google-app-engine",
"deployment",
"caching",
"memcached"
] |
How can I have Google App Engine clear memcache every time a site is deployed? | 1,983,556 | <p>The title asks it all. The content on the site I'm building wont change very quickly at all and so Memcache could potentially store data for months except for when I put up an update. Is there a way to make it clear the cache every time I deploy the site? I'm using the Python runtime.</p>
<h3>Update 1</h3>
<p><del... | 25 | 2009-12-31T01:45:30Z | 1,983,588 | <p>You could just create an admin-only path that would flush the cache when it's accessed.</p>
| 0 | 2009-12-31T01:57:34Z | [
"python",
"google-app-engine",
"deployment",
"caching",
"memcached"
] |
How can I have Google App Engine clear memcache every time a site is deployed? | 1,983,556 | <p>The title asks it all. The content on the site I'm building wont change very quickly at all and so Memcache could potentially store data for months except for when I put up an update. Is there a way to make it clear the cache every time I deploy the site? I'm using the Python runtime.</p>
<h3>Update 1</h3>
<p><del... | 25 | 2009-12-31T01:45:30Z | 1,983,896 | <p>When creating keys for your cached values, include the version of the file that is doing the cache gets/sets in the key. That way, when a new version of the file exists, it will no longer reference the old versions in the cache - they will be left to expire out on their own.</p>
<p>We use CVS and java, so we decla... | 3 | 2009-12-31T04:13:09Z | [
"python",
"google-app-engine",
"deployment",
"caching",
"memcached"
] |
How can I have Google App Engine clear memcache every time a site is deployed? | 1,983,556 | <p>The title asks it all. The content on the site I'm building wont change very quickly at all and so Memcache could potentially store data for months except for when I put up an update. Is there a way to make it clear the cache every time I deploy the site? I'm using the Python runtime.</p>
<h3>Update 1</h3>
<p><del... | 25 | 2009-12-31T01:45:30Z | 7,402,937 | <p>I have not tested this but perhaps if you insert into memcache a key with version # on instance start.</p>
<p>Then when the next instance is started, aka after a deployment, it would check memcache and its local version, if they differ, flush all and re-initalize the key.</p>
<p>Only flaw is what if the key is evi... | 2 | 2011-09-13T13:46:38Z | [
"python",
"google-app-engine",
"deployment",
"caching",
"memcached"
] |
wxPython GridSizer not attached to panel? | 1,983,727 | <p>I'm trying to build a level editor for a game I'm working on. It pulls data from a flat file and then based on a byte-by-byte search it'll assemble a grid from pre-set tiles. This part of the app I should have no issues with. The problem is that my test version of the editor which just loads a 16x16 grid of test til... | 0 | 2009-12-31T02:59:01Z | 1,983,801 | <p>That's a lot of code and a lot of sizers! But I think maybe your ImgPanels should have the rightPanel as their parent, and not self.</p>
<p>Also, do you ever call self.SetSizer(self.h_sizer)? Didn't see that anywhere.</p>
<p>I recommend creating portions of the layout in separate functions. Then you don't have t... | 1 | 2009-12-31T03:26:39Z | [
"python",
"image",
"wxpython",
"panel",
"sizer"
] |
Remove row or column from 2D list if all values (in that row or column) are None | 1,983,902 | <p>I have a grid (6 rows, 5 columns):</p>
<pre><code>grid = [
[None, None, None, None, None],
[None, None, None, None, None],
[None, None, None, None, None],
[None, None, None, None, None],
[None, None, None, None, None],
[None, None, None, None, None],
]
</code>... | 3 | 2009-12-31T04:16:14Z | 1,983,960 | <p>If only you had a transpose function, you could do: transpose(removeRows(transpose(removeRows(mat))))</p>
<p>Actually ... using a bitmask is a better idea.</p>
<p>Let me think about that ...</p>
<p>First compute gridmask:</p>
<pre><code>grid_mask = [
10000,
00000,
00000,
00010,
00000
]
</code></pre>
<p>Now remo... | 0 | 2009-12-31T04:42:06Z | [
"python",
"list"
] |
Remove row or column from 2D list if all values (in that row or column) are None | 1,983,902 | <p>I have a grid (6 rows, 5 columns):</p>
<pre><code>grid = [
[None, None, None, None, None],
[None, None, None, None, None],
[None, None, None, None, None],
[None, None, None, None, None],
[None, None, None, None, None],
[None, None, None, None, None],
]
</code>... | 3 | 2009-12-31T04:16:14Z | 1,983,961 | <pre><code>grid = ...
# remove empty rows
grid = [x for x in grid if any(x)]
# if any value you put in won't evaluate to False
# e.g. an empty string or empty list wouldn't work here
# in that case, use:
grid = [x for x in grid if any(n is not None for n in x)]
# remove empty columns
if not grid:
raise ValueError("... | 1 | 2009-12-31T04:42:48Z | [
"python",
"list"
] |
Remove row or column from 2D list if all values (in that row or column) are None | 1,983,902 | <p>I have a grid (6 rows, 5 columns):</p>
<pre><code>grid = [
[None, None, None, None, None],
[None, None, None, None, None],
[None, None, None, None, None],
[None, None, None, None, None],
[None, None, None, None, None],
[None, None, None, None, None],
]
</code>... | 3 | 2009-12-31T04:16:14Z | 1,983,964 | <p>Use <code>zip()</code> to transpose the ragged array, run the clearing routine again, then <code>zip()</code> it again.</p>
| 1 | 2009-12-31T04:43:24Z | [
"python",
"list"
] |
Remove row or column from 2D list if all values (in that row or column) are None | 1,983,902 | <p>I have a grid (6 rows, 5 columns):</p>
<pre><code>grid = [
[None, None, None, None, None],
[None, None, None, None, None],
[None, None, None, None, None],
[None, None, None, None, None],
[None, None, None, None, None],
[None, None, None, None, None],
]
</code>... | 3 | 2009-12-31T04:16:14Z | 1,983,967 | <p>It's not the fastest way but I think it's quite easy to understand:</p>
<pre><code>def transpose(grid):
return zip(*grid)
def removeBlankRows(grid):
return [list(row) for row in grid if any(row)]
print removeBlankRows(transpose(removeBlankRows(transpose(grid))))
</code></pre>
<p>Output:</p>
<pre><code>[... | 6 | 2009-12-31T04:44:49Z | [
"python",
"list"
] |
Remove row or column from 2D list if all values (in that row or column) are None | 1,983,902 | <p>I have a grid (6 rows, 5 columns):</p>
<pre><code>grid = [
[None, None, None, None, None],
[None, None, None, None, None],
[None, None, None, None, None],
[None, None, None, None, None],
[None, None, None, None, None],
[None, None, None, None, None],
]
</code>... | 3 | 2009-12-31T04:16:14Z | 1,983,968 | <p>Here is quick attempt</p>
<p>It will work for any size matrix and rows can be different sizes too , and may be fast :)</p>
<pre><code>from collections import defaultdict
grid = [
[{"some" : "thing"}, None, None, None, None],
[None, None, None, None, None],
[None, None, None, None, None],
... | 0 | 2009-12-31T04:45:34Z | [
"python",
"list"
] |
Remove row or column from 2D list if all values (in that row or column) are None | 1,983,902 | <p>I have a grid (6 rows, 5 columns):</p>
<pre><code>grid = [
[None, None, None, None, None],
[None, None, None, None, None],
[None, None, None, None, None],
[None, None, None, None, None],
[None, None, None, None, None],
[None, None, None, None, None],
]
</code>... | 3 | 2009-12-31T04:16:14Z | 1,984,638 | <p>You can also use the built-in function <code>any()</code>, which checks if any of the elements of an iterable has a not <code>None</code> value. It's faster than comparing and you don't need to know the size of the iterable.</p>
<pre><code>>>> def remove_rows( matrix ):
... '''Returns a matrix without e... | 0 | 2009-12-31T09:14:32Z | [
"python",
"list"
] |
How to avoid explicit 'self' in Python? | 1,984,104 | <p>I have been learning Python by following some <a href="http://www.pygame.org/wiki/tutorials">pygame tutorials</a>.</p>
<p>Therein I found extensive use of the keyword <em>self</em>, and coming from a primarily Java background, I find that I keep forgetting to type <em>self</em>. For example, instead of <code>self.... | 55 | 2009-12-31T05:50:07Z | 1,984,112 | <p>self is part of the python syntax to access members of objects, so I'm afraid you're stuck with it</p>
| 5 | 2009-12-31T05:53:27Z | [
"python",
"self"
] |
How to avoid explicit 'self' in Python? | 1,984,104 | <p>I have been learning Python by following some <a href="http://www.pygame.org/wiki/tutorials">pygame tutorials</a>.</p>
<p>Therein I found extensive use of the keyword <em>self</em>, and coming from a primarily Java background, I find that I keep forgetting to type <em>self</em>. For example, instead of <code>self.... | 55 | 2009-12-31T05:50:07Z | 1,984,116 | <p>yes, you must always specify <code>self</code>, because explicit is better than implicit, according to python philosophy.</p>
<p>You will also find out that the way you program in python is very different from the way you program in java, hence the use of <code>self</code> tends to decrease because you don't projec... | 7 | 2009-12-31T05:54:33Z | [
"python",
"self"
] |
How to avoid explicit 'self' in Python? | 1,984,104 | <p>I have been learning Python by following some <a href="http://www.pygame.org/wiki/tutorials">pygame tutorials</a>.</p>
<p>Therein I found extensive use of the keyword <em>self</em>, and coming from a primarily Java background, I find that I keep forgetting to type <em>self</em>. For example, instead of <code>self.... | 55 | 2009-12-31T05:50:07Z | 1,984,120 | <p>Actually <code>self</code> is not a keyword, it's just the name conventionally given to the first parameter of instance methods in Python. And that first parameter can't be skipped, as it's the only mechanism a method has of knowing which instance of your class it's being called on.</p>
| 13 | 2009-12-31T05:56:37Z | [
"python",
"self"
] |
How to avoid explicit 'self' in Python? | 1,984,104 | <p>I have been learning Python by following some <a href="http://www.pygame.org/wiki/tutorials">pygame tutorials</a>.</p>
<p>Therein I found extensive use of the keyword <em>self</em>, and coming from a primarily Java background, I find that I keep forgetting to type <em>self</em>. For example, instead of <code>self.... | 55 | 2009-12-31T05:50:07Z | 1,984,121 | <p><strong>Python requires specifying self.</strong> The result is there's never any confusion over what's a member and what's not, even without the full class definition visible. This leads to useful properties, such as: you can't add members which accidentally shadow non-members and thereby break code.</p>
<p>One ... | 61 | 2009-12-31T05:57:29Z | [
"python",
"self"
] |
How to avoid explicit 'self' in Python? | 1,984,104 | <p>I have been learning Python by following some <a href="http://www.pygame.org/wiki/tutorials">pygame tutorials</a>.</p>
<p>Therein I found extensive use of the keyword <em>self</em>, and coming from a primarily Java background, I find that I keep forgetting to type <em>self</em>. For example, instead of <code>self.... | 55 | 2009-12-31T05:50:07Z | 1,984,191 | <p>You can use whatever name you want, for example</p>
<pre><code>class test(object):
def function(this, variable):
this.variable = variable
</code></pre>
<p>or even</p>
<pre><code>class test(object):
def function(s, variable):
s.variable = variable
</code></pre>
<p>but you are stuck with us... | 11 | 2009-12-31T06:18:24Z | [
"python",
"self"
] |
How to avoid explicit 'self' in Python? | 1,984,104 | <p>I have been learning Python by following some <a href="http://www.pygame.org/wiki/tutorials">pygame tutorials</a>.</p>
<p>Therein I found extensive use of the keyword <em>self</em>, and coming from a primarily Java background, I find that I keep forgetting to type <em>self</em>. For example, instead of <code>self.... | 55 | 2009-12-31T05:50:07Z | 13,940,372 | <p>The "self" is the conventional placeholder of the current object instance of a class. Its used when you want to refer to the object's property or field or method inside a class as if you're referring to "itself". But to make it shorter someone in the Python programming realm started to use "self" , other realms use ... | 2 | 2012-12-18T19:47:05Z | [
"python",
"self"
] |
How to avoid explicit 'self' in Python? | 1,984,104 | <p>I have been learning Python by following some <a href="http://www.pygame.org/wiki/tutorials">pygame tutorials</a>.</p>
<p>Therein I found extensive use of the keyword <em>self</em>, and coming from a primarily Java background, I find that I keep forgetting to type <em>self</em>. For example, instead of <code>self.... | 55 | 2009-12-31T05:50:07Z | 16,205,561 | <p>Yeah, self is tedious. But, is it better?</p>
<pre><code>class Test:
def __init__(_):
_.test = 'test'
def run(_):
print _.test
</code></pre>
| 1 | 2013-04-25T02:48:21Z | [
"python",
"self"
] |
How to avoid explicit 'self' in Python? | 1,984,104 | <p>I have been learning Python by following some <a href="http://www.pygame.org/wiki/tutorials">pygame tutorials</a>.</p>
<p>Therein I found extensive use of the keyword <em>self</em>, and coming from a primarily Java background, I find that I keep forgetting to type <em>self</em>. For example, instead of <code>self.... | 55 | 2009-12-31T05:50:07Z | 33,670,307 | <p>From: <a href="http://kmkeen.com/self-hell/" rel="nofollow">Self Hell - More stateful functions.</a></p>
<blockquote>
<p>...a hybrid approach works best. All of your class methods that actually
do computation should be moved into closures, and extensions to clean up syntax should be kept in classes. Stuff the ... | 0 | 2015-11-12T11:22:16Z | [
"python",
"self"
] |
How to avoid explicit 'self' in Python? | 1,984,104 | <p>I have been learning Python by following some <a href="http://www.pygame.org/wiki/tutorials">pygame tutorials</a>.</p>
<p>Therein I found extensive use of the keyword <em>self</em>, and coming from a primarily Java background, I find that I keep forgetting to type <em>self</em>. For example, instead of <code>self.... | 55 | 2009-12-31T05:50:07Z | 33,988,803 | <p>Actually you can use recipe "Implicit self" from Armin Ronacher presentation "5 years of bad ideas" ( google it).</p>
<p>It's a very clever recipe, as almost everything from Armin Ronacher, but I don't think this idea is very appealing. I think I'd prefer explicit <strong>this</strong> in C#/Java.</p>
| 0 | 2015-11-29T22:16:39Z | [
"python",
"self"
] |
SimpleHTTPServer, shoutdown and blocked request handlers | 1,984,159 | <p>I have an instance of SimpleHTTPServer, however when I try to call
"shutdown" on it and there is a request handler that is blocked - the
whole process will block. </p>
<p>It does so even if I run the "serve_forever" method in a deamon
thread. </p>
<p>See example code at <a href="http://codepad.org/cn8EYdfg" rel... | 0 | 2009-12-31T06:06:06Z | 1,984,287 | <p>the <code>shutdown</code> method won't take affect until after the <code>GET</code> request is processed.</p>
<p>And that request is blocking because of the queue operation.</p>
<p>Maybe this will help: <a href="http://blog.odegra.com/?p=3" rel="nofollow">Stoppable Interruptable Python HTTP Server</a></p>
| 0 | 2009-12-31T06:55:08Z | [
"python",
"multithreading",
"http"
] |
Purpose of Python's __repr__ | 1,984,162 | <pre><code>def __repr__(self):
return '<%s %s (%s:%s) %s>' % (
self.__class__.__name__, self.urlconf_name, self.app_name,
self.namespace, self.regex.pattern)
</code></pre>
<p>What is the significance/purpose of this method?</p>
| 56 | 2009-12-31T06:06:39Z | 1,984,174 | <p>This is explained quite well in the <a href="http://docs.python.org/library/functions.html#repr">Python documentation</a>:</p>
<blockquote>
<p><strong>repr(object)</strong>: Return a string containing a printable representation of an object. This is the same value yielded by conversions (reverse quotes). It is so... | 11 | 2009-12-31T06:11:46Z | [
"python"
] |
Purpose of Python's __repr__ | 1,984,162 | <pre><code>def __repr__(self):
return '<%s %s (%s:%s) %s>' % (
self.__class__.__name__, self.urlconf_name, self.app_name,
self.namespace, self.regex.pattern)
</code></pre>
<p>What is the significance/purpose of this method?</p>
| 56 | 2009-12-31T06:06:39Z | 1,984,177 | <p><code>__repr__</code> should return a printable representation of the object, most likely <em>one</em> of the ways possible to create this object. See official documentation <a href="http://docs.python.org/library/functions.html#repr">here</a>. <code>__repr__</code> is more for developers while <code>__str__</code> ... | 80 | 2009-12-31T06:12:38Z | [
"python"
] |
Purpose of Python's __repr__ | 1,984,162 | <pre><code>def __repr__(self):
return '<%s %s (%s:%s) %s>' % (
self.__class__.__name__, self.urlconf_name, self.app_name,
self.namespace, self.regex.pattern)
</code></pre>
<p>What is the significance/purpose of this method?</p>
| 56 | 2009-12-31T06:06:39Z | 39,673,895 | <p>The <strong>__repr__</strong> method simply tells Python how to print objects of a class</p>
| 0 | 2016-09-24T07:47:03Z | [
"python"
] |
why my code 'next()' function not called in this example? | 1,984,184 | <pre><code>class a(object):
w={'a':'aaa','b':'bbb'}
def __iter__(self):
return iter(self.w)
def next(self):#this is not be called
print 'sss'
for i in self.w:
return i
b=a()
for i in b:
print i
</code></pre>
<p>and what is Relations between <code>__iter__</code> and... | 0 | 2009-12-31T06:15:53Z | 1,984,203 | <p>In <code>__iter__()</code> you return an iterator on the dict stored in <code>self.w</code>, not on the class itself. Returning <code>self</code> instead will fix that.</p>
| 1 | 2009-12-31T06:24:33Z | [
"python",
"iterator"
] |
why my code 'next()' function not called in this example? | 1,984,184 | <pre><code>class a(object):
w={'a':'aaa','b':'bbb'}
def __iter__(self):
return iter(self.w)
def next(self):#this is not be called
print 'sss'
for i in self.w:
return i
b=a()
for i in b:
print i
</code></pre>
<p>and what is Relations between <code>__iter__</code> and... | 0 | 2009-12-31T06:15:53Z | 1,984,208 | <p>I'm not entirely sure what you are asking, but the <code>next()</code> function isn't called because you never explicitly call it. You define <code>__iter__</code>, which gets called when you do:</p>
<pre><code>for i in b:
</code></pre>
<p>This should implicitly call the .next() method of the iterator, but the ite... | 1 | 2009-12-31T06:26:11Z | [
"python",
"iterator"
] |
why my code 'next()' function not called in this example? | 1,984,184 | <pre><code>class a(object):
w={'a':'aaa','b':'bbb'}
def __iter__(self):
return iter(self.w)
def next(self):#this is not be called
print 'sss'
for i in self.w:
return i
b=a()
for i in b:
print i
</code></pre>
<p>and what is Relations between <code>__iter__</code> and... | 0 | 2009-12-31T06:15:53Z | 1,984,263 | <p><code>next</code> should remember the last position and return the next item (not always return the first item, like in your code), and when there are no further items, raise the <code>StopIteration</code> exception.</p>
<p>Also <code>__iter__</code> should return the class itself.</p>
<p>See <a href="http://docs.... | 1 | 2009-12-31T06:48:02Z | [
"python",
"iterator"
] |
Explaining Python's '__enter__' and '__exit__' | 1,984,325 | <p>this is i saw in someone's code: </p>
<pre><code> def __enter__(self):
return self
def __exit__(self, type, value, tb):
self.stream.close()
</code></pre>
<hr>
<pre><code>from __future__ import with_statement#for python2.5
class a(object):
def __enter__(self):
print 'sss'
... | 114 | 2009-12-31T07:07:18Z | 1,984,346 | <p>Using these magic methods (<code>__enter__</code>, <code>__exit__</code>) allows you to implement objects which can be used easily with the <code>with</code> statement. </p>
<p>The idea is that it makes it easy to build code which needs some 'cleandown' code executed (think of it as a <code>try-finally</code> block... | 145 | 2009-12-31T07:13:06Z | [
"python"
] |
Explaining Python's '__enter__' and '__exit__' | 1,984,325 | <p>this is i saw in someone's code: </p>
<pre><code> def __enter__(self):
return self
def __exit__(self, type, value, tb):
self.stream.close()
</code></pre>
<hr>
<pre><code>from __future__ import with_statement#for python2.5
class a(object):
def __enter__(self):
print 'sss'
... | 114 | 2009-12-31T07:07:18Z | 38,685,520 | <p>If you know what <strong>context managers</strong> are then you need nothing more to understand <code>__enter__</code> and <code>__exit__</code> magic methods. Lets see a very simple example.</p>
<p>In this example I am opening <strong>myfile.txt</strong> with help of <strong>open</strong> function. The <strong>try... | 4 | 2016-07-31T15:29:36Z | [
"python"
] |
Interaction between Java App and Python App | 1,984,445 | <p>I have a python application which I cant edit its a black box from my point of view. The python application knows how to process text and return processed text.
I have another application written in Java which knows how to collect non processed texts.</p>
<p>Current state, the python app works in batch mode every x... | 2 | 2009-12-31T07:52:42Z | 1,984,453 | <p>Look into <a href="http://www.jython.org/" rel="nofollow">Jython</a> - you can run Python programs directly from Java code, and interact seamlessly back and forth.</p>
| 6 | 2009-12-31T07:57:12Z | [
"java",
"python",
"interface",
"interaction"
] |
Interaction between Java App and Python App | 1,984,445 | <p>I have a python application which I cant edit its a black box from my point of view. The python application knows how to process text and return processed text.
I have another application written in Java which knows how to collect non processed texts.</p>
<p>Current state, the python app works in batch mode every x... | 2 | 2009-12-31T07:52:42Z | 1,984,457 | <p>Expose one of the two as a service of some kind, web service maybe. Another option is to port the python code to Jython</p>
| 0 | 2009-12-31T07:58:32Z | [
"java",
"python",
"interface",
"interaction"
] |
Interaction between Java App and Python App | 1,984,445 | <p>I have a python application which I cant edit its a black box from my point of view. The python application knows how to process text and return processed text.
I have another application written in Java which knows how to collect non processed texts.</p>
<p>Current state, the python app works in batch mode every x... | 2 | 2009-12-31T07:52:42Z | 1,984,611 | <p>One possible solution is <a href="http://jpype.sourceforge.net/" rel="nofollow">jpype</a>. This allows you to launch a JVM from Python and pass data back and forth between them.</p>
<p>Another solution may be to write the Python program as a filter (reading data from stdin and writing result to stdout) then run it... | 0 | 2009-12-31T09:01:41Z | [
"java",
"python",
"interface",
"interaction"
] |
Interaction between Java App and Python App | 1,984,445 | <p>I have a python application which I cant edit its a black box from my point of view. The python application knows how to process text and return processed text.
I have another application written in Java which knows how to collect non processed texts.</p>
<p>Current state, the python app works in batch mode every x... | 2 | 2009-12-31T07:52:42Z | 1,984,649 | <p>I don't know nothing about Jython and the like. I guess it's the best solution if you can execute two programs without executing a new process each time the Java app needs to transform text. Anyway a simple proof of concept is to execute a separate process from the Java App to make it work. Next you can enhance the ... | 4 | 2009-12-31T09:22:28Z | [
"java",
"python",
"interface",
"interaction"
] |
Interaction between Java App and Python App | 1,984,445 | <p>I have a python application which I cant edit its a black box from my point of view. The python application knows how to process text and return processed text.
I have another application written in Java which knows how to collect non processed texts.</p>
<p>Current state, the python app works in batch mode every x... | 2 | 2009-12-31T07:52:42Z | 1,984,650 | <p>An option is making the python application work as a server, listens for request via sockets (TCP).</p>
| 0 | 2009-12-31T09:22:30Z | [
"java",
"python",
"interface",
"interaction"
] |
Interaction between Java App and Python App | 1,984,445 | <p>I have a python application which I cant edit its a black box from my point of view. The python application knows how to process text and return processed text.
I have another application written in Java which knows how to collect non processed texts.</p>
<p>Current state, the python app works in batch mode every x... | 2 | 2009-12-31T07:52:42Z | 1,985,463 | <p>Use <a href="http://java.sun.com/javase/6/docs/api/java/lang/ProcessBuilder.html" rel="nofollow">ProcessBuilder</a> to execute your <a href="http://docs.python.org/" rel="nofollow">Python</a> code as a filter:</p>
<pre><code>import java.io.BufferedReader;
import java.io.InputStreamReader;
public class PBTest {
... | 2 | 2009-12-31T13:42:54Z | [
"java",
"python",
"interface",
"interaction"
] |
How to access fields in a struct imported from a .mat file using loadmat in Python? | 1,984,714 | <p>Following <a href="http://stackoverflow.com/questions/874461/read-mat-fils-in-python">this question</a> which asks (and answers) how to read .mat files that were created in Matlab using Scipy, I want to know how to access the fields in the imported structs.</p>
<p>I have a file in Matlab from which I can import a s... | 7 | 2009-12-31T09:48:11Z | 1,990,050 | <p>First, I'd recommend to upgrade to Scipy svn if possible - there has been active development of the matlab io with some really dramatic speed ups recently.</p>
<p>Also as mentioned it might be worth trying with <code>struct_as_record=True</code>. But otherwise you should be able to get it out by playing around inte... | 6 | 2010-01-01T23:40:56Z | [
"python",
"matlab",
"file-io",
"scipy",
"mat-file"
] |
Export with alphabetical sort in Python ConfigParser | 1,984,759 | <p>Is there any solution to force the RawConfigParser.write() method to export the config file with an alphabetical sort?</p>
<p>Even if the original/loaded config file is sorted, the module mixes the section and the options into the sections arbitrarily, and is really annoying to edit manually a huge unsorted config ... | 6 | 2009-12-31T09:59:10Z | 1,984,787 | <p>Three solutions:</p>
<ol>
<li>Pass in a dict type (second argument to the constructor) which returns the keys in your preferred sort order.</li>
<li>Extend the class and overload <code>write()</code> (just copy this method from the original source and modify it).</li>
<li>Copy the file ConfigParser.py and add the s... | 3 | 2009-12-31T10:08:40Z | [
"python",
"configuration-files",
"configparser"
] |
Export with alphabetical sort in Python ConfigParser | 1,984,759 | <p>Is there any solution to force the RawConfigParser.write() method to export the config file with an alphabetical sort?</p>
<p>Even if the original/loaded config file is sorted, the module mixes the section and the options into the sections arbitrarily, and is really annoying to edit manually a huge unsorted config ... | 6 | 2009-12-31T09:59:10Z | 2,418,400 | <p>The first method looked as the most easier, and safer way.</p>
<p>But, after looking at the source code of the ConfigParser, it creates an empty built-in dict, and then copies all the values from the "second parameter" one-by-one. That means it won't use the OrderedDict type. An easy work around can be to overload ... | 1 | 2010-03-10T16:04:27Z | [
"python",
"configuration-files",
"configparser"
] |
Export with alphabetical sort in Python ConfigParser | 1,984,759 | <p>Is there any solution to force the RawConfigParser.write() method to export the config file with an alphabetical sort?</p>
<p>Even if the original/loaded config file is sorted, the module mixes the section and the options into the sections arbitrarily, and is really annoying to edit manually a huge unsorted config ... | 6 | 2009-12-31T09:59:10Z | 3,838,207 | <p>This is my solution for writing config file in alphabetical sort:</p>
<pre><code>class OrderedRawConfigParser( ConfigParser.RawConfigParser ):
"""
Overload standart Class ConfigParser.RawConfigParser
"""
def __init__( self, defaults = None, dict_type = dict ):
ConfigParser.RawConfigParser.__init__( self, defaul... | 2 | 2010-10-01T10:08:31Z | [
"python",
"configuration-files",
"configparser"
] |
Export with alphabetical sort in Python ConfigParser | 1,984,759 | <p>Is there any solution to force the RawConfigParser.write() method to export the config file with an alphabetical sort?</p>
<p>Even if the original/loaded config file is sorted, the module mixes the section and the options into the sections arbitrarily, and is really annoying to edit manually a huge unsorted config ... | 6 | 2009-12-31T09:59:10Z | 16,503,138 | <p>I was looking into this for merging a .gitmodules doing a subtree merge with a supermodule -- was super confused to start with, and having different orders for submodules was confusing enough haha.</p>
<p>Using GitPython helped alot:</p>
<pre><code>from collections import OrderedDict
import git
filePath = '/tmp/g... | 0 | 2013-05-12T00:51:30Z | [
"python",
"configuration-files",
"configparser"
] |
Cross product of two vectors in Python | 1,984,799 | <p>How can I calculate the cross product of two vectors without the use of programming libraries?</p>
<p>E.g given vectors <code>a = (1, 2, 3)</code> and <code>b = (4, 5, 6)</code></p>
| 11 | 2009-12-31T10:13:41Z | 1,984,817 | <pre><code>import numpy as np
a = np.array([1,0,0])
b = np.array([0,1,0])
print np.cross(a,b)
</code></pre>
| 25 | 2009-12-31T10:20:10Z | [
"python"
] |
Cross product of two vectors in Python | 1,984,799 | <p>How can I calculate the cross product of two vectors without the use of programming libraries?</p>
<p>E.g given vectors <code>a = (1, 2, 3)</code> and <code>b = (4, 5, 6)</code></p>
| 11 | 2009-12-31T10:13:41Z | 1,984,823 | <p>are you asking about the formula for the cross product? Or how to do indexing and lists in python? </p>
<p>The basic idea is that you access the elements of a and b as a[0], a[1], a[2], etc. (for x, y, z) and that you create a new list with [element_0, element_1, ...]. We can also wrap it in a function.</p>
<p>On ... | 27 | 2009-12-31T10:21:34Z | [
"python"
] |
Cross product of two vectors in Python | 1,984,799 | <p>How can I calculate the cross product of two vectors without the use of programming libraries?</p>
<p>E.g given vectors <code>a = (1, 2, 3)</code> and <code>b = (4, 5, 6)</code></p>
| 11 | 2009-12-31T10:13:41Z | 1,984,853 | <p>If you want to implement the cross product yourself you may see <a href="http://en.wikipedia.org/wiki/Vector%5Fcross%5Fproduct" rel="nofollow">http://en.wikipedia.org/wiki/Vector%5Fcross%5Fproduct</a>
or a math/physics book.
Shortly (a1, a2, a3) X (b1, b2, b3) = (a2*b3-a3*b2, a3*b1-a1*b3, a1*b2-a2*b1)</p>
| 1 | 2009-12-31T10:30:02Z | [
"python"
] |
Cross product of two vectors in Python | 1,984,799 | <p>How can I calculate the cross product of two vectors without the use of programming libraries?</p>
<p>E.g given vectors <code>a = (1, 2, 3)</code> and <code>b = (4, 5, 6)</code></p>
| 11 | 2009-12-31T10:13:41Z | 9,489,115 | <p>for multiple dimensions, this might work;</p>
<pre><code> def crossProd(a,b):
dimension = len(a)
c = []
for i in range(dimension):
c.append(0)
for j in range(dimension):
if j <> i:
for k in range(dimension):
if k <> i:
... | 1 | 2012-02-28T20:22:04Z | [
"python"
] |
Cross product of two vectors in Python | 1,984,799 | <p>How can I calculate the cross product of two vectors without the use of programming libraries?</p>
<p>E.g given vectors <code>a = (1, 2, 3)</code> and <code>b = (4, 5, 6)</code></p>
| 11 | 2009-12-31T10:13:41Z | 37,317,560 | <p>old, but if some one will ever need:
i did it like this:</p>
<p><strong>def cross_product(u,v):</strong> </p>
<pre><code>dim = len(u)
s = []
for i in range(dim):
if i == 0:
j,k = 1,2
s.append(u[j]*v[k] - u[k]*v[j])
elif i == 1:
j,k = 2,0
s.append(u[j]*v[k] - u[k]*v[j])
... | 0 | 2016-05-19T08:15:25Z | [
"python"
] |
Need init.d script for Python application | 1,984,847 | <p>I have a python based application which works like a feed aggregator and needs to be part of init.d script so that I could control the execution with start/stop/restart options. Also I want the init.d script to be setup as a cron job (I have example here). </p>
<p>I found one sample here <a href="http://homepage.hi... | 2 | 2009-12-31T10:27:59Z | 1,984,855 | <p>You could consider writing a Upstart task for operating systems which use Upstart. </p>
<p>Example:</p>
<pre><code># Start zeya
#
description "Start Zeya music server"
start on startup
task
exec python /home/r00t/code-hacking/serve-music/zeya/src/zeya/zeya.py
--path=/home/r00t/Music
</code></pre>
<p>Add th... | 7 | 2009-12-31T10:30:21Z | [
"python",
"ubuntu",
"init.d"
] |
Need init.d script for Python application | 1,984,847 | <p>I have a python based application which works like a feed aggregator and needs to be part of init.d script so that I could control the execution with start/stop/restart options. Also I want the init.d script to be setup as a cron job (I have example here). </p>
<p>I found one sample here <a href="http://homepage.hi... | 2 | 2009-12-31T10:27:59Z | 1,984,865 | <p>I did something like this recently and wrote some small config files using <a href="http://supervisord.org/" rel="nofollow">Supervisord</a>.</p>
<p>From the init script (pretty much barebones), I simply called supervisor-ctl with the appropriate arguments. </p>
<p>Also, you should note that the actual functions (e... | 2 | 2009-12-31T10:33:20Z | [
"python",
"ubuntu",
"init.d"
] |
Need init.d script for Python application | 1,984,847 | <p>I have a python based application which works like a feed aggregator and needs to be part of init.d script so that I could control the execution with start/stop/restart options. Also I want the init.d script to be setup as a cron job (I have example here). </p>
<p>I found one sample here <a href="http://homepage.hi... | 2 | 2009-12-31T10:27:59Z | 1,984,917 | <p>A counter-question really, but I've noticed, that you've mentioned cron, meaning, your app is going to be run periodically, as opposed to being run continously, in a so-called daemon fashion.</p>
<p>What is the sense in having commands like start, stop and restart for an application that is run periodically? I mean... | 0 | 2009-12-31T10:47:35Z | [
"python",
"ubuntu",
"init.d"
] |
Need init.d script for Python application | 1,984,847 | <p>I have a python based application which works like a feed aggregator and needs to be part of init.d script so that I could control the execution with start/stop/restart options. Also I want the init.d script to be setup as a cron job (I have example here). </p>
<p>I found one sample here <a href="http://homepage.hi... | 2 | 2009-12-31T10:27:59Z | 7,810,311 | <blockquote>
<p>I found one sample here <a href="http://homepage.hispeed.ch/py430/python/daemon" rel="nofollow">http://homepage.hispeed.ch/py430/python/daemon</a></p>
</blockquote>
<p>I know is an old question but actually the example that you found is the recommended way to do that(start/stop/restart) in ubuntu and... | 0 | 2011-10-18T16:06:53Z | [
"python",
"ubuntu",
"init.d"
] |
Filter with field has relationship in Django? | 1,985,026 | <p>I have these models in Django:</p>
<pre><code>class Customer(models.Model):
def __unicode__(self):
return self.name
name = models.CharField(max_length=200)
class Sale(models.Model):
def __unicode__(self):
return "Sale %s (%i)" % (self.type, self.id)
customer = models.ForeignKey(Cust... | 0 | 2009-12-31T11:20:34Z | 1,985,118 | <p>Have a look at <a href="http://docs.djangoproject.com/en/dev/topics/db/aggregation/" rel="nofollow">aggregation documentation</a>.</p>
<p>I believe this should do the trick (only with version 1.1 or dev.):</p>
<pre><code>Customer.objects.annotate(total=Sum('sale__total'))
</code></pre>
<p><strong>EDIT</strong>: Y... | 1 | 2009-12-31T11:49:51Z | [
"python",
"django",
"django-models",
"django-orm"
] |
Python: Colorbands in the PIL-Module | 1,985,178 | <p>I have this code from the PIL-handbook but I get an error message.</p>
<pre><code>from PIL import Image, ImageEnhance, ImageChops
im = Image.open("D:\\Python26\\PYTHON-PROGRAMME\\bild.jpg")
# split the image into individual bands
source = im.split()
R, G, B = 0, 1, 2
# select regions where red is less than 100
... | 0 | 2009-12-31T12:08:19Z | 1,985,437 | <p>Code runs fine for me, on a colour image.</p>
<p>I would expect you to get the quoted error if you tried to operate on an image that only had one colour channelâââie. a black-and-white JPEG. How about <code>im= im.convert('RGB')</code> before the <code>split</code>, to be sure?</p>
| 3 | 2009-12-31T13:36:25Z | [
"python",
"image"
] |
Using SimpleHTTPServer for unit testing | 1,985,197 | <p>I'm writing a Python module that wraps out a certain web service API. It's all REST, so relatively straightforward to implement. </p>
<p>However, I found a problem when it comes to unit testing: as I don't run the services I made this module for, I don't want to hammer them, but at the same time, I need to retrieve... | 14 | 2009-12-31T12:14:25Z | 1,985,270 | <p>We use a server built on <code>wsgiref</code>. <a href="http://docs.python.org/library/wsgiref.html" rel="nofollow">http://docs.python.org/library/wsgiref.html</a></p>
<p>It's very easy to add features to this server as we add unit tests.</p>
<p>We start the server with <code>subprocess</code>. <a href="http://d... | 4 | 2009-12-31T12:46:38Z | [
"python",
"unit-testing",
"simplehttpserver"
] |
Using SimpleHTTPServer for unit testing | 1,985,197 | <p>I'm writing a Python module that wraps out a certain web service API. It's all REST, so relatively straightforward to implement. </p>
<p>However, I found a problem when it comes to unit testing: as I don't run the services I made this module for, I don't want to hammer them, but at the same time, I need to retrieve... | 14 | 2009-12-31T12:14:25Z | 1,985,511 | <p>Try using a <a href="http://docs.python.org/library/socketserver.html#SocketServer.BaseServer.allow_reuse_address">subclass of TCPServer with <code>allow_reuse_address</code> set True</a>:</p>
<pre><code>class TestServer(SocketServer.TCPServer):
allow_reuse_address = True
...
httpd = TestServer(("", PORT), han... | 11 | 2009-12-31T13:57:26Z | [
"python",
"unit-testing",
"simplehttpserver"
] |
Using SimpleHTTPServer for unit testing | 1,985,197 | <p>I'm writing a Python module that wraps out a certain web service API. It's all REST, so relatively straightforward to implement. </p>
<p>However, I found a problem when it comes to unit testing: as I don't run the services I made this module for, I don't want to hammer them, but at the same time, I need to retrieve... | 14 | 2009-12-31T12:14:25Z | 13,136,864 | <p>Old thread but the answers here didn't help me, I'm using HTTPServer, and shutting down after each unit test (by default HTTPServer has allow_reuse_address = 1 set). However I still got the address already in use problem after calling shutdown. I fixed using:</p>
<pre><code>from BaseHTTPServer import HTTPServer
cl... | 4 | 2012-10-30T10:17:09Z | [
"python",
"unit-testing",
"simplehttpserver"
] |
update django database to reflect changes in existing models | 1,985,383 | <p>I've already defined a model and created its associated database via <code>manager.py syncdb</code>. Now that I've added some fields to the model, I tried <code>syncdb</code> again, but no output appears. Upon trying to access these new fields from my templates, I get a "No Such Column" exception, leading me to beli... | 65 | 2009-12-31T13:23:46Z | 1,985,405 | <p><a href="http://code.google.com/p/deseb/" rel="nofollow">deseb</a> is a great tool for that.</p>
<p>Having it installed, you can write ./manage.py sqlevolve and it'll generate sql commands necessary to keep the database structure in sync with your models.</p>
| 2 | 2009-12-31T13:28:07Z | [
"python",
"django",
"django-models"
] |
update django database to reflect changes in existing models | 1,985,383 | <p>I've already defined a model and created its associated database via <code>manager.py syncdb</code>. Now that I've added some fields to the model, I tried <code>syncdb</code> again, but no output appears. Upon trying to access these new fields from my templates, I get a "No Such Column" exception, leading me to beli... | 65 | 2009-12-31T13:23:46Z | 1,985,409 | <p>Seems like what you need is a migration system. <a href="http://south.aeracode.org/">South</a> is really nice, working great, has some automation tools to ease your workflow. And has a great <a href="http://south.aeracode.org/wiki/Tutorial1">tutorial</a>.</p>
<hr>
<p>note: syncdb can't update your existing tables.... | 34 | 2009-12-31T13:28:54Z | [
"python",
"django",
"django-models"
] |
update django database to reflect changes in existing models | 1,985,383 | <p>I've already defined a model and created its associated database via <code>manager.py syncdb</code>. Now that I've added some fields to the model, I tried <code>syncdb</code> again, but no output appears. Upon trying to access these new fields from my templates, I get a "No Such Column" exception, leading me to beli... | 65 | 2009-12-31T13:23:46Z | 1,985,415 | <p>You need to drop your tables before you can recreate them with <code>syncdb</code>.</p>
<p>If you want to preserve your existing data, then you need to unload your database,
drop your tables, run <code>syncdb</code> to build a new database, then reload your old data into your new tables.</p>
<p>There are tools tha... | 1 | 2009-12-31T13:30:14Z | [
"python",
"django",
"django-models"
] |
update django database to reflect changes in existing models | 1,985,383 | <p>I've already defined a model and created its associated database via <code>manager.py syncdb</code>. Now that I've added some fields to the model, I tried <code>syncdb</code> again, but no output appears. Upon trying to access these new fields from my templates, I get a "No Such Column" exception, leading me to beli... | 65 | 2009-12-31T13:23:46Z | 1,985,567 | <p>Django's syncdb doesn't alter existing tables in the database so you have to do it manually. The way I always do it is: </p>
<ol>
<li>Change the model class first.</li>
<li>Then run: manage.py sql myapp.</li>
<li>Look at the sql it prints out and see how it represented the change you are going to make.</li>
<li>Mak... | 7 | 2009-12-31T14:12:31Z | [
"python",
"django",
"django-models"
] |
update django database to reflect changes in existing models | 1,985,383 | <p>I've already defined a model and created its associated database via <code>manager.py syncdb</code>. Now that I've added some fields to the model, I tried <code>syncdb</code> again, but no output appears. Upon trying to access these new fields from my templates, I get a "No Such Column" exception, leading me to beli... | 65 | 2009-12-31T13:23:46Z | 1,989,523 | <p>Another tool would be django evolution. No table dropping needed in most cases.</p>
<p><a href="http://code.google.com/p/django-evolution/">django evolution</a></p>
<p>Just install it as any other django app and run:</p>
<p>python manage.py evolve --hint --execute </p>
| 7 | 2010-01-01T20:24:37Z | [
"python",
"django",
"django-models"
] |
update django database to reflect changes in existing models | 1,985,383 | <p>I've already defined a model and created its associated database via <code>manager.py syncdb</code>. Now that I've added some fields to the model, I tried <code>syncdb</code> again, but no output appears. Upon trying to access these new fields from my templates, I get a "No Such Column" exception, leading me to beli... | 65 | 2009-12-31T13:23:46Z | 1,992,512 | <p>Another option, not requiring additional apps, is to use the built in <code>manage.py</code> functions to export your data, clear the database and restore the exported data.</p>
<p>The methods below will update the database tables for your app, but will <strong>completely destroy</strong> any data that existed in t... | 132 | 2010-01-02T19:12:43Z | [
"python",
"django",
"django-models"
] |
update django database to reflect changes in existing models | 1,985,383 | <p>I've already defined a model and created its associated database via <code>manager.py syncdb</code>. Now that I've added some fields to the model, I tried <code>syncdb</code> again, but no output appears. Upon trying to access these new fields from my templates, I get a "No Such Column" exception, leading me to beli... | 65 | 2009-12-31T13:23:46Z | 20,461,577 | <p>For versions 1.4.1 and above users the command has changed to</p>
<pre><code>python manage.py flush
</code></pre>
<p>Please read the <a href="https://docs.djangoproject.com/en/1.5/faq/models/#if-i-make-changes-to-a-model-how-do-i-update-the-database" rel="nofollow">official document</a> before using it as <strong>... | 1 | 2013-12-09T01:26:56Z | [
"python",
"django",
"django-models"
] |
update django database to reflect changes in existing models | 1,985,383 | <p>I've already defined a model and created its associated database via <code>manager.py syncdb</code>. Now that I've added some fields to the model, I tried <code>syncdb</code> again, but no output appears. Upon trying to access these new fields from my templates, I get a "No Such Column" exception, leading me to beli... | 65 | 2009-12-31T13:23:46Z | 27,664,925 | <p>As of Django 1.7, you can now do this with native migrations. Just run</p>
<pre><code>python manage.py makemigrations <your app name>
python manage.py migrate
</code></pre>
| 24 | 2014-12-27T06:17:57Z | [
"python",
"django",
"django-models"
] |
Plane equation for 3D vectors | 1,985,427 | <p>I want to find a 3D plane equation given 3 points. I have got the normal calculated after applying the cross product. But the equation of a plane is known to be the normal multiply by another vector which what I am taught to be as P.OP. I substitute my main reference point as OP and i want P to be in (x, y, z) form.... | 2 | 2009-12-31T13:33:26Z | 1,985,450 | <p>Plane implicit Eqn:</p>
<p>All points <strong>P</strong> = (x, y, z) satisfying</p>
<p><<strong>n</strong>, <strong>QP</strong>> = 0</p>
<p>where</p>
<ul>
<li><strong>n</strong> is the plane normal vector,</li>
<li><strong>Q</strong> is some point on the plane (any will do)</li>
<li><strong>QP</strong> is the... | 2 | 2009-12-31T13:39:23Z | [
"python",
"math",
"linear-algebra"
] |
Plane equation for 3D vectors | 1,985,427 | <p>I want to find a 3D plane equation given 3 points. I have got the normal calculated after applying the cross product. But the equation of a plane is known to be the normal multiply by another vector which what I am taught to be as P.OP. I substitute my main reference point as OP and i want P to be in (x, y, z) form.... | 2 | 2009-12-31T13:33:26Z | 1,985,483 | <p>One good way is:</p>
<pre><code>| x1 y1 z2 1 |
| x2 y2 z2 1 |
| x3 y3 z3 1 | = 0
| x y z 1 |
</code></pre>
<p>Where the vertical pipes mean the determinant of the matrix, and <code>(x1 y1 z1)</code>, <code>(x2 y2 z2)</code>, and <code>(x3 y3 z3)</code> are your given points.</p>
| 2 | 2009-12-31T13:50:02Z | [
"python",
"math",
"linear-algebra"
] |
Plane equation for 3D vectors | 1,985,427 | <p>I want to find a 3D plane equation given 3 points. I have got the normal calculated after applying the cross product. But the equation of a plane is known to be the normal multiply by another vector which what I am taught to be as P.OP. I substitute my main reference point as OP and i want P to be in (x, y, z) form.... | 2 | 2009-12-31T13:33:26Z | 7,379,772 | <p>this paper gives the algebraic way to find the equation from 3 points on the plane</p>
<p><a href="http://www.math.washington.edu/~king/coursedir/m445w04/notes/vector/equations.html" rel="nofollow">http://www.math.washington.edu/~king/coursedir/m445w04/notes/vector/equations.html</a></p>
<p>and this is a more deta... | 1 | 2011-09-11T16:53:35Z | [
"python",
"math",
"linear-algebra"
] |
Plane equation for 3D vectors | 1,985,427 | <p>I want to find a 3D plane equation given 3 points. I have got the normal calculated after applying the cross product. But the equation of a plane is known to be the normal multiply by another vector which what I am taught to be as P.OP. I substitute my main reference point as OP and i want P to be in (x, y, z) form.... | 2 | 2009-12-31T13:33:26Z | 24,540,938 | <p>I wish this answer already existed. Coded from <a href="http://www.had2know.com/academics/equation-plane-through-3-points.html" rel="nofollow">http://www.had2know.com/academics/equation-plane-through-3-points.html</a></p>
<p>Supposing 3 points p1, p2, p3 - consisting of [x1, y1, z1], etc.</p>
<pre><code>vector1 =... | 2 | 2014-07-02T21:00:13Z | [
"python",
"math",
"linear-algebra"
] |
Plane equation for 3D vectors | 1,985,427 | <p>I want to find a 3D plane equation given 3 points. I have got the normal calculated after applying the cross product. But the equation of a plane is known to be the normal multiply by another vector which what I am taught to be as P.OP. I substitute my main reference point as OP and i want P to be in (x, y, z) form.... | 2 | 2009-12-31T13:33:26Z | 25,054,449 | <p>Say you have three known points, each with (x, y, z). For example:</p>
<pre><code>p1 = (1, 2, 3)
p2 = (4, 6, 9)
p3 = (12, 11, 9)
</code></pre>
<p>Make them into symbols that are easier to look at for further processing:</p>
<pre><code>x1, y1, z1 = p1
x2, y2, z2 = p2
x3, y3, z3 = p3
</code></pre>
<p>Determine two... | 1 | 2014-07-31T08:43:08Z | [
"python",
"math",
"linear-algebra"
] |
Plane equation for 3D vectors | 1,985,427 | <p>I want to find a 3D plane equation given 3 points. I have got the normal calculated after applying the cross product. But the equation of a plane is known to be the normal multiply by another vector which what I am taught to be as P.OP. I substitute my main reference point as OP and i want P to be in (x, y, z) form.... | 2 | 2009-12-31T13:33:26Z | 25,809,052 | <p>If I am not mistaken, one good solution here contains mistypes</p>
<pre><code>vector1 = [x2 - x1, y2 - y1, z2 - z1]
vector2 = [x3 - x1, y3 - y1, z3 - z1]
cross_product = [vector1[1] * vector2[2] - vector1[2] * vector2[1], -1 * (vector1[0] * vector2[2] - vector1[2] * vector2[0]), vector1[0] * vector2[1] - vector1[1... | 3 | 2014-09-12T13:06:52Z | [
"python",
"math",
"linear-algebra"
] |
Which is more fundamental: Python functions or Python object-methods? | 1,985,635 | <p>I am trying to get a conceptual understanding of the nature of Python functions and methods. I get that functions are actually objects, with a method that is called when the function is executed. But is that function-object method actually another function?</p>
<p>For example:</p>
<pre><code>def fred():
pass
<... | 10 | 2009-12-31T14:31:51Z | 1,985,743 | <p>Not specifically a Python answer, but at the lowest level the processor understands only actions and variables. From that we extrapolate functions, and from variables and functions we extrapolate objects. So from a low-level programming perspective I'd say that the more fundamental thing is the function.</p>
<p>T... | 2 | 2009-12-31T15:03:19Z | [
"python",
"function",
"object"
] |
Which is more fundamental: Python functions or Python object-methods? | 1,985,635 | <p>I am trying to get a conceptual understanding of the nature of Python functions and methods. I get that functions are actually objects, with a method that is called when the function is executed. But is that function-object method actually another function?</p>
<p>For example:</p>
<pre><code>def fred():
pass
<... | 10 | 2009-12-31T14:31:51Z | 1,985,820 | <blockquote>
<p>Which is more fundamental: functions
or object-methods?</p>
</blockquote>
<p>I think the best answer might be "neither". See the <a href="http://docs.python.org/reference/executionmodel.html" rel="nofollow">Execution model</a> part of the Python reference, where it refers to "blocks". This is wha... | 1 | 2009-12-31T15:27:18Z | [
"python",
"function",
"object"
] |
Which is more fundamental: Python functions or Python object-methods? | 1,985,635 | <p>I am trying to get a conceptual understanding of the nature of Python functions and methods. I get that functions are actually objects, with a method that is called when the function is executed. But is that function-object method actually another function?</p>
<p>For example:</p>
<pre><code>def fred():
pass
<... | 10 | 2009-12-31T14:31:51Z | 1,986,338 | <p>Short answer: both are fundamental, <code>.__call__()</code> on functions is just a virtual trick.</p>
<hr>
<p>The rest of this answer is a bit complicated. You don't have to understand it, but I find the subject interesting. Be warned that I'm going to present a series of lies, progressively fixing them.</p>
<... | 4 | 2009-12-31T17:35:48Z | [
"python",
"function",
"object"
] |
How to make a 3D scatter plot in Python? | 1,985,856 | <p>I am currently have a nx3 matrix array. I want plot the three columns as three axis's.
How can I do that? </p>
<p>I have googled and people suggested using <strong>Matlab</strong>, but I am really having a hard time with understanding it. I also need it be a scatter plot.</p>
<p>Can someone teach me? </p>
| 27 | 2009-12-31T15:37:06Z | 1,985,871 | <p>Use asymptote instead!</p>
<p>This is what it can look like:</p>
<p><a href="http://asymptote.sourceforge.net/gallery/3D%20graphs/helix.pdf" rel="nofollow">http://asymptote.sourceforge.net/gallery/3D%20graphs/helix.pdf</a></p>
<p>This is the code:
<a href="http://asymptote.sourceforge.net/gallery/3D%20graphs/heli... | 1 | 2009-12-31T15:42:45Z | [
"python",
"3d",
"matplotlib",
"plot",
"scatter-plot"
] |
How to make a 3D scatter plot in Python? | 1,985,856 | <p>I am currently have a nx3 matrix array. I want plot the three columns as three axis's.
How can I do that? </p>
<p>I have googled and people suggested using <strong>Matlab</strong>, but I am really having a hard time with understanding it. I also need it be a scatter plot.</p>
<p>Can someone teach me? </p>
| 27 | 2009-12-31T15:37:06Z | 1,986,020 | <p>You can use <a href="http://matplotlib.sourceforge.net/">matplotlib</a> for this. matplotlib has a <a href="http://matplotlib.sourceforge.net/mpl_toolkits/mplot3d/index.html">mplot3d</a> module that will do exactly what you want.</p>
<pre><code>from matplotlib import pyplot
import pylab
from mpl_toolkits.mplot3d im... | 46 | 2009-12-31T16:29:09Z | [
"python",
"3d",
"matplotlib",
"plot",
"scatter-plot"
] |
How to make a 3D scatter plot in Python? | 1,985,856 | <p>I am currently have a nx3 matrix array. I want plot the three columns as three axis's.
How can I do that? </p>
<p>I have googled and people suggested using <strong>Matlab</strong>, but I am really having a hard time with understanding it. I also need it be a scatter plot.</p>
<p>Can someone teach me? </p>
| 27 | 2009-12-31T15:37:06Z | 1,986,047 | <p><a href="http://code.enthought.com/projects/mayavi/docs/development/html/mayavi/mlab.html#a-demo" rel="nofollow">from enthought.mayavi import mlab</a></p>
| -1 | 2009-12-31T16:35:38Z | [
"python",
"3d",
"matplotlib",
"plot",
"scatter-plot"
] |
Memory requirments for large python list | 1,985,975 | <p>I was doing a foolish thing like</p>
<pre><code>from itertools import *
rows = combinations(range(0, 1140), 17)
all_rows = []
for row in rows:
all_rows.append(row)
</code></pre>
<p>No surprise I run out of memory address space (32 bit python 3.1)
My question i, how do I calculate how much memory address space ... | 5 | 2009-12-31T16:15:12Z | 1,986,007 | <p>You are asking for</p>
<p><a href="http://en.wikipedia.org/wiki/Binomial_coefficient" rel="nofollow">http://en.wikipedia.org/wiki/Binomial_coefficient</a></p>
<p><a href="http://www.brpreiss.com/books/opus7/programs/pgm14_10.txt" rel="nofollow">http://www.brpreiss.com/books/opus7/programs/pgm14_10.txt</a></p>
<p>... | 1 | 2009-12-31T16:26:26Z | [
"python",
"memory-management",
"32bit-64bit"
] |
Memory requirments for large python list | 1,985,975 | <p>I was doing a foolish thing like</p>
<pre><code>from itertools import *
rows = combinations(range(0, 1140), 17)
all_rows = []
for row in rows:
all_rows.append(row)
</code></pre>
<p>No surprise I run out of memory address space (32 bit python 3.1)
My question i, how do I calculate how much memory address space ... | 5 | 2009-12-31T16:15:12Z | 1,986,021 | <p>Well first rather than writing:</p>
<pre><code>all_rows = []
for row in rows:
all_rows.append(row)
</code></pre>
<p>You can simply write:</p>
<pre><code>all_rows = list(rows)
</code></pre>
<p>which will be quite a bit more efficient.</p>
<p>Then, there are two things to consider for memory consumption of a ... | 4 | 2009-12-31T16:29:47Z | [
"python",
"memory-management",
"32bit-64bit"
] |
Memory requirments for large python list | 1,985,975 | <p>I was doing a foolish thing like</p>
<pre><code>from itertools import *
rows = combinations(range(0, 1140), 17)
all_rows = []
for row in rows:
all_rows.append(row)
</code></pre>
<p>No surprise I run out of memory address space (32 bit python 3.1)
My question i, how do I calculate how much memory address space ... | 5 | 2009-12-31T16:15:12Z | 1,986,046 | <p>There's a handy function <a href="http://docs.python.org/library/sys.html#sys.getsizeof" rel="nofollow"><code>sys.getsizeof()</code></a> (since Python 2.6) that helps with this:</p>
<pre><code>>>> import sys
>>> sys.getsizeof(1) # integer
12
>>> sys.getsizeof([]) # empty list
36
>>... | 10 | 2009-12-31T16:35:36Z | [
"python",
"memory-management",
"32bit-64bit"
] |
Memory requirments for large python list | 1,985,975 | <p>I was doing a foolish thing like</p>
<pre><code>from itertools import *
rows = combinations(range(0, 1140), 17)
all_rows = []
for row in rows:
all_rows.append(row)
</code></pre>
<p>No surprise I run out of memory address space (32 bit python 3.1)
My question i, how do I calculate how much memory address space ... | 5 | 2009-12-31T16:15:12Z | 1,986,111 | <p>Addendum: Since you're dealing with lists of integers and worry about memory usage --- there is also the <a href="http://docs.python.org/library/array.html" rel="nofollow"><code>array</code></a>-module:</p>
<blockquote>
<p>[<code>array</code>] defines an object type which can compactly represent an array of basic... | 2 | 2009-12-31T16:47:54Z | [
"python",
"memory-management",
"32bit-64bit"
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.