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 |
|---|---|---|---|---|---|---|---|---|---|
Why should exec() and eval() be avoided? | 1,933,451 | <p>I've seen this multiple times in multiple places, but never have found a satisfying explanation as to why this should be the case. </p>
<p>So, hopefully, one will be presented here. Why should we (at least, generally) not use <code>exec()</code> and <code>eval()</code>?</p>
<p>EDIT: I see that people are assuming ... | 18 | 2009-12-19T16:58:08Z | 1,933,555 | <p>eval() and exec() can promote lazy programming. More importantly it indicates the code being executed may not have been written at design time therefore not tested. In other words, how do you test dynamically generated code? Especially across browsers.</p>
| 7 | 2009-12-19T17:22:19Z | [
"python"
] |
Why should exec() and eval() be avoided? | 1,933,451 | <p>I've seen this multiple times in multiple places, but never have found a satisfying explanation as to why this should be the case. </p>
<p>So, hopefully, one will be presented here. Why should we (at least, generally) not use <code>exec()</code> and <code>eval()</code>?</p>
<p>EDIT: I see that people are assuming ... | 18 | 2009-12-19T16:58:08Z | 1,933,703 | <p>I have used <code>eval()</code> in the past (and still do from time-to-time) for massaging data during quick and dirty operations. It is part of the toolkit that can be used for getting a job done, but should <strong>NEVER be used for anything you plan to use in production</strong> such as any command-line tools or... | 4 | 2009-12-19T18:12:13Z | [
"python"
] |
Why should exec() and eval() be avoided? | 1,933,451 | <p>I've seen this multiple times in multiple places, but never have found a satisfying explanation as to why this should be the case. </p>
<p>So, hopefully, one will be presented here. Why should we (at least, generally) not use <code>exec()</code> and <code>eval()</code>?</p>
<p>EDIT: I see that people are assuming ... | 18 | 2009-12-19T16:58:08Z | 1,933,723 | <p>When you need exec and eval, yeah, you really do need them.</p>
<p>But, the majority of the in-the-wild usage of these functions (and the similar constructs in other scripting languages) is totally inappropriate and could be replaced with other simpler constructs that are faster, more secure and have fewer bugs.</p... | 7 | 2009-12-19T18:20:30Z | [
"python"
] |
Why should exec() and eval() be avoided? | 1,933,451 | <p>I've seen this multiple times in multiple places, but never have found a satisfying explanation as to why this should be the case. </p>
<p>So, hopefully, one will be presented here. Why should we (at least, generally) not use <code>exec()</code> and <code>eval()</code>?</p>
<p>EDIT: I see that people are assuming ... | 18 | 2009-12-19T16:58:08Z | 1,934,554 | <p>In contrast to what most answers are saying here, exec is actually part of the recipe for building super-complete decorators in Python, as you can duplicate everything about the decorated function exactly, producing the same signature for the purposes of documentation and such. It's key to the functionality of the... | 7 | 2009-12-20T00:22:00Z | [
"python"
] |
How to refactor this python code block to be more efficient | 1,933,564 | <p>This code block works - it loops through a file that has a repeating number of sets of data
and extracts out each of the 5 pieces of information for each set.</p>
<p>But I I know that the current factoring is not as efficient as it can be since it is looping
through each key for each line found. </p>
<p>Wonderin... | 1 | 2009-12-19T17:25:31Z | 1,933,614 | <p>There is a lot of duplication there, and if you ever add another <code>key</code> or <code>param</code>, you're going to have to add it in many places, which leaves you ripe for errors. What you want to do is pare down all of the places you have repeated things and use some sort of data model, such as a <code>dict<... | 1 | 2009-12-19T17:41:45Z | [
"python"
] |
How to refactor this python code block to be more efficient | 1,933,564 | <p>This code block works - it loops through a file that has a repeating number of sets of data
and extracts out each of the 5 pieces of information for each set.</p>
<p>But I I know that the current factoring is not as efficient as it can be since it is looping
through each key for each line found. </p>
<p>Wonderin... | 1 | 2009-12-19T17:25:31Z | 1,933,619 | <p>It's not totally easy to see the expected format. From what I can see, the format is like:</p>
<pre><code>lines = [
"model.paramName 1 foo",
"model.paramValue 2 bar",
"model.optimizeParam 3 bat",
"model.paramLowerBound 4 zip",
"model.paramUpperBound 5 ech",
"model.paramName 1 foo2",
"mo... | 1 | 2009-12-19T17:43:47Z | [
"python"
] |
How to refactor this python code block to be more efficient | 1,933,564 | <p>This code block works - it loops through a file that has a repeating number of sets of data
and extracts out each of the 5 pieces of information for each set.</p>
<p>But I I know that the current factoring is not as efficient as it can be since it is looping
through each key for each line found. </p>
<p>Wonderin... | 1 | 2009-12-19T17:25:31Z | 1,933,630 | <p>It's not entirely obvious from your code, but it looks like each line can have one "hit" at most; if that's indeed the case, then something like:</p>
<pre><code>import re
def parse_params(num_of_params, lines):
sn = 'Names Params Optimize Upper Lower'.split()
ks = '''paramName paramValue optimizeParam
... | 1 | 2009-12-19T17:46:51Z | [
"python"
] |
How to refactor this python code block to be more efficient | 1,933,564 | <p>This code block works - it loops through a file that has a repeating number of sets of data
and extracts out each of the 5 pieces of information for each set.</p>
<p>But I I know that the current factoring is not as efficient as it can be since it is looping
through each key for each line found. </p>
<p>Wonderin... | 1 | 2009-12-19T17:25:31Z | 1,933,653 | <p>Though this doesn't answer your question (other answers are getting at that) something that has helped me a lot in doing things similar to what you're doing are <a href="http://docs.python.org/tutorial/datastructures.html#list-comprehensions" rel="nofollow">List Comprehensions</a>. They allow you to build lists in a... | 2 | 2009-12-19T17:52:38Z | [
"python"
] |
How to refactor this python code block to be more efficient | 1,933,564 | <p>This code block works - it loops through a file that has a repeating number of sets of data
and extracts out each of the 5 pieces of information for each set.</p>
<p>But I I know that the current factoring is not as efficient as it can be since it is looping
through each key for each line found. </p>
<p>Wonderin... | 1 | 2009-12-19T17:25:31Z | 1,933,673 | <p>The code given in the OP does multiple tests per line to try to match against the expected set of values, each of which is being constructed on the fly. Rather than construct <code>paramValue1</code>, <code>paramValue2</code>, etc. for each line, we can use a regular expression to try to do the matching in a cheaper... | 1 | 2009-12-19T18:01:35Z | [
"python"
] |
How to refactor this python code block to be more efficient | 1,933,564 | <p>This code block works - it loops through a file that has a repeating number of sets of data
and extracts out each of the 5 pieces of information for each set.</p>
<p>But I I know that the current factoring is not as efficient as it can be since it is looping
through each key for each line found. </p>
<p>Wonderin... | 1 | 2009-12-19T17:25:31Z | 1,933,684 | <p>Are you sure that parse_params is the bottle-neck? Have you profiled your app?</p>
<pre><code>import re
from collections import defaultdict
names = ("paramName paramValue optimizeParam "
"paramLowerBound paramUpperBound".split())
stmt_regex = re.compile(r'model\.(%s)\s+(\d+)\s+(.*)' % '|'.join(names))
d... | 1 | 2009-12-19T18:05:25Z | [
"python"
] |
How to refactor this python code block to be more efficient | 1,933,564 | <p>This code block works - it loops through a file that has a repeating number of sets of data
and extracts out each of the 5 pieces of information for each set.</p>
<p>But I I know that the current factoring is not as efficient as it can be since it is looping
through each key for each line found. </p>
<p>Wonderin... | 1 | 2009-12-19T17:25:31Z | 1,933,701 | <p>It can certainly be made more efficient. But, to be honest, unless this function is called hundreds of times a second, or works on thousands of lines, is it necessary?</p>
<p>I would be more concerned about making it clear what is happening... currently, I'm far from clear on that aspect.</p>
<p>Just eyeballing it... | 0 | 2009-12-19T18:11:14Z | [
"python"
] |
Deepcopy a simple Python object | 1,933,621 | <p>I have an object which defines a <code>__deepcopy__</code> method. I would like a function that will deepcopy it <em>not</em> by the method given by it, but in the default way that objects of the class <code>object</code> are copied.</p>
<p>How could I do that? I think I could try to code it but there are probably ... | 1 | 2009-12-19T17:44:12Z | 1,933,642 | <p>You basically need to override the existing <code>__deepcopy__</code> method, which means temporarily setting the object's class to something different -- whether that's acceptable essentially depends on whether the "<code>__deepcopy__</code> override" needs to affect only one, "top-level" object (in which case the... | 4 | 2009-12-19T17:50:46Z | [
"python",
"deep-copy"
] |
fonts clipping with PIL | 1,933,766 | <p>This image was created with PIL. See how the g's and the y's are cut off in this image? How can I prevent this?</p>
<p><img src="http://img109.imageshack.us/img109/8874/screenshotep.png" alt="" title=""></p>
<p>The code that created this image is pretty straight forward (abbreviated):</p>
<pre><code>import Image,... | 5 | 2009-12-19T18:38:52Z | 1,935,498 | <p>My suggestion is, before you create the image object, to get the required size for the text.</p>
<p>This is done using <code>font.getsize("text")</code> (<a href="http://effbot.org/imagingbook/imagefont.htm" rel="nofollow">documentation</a>).</p>
<p>In a image generating script I made, I first found the maximum he... | 0 | 2009-12-20T10:48:59Z | [
"python",
"python-imaging-library"
] |
fonts clipping with PIL | 1,933,766 | <p>This image was created with PIL. See how the g's and the y's are cut off in this image? How can I prevent this?</p>
<p><img src="http://img109.imageshack.us/img109/8874/screenshotep.png" alt="" title=""></p>
<p>The code that created this image is pretty straight forward (abbreviated):</p>
<pre><code>import Image,... | 5 | 2009-12-19T18:38:52Z | 9,080,169 | <p>I couldn't solve this problem for some fonts using the approaches mentioned so far, so I ended up using <a href="http://effbot.org/zone/aggdraw-index.htm" rel="nofollow">aggdraw</a> as a transparent replacement for PIL's text drawig methods.</p>
<p>Your code rewritten to aggdraw would look like:</p>
<pre><code>imp... | 0 | 2012-01-31T13:17:02Z | [
"python",
"python-imaging-library"
] |
fonts clipping with PIL | 1,933,766 | <p>This image was created with PIL. See how the g's and the y's are cut off in this image? How can I prevent this?</p>
<p><img src="http://img109.imageshack.us/img109/8874/screenshotep.png" alt="" title=""></p>
<p>The code that created this image is pretty straight forward (abbreviated):</p>
<pre><code>import Image,... | 5 | 2009-12-19T18:38:52Z | 9,791,755 | <p>The "bug" still exists in 2012, with Ubuntu 11.10. Fontsize 11, 12, 13 and 15 clip the underscore completely.</p>
<pre><code>#!/usr/bin/env python
""" demonstrates clipping of descenders for certain font sizes """
import Image, ImageDraw, ImageFont
fontPath = "/usr/share/fonts/truetype/ttf-dejavu/DejaVuSans-Bold.t... | 0 | 2012-03-20T17:19:38Z | [
"python",
"python-imaging-library"
] |
fonts clipping with PIL | 1,933,766 | <p>This image was created with PIL. See how the g's and the y's are cut off in this image? How can I prevent this?</p>
<p><img src="http://img109.imageshack.us/img109/8874/screenshotep.png" alt="" title=""></p>
<p>The code that created this image is pretty straight forward (abbreviated):</p>
<pre><code>import Image,... | 5 | 2009-12-19T18:38:52Z | 29,178,161 | <p>Here is an kludge that works well for me. It is a variant on gnud's answer. (Different enough to deserve a separate answer vs. comment I hope.) I have tested a lot of word placements and this has performed consistently.</p>
<p>When a text is drawn without fully reaching the full height of the font, clipping can occ... | 0 | 2015-03-21T01:15:22Z | [
"python",
"python-imaging-library"
] |
How do you clone a class in Python? | 1,933,784 | <p>I have a class A and i want a class B with exactly the same capabilities.
I cannot or do not want to inherit from B, such as doing class B(A):pass
Still i want B to be identical to A, yet have a different i: id(A) != id(B)
Watch out, i am not talking about instances but classes to be cloned.</p>
| 6 | 2009-12-19T18:45:46Z | 1,933,811 | <p>I'm pretty sure whatever you are trying to do can be solved in a better way, but here is something that gives you a clone of the class with a new id:</p>
<pre><code>def c():
class Clone(object):
pass
return Clone
c1 = c()
c2 = c()
print id(c1)
print id(c2)
</code></pre>
<p>gives:</p>
<pre><code>... | 13 | 2009-12-19T18:52:37Z | [
"python"
] |
How do you clone a class in Python? | 1,933,784 | <p>I have a class A and i want a class B with exactly the same capabilities.
I cannot or do not want to inherit from B, such as doing class B(A):pass
Still i want B to be identical to A, yet have a different i: id(A) != id(B)
Watch out, i am not talking about instances but classes to be cloned.</p>
| 6 | 2009-12-19T18:45:46Z | 1,933,816 | <p>You can clone the class via inheritance. Otherwise you are just passing around a reference to the class itself (rather than a reference to an instance of the class). Why would you want to duplicate the class anyway? It's obvious why you would want to create multiple instances of the class, but I can't fathom why ... | -1 | 2009-12-19T18:54:02Z | [
"python"
] |
How do you clone a class in Python? | 1,933,784 | <p>I have a class A and i want a class B with exactly the same capabilities.
I cannot or do not want to inherit from B, such as doing class B(A):pass
Still i want B to be identical to A, yet have a different i: id(A) != id(B)
Watch out, i am not talking about instances but classes to be cloned.</p>
| 6 | 2009-12-19T18:45:46Z | 1,933,845 | <pre><code>class C(object):
pass
class A(C):
pass
class B(C):
pass
</code></pre>
| -1 | 2009-12-19T19:04:08Z | [
"python"
] |
How do you clone a class in Python? | 1,933,784 | <p>I have a class A and i want a class B with exactly the same capabilities.
I cannot or do not want to inherit from B, such as doing class B(A):pass
Still i want B to be identical to A, yet have a different i: id(A) != id(B)
Watch out, i am not talking about instances but classes to be cloned.</p>
| 6 | 2009-12-19T18:45:46Z | 1,933,856 | <p>maybe i misunderstood you question but what about wrapping A in B?</p>
<pre><code>class A:
def foo(self):
print "A.foo"
class B:
def __init__(self):
self._i = A()
def __getattr__(self, n):
return getattr(self._i, n)
</code></pre>
| 0 | 2009-12-19T19:09:14Z | [
"python"
] |
How do you clone a class in Python? | 1,933,784 | <p>I have a class A and i want a class B with exactly the same capabilities.
I cannot or do not want to inherit from B, such as doing class B(A):pass
Still i want B to be identical to A, yet have a different i: id(A) != id(B)
Watch out, i am not talking about instances but classes to be cloned.</p>
| 6 | 2009-12-19T18:45:46Z | 1,933,863 | <p>I guess this is not what you wanted but its what the question seems to be asking for...</p>
<pre><code>class Foo(object):
def bar(self):
return "BAR!"
cls = type("Bar", (object,), dict(Foo.__dict__))
print cls
x = cls()
print x.bar()
</code></pre>
| 6 | 2009-12-19T19:12:10Z | [
"python"
] |
A pythonic way how to find if a value is between two values in a list | 1,933,919 | <p>Having a sorted list and some random value, I would like to find in which range the value is.</p>
<p>List goes like this: [0, 5, 10, 15, 20]
And value is, say 8.</p>
<p>The standard way would be to either go from start until we hit value that is bigger than ours (like in the example below), or to perform <a href="... | 7 | 2009-12-19T19:33:03Z | 1,933,932 | <pre><code>>>> import bisect
>>> grid = [0, 5, 10, 15, 20]
>>> value = 8
>>> bisect.bisect(grid, value)
2
</code></pre>
<p>Edit:</p>
<p><a href="http://docs.python.org/library/bisect.html">bisect â Array bisection algorithm</a></p>
| 20 | 2009-12-19T19:36:56Z | [
"list",
"grid",
"range",
"python",
"snapping"
] |
A pythonic way how to find if a value is between two values in a list | 1,933,919 | <p>Having a sorted list and some random value, I would like to find in which range the value is.</p>
<p>List goes like this: [0, 5, 10, 15, 20]
And value is, say 8.</p>
<p>The standard way would be to either go from start until we hit value that is bigger than ours (like in the example below), or to perform <a href="... | 7 | 2009-12-19T19:33:03Z | 1,933,974 | <pre><code>for min, max in zip(grid, grid[1:]): # [(0, 5), (5, 10), (10, 15), (15, 20), (20, 25)]
if max <= value < min: #previously: if value in xrange(min, max):
return min, max
raise ValueError("value out of range")
</code></pre>
| 1 | 2009-12-19T19:58:47Z | [
"list",
"grid",
"range",
"python",
"snapping"
] |
help with python urllib2 import error | 1,933,928 | <p>In my script, I've imported urrlib2 and the script was working fine. After reboot, I get the following error:</p>
<pre><code> File "demo.py", line 2, in <module>
import urllib2
File "/usr/lib/python2.6/urllib2.py", line 92, in <module>
import httplib
File "/usr/lib/python2.6/httplib.py", li... | 3 | 2009-12-19T19:35:37Z | 1,933,953 | <p>The usual answer is that you've got a file called <code>random.py</code> in the current directory when the script is running. <code>tempfile</code> would be accidentally importing that <code>random</code> and not the stdlib <code>random</code> module.</p>
| 5 | 2009-12-19T19:47:52Z | [
"python",
"import",
"urllib2"
] |
help with python urllib2 import error | 1,933,928 | <p>In my script, I've imported urrlib2 and the script was working fine. After reboot, I get the following error:</p>
<pre><code> File "demo.py", line 2, in <module>
import urllib2
File "/usr/lib/python2.6/urllib2.py", line 92, in <module>
import httplib
File "/usr/lib/python2.6/httplib.py", li... | 3 | 2009-12-19T19:35:37Z | 1,933,954 | <p>Check that <code>random</code> is the stdlib's module and not some arbitrary module with the same name from <code>sys.path</code>.</p>
<pre><code>>>> inspect.getabsfile(random)
</code></pre>
| 0 | 2009-12-19T19:48:55Z | [
"python",
"import",
"urllib2"
] |
Rotating Proxies for web scraping | 1,934,088 | <p>I've got a python web crawler and I want to distribute the download requests among many different proxy servers, probably running squid (though I'm open to alternatives). For example, it could work in a round-robin fashion, where request1 goes to proxy1, request2 to proxy2, and eventually looping back around. Any id... | 8 | 2009-12-19T20:46:21Z | 1,934,198 | <p>Make your crawler have a list of proxies and with each HTTP request let it use the next proxy from the list in a round robin fashion. However, this will prevent you from using HTTP/1.1 persistent connections. Modifying the proxy list will eventually result in using a new or not using a proxy.</p>
<p>Or have several... | 4 | 2009-12-19T21:30:18Z | [
"python",
"proxy",
"screen-scraping",
"web-crawler",
"squid"
] |
Rotating Proxies for web scraping | 1,934,088 | <p>I've got a python web crawler and I want to distribute the download requests among many different proxy servers, probably running squid (though I'm open to alternatives). For example, it could work in a round-robin fashion, where request1 goes to proxy1, request2 to proxy2, and eventually looping back around. Any id... | 8 | 2009-12-19T20:46:21Z | 8,612,054 | <p>I've setted up rotating proxies using HAProxy + DeleGate + Multiple Tor Instances. With Tor you don't have good control of bandwidth and latency but it's useful for web scraping. I've just published an article on the subject: <a href="http://blog.databigbang.com/running-your-own-anonymous-rotating-proxies/">Running ... | 11 | 2011-12-23T03:46:07Z | [
"python",
"proxy",
"screen-scraping",
"web-crawler",
"squid"
] |
Setting an alias to a Django "plug-in" app | 1,934,188 | <p>is there some pythonic way to load a django app trough an alias name? This I think would be one way to make an app more "pluggable-friendly".</p>
<p>there is a pattern used in settings.py:</p>
<pre><code>INSTALLED_APPS = ('... ','...', )
</code></pre>
<p>where <code>INSTALLED_APPS</code> is a tuple containing nam... | 2 | 2009-12-19T21:24:09Z | 1,934,230 | <p>Set</p>
<pre><code>LOGIN_APP_NAME = 'drupal_login' # or 'mediawiki_login', or whatever
</code></pre>
<p>early enough in settings.py, then put <code>LOGIN_APP_NAME</code> (without any quotes around it!) in your <code>INSTALLED_APPS</code> instead of the name of the actual app.</p>
<p>If you need more complex funct... | 4 | 2009-12-19T21:41:57Z | [
"python",
"django"
] |
Setting an alias to a Django "plug-in" app | 1,934,188 | <p>is there some pythonic way to load a django app trough an alias name? This I think would be one way to make an app more "pluggable-friendly".</p>
<p>there is a pattern used in settings.py:</p>
<pre><code>INSTALLED_APPS = ('... ','...', )
</code></pre>
<p>where <code>INSTALLED_APPS</code> is a tuple containing nam... | 2 | 2009-12-19T21:24:09Z | 1,936,834 | <p>Defining the app name in settings(as MichaÅ and your edit do) works well:</p>
<pre><code>EXTERNAL_LOGIN_APP = 'drupal_login'
INSTALLED_APPS = (
'...',
EXTERNAL_LOGIN_APP,
)
</code></pre>
<p>Also in settings, or in a common module, you could then factor in import... | 2 | 2009-12-20T20:04:16Z | [
"python",
"django"
] |
python - urrlib2 request https site - getting 400 error | 1,934,284 | <p>using the following snip of code to access a url with a post.</p>
<p>i can get it using wget and the following:
wget --post-data 'p_calling_proc=bwckschd.p_disp_dyn_sched&p_term=201010' <a href="https://spectrumssb2.memphis.edu/pls/PROD/bwckgens.p%5Fproc%5Fterm%5Fdate" rel="nofollow">https://spectrumssb2.memph... | 2 | 2009-12-19T22:18:35Z | 1,934,296 | <p>I think your query string is not quite right. Try using the urllib.urlencode() method to generate the query, a la</p>
<pre><code>urllib.urlencode([ ('param1', value1), ('param2',value2) ])
</code></pre>
| 0 | 2009-12-19T22:26:31Z | [
"python",
"https",
"parsing",
"request",
"urllib2"
] |
python - urrlib2 request https site - getting 400 error | 1,934,284 | <p>using the following snip of code to access a url with a post.</p>
<p>i can get it using wget and the following:
wget --post-data 'p_calling_proc=bwckschd.p_disp_dyn_sched&p_term=201010' <a href="https://spectrumssb2.memphis.edu/pls/PROD/bwckgens.p%5Fproc%5Fterm%5Fdate" rel="nofollow">https://spectrumssb2.memph... | 2 | 2009-12-19T22:18:35Z | 1,934,364 | <p>Try not encoding the query string. The &'s and ='s in the POST data don't need to be <a href="http://www.w3.org/MarkUp/html-spec/html-spec%5Ftoc.html#SEC8.2.1" rel="nofollow">urlencoded</a>. If the web app on the remote end does not expect the %xx encoding in the query string, it won't be able to parse it. </p>... | 1 | 2009-12-19T22:56:41Z | [
"python",
"https",
"parsing",
"request",
"urllib2"
] |
Python: incorporating index from for loop as part of a list name | 1,934,344 | <p>How does one generate a set of lists that incorporate the index from a for loop in the list name:</p>
<pre><code>for j in range(10):
li"j" = []
</code></pre>
<p>How can the index 'j' be part of the name, so the lists are li0, li1, li2, ...</p>
<p>Thanks!</p>
| 0 | 2009-12-19T22:49:01Z | 1,934,350 | <p>You can make <code>li</code> a <a href="http://docs.python.org/tutorial/datastructures.html#dictionaries" rel="nofollow">dictionary</a>:</p>
<pre><code>li = {}
for j in range(10):
li[j] = []
</code></pre>
| 9 | 2009-12-19T22:50:45Z | [
"python",
"list",
"indexing",
"for-loop"
] |
Python: incorporating index from for loop as part of a list name | 1,934,344 | <p>How does one generate a set of lists that incorporate the index from a for loop in the list name:</p>
<pre><code>for j in range(10):
li"j" = []
</code></pre>
<p>How can the index 'j' be part of the name, so the lists are li0, li1, li2, ...</p>
<p>Thanks!</p>
| 0 | 2009-12-19T22:49:01Z | 1,934,368 | <p>You can actually do this with exec, like so: </p>
<pre><code>exec ("li%s = []" % 4)
</code></pre>
<p>But don't do this. You almost certainly do not want dynamically named variables. Greg Hewgill's approach will probably solve your problem.</p>
| 0 | 2009-12-19T22:57:23Z | [
"python",
"list",
"indexing",
"for-loop"
] |
Python: incorporating index from for loop as part of a list name | 1,934,344 | <p>How does one generate a set of lists that incorporate the index from a for loop in the list name:</p>
<pre><code>for j in range(10):
li"j" = []
</code></pre>
<p>How can the index 'j' be part of the name, so the lists are li0, li1, li2, ...</p>
<p>Thanks!</p>
| 0 | 2009-12-19T22:49:01Z | 1,934,389 | <p>If you do this simply to initialize lists to use them later, you should instead use <em>one</em> multi-dimensional list or even better tuple to do this:</p>
<pre><code>li = tuple( [] for i in range( 10 ) )
li[0].append( 'foo' )
li[5].append( 'bar' )
</code></pre>
| 3 | 2009-12-19T23:03:08Z | [
"python",
"list",
"indexing",
"for-loop"
] |
Item assignment on bytes object in Python | 1,934,624 | <p>GAHH, code not working is bad code indeed!</p>
<blockquote>
<p>in RemoveRETNs
toOutput[currentLoc - 0x00400000] = b'\xCC' TypeError: 'bytes' object does not support item assignment</p>
</blockquote>
<p>How can I fix this:</p>
<pre><code>inputFile = 'original.exe'
outputFile = 'output.txt'
patchedFile = 'o... | 2 | 2009-12-20T01:16:16Z | 1,934,635 | <p>Bytestrings (and strings in general) are immutable objects in Python. Once you create them, you can't change them. Instead, you have to create a new one that happens to have some of the old content. (For instance, with a basic string, <code>newString = oldString[:offset] + newChar + oldString[offset+1:]</code> or th... | 4 | 2009-12-20T01:24:30Z | [
"python",
"python-3.x"
] |
Item assignment on bytes object in Python | 1,934,624 | <p>GAHH, code not working is bad code indeed!</p>
<blockquote>
<p>in RemoveRETNs
toOutput[currentLoc - 0x00400000] = b'\xCC' TypeError: 'bytes' object does not support item assignment</p>
</blockquote>
<p>How can I fix this:</p>
<pre><code>inputFile = 'original.exe'
outputFile = 'output.txt'
patchedFile = 'o... | 2 | 2009-12-20T01:16:16Z | 1,934,649 | <p>Change the <code>return</code> statement of <code>GetFileContents</code> into</p>
<pre><code>return bytearray(fileContents)
</code></pre>
<p>and the rest should work. You need to use <code>bytearray</code> rather than <code>bytes</code> simply because the former is read/write, the latter (which is what you're usi... | 10 | 2009-12-20T01:39:59Z | [
"python",
"python-3.x"
] |
How to execute Python scripts in Windows? | 1,934,675 | <p>I have a simple script blah.py (using Python 2):</p>
<pre><code>import sys
print sys.argv[1]
</code></pre>
<p>If I execute my script by:</p>
<pre><code>python c:/..../blah.py argument
</code></pre>
<p>It prints argument but if I execute script by:</p>
<pre><code>blah.py argument
</code></pre>
<p>error occurs:<... | 70 | 2009-12-20T02:09:25Z | 1,934,685 | <p>Can you execute python.exe from any map?
If you do not, chek if you have proper values for python.exe in PATH enviroment</p>
<p>Are you in same directory than blah.py. Check this by issuing command -> edit blah.py and check if you can open this file</p>
<p><strong>EDIT:</strong></p>
<p>In that case you can not. (... | 0 | 2009-12-20T02:21:05Z | [
"python",
"windows",
"scripting",
"command-line",
"file-association"
] |
How to execute Python scripts in Windows? | 1,934,675 | <p>I have a simple script blah.py (using Python 2):</p>
<pre><code>import sys
print sys.argv[1]
</code></pre>
<p>If I execute my script by:</p>
<pre><code>python c:/..../blah.py argument
</code></pre>
<p>It prints argument but if I execute script by:</p>
<pre><code>blah.py argument
</code></pre>
<p>error occurs:<... | 70 | 2009-12-20T02:09:25Z | 1,934,695 | <p>you should make the default application to handle python files be python.exe.</p>
<p>right click a *.py file, select "Open With" dialog. In there select "python.exe" and check "always use this program for this file type" (something like that).</p>
<p>then your python files will always be run using python.exe</p>
| 20 | 2009-12-20T02:32:28Z | [
"python",
"windows",
"scripting",
"command-line",
"file-association"
] |
How to execute Python scripts in Windows? | 1,934,675 | <p>I have a simple script blah.py (using Python 2):</p>
<pre><code>import sys
print sys.argv[1]
</code></pre>
<p>If I execute my script by:</p>
<pre><code>python c:/..../blah.py argument
</code></pre>
<p>It prints argument but if I execute script by:</p>
<pre><code>blah.py argument
</code></pre>
<p>error occurs:<... | 70 | 2009-12-20T02:09:25Z | 1,936,078 | <p>When you execute a script without typing "python" in front, you need to know two things about how Windows invokes the program. First is to find out what kind of file Windows thinks it is: </p>
<pre>
C:\>assoc .py
.py=Python.File
</pre>
<p>Next, you need to know how Windows is executing things with that ex... | 113 | 2009-12-20T15:05:41Z | [
"python",
"windows",
"scripting",
"command-line",
"file-association"
] |
How to execute Python scripts in Windows? | 1,934,675 | <p>I have a simple script blah.py (using Python 2):</p>
<pre><code>import sys
print sys.argv[1]
</code></pre>
<p>If I execute my script by:</p>
<pre><code>python c:/..../blah.py argument
</code></pre>
<p>It prints argument but if I execute script by:</p>
<pre><code>blah.py argument
</code></pre>
<p>error occurs:<... | 70 | 2009-12-20T02:09:25Z | 13,023,969 | <p>Additionally, if you want to be able to run your python scripts without typing the <code>.py</code> (or <code>.pyw</code>) on the end of the file name, you need to add <code>.PY</code> (or <code>.PY;.PYW</code>) to the list of extensions in the PATHEXT environment variable.</p>
<p>In Windows 7:</p>
<p>right-click ... | 10 | 2012-10-23T05:15:37Z | [
"python",
"windows",
"scripting",
"command-line",
"file-association"
] |
How to execute Python scripts in Windows? | 1,934,675 | <p>I have a simple script blah.py (using Python 2):</p>
<pre><code>import sys
print sys.argv[1]
</code></pre>
<p>If I execute my script by:</p>
<pre><code>python c:/..../blah.py argument
</code></pre>
<p>It prints argument but if I execute script by:</p>
<pre><code>blah.py argument
</code></pre>
<p>error occurs:<... | 70 | 2009-12-20T02:09:25Z | 13,025,018 | <blockquote>
<p>How to execute Python scripts in Windows?</p>
</blockquote>
<p>You could install <a href="https://bitbucket.org/vinay.sajip/pylauncher" rel="nofollow">pylauncher</a>. It is used to launch .py, .pyw, .pyc, .pyo files and supports multiple Python installations:</p>
<pre><code>T\:> blah.py argument
... | 2 | 2012-10-23T06:55:25Z | [
"python",
"windows",
"scripting",
"command-line",
"file-association"
] |
How to execute Python scripts in Windows? | 1,934,675 | <p>I have a simple script blah.py (using Python 2):</p>
<pre><code>import sys
print sys.argv[1]
</code></pre>
<p>If I execute my script by:</p>
<pre><code>python c:/..../blah.py argument
</code></pre>
<p>It prints argument but if I execute script by:</p>
<pre><code>blah.py argument
</code></pre>
<p>error occurs:<... | 70 | 2009-12-20T02:09:25Z | 20,108,000 | <p>I encountered the same problem but in the context of needing to package my code for Windows users (coming from Linux).
My package contains a number of scripts with command line options.</p>
<p>I need these scripts to get installed in the appropriate location on Windows users' machines so that they can invoke them f... | 3 | 2013-11-20T22:03:43Z | [
"python",
"windows",
"scripting",
"command-line",
"file-association"
] |
How to execute Python scripts in Windows? | 1,934,675 | <p>I have a simple script blah.py (using Python 2):</p>
<pre><code>import sys
print sys.argv[1]
</code></pre>
<p>If I execute my script by:</p>
<pre><code>python c:/..../blah.py argument
</code></pre>
<p>It prints argument but if I execute script by:</p>
<pre><code>blah.py argument
</code></pre>
<p>error occurs:<... | 70 | 2009-12-20T02:09:25Z | 22,439,338 | <p>Found an incredibly useful answer <a href="http://stackoverflow.com/questions/20786478/how-to-run-different-python-versions-in-cmd#20787033">here</a>: <strong>How to run different python versions in cmd?</strong></p>
<blockquote>
<p>I would suggest using the Python Launcher for Windows utility that introduced was... | 0 | 2014-03-16T16:13:43Z | [
"python",
"windows",
"scripting",
"command-line",
"file-association"
] |
How to execute Python scripts in Windows? | 1,934,675 | <p>I have a simple script blah.py (using Python 2):</p>
<pre><code>import sys
print sys.argv[1]
</code></pre>
<p>If I execute my script by:</p>
<pre><code>python c:/..../blah.py argument
</code></pre>
<p>It prints argument but if I execute script by:</p>
<pre><code>blah.py argument
</code></pre>
<p>error occurs:<... | 70 | 2009-12-20T02:09:25Z | 30,993,331 | <p>On <strong>Windows</strong>, </p>
<p>To <strong>run a python module without typing "python"</strong>,</p>
<p>--> Right click any python(*.py) file</p>
<p>--> Set the open with property to "python.exe" </p>
<p>--> Check the "always use this program for this file type"</p>
<p>--> Append the path of python.exe to ... | 1 | 2015-06-23T03:26:47Z | [
"python",
"windows",
"scripting",
"command-line",
"file-association"
] |
Combine matrix in numpy | 1,934,683 | <p>Suppose I have three "sheets" of matrix a,b and c, each with the same m*n*p dimension. And I want to combine them to get a new m*n*p*3 matrix whose (i,j,k) element is (a[i,j,k],b[i,j,k],c[i,j,k]). Which command should I use ? The dstack command seems not work here. Thanks.</p>
| 2 | 2009-12-20T02:17:25Z | 1,934,701 | <p>I think what you want is:</p>
<pre><code>np.concatenate([np.expand_dims(x, -1) for x in (a, b, c)], axis=3)
</code></pre>
| 2 | 2009-12-20T02:41:53Z | [
"python",
"numpy"
] |
Combine matrix in numpy | 1,934,683 | <p>Suppose I have three "sheets" of matrix a,b and c, each with the same m*n*p dimension. And I want to combine them to get a new m*n*p*3 matrix whose (i,j,k) element is (a[i,j,k],b[i,j,k],c[i,j,k]). Which command should I use ? The dstack command seems not work here. Thanks.</p>
| 2 | 2009-12-20T02:17:25Z | 1,934,712 | <p>Another one liner would be:</p>
<pre><code>result = numpy.array( (a,b,c) ).transpose( (1,2,3,0) )
</code></pre>
<p>or a more self-descriptive method:</p>
<pre><code>result = empty( (m,n,p,3) )
result[:,:,:,0] = a
result[:,:,:,1] = b
result[:,:,:,2] = c
</code></pre>
| 4 | 2009-12-20T03:03:21Z | [
"python",
"numpy"
] |
Xpath builder in Python | 1,934,720 | <p>I'm building relatively complicated xpath expressions in Python, in order to pass them to selenium. However, its pretty easy to make a mistake, so I'm looking for a library that allows me to build the expressions without messing about with strings. For example, instead of writing</p>
<pre><code>locator='//ul[@class... | 4 | 2009-12-20T03:11:02Z | 1,934,773 | <p>You can use <a href="http://codespeak.net/lxml/tutorial.html#the-e-factory" rel="nofollow" title="lxml.etree">lxml.etree</a> that allows to write code as the following:</p>
<pre><code>from lxml.builder import ElementMaker # lxml only !
E = ElementMaker(namespace="http://my.de/fault/namespace", nsmap={'p' : "http:/... | 0 | 2009-12-20T03:53:22Z | [
"python",
"xml",
"xpath",
"selenium"
] |
Xpath builder in Python | 1,934,720 | <p>I'm building relatively complicated xpath expressions in Python, in order to pass them to selenium. However, its pretty easy to make a mistake, so I'm looking for a library that allows me to build the expressions without messing about with strings. For example, instead of writing</p>
<pre><code>locator='//ul[@class... | 4 | 2009-12-20T03:11:02Z | 1,936,038 | <p>though this is not exactly what you want.. you can use css selector</p>
<pre><code>...
import lxml.cssselect
csssel = 'div[class="main"]'
selobj = lxml.cssselect.CSSSelector(csssel)
elements = selobj(documenttree)
</code></pre>
<p>generated XPath expression is in <code>selobj.path</code></p>
<pre><code>>>&g... | 1 | 2009-12-20T14:49:30Z | [
"python",
"xml",
"xpath",
"selenium"
] |
numpy to matlab interface with mlabwrap | 1,934,740 | <p>I am looking for a simple way to visualize some of my data in numpy, and I discovered the <code>mlabwrap</code> package which looks really promising. I am trying to create a simple plot with the ability to be updated as the data changes. </p>
<p>Here is the matlab code that I am trying to duplicate</p>
<pre><code>... | 6 | 2009-12-20T03:25:38Z | 1,934,821 | <p>Maybe mlab is mad that you're not saving matlab's return value for that set() call...</p>
<p>I don't have this installed, what does <code>someval = mlab.set(h,'XData')</code> give?</p>
<p>edit: you could also try using nout... <code>mlab.set(h,'XData',[0,0,0],nout=0)</code></p>
| 6 | 2009-12-20T04:16:07Z | [
"python",
"matlab",
"interface",
"mlabwrap"
] |
numpy to matlab interface with mlabwrap | 1,934,740 | <p>I am looking for a simple way to visualize some of my data in numpy, and I discovered the <code>mlabwrap</code> package which looks really promising. I am trying to create a simple plot with the ability to be updated as the data changes. </p>
<p>Here is the matlab code that I am trying to duplicate</p>
<pre><code>... | 6 | 2009-12-20T03:25:38Z | 1,934,845 | <p>Since <code>set</code> takes no output arguments, we need to tell <code>mlabwrap</code> that no output arguments should be given to it to avoid the error message above.</p>
<pre><code>mlab.set(h, 'XData', [0,0,0], nout=0)
</code></pre>
| 5 | 2009-12-20T04:26:18Z | [
"python",
"matlab",
"interface",
"mlabwrap"
] |
Python, Threads, the GIL, and C++ | 1,934,898 | <p>Is there some way to make boost::python control the Python GIL for every interaction with python? </p>
<p>I am writing a project with boost::python. I am trying to write a C++ wrapper for an external library, and control the C++ library with python scripts. I cannot change the external library, only my wrapper pr... | 1 | 2009-12-20T04:56:04Z | 1,935,084 | <p>I found a really obscure post on the mailing list that said to use
PyEval_InitThreads();
in BOOST_PYTHON_MODULE
and that actually seemed to stop the crashes.</p>
<p>Its still a crap shoot whether it the program reports all the messages it got or not. If i send 2000, most of the time it says it got 2000, but somet... | 3 | 2009-12-20T07:03:23Z | [
"c++",
"python",
"c",
"multithreading",
"boost-python"
] |
Python, Threads, the GIL, and C++ | 1,934,898 | <p>Is there some way to make boost::python control the Python GIL for every interaction with python? </p>
<p>I am writing a project with boost::python. I am trying to write a C++ wrapper for an external library, and control the C++ library with python scripts. I cannot change the external library, only my wrapper pr... | 1 | 2009-12-20T04:56:04Z | 2,119,205 | <p>Don't know about your problem exactly, but take a look at CallPolicies:</p>
<p><a href="http://www.boost.org/doc/libs/1_37_0/libs/python/doc/v2/CallPolicies.html#CallPolicies-concept">http://www.boost.org/doc/libs/1_37_0/libs/python/doc/v2/CallPolicies.html#CallPolicies-concept</a></p>
<p>You can define new call p... | 4 | 2010-01-22T17:37:43Z | [
"c++",
"python",
"c",
"multithreading",
"boost-python"
] |
Python, Threads, the GIL, and C++ | 1,934,898 | <p>Is there some way to make boost::python control the Python GIL for every interaction with python? </p>
<p>I am writing a project with boost::python. I am trying to write a C++ wrapper for an external library, and control the C++ library with python scripts. I cannot change the external library, only my wrapper pr... | 1 | 2009-12-20T04:56:04Z | 3,475,173 | <p>I think the best approach is to avoid the GIL and ensure your interaction with python is single-threaded.</p>
<p>I'm designing a boost.python based test tool at the moment and think I'll probably use a producer/consumer queue to dispatch events from the multi-threaded libraries which will be read sequentially by th... | 1 | 2010-08-13T08:34:06Z | [
"c++",
"python",
"c",
"multithreading",
"boost-python"
] |
Displaying graphics on top of another full screen application; hardware overlay? | 1,934,910 | <p>On Windows (Vista32), I want to display some simple graphics on top of a fullscreen flash window (an overlay of useful information while using the flash application). What's the fastest way to accomplish it?</p>
<p>I think I may be able to achieve it using DirectX with the DDSCAPS_OVERLAY flag but with the only exa... | 0 | 2009-12-20T05:02:44Z | 1,942,558 | <p>Just create a Layered Window and draw to it with an alpha channel - in WPF, this is as easy as setting the AllowsTransparency bit on the Window</p>
| 1 | 2009-12-21T20:52:27Z | [
"c++",
"python",
"windows",
"flash",
"directx"
] |
Displaying graphics on top of another full screen application; hardware overlay? | 1,934,910 | <p>On Windows (Vista32), I want to display some simple graphics on top of a fullscreen flash window (an overlay of useful information while using the flash application). What's the fastest way to accomplish it?</p>
<p>I think I may be able to achieve it using DirectX with the DDSCAPS_OVERLAY flag but with the only exa... | 0 | 2009-12-20T05:02:44Z | 1,949,129 | <p>While the transparent layered window is useful, it doesn't appear on top of the fullscreen flash with WS_EX_TOPMOST set.</p>
<p>Note sure how to reply to Paul sadly.</p>
<p><a href="http://stackoverflow.com/questions/925981/overlaying-on-a-3d-fullscreen-application">http://stackoverflow.com/questions/925981/overla... | 0 | 2009-12-22T21:04:08Z | [
"c++",
"python",
"windows",
"flash",
"directx"
] |
Why use Django on Google App Engine? | 1,934,914 | <p>When researching Google App Engine (GAE), it's clear that using Django is wildly popular for developing in Python on GAE. I've been scouring the web to find information on the costs and benefits of using Django, to find out <em>why</em> it's so popular. While I've been able to find a wide variety of sources on <em... | 78 | 2009-12-20T05:03:45Z | 1,934,918 | <p>I have experience using Django and not GAE. From my experiences with Django it was a very simplistic setup and the deployment process was incredibly easy in terms of web projects. Granted I had to learn Python to really get a good hold on things, but at the end of the day I would use it again on a project. This w... | 2 | 2009-12-20T05:07:30Z | [
"python",
"django",
"google-app-engine"
] |
Why use Django on Google App Engine? | 1,934,914 | <p>When researching Google App Engine (GAE), it's clear that using Django is wildly popular for developing in Python on GAE. I've been scouring the web to find information on the costs and benefits of using Django, to find out <em>why</em> it's so popular. While I've been able to find a wide variety of sources on <em... | 78 | 2009-12-20T05:03:45Z | 1,934,925 | <p>Django probably isn't the right choice for you, if you're sure that GAE is right for you. The strengths of the two technologies don't align very well - you completely lose a lot of Django's wonderful orm on GAE, and if you do use it, you write code that isn't really directly suitable to bigtable and the way GAE work... | 48 | 2009-12-20T05:17:02Z | [
"python",
"django",
"google-app-engine"
] |
Why use Django on Google App Engine? | 1,934,914 | <p>When researching Google App Engine (GAE), it's clear that using Django is wildly popular for developing in Python on GAE. I've been scouring the web to find information on the costs and benefits of using Django, to find out <em>why</em> it's so popular. While I've been able to find a wide variety of sources on <em... | 78 | 2009-12-20T05:03:45Z | 1,934,951 | <p>I've done lots of projects on GAE. Some in django, some in their normal framework.</p>
<p>For small things, I usually use their normal framework for simplicity and quickness. Like <a href="http://stdicon.com">http://stdicon.com</a>, <a href="http://yaml-online-parser.appspot.com/">http://yaml-online-parser.appspot.... | 15 | 2009-12-20T05:31:57Z | [
"python",
"django",
"google-app-engine"
] |
Why use Django on Google App Engine? | 1,934,914 | <p>When researching Google App Engine (GAE), it's clear that using Django is wildly popular for developing in Python on GAE. I've been scouring the web to find information on the costs and benefits of using Django, to find out <em>why</em> it's so popular. While I've been able to find a wide variety of sources on <em... | 78 | 2009-12-20T05:03:45Z | 1,935,061 | <p>I cannot answer the question but you may want to look into web2py. It is similar to Django in many respects but its database abstraction layer works on GAE and supports most of the GAE functionality (not all but we try to catch up). In this way if GAE works for you great, if it does not, you can move your code to a ... | 0 | 2009-12-20T06:39:26Z | [
"python",
"django",
"google-app-engine"
] |
Why use Django on Google App Engine? | 1,934,914 | <p>When researching Google App Engine (GAE), it's clear that using Django is wildly popular for developing in Python on GAE. I've been scouring the web to find information on the costs and benefits of using Django, to find out <em>why</em> it's so popular. While I've been able to find a wide variety of sources on <em... | 78 | 2009-12-20T05:03:45Z | 1,935,686 | <p>We use django on our appengine instances mostly when we have to serve actual websites to the user. It has a great template engine, url routing and all the request/response/error handling built in. So even while we can't use the magic orm/admin stuff it has a lot going for it.</p>
<p>For api services we built someth... | 18 | 2009-12-20T12:26:29Z | [
"python",
"django",
"google-app-engine"
] |
Why use Django on Google App Engine? | 1,934,914 | <p>When researching Google App Engine (GAE), it's clear that using Django is wildly popular for developing in Python on GAE. I've been scouring the web to find information on the costs and benefits of using Django, to find out <em>why</em> it's so popular. While I've been able to find a wide variety of sources on <em... | 78 | 2009-12-20T05:03:45Z | 1,942,826 | <p>If you decide to run you app outside of GAE, you can still use Django. You won't really have that much luck with the GAE webapp</p>
| -1 | 2009-12-21T21:46:36Z | [
"python",
"django",
"google-app-engine"
] |
Why use Django on Google App Engine? | 1,934,914 | <p>When researching Google App Engine (GAE), it's clear that using Django is wildly popular for developing in Python on GAE. I've been scouring the web to find information on the costs and benefits of using Django, to find out <em>why</em> it's so popular. While I've been able to find a wide variety of sources on <em... | 78 | 2009-12-20T05:03:45Z | 2,988,728 | <p>I am still very new to Google App engine development, but the interfaces Django provides do appear much nicer than the default. The benefits will depend on what you are using to run Django on the app engine. The Google App Engine Helper for Django allows you to use the full power of the Google App Engine with some D... | 0 | 2010-06-07T10:36:12Z | [
"python",
"django",
"google-app-engine"
] |
Why use Django on Google App Engine? | 1,934,914 | <p>When researching Google App Engine (GAE), it's clear that using Django is wildly popular for developing in Python on GAE. I've been scouring the web to find information on the costs and benefits of using Django, to find out <em>why</em> it's so popular. While I've been able to find a wide variety of sources on <em... | 78 | 2009-12-20T05:03:45Z | 28,627,569 | <p>I think all this answers are a bit obsolete.</p>
<p>Now you can use <code>Google Cloud SQL</code></p>
<blockquote>
<p>Django is a popular third-party Python web framework. <strong>When coupled
with Google Cloud SQL, all of its functionality can be <em>fully</em> supported
by applications running on App Engin... | 8 | 2015-02-20T11:10:12Z | [
"python",
"django",
"google-app-engine"
] |
__del__ method being called in python when it is not expected | 1,935,153 | <p>I am new to python and have been working through the examples in Swaroop CH's "A Byte of Python". I am seeing some behavior with the <code>__del__</code> method that is puzzling me. </p>
<p>Basically, if I run the following script (in Python 2.6.2) </p>
<pre><code>class Person4:
'''Represents a person'''
... | 6 | 2009-12-20T07:42:46Z | 1,935,179 | <p>There are a couple of things going on here. When your <code>Person4</code> class is instantiated, it initialises its <code>population</code> class variable to 0. From your interactive console, you appear to be running your "test1.py" file multiple times. The second time you run it, the <code>Person4</code> class is ... | 18 | 2009-12-20T07:54:26Z | [
"python",
"object-lifetime",
"del"
] |
__del__ method being called in python when it is not expected | 1,935,153 | <p>I am new to python and have been working through the examples in Swaroop CH's "A Byte of Python". I am seeing some behavior with the <code>__del__</code> method that is puzzling me. </p>
<p>Basically, if I run the following script (in Python 2.6.2) </p>
<pre><code>class Person4:
'''Represents a person'''
... | 6 | 2009-12-20T07:42:46Z | 1,935,560 | <p>General advice: don't use __ del __ in Python. It can break garbage collection in a number of ways, esp. in the case of circular references between objects.</p>
<p>In your example, there're various issues related to the usage of execfile() - which is not a best practice - and the redefinition of global variables. B... | 6 | 2009-12-20T11:26:30Z | [
"python",
"object-lifetime",
"del"
] |
how do I add a python module on MacOS X? | 1,935,290 | <p>I'm trying to use pywn, a python library for using WordNet. I've played about with python a little under Windows, but am completely new at MacOS X stuff. I'm running under MacOS 10.5.8, so my default Python interpreter is 2.5.1</p>
<p>The pywn instructions say: "Put each of the .py files somewhere in your python se... | 0 | 2009-12-20T08:52:40Z | 1,935,309 | <p>Try <code>print sys.path</code> from a Python shell. This will tell you what directories Python is searching for modules.</p>
<p>It is set via a combination of an environment variable (<code>PYTHONPATH</code>) and a base set of directories specific to your installation.</p>
<p>For more info: <a href="http://docs.p... | 4 | 2009-12-20T09:01:00Z | [
"python",
"osx",
"module-search-path"
] |
how do I add a python module on MacOS X? | 1,935,290 | <p>I'm trying to use pywn, a python library for using WordNet. I've played about with python a little under Windows, but am completely new at MacOS X stuff. I'm running under MacOS 10.5.8, so my default Python interpreter is 2.5.1</p>
<p>The pywn instructions say: "Put each of the .py files somewhere in your python se... | 0 | 2009-12-20T08:52:40Z | 1,935,323 | <p>I think by default <code>/Library/Python/2.5/site-packages/</code> is part of your search path. This directory is usually used for third party libraries.</p>
| 3 | 2009-12-20T09:09:33Z | [
"python",
"osx",
"module-search-path"
] |
how do I add a python module on MacOS X? | 1,935,290 | <p>I'm trying to use pywn, a python library for using WordNet. I've played about with python a little under Windows, but am completely new at MacOS X stuff. I'm running under MacOS 10.5.8, so my default Python interpreter is 2.5.1</p>
<p>The pywn instructions say: "Put each of the .py files somewhere in your python se... | 0 | 2009-12-20T08:52:40Z | 1,935,635 | <p>More generally, if you do not have enough administrative rights to modify the system, or if you want to keep some modules in your home directory, you can either do:</p>
<pre><code>import sys
sys.path.append('/Users/nick/programming/')
import pywn
</code></pre>
<p>You can alternatively add /Users/nick/programming t... | 3 | 2009-12-20T12:03:09Z | [
"python",
"osx",
"module-search-path"
] |
how do I add a python module on MacOS X? | 1,935,290 | <p>I'm trying to use pywn, a python library for using WordNet. I've played about with python a little under Windows, but am completely new at MacOS X stuff. I'm running under MacOS 10.5.8, so my default Python interpreter is 2.5.1</p>
<p>The pywn instructions say: "Put each of the .py files somewhere in your python se... | 0 | 2009-12-20T08:52:40Z | 17,975,757 | <p>Simply use: </p>
<pre><code>easy_install [LIBRARY NAME]
</code></pre>
<p>By the way... need to be root so before that:</p>
<pre><code>su root
</code></pre>
| 1 | 2013-07-31T16:22:11Z | [
"python",
"osx",
"module-search-path"
] |
How to extract the first hit elements from an XML NCBI BLAST file? | 1,935,385 | <p>Im trying to extract only the first hit from an NCBI xml BLAST file. next I would like to get only the first HSP. at the final stage I would like to get these based on best score.
to make things clear here a sample of the xml file:</p>
<pre><code><?xml version="1.0"?>
<!DOCTYPE BlastOutput PUBLIC "-//NCBI/... | 6 | 2009-12-20T09:44:19Z | 1,937,694 | <p>While building your own parser may be "fun" there is already a package out there that can parse BLAST xml files ... it can even do the intermediate calling of a local BLAST instance for you if you so desire.</p>
<p>The main site is here:
<a href="http://biopython.org/wiki/Main_Page" rel="nofollow">http://biopython.... | 7 | 2009-12-21T01:03:29Z | [
"python",
"xml",
"bioinformatics",
"elementtree",
"ncbi"
] |
How to extract the first hit elements from an XML NCBI BLAST file? | 1,935,385 | <p>Im trying to extract only the first hit from an NCBI xml BLAST file. next I would like to get only the first HSP. at the final stage I would like to get these based on best score.
to make things clear here a sample of the xml file:</p>
<pre><code><?xml version="1.0"?>
<!DOCTYPE BlastOutput PUBLIC "-//NCBI/... | 6 | 2009-12-20T09:44:19Z | 2,167,213 | <p>I'll second what JudoWill suggested - work smarter, not harder with the BioPython parser.
This should get you a little further:</p>
<pre><code>from Bio.Blast import NCBIXML
blast = NCBIXML.parse(open('results.xml','rU'))
for record in blast:
if record.alignments:
# to print the "best" matches e-score
... | 5 | 2010-01-30T07:44:18Z | [
"python",
"xml",
"bioinformatics",
"elementtree",
"ncbi"
] |
How to extract the first hit elements from an XML NCBI BLAST file? | 1,935,385 | <p>Im trying to extract only the first hit from an NCBI xml BLAST file. next I would like to get only the first HSP. at the final stage I would like to get these based on best score.
to make things clear here a sample of the xml file:</p>
<pre><code><?xml version="1.0"?>
<!DOCTYPE BlastOutput PUBLIC "-//NCBI/... | 6 | 2009-12-20T09:44:19Z | 4,800,957 | <p>If I understand your basic requirement then you want to get the top hit/HSP of the query protein/nucleotide sequence.Why dont you install the standalone blast on your system with formatted nr/nt database.
Type the options</p>
<pre><code>blastall -p {blast programme blastp for protein,blastn for nucleotide} -d {data... | 1 | 2011-01-26T02:35:28Z | [
"python",
"xml",
"bioinformatics",
"elementtree",
"ncbi"
] |
File searching: TypeError | 1,935,465 | <p>Im trying to search a file where the the line containing the search term is found and printed along with a number of lines before and after the search term defined by the user. The coding i have so far is: </p>
<pre><code>f = open(f, 'r')
d = {}
for n, line in enumerate(f):
d[n%numb] = line.rstrip()
if sear... | 1 | 2009-12-20T10:23:39Z | 1,935,471 | <p>You haven't specified what <code>numb</code> is, but I'm guessing it's something like:</p>
<pre><code>numb = sys.argv[1]
</code></pre>
<p>The <code>sys.argv</code> is an array of strings, rather than integers. Try converting the string to an integer:</p>
<pre><code>numb = int(sys.argv[1])
</code></pre>
| 1 | 2009-12-20T10:27:26Z | [
"python"
] |
File searching: TypeError | 1,935,465 | <p>Im trying to search a file where the the line containing the search term is found and printed along with a number of lines before and after the search term defined by the user. The coding i have so far is: </p>
<pre><code>f = open(f, 'r')
d = {}
for n, line in enumerate(f):
d[n%numb] = line.rstrip()
if sear... | 1 | 2009-12-20T10:23:39Z | 1,935,513 | <p>n % numb can have different meanings, depending on the type of n and numb. If they are both numbers it means "take the modulus" which I presume is what you intend. If n is a string then it means do % formatting. If n is a number and numb is a string Python does not know what to do and raises a TypeError. Did you... | 0 | 2009-12-20T10:59:09Z | [
"python"
] |
pyfacebook and javascript query | 1,935,636 | <p>I'm using pyfacebook on the backend and javascript on the client side. Now if I want to pass a variable to the javascript from pyfacebook. how would I go about doing that, any ideas?</p>
| 0 | 2009-12-20T12:04:18Z | 1,935,664 | <p>You can't pass a variable directly, as JavaScript is running on the client (browser), and Python is running on the server.
You could make a XHR (AJAX) request from JavaScript to the server which would then return your values back to JS (JSON could be used here).
Or you could put a hidden field to your markup that wo... | 1 | 2009-12-20T12:14:24Z | [
"javascript",
"python"
] |
Python send cmd on socket | 1,935,939 | <p>I have a simple question about Python:</p>
<p>I have another Python script listening on a port on a Linux machine.
I have made it so I can send a request to it, and it will inform another system that it is alive and listening.</p>
<p>My problem is that I don't know how to send this request from another python scri... | 3 | 2009-12-20T14:14:48Z | 1,935,965 | <p>This is a bit outside my knowledge, but maybe this question might help?</p>
<p><a href="http://stackoverflow.com/questions/316866/ping-a-site-in-python">Ping a site in Python?</a></p>
| 0 | 2009-12-20T14:23:05Z | [
"python",
"sockets"
] |
Python send cmd on socket | 1,935,939 | <p>I have a simple question about Python:</p>
<p>I have another Python script listening on a port on a Linux machine.
I have made it so I can send a request to it, and it will inform another system that it is alive and listening.</p>
<p>My problem is that I don't know how to send this request from another python scri... | 3 | 2009-12-20T14:14:48Z | 1,935,968 | <p>Considered <a href="http://www.twistedmatrix.com" rel="nofollow">Twisted</a>? What you're trying to achieve could be taken straight out of their <a href="http://twistedmatrix.com/documents/current/core/examples/" rel="nofollow">examples</a>. It might be overkill, but if you'll eventually want to start adding authent... | 0 | 2009-12-20T14:23:22Z | [
"python",
"sockets"
] |
Python send cmd on socket | 1,935,939 | <p>I have a simple question about Python:</p>
<p>I have another Python script listening on a port on a Linux machine.
I have made it so I can send a request to it, and it will inform another system that it is alive and listening.</p>
<p>My problem is that I don't know how to send this request from another python scri... | 3 | 2009-12-20T14:14:48Z | 1,935,988 | <p>It looks like you are doing an HTTP request, rather than an ICMP ping.</p>
<p><a href="http://www.voidspace.org.uk/python/articles/urllib2.shtml#sockets-and-layers" rel="nofollow">urllib2</a>, built-in to Python, can help you do that.</p>
<p>You'll need to override the timeout so you aren't hanging too long. Strai... | 4 | 2009-12-20T14:30:30Z | [
"python",
"sockets"
] |
Python send cmd on socket | 1,935,939 | <p>I have a simple question about Python:</p>
<p>I have another Python script listening on a port on a Linux machine.
I have made it so I can send a request to it, and it will inform another system that it is alive and listening.</p>
<p>My problem is that I don't know how to send this request from another python scri... | 3 | 2009-12-20T14:14:48Z | 1,936,923 | <pre><code>import urllib2
try:
response = urllib2.urlopen('http://192.168.1.46:8193/?Ping', timeout=2)
print 'response headers: "%s"' % response.info()
except IOError, e:
if hasattr(e, 'code'): # HTTPError
print 'http error code: ', e.code
elif hasattr(e, 'reason'): # URLError
print "c... | 2 | 2009-12-20T20:29:43Z | [
"python",
"sockets"
] |
Excluding last element in 0-based indexing | 1,935,990 | <p>Once when I was reading some python docs I came across a reference to an article that explained why programming languages with 0-based indexing should always exclude the last element during operations like slicing:</p>
<pre><code>>> a = [1, 2, 3]
>> a[0:1]
[1] #and not [1,2]
</code></pre>
<p>Unfortuna... | 2 | 2009-12-20T14:31:01Z | 1,936,018 | <p>Don't know any specific article, but I think the rationale is simply that this way you get the number of resulting elements via simple subtraction, 1-0=1, instead of having to add 1 there (which you would forget half of the time anyway).</p>
| 0 | 2009-12-20T14:40:44Z | [
"python",
"arrays",
"programming-languages"
] |
Excluding last element in 0-based indexing | 1,935,990 | <p>Once when I was reading some python docs I came across a reference to an article that explained why programming languages with 0-based indexing should always exclude the last element during operations like slicing:</p>
<pre><code>>> a = [1, 2, 3]
>> a[0:1]
[1] #and not [1,2]
</code></pre>
<p>Unfortuna... | 2 | 2009-12-20T14:31:01Z | 1,936,019 | <p>No, but there are at least two good reasons:</p>
<ol>
<li><code>a[m:n]</code> gives you <em>n</em>-<em>m</em> elements, making it easy to compute how many elements you are requesting.</li>
<li>With inclusive end-points, it's awkward to request an empty slice (<code>a[3:2]</code>? yuck).</li>
</ol>
<p><strong>Edit:... | 5 | 2009-12-20T14:41:37Z | [
"python",
"arrays",
"programming-languages"
] |
Excluding last element in 0-based indexing | 1,935,990 | <p>Once when I was reading some python docs I came across a reference to an article that explained why programming languages with 0-based indexing should always exclude the last element during operations like slicing:</p>
<pre><code>>> a = [1, 2, 3]
>> a[0:1]
[1] #and not [1,2]
</code></pre>
<p>Unfortuna... | 2 | 2009-12-20T14:31:01Z | 1,936,046 | <p>You might be thinking of <a href="http://nedbatchelder.com/blog/200909/why%5Fnumbering%5Fshould%5Fstart%5Fat%5Fzero.html" rel="nofollow">Dijkstra's short note about zero-based numbering</a>.</p>
| 3 | 2009-12-20T14:52:02Z | [
"python",
"arrays",
"programming-languages"
] |
Excluding last element in 0-based indexing | 1,935,990 | <p>Once when I was reading some python docs I came across a reference to an article that explained why programming languages with 0-based indexing should always exclude the last element during operations like slicing:</p>
<pre><code>>> a = [1, 2, 3]
>> a[0:1]
[1] #and not [1,2]
</code></pre>
<p>Unfortuna... | 2 | 2009-12-20T14:31:01Z | 1,936,048 | <p>Could it be <a href="http://www.cs.utexas.edu/~EWD/ewd08xx/EWD831.PDF" rel="nofollow">this note</a> from E. W. Dijkstra?</p>
| 8 | 2009-12-20T14:52:55Z | [
"python",
"arrays",
"programming-languages"
] |
Excluding last element in 0-based indexing | 1,935,990 | <p>Once when I was reading some python docs I came across a reference to an article that explained why programming languages with 0-based indexing should always exclude the last element during operations like slicing:</p>
<pre><code>>> a = [1, 2, 3]
>> a[0:1]
[1] #and not [1,2]
</code></pre>
<p>Unfortuna... | 2 | 2009-12-20T14:31:01Z | 1,936,066 | <p>I don't know exactly which article you are referring to, but Googling <a href="http://www.google.com/search?q=half-open+ranges" rel="nofollow">half-open ranges</a> should find it for you. It found <a href="http://www.siliconbrain.com/ranges.htm" rel="nofollow">this surprisingly good one</a> that I think is a new pe... | 1 | 2009-12-20T14:58:58Z | [
"python",
"arrays",
"programming-languages"
] |
Excluding last element in 0-based indexing | 1,935,990 | <p>Once when I was reading some python docs I came across a reference to an article that explained why programming languages with 0-based indexing should always exclude the last element during operations like slicing:</p>
<pre><code>>> a = [1, 2, 3]
>> a[0:1]
[1] #and not [1,2]
</code></pre>
<p>Unfortuna... | 2 | 2009-12-20T14:31:01Z | 1,936,400 | <p>As far as I know, the first extensive treatment in print was in Koenig's great book, <a href="http://rads.stackoverflow.com/amzn/click/0201179288" rel="nofollow">C Traps and Pitfalls</a> -- 20 years old and still in print (indeed, in-stock and shipped immediately from Amazon!-), quite a tribute to its nature as a cl... | 1 | 2009-12-20T17:23:07Z | [
"python",
"arrays",
"programming-languages"
] |
wxPython - DatePickerCtrl seems to ignore SetValue() | 1,936,074 | <p>I'm trying to pre-populate a wxPython DatePicker with a value using the following code:</p>
<pre><code>month, day, year = runData[2][0:8].split('/')
displayDate = wx.DateTimeFromDMY(int(day), int(month) - 1, int(year))
self.datePicker.SetValue(displayDate)
</code></pre>
<p>Here are the printed values:</p>
<ul>
<l... | 4 | 2009-12-20T15:02:17Z | 1,936,722 | <p>Have you tried making year 2009 instead of 9?</p>
| 2 | 2009-12-20T19:33:04Z | [
"python",
"wxpython"
] |
Can I do Django & Python web development using Xcode 3.2? | 1,936,080 | <p>I'm not sure but I believe that Python is -next to Objective-C- somewhat natural to Mac OSX and the Xcode IDE. I might be wrong. So is it a good idea to use Xcode for Django / Python web development when I'm already a bit familiar with Xcode? Actually I only do iPhone dev with it, but now I need a website and I stum... | 2 | 2009-12-20T15:06:02Z | 1,936,092 | <p>You can use XCode to program on Django, as it's plain Python 2.x and <a href="http://zovirl.com/2006/07/13/xcode-python/" rel="nofollow">XCode is a good tool for Python</a>.</p>
<p>Make sure that you learn the <a href="http://dougalmatthews.com/articles/2009/dec/14/django-its-just-python/" rel="nofollow">pythonic c... | 5 | 2009-12-20T15:08:45Z | [
"python",
"django"
] |
Can I do Django & Python web development using Xcode 3.2? | 1,936,080 | <p>I'm not sure but I believe that Python is -next to Objective-C- somewhat natural to Mac OSX and the Xcode IDE. I might be wrong. So is it a good idea to use Xcode for Django / Python web development when I'm already a bit familiar with Xcode? Actually I only do iPhone dev with it, but now I need a website and I stum... | 2 | 2009-12-20T15:06:02Z | 1,936,093 | <p>I wouldn't suggest XCode for python/django development - it's another world. An editor may be sufficient. A list of IDEs for python can be found here: <a href="http://stackoverflow.com/questions/81584/what-ide-to-use-for-python">http://stackoverflow.com/questions/81584/what-ide-to-use-for-python</a></p>
| 6 | 2009-12-20T15:08:54Z | [
"python",
"django"
] |
Can I do Django & Python web development using Xcode 3.2? | 1,936,080 | <p>I'm not sure but I believe that Python is -next to Objective-C- somewhat natural to Mac OSX and the Xcode IDE. I might be wrong. So is it a good idea to use Xcode for Django / Python web development when I'm already a bit familiar with Xcode? Actually I only do iPhone dev with it, but now I need a website and I stum... | 2 | 2009-12-20T15:06:02Z | 1,936,102 | <p>I think Eclipse+Pydev Plugin is a good choice!!</p>
| 2 | 2009-12-20T15:13:41Z | [
"python",
"django"
] |
Is it true that I can't use curly braces in Python? | 1,936,190 | <p>I was reading that Python does all it's "code blocks" by indentation, rather than with curly braces. Is that right? So functions, if's and stuff like that all appear without surrounding their block with curly braces?</p>
| 21 | 2009-12-20T15:57:52Z | 1,936,194 | <p>Yes.</p>
<pre><code>if True:
#dosomething
else:
#dosomething else
#continue on with whatever you were doing
</code></pre>
<p>Basically, wherever you would've had an opening curly brace, use a colon instead. Unindent to close the region. It doesn't take long for it to feel completely natural.</p>
| 6 | 2009-12-20T15:59:43Z | [
"python"
] |
Is it true that I can't use curly braces in Python? | 1,936,190 | <p>I was reading that Python does all it's "code blocks" by indentation, rather than with curly braces. Is that right? So functions, if's and stuff like that all appear without surrounding their block with curly braces?</p>
| 21 | 2009-12-20T15:57:52Z | 1,936,195 | <p>Yup :)</p>
<p>And there's (usually) a difference between 4 spaces and a tab, so make sure you standardize the usage ..</p>
| 8 | 2009-12-20T15:59:50Z | [
"python"
] |
Is it true that I can't use curly braces in Python? | 1,936,190 | <p>I was reading that Python does all it's "code blocks" by indentation, rather than with curly braces. Is that right? So functions, if's and stuff like that all appear without surrounding their block with curly braces?</p>
| 21 | 2009-12-20T15:57:52Z | 1,936,197 | <p>Yes. Curly braces are not used. Instead, you use the <code>:</code> symbol to introduce new blocks, like so:</p>
<pre><code>if True:
do_something()
something_else()
else:
something()
</code></pre>
| 22 | 2009-12-20T16:00:20Z | [
"python"
] |
Is it true that I can't use curly braces in Python? | 1,936,190 | <p>I was reading that Python does all it's "code blocks" by indentation, rather than with curly braces. Is that right? So functions, if's and stuff like that all appear without surrounding their block with curly braces?</p>
| 21 | 2009-12-20T15:57:52Z | 1,936,200 | <p>Correct for code blocks. However, you do define dictionaries in Python using curly braces:</p>
<pre><code>a_dict = {
'key': 'value',
}
</code></pre>
<p>Ahhhhhh.</p>
| 24 | 2009-12-20T16:01:43Z | [
"python"
] |
Is it true that I can't use curly braces in Python? | 1,936,190 | <p>I was reading that Python does all it's "code blocks" by indentation, rather than with curly braces. Is that right? So functions, if's and stuff like that all appear without surrounding their block with curly braces?</p>
| 21 | 2009-12-20T15:57:52Z | 1,936,210 | <pre><code>if foo: #{
print "it's true"
#}
else: #{
print "it's false!"
#}
</code></pre>
<p>(Obviously, this is a joke.)</p>
| 189 | 2009-12-20T16:04:23Z | [
"python"
] |
Is it true that I can't use curly braces in Python? | 1,936,190 | <p>I was reading that Python does all it's "code blocks" by indentation, rather than with curly braces. Is that right? So functions, if's and stuff like that all appear without surrounding their block with curly braces?</p>
| 21 | 2009-12-20T15:57:52Z | 1,936,223 | <p>You can try to add support for braces using a <a href="http://python.org/doc/2.5.2/ref/future.html">future import</a> statement, but it's not yet supported, so you'll get a syntax error:</p>
<pre><code>>>> from __future__ import braces
File "<stdin>", line 1
SyntaxError: not a chance
</code></pre>
| 68 | 2009-12-20T16:07:44Z | [
"python"
] |
Is it true that I can't use curly braces in Python? | 1,936,190 | <p>I was reading that Python does all it's "code blocks" by indentation, rather than with curly braces. Is that right? So functions, if's and stuff like that all appear without surrounding their block with curly braces?</p>
| 21 | 2009-12-20T15:57:52Z | 1,936,380 | <p>As others have mentioned, you are correct, no curly braces in Python. Also, you do not have no <em>end</em> or <em>endif</em> or <em>endfor</em> or anything like that (as in pascal or ruby). All code blocks are indentation based.</p>
| 3 | 2009-12-20T17:10:08Z | [
"python"
] |
Is it true that I can't use curly braces in Python? | 1,936,190 | <p>I was reading that Python does all it's "code blocks" by indentation, rather than with curly braces. Is that right? So functions, if's and stuff like that all appear without surrounding their block with curly braces?</p>
| 21 | 2009-12-20T15:57:52Z | 6,305,655 | <p>Use Whyton:</p>
<p><a href="http://writeonly.wordpress.com/2010/04/01/whython-python-for-people-who-hate-whitespace/">http://writeonly.wordpress.com/2010/04/01/whython-python-for-people-who-hate-whitespace/</a></p>
| 8 | 2011-06-10T11:24:03Z | [
"python"
] |
Is it true that I can't use curly braces in Python? | 1,936,190 | <p>I was reading that Python does all it's "code blocks" by indentation, rather than with curly braces. Is that right? So functions, if's and stuff like that all appear without surrounding their block with curly braces?</p>
| 21 | 2009-12-20T15:57:52Z | 15,169,048 | <p>Yes, code blocks in Python are defined by their indentation. The creators of Python were very interested in self-documenting code. They included indentation in the syntax as a way of innately enforcing good formatting practice.</p>
<p>I programmed in Python for a few years and became quite fond of its code struct... | 1 | 2013-03-02T00:12:48Z | [
"python"
] |
Is it true that I can't use curly braces in Python? | 1,936,190 | <p>I was reading that Python does all it's "code blocks" by indentation, rather than with curly braces. Is that right? So functions, if's and stuff like that all appear without surrounding their block with curly braces?</p>
| 21 | 2009-12-20T15:57:52Z | 21,665,382 | <p><a href="http://python-with-braces.appspot.com/" rel="nofollow">Python with Braces</a> is a variant of python that lets you do exactly that.
It's a project that I've been working on lately together with my friend.</p>
| 2 | 2014-02-09T21:37:14Z | [
"python"
] |
Is it true that I can't use curly braces in Python? | 1,936,190 | <p>I was reading that Python does all it's "code blocks" by indentation, rather than with curly braces. Is that right? So functions, if's and stuff like that all appear without surrounding their block with curly braces?</p>
| 21 | 2009-12-20T15:57:52Z | 22,060,351 | <p>Python does not use curly braces:</p>
<pre><code>>>> from __future__ import braces
File "<stdin>", line 1
SyntaxError: not a chance
>>> while True {
File "<stdin>", line 1
while True {
^
SyntaxError: invalid syntax
</code></pre>
<p>As a language designed to be ... | 0 | 2014-02-27T06:05:27Z | [
"python"
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.