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 listlengths 1 5 |
|---|---|---|---|---|---|---|---|---|---|
For list unless empty in python | 1,531,402 | <p>I've been writing a lot of constructs like this the past couple of days:</p>
<pre><code>list = get_list()
if list:
for i in list:
pass # do something with the list
else:
pass # do something if the list was empty
</code></pre>
<p>Lot of junk and I assign the list to a real variable (keeping it in me... | 12 | 2009-10-07T12:43:07Z | 1,531,525 | <p>Use a list comprehension:</p>
<pre><code>def do_something(x):
return x**2
list = []
result = [do_something(x) for x in list if list]
print result # []
list = [1, 2, 3]
result = [do_something(x) for x in list if list]
print result # [1, 4, 9]
</code></pre>
| 7 | 2009-10-07T13:05:42Z | [
"for-loop",
"python"
] |
For list unless empty in python | 1,531,402 | <p>I've been writing a lot of constructs like this the past couple of days:</p>
<pre><code>list = get_list()
if list:
for i in list:
pass # do something with the list
else:
pass # do something if the list was empty
</code></pre>
<p>Lot of junk and I assign the list to a real variable (keeping it in me... | 12 | 2009-10-07T12:43:07Z | 1,533,325 | <p>If your actions are <strong>different</strong>, I would do:</p>
<pre><code>list_ = get_list() # underscore to keep built-in list
if not list_:
# do something
for i in list_: #
# do something for each item
</code></pre>
<p>If your actions are <strong>similar</strong>, this is more beautiful:</p>
<pre><code... | 1 | 2009-10-07T18:21:44Z | [
"for-loop",
"python"
] |
For list unless empty in python | 1,531,402 | <p>I've been writing a lot of constructs like this the past couple of days:</p>
<pre><code>list = get_list()
if list:
for i in list:
pass # do something with the list
else:
pass # do something if the list was empty
</code></pre>
<p>Lot of junk and I assign the list to a real variable (keeping it in me... | 12 | 2009-10-07T12:43:07Z | 1,534,260 | <p>Based on the other answers, I think the cleanest solutions are</p>
<pre><code>#Handles None return from get_list
for item in get_list() or []:
pass #do something
</code></pre>
<p>or the comprehension equiv</p>
<pre><code>result = [item*item for item in get_list() or []]
</code></pre>
| 16 | 2009-10-07T21:21:24Z | [
"for-loop",
"python"
] |
For list unless empty in python | 1,531,402 | <p>I've been writing a lot of constructs like this the past couple of days:</p>
<pre><code>list = get_list()
if list:
for i in list:
pass # do something with the list
else:
pass # do something if the list was empty
</code></pre>
<p>Lot of junk and I assign the list to a real variable (keeping it in me... | 12 | 2009-10-07T12:43:07Z | 1,534,275 | <p>I think your way is ok in general case, but you may consider this approach:</p>
<pre><code>def do_something(item):
pass # do something with the list
def action_when_empty():
pass # do something if the list was empty
# and here goes your example
yourlist = get_list() or []
another_list = [do_something(x) for... | 1 | 2009-10-07T21:23:12Z | [
"for-loop",
"python"
] |
For list unless empty in python | 1,531,402 | <p>I've been writing a lot of constructs like this the past couple of days:</p>
<pre><code>list = get_list()
if list:
for i in list:
pass # do something with the list
else:
pass # do something if the list was empty
</code></pre>
<p>Lot of junk and I assign the list to a real variable (keeping it in me... | 12 | 2009-10-07T12:43:07Z | 5,340,888 | <pre><code>i = None
for i in get_list():
pass # do something with the list
else:
if i is None:
pass # do something if the list was empty
</code></pre>
<p>Does that help? Yes I know we are two years away from the need :-)</p>
| -1 | 2011-03-17T15:03:36Z | [
"for-loop",
"python"
] |
JSON serialization of Google App Engine models | 1,531,501 | <p>I've been searching for quite a while with no success. My project isn't using Django, is there a simple way to serialize App Engine models (google.appengine.ext.db.Model) into JSON or do I need to write my own serializer? </p>
<p><strong>Model:</strong></p>
<pre><code>class Photo(db.Model):
filename = db.Stri... | 83 | 2009-10-07T13:01:17Z | 1,531,539 | <p>Even if you are not using django as a framework, those libraries are still available for you to use. </p>
<pre><code>from django.core import serializers
data = serializers.serialize("xml", Photo.objects.all())
</code></pre>
| 3 | 2009-10-07T13:07:50Z | [
"python",
"json",
"google-app-engine"
] |
JSON serialization of Google App Engine models | 1,531,501 | <p>I've been searching for quite a while with no success. My project isn't using Django, is there a simple way to serialize App Engine models (google.appengine.ext.db.Model) into JSON or do I need to write my own serializer? </p>
<p><strong>Model:</strong></p>
<pre><code>class Photo(db.Model):
filename = db.Stri... | 83 | 2009-10-07T13:01:17Z | 1,531,555 | <p>You don't need to write your own "parser" (a parser would presumably turn JSON into a Python object), but you can still serialize your Python object yourself.</p>
<p>Using <a href="http://simplejson.googlecode.com/svn/tags/simplejson-2.0.9/docs/index.html" rel="nofollow">simplejson</a>:</p>
<pre><code>import simpl... | 4 | 2009-10-07T13:11:26Z | [
"python",
"json",
"google-app-engine"
] |
JSON serialization of Google App Engine models | 1,531,501 | <p>I've been searching for quite a while with no success. My project isn't using Django, is there a simple way to serialize App Engine models (google.appengine.ext.db.Model) into JSON or do I need to write my own serializer? </p>
<p><strong>Model:</strong></p>
<pre><code>class Photo(db.Model):
filename = db.Stri... | 83 | 2009-10-07T13:01:17Z | 1,532,035 | <p>A simple recursive function can be used to convert an entity (and any referents) to a nested dictionary that can be passed to <code>simplejson</code>:</p>
<pre><code>import datetime
import time
SIMPLE_TYPES = (int, long, float, bool, dict, basestring, list)
def to_dict(model):
output = {}
for key, prop i... | 60 | 2009-10-07T14:36:52Z | [
"python",
"json",
"google-app-engine"
] |
JSON serialization of Google App Engine models | 1,531,501 | <p>I've been searching for quite a while with no success. My project isn't using Django, is there a simple way to serialize App Engine models (google.appengine.ext.db.Model) into JSON or do I need to write my own serializer? </p>
<p><strong>Model:</strong></p>
<pre><code>class Photo(db.Model):
filename = db.Stri... | 83 | 2009-10-07T13:01:17Z | 1,532,108 | <p>For simple cases, I like the approach advocated <a href="http://skonieczny.pl/blog/it-should-just-work/post/2009/04/30/json-serialization-of-google-app-engine-models/" rel="nofollow">here</a> at the end of the article:</p>
<pre><code> # after obtaining a list of entities in some way, e.g.:
user = users.get_curre... | 4 | 2009-10-07T14:45:23Z | [
"python",
"json",
"google-app-engine"
] |
JSON serialization of Google App Engine models | 1,531,501 | <p>I've been searching for quite a while with no success. My project isn't using Django, is there a simple way to serialize App Engine models (google.appengine.ext.db.Model) into JSON or do I need to write my own serializer? </p>
<p><strong>Model:</strong></p>
<pre><code>class Photo(db.Model):
filename = db.Stri... | 83 | 2009-10-07T13:01:17Z | 1,535,243 | <p>If you use <a href="http://code.google.com/p/app-engine-patch/" rel="nofollow">app-engine-patch</a> it will automatically declare the <code>_meta</code> attribute for you, and then you can use <code>django.core.serializers</code> as you would normally do on django models (as in sledge's code).</p>
<p>App-engine-pat... | 2 | 2009-10-08T02:05:25Z | [
"python",
"json",
"google-app-engine"
] |
JSON serialization of Google App Engine models | 1,531,501 | <p>I've been searching for quite a while with no success. My project isn't using Django, is there a simple way to serialize App Engine models (google.appengine.ext.db.Model) into JSON or do I need to write my own serializer? </p>
<p><strong>Model:</strong></p>
<pre><code>class Photo(db.Model):
filename = db.Stri... | 83 | 2009-10-07T13:01:17Z | 2,305,601 | <p>This is the simplest solution I found. It requires only 3 lines of codes.</p>
<p>Simply add a method to your model to return a dictionary:</p>
<pre><code>class DictModel(db.Model):
def to_dict(self):
return dict([(p, unicode(getattr(self, p))) for p in self.properties()])
</code></pre>
<p>SimpleJSON no... | 58 | 2010-02-21T10:42:46Z | [
"python",
"json",
"google-app-engine"
] |
JSON serialization of Google App Engine models | 1,531,501 | <p>I've been searching for quite a while with no success. My project isn't using Django, is there a simple way to serialize App Engine models (google.appengine.ext.db.Model) into JSON or do I need to write my own serializer? </p>
<p><strong>Model:</strong></p>
<pre><code>class Photo(db.Model):
filename = db.Stri... | 83 | 2009-10-07T13:01:17Z | 2,598,073 | <p>There's a method, "Model.properties()", defined for all Model classes. It returns the dict you seek.</p>
<pre><code>from django.utils import simplejson
class Photo(db.Model):
# ...
my_photo = Photo(...)
simplejson.dumps(my_photo.properties())
</code></pre>
<p>See <a href="http://code.google.com/appengine/docs/... | 1 | 2010-04-08T06:51:39Z | [
"python",
"json",
"google-app-engine"
] |
JSON serialization of Google App Engine models | 1,531,501 | <p>I've been searching for quite a while with no success. My project isn't using Django, is there a simple way to serialize App Engine models (google.appengine.ext.db.Model) into JSON or do I need to write my own serializer? </p>
<p><strong>Model:</strong></p>
<pre><code>class Photo(db.Model):
filename = db.Stri... | 83 | 2009-10-07T13:01:17Z | 3,063,649 | <p>To serialize models, add a custom json encoder as in the following python:</p>
<pre><code>import datetime
from google.appengine.api import users
from google.appengine.ext import db
from django.utils import simplejson
class jsonEncoder(simplejson.JSONEncoder):
def default(self, obj):
if isinstance(obj, ... | 7 | 2010-06-17T16:39:10Z | [
"python",
"json",
"google-app-engine"
] |
JSON serialization of Google App Engine models | 1,531,501 | <p>I've been searching for quite a while with no success. My project isn't using Django, is there a simple way to serialize App Engine models (google.appengine.ext.db.Model) into JSON or do I need to write my own serializer? </p>
<p><strong>Model:</strong></p>
<pre><code>class Photo(db.Model):
filename = db.Stri... | 83 | 2009-10-07T13:01:17Z | 3,588,306 | <p>Mtgred's answer above worked wonderfully for me -- I slightly modified it so I could also get the key for the entry. Not as few lines of code, but it gives me the unique key:</p>
<pre><code>class DictModel(db.Model):
def to_dict(self):
tempdict1 = dict([(p, unicode(getattr(self, p))) for p in self.properties()... | 1 | 2010-08-27T21:38:00Z | [
"python",
"json",
"google-app-engine"
] |
JSON serialization of Google App Engine models | 1,531,501 | <p>I've been searching for quite a while with no success. My project isn't using Django, is there a simple way to serialize App Engine models (google.appengine.ext.db.Model) into JSON or do I need to write my own serializer? </p>
<p><strong>Model:</strong></p>
<pre><code>class Photo(db.Model):
filename = db.Stri... | 83 | 2009-10-07T13:01:17Z | 6,829,471 | <p>In the latest (1.5.2) release of the App Engine SDK, a <code>to_dict()</code> function that converts model instances to dictionaries was introduced in <code>db.py</code>. See the <a href="http://code.google.com/p/googleappengine/wiki/SdkReleaseNotes#Version_1.5.2_-_July_21,_2011">release notes</a>. </p>
<p>There i... | 15 | 2011-07-26T11:43:18Z | [
"python",
"json",
"google-app-engine"
] |
JSON serialization of Google App Engine models | 1,531,501 | <p>I've been searching for quite a while with no success. My project isn't using Django, is there a simple way to serialize App Engine models (google.appengine.ext.db.Model) into JSON or do I need to write my own serializer? </p>
<p><strong>Model:</strong></p>
<pre><code>class Photo(db.Model):
filename = db.Stri... | 83 | 2009-10-07T13:01:17Z | 9,452,999 | <p>I've extended the JSON Encoder class written by <a href="http://stackoverflow.com/a/3063649">dpatru</a> to support:</p>
<ul>
<li>Query results properties (e.g. car.owner_set)</li>
<li>ReferenceProperty - recursively turn it into JSON</li>
<li><p>Filtering properties - only properties with a <code>verbose_name</code... | 2 | 2012-02-26T12:18:31Z | [
"python",
"json",
"google-app-engine"
] |
JSON serialization of Google App Engine models | 1,531,501 | <p>I've been searching for quite a while with no success. My project isn't using Django, is there a simple way to serialize App Engine models (google.appengine.ext.db.Model) into JSON or do I need to write my own serializer? </p>
<p><strong>Model:</strong></p>
<pre><code>class Photo(db.Model):
filename = db.Stri... | 83 | 2009-10-07T13:01:17Z | 10,399,944 | <p>As mentioned by <a href="http://stackoverflow.com/users/806432/fredva">http://stackoverflow.com/users/806432/fredva</a>, the to_dict works great. Here is my code i'm using.</p>
<pre><code>foos = query.fetch(10)
prepJson = []
for f in foos:
prepJson.append(db.to_dict(f))
myJson = json.dumps(prepJson))
</code></p... | 2 | 2012-05-01T15:26:03Z | [
"python",
"json",
"google-app-engine"
] |
JSON serialization of Google App Engine models | 1,531,501 | <p>I've been searching for quite a while with no success. My project isn't using Django, is there a simple way to serialize App Engine models (google.appengine.ext.db.Model) into JSON or do I need to write my own serializer? </p>
<p><strong>Model:</strong></p>
<pre><code>class Photo(db.Model):
filename = db.Stri... | 83 | 2009-10-07T13:01:17Z | 19,205,188 | <p>To serialize a Datastore Model instance you can't use json.dumps (haven't tested but Lorenzo pointed it out). Maybe in the future the following will work.</p>
<p><a href="http://docs.python.org/2/library/json.html" rel="nofollow">http://docs.python.org/2/library/json.html</a></p>
<pre><code>import json
string = js... | 0 | 2013-10-06T03:43:36Z | [
"python",
"json",
"google-app-engine"
] |
How to yank an entire block in Vim? | 1,531,551 | <p>Is it possible to yank an entire block of Python code in Vim?</p>
<p>Be it a <code>def</code>, <code>for</code>, <code>if</code>, etc. block...</p>
| 17 | 2009-10-07T13:10:07Z | 1,531,576 | <p>You can yank a paragraph with <code>y}</code>. This will not yank all the methods if you have a blank line though.</p>
| 18 | 2009-10-07T13:15:24Z | [
"python",
"vim"
] |
How to yank an entire block in Vim? | 1,531,551 | <p>Is it possible to yank an entire block of Python code in Vim?</p>
<p>Be it a <code>def</code>, <code>for</code>, <code>if</code>, etc. block...</p>
| 17 | 2009-10-07T13:10:07Z | 1,531,578 | <p>There's a vim add-on script <a href="http://www.vim.org/scripts/script.php?script%5Fid=30" rel="nofollow">python_fn.vim</a> which has, as one of its functions, a key binding to visually select a block of Python code using <code>]v</code>. You could then yank it with <code>y</code> as normal.</p>
| 4 | 2009-10-07T13:15:30Z | [
"python",
"vim"
] |
How to yank an entire block in Vim? | 1,531,551 | <p>Is it possible to yank an entire block of Python code in Vim?</p>
<p>Be it a <code>def</code>, <code>for</code>, <code>if</code>, etc. block...</p>
| 17 | 2009-10-07T13:10:07Z | 1,531,977 | <p>I usually just use visual block mode. Shift-V, move, and 'y'ank the highlighted block. There's only so many shortcuts I can keep in memory at once :) </p>
| 3 | 2009-10-07T14:27:09Z | [
"python",
"vim"
] |
How to yank an entire block in Vim? | 1,531,551 | <p>Is it possible to yank an entire block of Python code in Vim?</p>
<p>Be it a <code>def</code>, <code>for</code>, <code>if</code>, etc. block...</p>
| 17 | 2009-10-07T13:10:07Z | 1,534,960 | <ol>
<li>Enter visual line selection by pressing 'V'</li>
<li>When finished selecting the block pres 'y'</li>
<li>Paste it somewhere with 'p' or 'P'</li>
</ol>
| 3 | 2009-10-08T00:18:11Z | [
"python",
"vim"
] |
How to yank an entire block in Vim? | 1,531,551 | <p>Is it possible to yank an entire block of Python code in Vim?</p>
<p>Be it a <code>def</code>, <code>for</code>, <code>if</code>, etc. block...</p>
| 17 | 2009-10-07T13:10:07Z | 1,534,987 | <p>You can combine a search with yank, so if your function ends with <code>return retval</code> you can type <code>y/return retval</code></p>
| 3 | 2009-10-08T00:32:07Z | [
"python",
"vim"
] |
How to yank an entire block in Vim? | 1,531,551 | <p>Is it possible to yank an entire block of Python code in Vim?</p>
<p>Be it a <code>def</code>, <code>for</code>, <code>if</code>, etc. block...</p>
| 17 | 2009-10-07T13:10:07Z | 4,533,586 | <p>If you want to yank everything except the <code>{</code> use <code>yi{</code> (or <code>yi}</code>). If you to include the curly braces use <code>ya{</code> (or <code>ya}</code>). </p>
<p>The <code>i</code> and <code>a</code> modifiers mean <em>in</em> and <em>all</em>. </p>
<p>To yank a word no matter where in... | 5 | 2010-12-26T11:01:13Z | [
"python",
"vim"
] |
How to yank an entire block in Vim? | 1,531,551 | <p>Is it possible to yank an entire block of Python code in Vim?</p>
<p>Be it a <code>def</code>, <code>for</code>, <code>if</code>, etc. block...</p>
| 17 | 2009-10-07T13:10:07Z | 11,173,312 | <p>I made a plugin named <a href="http://www.vim.org/scripts/script.php?script_id=3997" rel="nofollow">spacebox</a> which does a Visual selection of all lines with the same or more indentation as the current line.</p>
<p>With Python whitespace being the way it is, you could place your cursor on the line below <code>de... | 1 | 2012-06-23T21:58:47Z | [
"python",
"vim"
] |
How to yank an entire block in Vim? | 1,531,551 | <p>Is it possible to yank an entire block of Python code in Vim?</p>
<p>Be it a <code>def</code>, <code>for</code>, <code>if</code>, etc. block...</p>
| 17 | 2009-10-07T13:10:07Z | 11,723,792 | <p>The excellent add-on suite <a href="https://github.com/klen/python-mode">Python-mode</a> includes some <a href="https://github.com/klen/python-mode#default-keys">key commands</a> to navigate classes, methods, and function blocks.</p>
<ul>
<li><p>To yank a method: <kbd>y</kbd><kbd>a</kbd><kbd>M</kbd> (inner method: ... | 5 | 2012-07-30T14:42:03Z | [
"python",
"vim"
] |
Double import in grok | 1,531,647 | <p>This is a normal case of mutual import. Suppose you have the following layout</p>
<pre><code>./test.py
./one
./one/__init__.py
./one/two
./one/two/__init__.py
./one/two/m.py
./one/two/three
./one/two/three/__init__.py
./one/two/three/four
./one/two/three/four/__init__.py
./one/two/three/four/e.py
./one/two/u.py
</c... | 0 | 2009-10-07T13:28:17Z | 1,531,809 | <p>This could possibly be a side-effect of the introspection Grok does, I'm not sure.</p>
<p>Try to put a pdb.set_trace() in m, and check at the stack trace to see what is importing the modules.</p>
| 0 | 2009-10-07T13:56:25Z | [
"python",
"grok"
] |
What are some useful non-built-in Django tags? | 1,532,021 | <p>I'm relatively new to Django and I'm trying to build up my toolbox for future projects. In my last project, when a built-in template tag didn't do quite what I needed, I would make a mangled mess of the template to shoe-horn in the feature. I later would find a template tag that would have saved me time and ugly c... | 3 | 2009-10-07T14:35:37Z | 1,532,076 | <p><a href="http://www.djangosnippets.org/snippets/1350/" rel="nofollow">smart-if</a>. Allows normal <code>if x > y</code> constructs in templates, among other things.</p>
<p>A better <code>if</code> tag is now part of Django 1.2 (see <a href="http://docs.djangoproject.com/en/dev/releases/1.2/#smart-if-tag" rel="no... | 3 | 2009-10-07T14:41:24Z | [
"python",
"django",
"favorites",
"django-tagging"
] |
What are some useful non-built-in Django tags? | 1,532,021 | <p>I'm relatively new to Django and I'm trying to build up my toolbox for future projects. In my last project, when a built-in template tag didn't do quite what I needed, I would make a mangled mess of the template to shoe-horn in the feature. I later would find a template tag that would have saved me time and ugly c... | 3 | 2009-10-07T14:35:37Z | 1,532,097 | <p>I'll start.</p>
<p><a href="http://www.djangosnippets.org/snippets/1350/" rel="nofollow">http://www.djangosnippets.org/snippets/1350/</a></p>
<h2>Smart {% if %} template tag</h2>
<p>If you've ever found yourself needing more than a test for True, this tag is for you. It supports equality, greater than, and less ... | 4 | 2009-10-07T14:43:37Z | [
"python",
"django",
"favorites",
"django-tagging"
] |
What are some useful non-built-in Django tags? | 1,532,021 | <p>I'm relatively new to Django and I'm trying to build up my toolbox for future projects. In my last project, when a built-in template tag didn't do quite what I needed, I would make a mangled mess of the template to shoe-horn in the feature. I later would find a template tag that would have saved me time and ugly c... | 3 | 2009-10-07T14:35:37Z | 1,532,373 | <p>James Bennet's over-the-top-dynamic <a href="http://www.b-list.org/weblog/2006/jun/07/django-tips-write-better-template-tags/" rel="nofollow"><code>get_latest</code> tag</a></p>
<p><strong>edit as response to jpartogi's comment</strong></p>
<pre><code>class GetItemsNode(Node):
def __init__(self, model, num, by... | 1 | 2009-10-07T15:30:37Z | [
"python",
"django",
"favorites",
"django-tagging"
] |
What are some useful non-built-in Django tags? | 1,532,021 | <p>I'm relatively new to Django and I'm trying to build up my toolbox for future projects. In my last project, when a built-in template tag didn't do quite what I needed, I would make a mangled mess of the template to shoe-horn in the feature. I later would find a template tag that would have saved me time and ugly c... | 3 | 2009-10-07T14:35:37Z | 1,543,958 | <p>In come case {% autopaginate queryset %} (<a href="http://code.google.com/p/django-pagination/" rel="nofollow">http://code.google.com/p/django-pagination/</a>) is useful. For example:</p>
<pre><code>#views.py
obj_list = News.objects.filter(status=News.PUBLISHED)
# do not use len(obj_list) - it's evaluate Qu... | 1 | 2009-10-09T13:58:51Z | [
"python",
"django",
"favorites",
"django-tagging"
] |
Reading HKEY CURRENT USER from the registry in Python, specifying the user | 1,532,306 | <p>In my application I run subprocesses under several different user accounts. I need to be able to read some of the information written to the registry by these subprocesses. Each one is writing to HKEY_CURRENT_USER, and I know the user account name that they are running under.</p>
<p>In Python, how can I read values... | 1 | 2009-10-07T15:20:19Z | 1,532,868 | <p>HKEY_CURRENT_USER maps to a HKEY_USERS\{id} key.</p>
<p>Try finding the id by matching the HKEY_USERS{id}\Volatile Environment\USERNAME key to the username of the user (by enumerating/iterating over the {id}s that are present on the system). When you find the match just use HKEY_USERS{id} as if it was HKEY_CURRENT_... | 2 | 2009-10-07T16:55:31Z | [
"python",
"windows",
"registry"
] |
Reading HKEY CURRENT USER from the registry in Python, specifying the user | 1,532,306 | <p>In my application I run subprocesses under several different user accounts. I need to be able to read some of the information written to the registry by these subprocesses. Each one is writing to HKEY_CURRENT_USER, and I know the user account name that they are running under.</p>
<p>In Python, how can I read values... | 1 | 2009-10-07T15:20:19Z | 1,532,874 | <p>According to <a href="http://technet.microsoft.com/en-us/library/cc976337.aspx" rel="nofollow">MSDN</a>, <code>HKEY_CURRENT_USER</code> is a pointer to <code>HKEY_USERS/SID of the current user</code>. You can use <a href="http://sourceforge.net/projects/pywin32/" rel="nofollow">pywin32</a> to look up the SID for an ... | 3 | 2009-10-07T16:56:20Z | [
"python",
"windows",
"registry"
] |
Reading HKEY CURRENT USER from the registry in Python, specifying the user | 1,532,306 | <p>In my application I run subprocesses under several different user accounts. I need to be able to read some of the information written to the registry by these subprocesses. Each one is writing to HKEY_CURRENT_USER, and I know the user account name that they are running under.</p>
<p>In Python, how can I read values... | 1 | 2009-10-07T15:20:19Z | 35,490,611 | <p>If you don't want to install win32 stuff for Python and since you are already using subprocess, you can run built in Windows commands to get at the registry data you are looking for.</p>
<p>To query the SID of a particular user:</p>
<p><code>wmic useraccount where name='John' get sid</code></p>
<p>Then you can us... | 0 | 2016-02-18T19:24:06Z | [
"python",
"windows",
"registry"
] |
Why does my function "hangs" | 1,532,474 | <pre><code>def retCursor():
host = "localhost"
user = "disappearedng"
db = "gupan_crawling3"
conn = MySQLdb.connect( host=host, user=user, passwd=passwd, db=db)
cursor = conn.cursor()
return cursor
singleCur = retCursor()
def checkTemplateBuilt(netlocH):
"""Used by crawler specifically, t... | 0 | 2009-10-07T15:46:16Z | 1,532,635 | <p>According to your traceback, you interrupted the script during the execution of <code>checkTemplateBuilt</code>, not <code>enoughPassedForTemplate</code>.</p>
<p>I think the problem lies in a different part of the code; maybe there is an infinite loop somewhere? Maybe in the <code>run</code> function?</p>
| 0 | 2009-10-07T16:14:11Z | [
"python",
"mysql"
] |
Why does my function "hangs" | 1,532,474 | <pre><code>def retCursor():
host = "localhost"
user = "disappearedng"
db = "gupan_crawling3"
conn = MySQLdb.connect( host=host, user=user, passwd=passwd, db=db)
cursor = conn.cursor()
return cursor
singleCur = retCursor()
def checkTemplateBuilt(netlocH):
"""Used by crawler specifically, t... | 0 | 2009-10-07T15:46:16Z | 1,533,848 | <p>There might be a lock on the table preventing the query from completing.</p>
| 1 | 2009-10-07T20:00:21Z | [
"python",
"mysql"
] |
Why does my function "hangs" | 1,532,474 | <pre><code>def retCursor():
host = "localhost"
user = "disappearedng"
db = "gupan_crawling3"
conn = MySQLdb.connect( host=host, user=user, passwd=passwd, db=db)
cursor = conn.cursor()
return cursor
singleCur = retCursor()
def checkTemplateBuilt(netlocH):
"""Used by crawler specifically, t... | 0 | 2009-10-07T15:46:16Z | 1,534,219 | <p>Try logging the query string to a file right before you execute it.
Then when you think it is hung, you can look at the query and see if it works manually</p>
| 1 | 2009-10-07T21:12:50Z | [
"python",
"mysql"
] |
Supporting Multiple Python Versions In Your Code? | 1,532,488 | <p>Today I tried using <a href="http://pybrary.net/pyPdf/">pyPdf</a> 1.12 in a script I was writing that targets Python 2.6. When running my script, and even importing pyPdf, I get complaints about deprecated functionality (md5->hashsum, sets). I'd like to contribute a patch to make this work cleanly in 2.6, but I imag... | 6 | 2009-10-07T15:48:28Z | 1,532,524 | <p>You can certainly do</p>
<pre><code>try:
import v26
except ImportError:
import v25
</code></pre>
<p><a href="http://www.diveintopython.net/file_handling/index.html#d0e14344" rel="nofollow">Dive Into PythonâUsing Exceptions for Other Purposes</a></p>
| 4 | 2009-10-07T15:53:59Z | [
"python",
"versioning"
] |
Supporting Multiple Python Versions In Your Code? | 1,532,488 | <p>Today I tried using <a href="http://pybrary.net/pyPdf/">pyPdf</a> 1.12 in a script I was writing that targets Python 2.6. When running my script, and even importing pyPdf, I get complaints about deprecated functionality (md5->hashsum, sets). I'd like to contribute a patch to make this work cleanly in 2.6, but I imag... | 6 | 2009-10-07T15:48:28Z | 1,532,531 | <p>There are two ways to do this:</p>
<p><hr /></p>
<p>(1) Just like you described: Try something and work around the exception for old versions. For example, you could try to import the <code>json</code> module and import a userland implementation if this fails:</p>
<pre><code>try:
import json
except ImportErro... | 9 | 2009-10-07T15:55:20Z | [
"python",
"versioning"
] |
Supporting Multiple Python Versions In Your Code? | 1,532,488 | <p>Today I tried using <a href="http://pybrary.net/pyPdf/">pyPdf</a> 1.12 in a script I was writing that targets Python 2.6. When running my script, and even importing pyPdf, I get complaints about deprecated functionality (md5->hashsum, sets). I'd like to contribute a patch to make this work cleanly in 2.6, but I imag... | 6 | 2009-10-07T15:48:28Z | 9,417,285 | <p>Multiple versions of Python <em>are</em> supported here. You can a) conditionally use the newer version, which takes a little work, or b) turn off the warnings, which should really be the default (and is on newer Pythons).</p>
| 0 | 2012-02-23T16:43:32Z | [
"python",
"versioning"
] |
Given a string, how do I know if it needs decoding | 1,532,567 | <p>I'm using python's base64 module and I get a string that can be encoded or not encoded. I would like to do something like:</p>
<pre><code>if isEncoded(s):
output = base64.decodestring(s)
else:
output = s
</code></pre>
<p>ideas?</p>
| 1 | 2009-10-07T16:01:33Z | 1,532,585 | <p>You could just try it, and see what happens:</p>
<pre><code>import base64
def decode_if_necessary(s):
try:
return base64.decodestring(s)
except:
return s
</code></pre>
<p>But you have to ask yourself: what if the original message was in fact a syntactically valid base64 string, but not m... | 4 | 2009-10-07T16:04:39Z | [
"python",
"base64"
] |
Given a string, how do I know if it needs decoding | 1,532,567 | <p>I'm using python's base64 module and I get a string that can be encoded or not encoded. I would like to do something like:</p>
<pre><code>if isEncoded(s):
output = base64.decodestring(s)
else:
output = s
</code></pre>
<p>ideas?</p>
| 1 | 2009-10-07T16:01:33Z | 1,532,595 | <p>In general, it's impossible; if you receive string 'MjMj', for example, how could you possibly know whether it's already decoded and needs to be used as is, or decoded into '23#'?</p>
| 10 | 2009-10-07T16:07:00Z | [
"python",
"base64"
] |
Given a string, how do I know if it needs decoding | 1,532,567 | <p>I'm using python's base64 module and I get a string that can be encoded or not encoded. I would like to do something like:</p>
<pre><code>if isEncoded(s):
output = base64.decodestring(s)
else:
output = s
</code></pre>
<p>ideas?</p>
| 1 | 2009-10-07T16:01:33Z | 1,586,707 | <p>You could check to see if a string <a href="https://www.theeggeadventure.com/wikimedia/index.php/IsBase64" rel="nofollow">may be base64 encoded</a>. In general, the function can predict with 75%+ accuracy is the data is encoded.</p>
<pre><code>def isBase64(s):
return (len(s) % 4 == 0) and re.match('^[A-Za-z0-9... | 2 | 2009-10-19T02:26:22Z | [
"python",
"base64"
] |
the fastest way to create checksum for large files in python | 1,532,720 | <p>i need to transfer large files across network and need to create checksum for them on hourly basis. so the speed for generating checksum is critical for me.</p>
<p>somehow i can't make zlib.crc32 and zlib.adler32 working with files larger than 4GB on Windows XP Pro 64bit machine. i suspect i've hit the 32bit limita... | 5 | 2009-10-07T16:28:08Z | 1,532,764 | <p>You cannot possibly use more than one core to calculate MD5 hash of a large file because of the very nature of MD5: it expects a message to be broken up in chunks and fed into hashing function in strict sequence. However, you can use one thread to read a file into internal queue, and then calculate hash in a separat... | 0 | 2009-10-07T16:36:30Z | [
"python",
"multithreading",
"md5",
"crc32",
"hashlib"
] |
the fastest way to create checksum for large files in python | 1,532,720 | <p>i need to transfer large files across network and need to create checksum for them on hourly basis. so the speed for generating checksum is critical for me.</p>
<p>somehow i can't make zlib.crc32 and zlib.adler32 working with files larger than 4GB on Windows XP Pro 64bit machine. i suspect i've hit the 32bit limita... | 5 | 2009-10-07T16:28:08Z | 1,532,779 | <p>md5 itself can't be run in parallel. However you can md5 the file in sections (in parallel) and the take an md5 of the list of hashes.</p>
<p>However that assumes that the hashing is not IO-limited, which I would suspect it is. As Anton Gogolev suggests - make sure that you're reading the file efficiently (in large... | 0 | 2009-10-07T16:39:25Z | [
"python",
"multithreading",
"md5",
"crc32",
"hashlib"
] |
the fastest way to create checksum for large files in python | 1,532,720 | <p>i need to transfer large files across network and need to create checksum for them on hourly basis. so the speed for generating checksum is critical for me.</p>
<p>somehow i can't make zlib.crc32 and zlib.adler32 working with files larger than 4GB on Windows XP Pro 64bit machine. i suspect i've hit the 32bit limita... | 5 | 2009-10-07T16:28:08Z | 1,532,792 | <p>Did you try the <a href="http://sourceforge.net/projects/crcmod/" rel="nofollow">crc-generator</a> module?</p>
| 0 | 2009-10-07T16:43:18Z | [
"python",
"multithreading",
"md5",
"crc32",
"hashlib"
] |
the fastest way to create checksum for large files in python | 1,532,720 | <p>i need to transfer large files across network and need to create checksum for them on hourly basis. so the speed for generating checksum is critical for me.</p>
<p>somehow i can't make zlib.crc32 and zlib.adler32 working with files larger than 4GB on Windows XP Pro 64bit machine. i suspect i've hit the 32bit limita... | 5 | 2009-10-07T16:28:08Z | 1,533,036 | <p>It's <strong>an algorithm selection problem</strong>, rather than a library/language selection problem!</p>
<p>There appears to be two points to consider primarily:</p>
<ul>
<li>how much would the <strong>disk I/O</strong> affect the overall performance?</li>
<li>what is the expected <strong>reliability of the err... | 4 | 2009-10-07T17:24:08Z | [
"python",
"multithreading",
"md5",
"crc32",
"hashlib"
] |
the fastest way to create checksum for large files in python | 1,532,720 | <p>i need to transfer large files across network and need to create checksum for them on hourly basis. so the speed for generating checksum is critical for me.</p>
<p>somehow i can't make zlib.crc32 and zlib.adler32 working with files larger than 4GB on Windows XP Pro 64bit machine. i suspect i've hit the 32bit limita... | 5 | 2009-10-07T16:28:08Z | 1,533,255 | <p>First, there is nothing inherent in any of the CRC algorithms that would prevent them working on an arbitrary length of data (however, a particular implementation might well impose a limit).</p>
<p>However, in a file syncing application, that probably doesn't matter, as you may not want to hash the entire file when... | 2 | 2009-10-07T18:02:08Z | [
"python",
"multithreading",
"md5",
"crc32",
"hashlib"
] |
the fastest way to create checksum for large files in python | 1,532,720 | <p>i need to transfer large files across network and need to create checksum for them on hourly basis. so the speed for generating checksum is critical for me.</p>
<p>somehow i can't make zlib.crc32 and zlib.adler32 working with files larger than 4GB on Windows XP Pro 64bit machine. i suspect i've hit the 32bit limita... | 5 | 2009-10-07T16:28:08Z | 1,540,992 | <p>You might be hitting a size limit for files in XP. The 64-bit gives you more addressing space (removing the 2GB (or so) addressing space per application), but probably does nothing for the file size problem.</p>
| 1 | 2009-10-08T23:02:25Z | [
"python",
"multithreading",
"md5",
"crc32",
"hashlib"
] |
Is there anyway to persuade python's getopt to handle optional parameters to options? | 1,532,737 | <p>According to the documentation on python's <code>getopt</code> (I think) the options fields should behave as the <code>getopt()</code> function. However I can't seem to enable optional parameters to my code:</p>
<pre><code>#!/usr/bin/python
import sys,getopt
if __name__ == "__main__":
try:
opts, args =... | 6 | 2009-10-07T16:30:58Z | 1,532,761 | <p><code>getopt</code> doesn't support optional parameters. in case of long option you could do:</p>
<pre><code>$ ./testopt.py --verbose=
</code></pre>
<p>which will result in empty-string value.</p>
<p>You could find <a href="http://code.google.com/p/argparse/"><code>argparse</code></a> module to be more flexible.<... | 7 | 2009-10-07T16:36:27Z | [
"python",
"getopt",
"getopt-long"
] |
Is there anyway to persuade python's getopt to handle optional parameters to options? | 1,532,737 | <p>According to the documentation on python's <code>getopt</code> (I think) the options fields should behave as the <code>getopt()</code> function. However I can't seem to enable optional parameters to my code:</p>
<pre><code>#!/usr/bin/python
import sys,getopt
if __name__ == "__main__":
try:
opts, args =... | 6 | 2009-10-07T16:30:58Z | 1,532,784 | <p>Unfortunately, there is no way. From the <a href="http://docs.python.org/library/optparse.html" rel="nofollow">optparse docs</a>: </p>
<blockquote>
<p>Typically, a given option either takes an argument or it doesnât. Lots of people want an âoptional option argumentsâ feature, meaning that some options will ... | 5 | 2009-10-07T16:40:54Z | [
"python",
"getopt",
"getopt-long"
] |
Is there anyway to persuade python's getopt to handle optional parameters to options? | 1,532,737 | <p>According to the documentation on python's <code>getopt</code> (I think) the options fields should behave as the <code>getopt()</code> function. However I can't seem to enable optional parameters to my code:</p>
<pre><code>#!/usr/bin/python
import sys,getopt
if __name__ == "__main__":
try:
opts, args =... | 6 | 2009-10-07T16:30:58Z | 1,533,040 | <p>If you're using version 2.3 or later, you may want to try the <a href="http://docs.python.org/library/optparse.html" rel="nofollow">optparse</a> module instead, as it is "more convenient, flexible, and powerful ...", as well as newer. Alas, as Pynt answered, it doesn't seem possible to get exactly what you want.</p... | 0 | 2009-10-07T17:25:16Z | [
"python",
"getopt",
"getopt-long"
] |
Is there anyway to persuade python's getopt to handle optional parameters to options? | 1,532,737 | <p>According to the documentation on python's <code>getopt</code> (I think) the options fields should behave as the <code>getopt()</code> function. However I can't seem to enable optional parameters to my code:</p>
<pre><code>#!/usr/bin/python
import sys,getopt
if __name__ == "__main__":
try:
opts, args =... | 6 | 2009-10-07T16:30:58Z | 8,528,365 | <p>You can do an optional parameter with getopt like this:</p>
<pre><code>import getopt
import sys
longopts, shortopts = getopt.getopt(sys.argv[1:], shortopts='', longopts=['env='])
argDict = dict(longopts)
if argDict.has_key('--env') and argDict['--env'] == 'prod':
print "production"
else:
print "sandbox"
<... | 2 | 2011-12-16T00:16:04Z | [
"python",
"getopt",
"getopt-long"
] |
Is there anyway to persuade python's getopt to handle optional parameters to options? | 1,532,737 | <p>According to the documentation on python's <code>getopt</code> (I think) the options fields should behave as the <code>getopt()</code> function. However I can't seem to enable optional parameters to my code:</p>
<pre><code>#!/usr/bin/python
import sys,getopt
if __name__ == "__main__":
try:
opts, args =... | 6 | 2009-10-07T16:30:58Z | 27,824,336 | <p>python's getopt should really support optional args, like GNU getopt by requiring '='
be used when specifying a parameter. Now you can simulate it quite easily though,
with this constraint by implicitly changing --option to --option=</p>
<p>I.E. you can specify that --option requires an argument,
and then adjust -... | 0 | 2015-01-07T16:47:48Z | [
"python",
"getopt",
"getopt-long"
] |
Good high-level python ftp/http lib? | 1,532,760 | <p>I'm looking for a good, high-level python ftp client/server library. I'm working on a project that has "evolved" a small http/ftp library on top of ftplib/urllib/urllib2 from what was originally one function, and almost none of it was designed to be built upon. So now it's time to refactor kind of seriously, and I'd... | 1 | 2009-10-07T16:36:15Z | 1,533,029 | <p>URLgrabber appears to be very mature, and since it's used by yum (and thus many Unix systems), I would expect it to be very stable. Python 2.x is largely backward compatible. You might encounter some warnings, but I would expect it to work suitably under Python 2.6.</p>
| 4 | 2009-10-07T17:22:31Z | [
"python",
"http",
"ftp"
] |
Good high-level python ftp/http lib? | 1,532,760 | <p>I'm looking for a good, high-level python ftp client/server library. I'm working on a project that has "evolved" a small http/ftp library on top of ftplib/urllib/urllib2 from what was originally one function, and almost none of it was designed to be built upon. So now it's time to refactor kind of seriously, and I'd... | 1 | 2009-10-07T16:36:15Z | 1,534,234 | <p>Depending on the sort of application you are writing, you might want to consider <a href="http://twistedmatrix.com/" rel="nofollow">twisted python</a>, as it has http server and client code built in. However, it is a rather large departure from standard procedural python programming. </p>
<p>The big advantage of tw... | 0 | 2009-10-07T21:14:59Z | [
"python",
"http",
"ftp"
] |
How to read lines from a file into a multidimensional array (or an array of lists) in python | 1,532,810 | <p>I have a file with a format similar to this:</p>
<pre><code>a,3,4,2,1
3,2,1,a,2
</code></pre>
<p>I want to read the file and create an array of lists</p>
<p>in a way that:</p>
<pre><code>array[0] = ['a','3','4','2','1']
array[1] = ['3','2','1','a','2']
</code></pre>
<p>How can I do that?</p>
<p>So far I am stu... | 3 | 2009-10-07T16:46:05Z | 1,532,816 | <p>you're almost there, you just need to do:</p>
<pre><code>arr = [line.split(',') for line in open('./urls-eu.csv')]
</code></pre>
<p>it iteratively process file line by line, splits each line by comma and accumulates resulting lists into a list of lists. you can drop opening mode (<code>'r'</code>) since it's a def... | 7 | 2009-10-07T16:47:42Z | [
"python",
"list",
"multidimensional-array"
] |
How to read lines from a file into a multidimensional array (or an array of lists) in python | 1,532,810 | <p>I have a file with a format similar to this:</p>
<pre><code>a,3,4,2,1
3,2,1,a,2
</code></pre>
<p>I want to read the file and create an array of lists</p>
<p>in a way that:</p>
<pre><code>array[0] = ['a','3','4','2','1']
array[1] = ['3','2','1','a','2']
</code></pre>
<p>How can I do that?</p>
<p>So far I am stu... | 3 | 2009-10-07T16:46:05Z | 1,532,899 | <p>Batteries included:</p>
<pre><code>>>> import csv
>>> array = list( csv.reader( open( r'./urls-eu.csv' ) ) )
>>> array[0]
['a', '3', '4', '2', '1']
>>> array[1]
['3', '2', '1', 'a', '2']
</code></pre>
| 16 | 2009-10-07T17:00:16Z | [
"python",
"list",
"multidimensional-array"
] |
Open IE Browser Window | 1,532,884 | <p>The <a href="http://docs.python.org/library/webbrowser.html"><code>webbrowser</code> library</a> provides a convenient way to launch a URL with a browser window through the <code>webbrowser.open()</code> method. Numerous browser types are available, but there does not appear to be an explicit way to launch Internet ... | 8 | 2009-10-07T16:58:10Z | 1,532,945 | <p>The simplest way:</p>
<pre><code>import subprocess
subprocess.Popen(r'"C:\Program Files\Internet Explorer\IEXPLORE.EXE" www.google.com')
</code></pre>
| 2 | 2009-10-07T17:08:17Z | [
"python",
"internet-explorer",
"browser"
] |
Open IE Browser Window | 1,532,884 | <p>The <a href="http://docs.python.org/library/webbrowser.html"><code>webbrowser</code> library</a> provides a convenient way to launch a URL with a browser window through the <code>webbrowser.open()</code> method. Numerous browser types are available, but there does not appear to be an explicit way to launch Internet ... | 8 | 2009-10-07T16:58:10Z | 1,532,983 | <p>You can always do something like</p>
<pre><code>subprocess.Popen('"C:\\Program Files\\Internet Explorer\\iexplore.exe" http://www.example.com')
</code></pre>
| 3 | 2009-10-07T17:13:09Z | [
"python",
"internet-explorer",
"browser"
] |
Open IE Browser Window | 1,532,884 | <p>The <a href="http://docs.python.org/library/webbrowser.html"><code>webbrowser</code> library</a> provides a convenient way to launch a URL with a browser window through the <code>webbrowser.open()</code> method. Numerous browser types are available, but there does not appear to be an explicit way to launch Internet ... | 8 | 2009-10-07T16:58:10Z | 1,532,990 | <pre><code>>>> ie = webbrowser.get('c:\\program files\\internet explorer\\iexplore.exe')
>>> ie.open('http://google.com')
True
</code></pre>
| 14 | 2009-10-07T17:14:03Z | [
"python",
"internet-explorer",
"browser"
] |
Open IE Browser Window | 1,532,884 | <p>The <a href="http://docs.python.org/library/webbrowser.html"><code>webbrowser</code> library</a> provides a convenient way to launch a URL with a browser window through the <code>webbrowser.open()</code> method. Numerous browser types are available, but there does not appear to be an explicit way to launch Internet ... | 8 | 2009-10-07T16:58:10Z | 1,533,016 | <pre><code>iexplore = os.path.join(os.environ.get("PROGRAMFILES", "C:\\Program Files"),
"Internet Explorer\\IEXPLORE.EXE")
ie = webbrowser.BackgroundBrowser(iexplore)
ie.open(...)
</code></pre>
<p>This is what the <code>webrowser</code> module uses internally.</p>
| 6 | 2009-10-07T17:19:34Z | [
"python",
"internet-explorer",
"browser"
] |
Open IE Browser Window | 1,532,884 | <p>The <a href="http://docs.python.org/library/webbrowser.html"><code>webbrowser</code> library</a> provides a convenient way to launch a URL with a browser window through the <code>webbrowser.open()</code> method. Numerous browser types are available, but there does not appear to be an explicit way to launch Internet ... | 8 | 2009-10-07T16:58:10Z | 1,533,021 | <p>If you plan to use the script in more than your machine, keep in mind that not everyone has a English version of Windows</p>
<pre><code>import subprocess
import os
subprocess.Popen(r'"' + os.environ["PROGRAMFILES"] + '\Internet Explorer\IEXPLORE.EXE" www.google.com')
</code></pre>
| 0 | 2009-10-07T17:20:29Z | [
"python",
"internet-explorer",
"browser"
] |
Open IE Browser Window | 1,532,884 | <p>The <a href="http://docs.python.org/library/webbrowser.html"><code>webbrowser</code> library</a> provides a convenient way to launch a URL with a browser window through the <code>webbrowser.open()</code> method. Numerous browser types are available, but there does not appear to be an explicit way to launch Internet ... | 8 | 2009-10-07T16:58:10Z | 11,976,103 | <p>More elegant code:</p>
<pre><code>import webbrowser
ie = webbrowser.get(webbrowser.iexplore)
ie.open('google.com')
</code></pre>
| 15 | 2012-08-15T19:43:36Z | [
"python",
"internet-explorer",
"browser"
] |
Can a WIN32 program authenticate into Django authentication system, using MYSQL? | 1,533,259 | <p>I have a web service with Django Framework.<br />
My friend's project is a WIN32 program and also a MS-sql server.</p>
<p>The Win32 program currently has a login system that talks to a MS-sql for authentication.</p>
<p>However, we would like to INTEGRATE this login system as one.</p>
<p>Please answer the 2 things... | 0 | 2009-10-07T02:00:40Z | 1,581,622 | <p>The Win32 client can act like a web client to pass the user's credentials to the server. You will want to store the session cookie you get once you are authenticated and use that cookie in all following requests</p>
| 1 | 2009-10-17T07:06:39Z | [
"python",
"mysql",
"windows",
"django"
] |
Turbogears: Can not start paster after updateing to mac osx 10.6 | 1,533,388 | <p>After updateing to mac osx 10.6 I had to switch back to python 2.5 in order to make virtual env work. But still I can not start my turbogears project. Paster is giving this :</p>
<pre><code>Traceback (most recent call last):
File ".../tg2env/bin/paster", line 5, in <module>
from pkg_resources import loa... | 0 | 2009-10-07T18:34:31Z | 1,534,097 | <p>Why did you need to switch back to 2.5 to make virtualenv work? I have upgraded to 10.6 and am happily using virtualenv in Python 2.6.</p>
| 0 | 2009-10-07T20:45:43Z | [
"python",
"osx",
"turbogears2"
] |
Turbogears: Can not start paster after updateing to mac osx 10.6 | 1,533,388 | <p>After updateing to mac osx 10.6 I had to switch back to python 2.5 in order to make virtual env work. But still I can not start my turbogears project. Paster is giving this :</p>
<pre><code>Traceback (most recent call last):
File ".../tg2env/bin/paster", line 5, in <module>
from pkg_resources import loa... | 0 | 2009-10-07T18:34:31Z | 1,534,121 | <p>Probably eggs are installed for 2.6 distro. Please run in your terminal:</p>
<pre><code>defaults write com.apple.versioner.python Version 2.5
export VERSIONER_PYTHON_VERSION=2.5
sudo easy_install virtualenv
</code></pre>
<p>Check out the second line, it should change python version for current terminal session.</p... | 0 | 2009-10-07T20:51:34Z | [
"python",
"osx",
"turbogears2"
] |
Turbogears: Can not start paster after updateing to mac osx 10.6 | 1,533,388 | <p>After updateing to mac osx 10.6 I had to switch back to python 2.5 in order to make virtual env work. But still I can not start my turbogears project. Paster is giving this :</p>
<pre><code>Traceback (most recent call last):
File ".../tg2env/bin/paster", line 5, in <module>
from pkg_resources import loa... | 0 | 2009-10-07T18:34:31Z | 1,534,863 | <p>As you've seen, in Snow Leopard 10.6, Apple supplies both a Python 2.6.2 (the default for <code>/usr/bin/python</code>) and a legacy Python 2.5.4 (<code>/usr/bin/python2.5</code>). The heart of both live in the <code>/System/Library/Frameworks/Python.framework</code>. In general, everything under <code>/System</cod... | 0 | 2009-10-07T23:53:04Z | [
"python",
"osx",
"turbogears2"
] |
Access is Denied loading a dll with ctypes on Vista | 1,533,466 | <p>I'm having issues with using ctypes. I'm trying to get the following project running on Vista.</p>
<p><a href="http://sourceforge.net/projects/fractalfrost/" rel="nofollow">http://sourceforge.net/projects/fractalfrost/</a></p>
<p>I've used the project before on Vista and had no problems. I don't see any think ch... | 1 | 2009-10-07T18:47:17Z | 1,533,475 | <p>I know it sounds like a silly thing, but since you didn't explicitly mention it:</p>
<p>Did you check the permissions on the file you're trying to access? Perhaps you, you know, don't have read or execute access to the file.</p>
| 2 | 2009-10-07T18:50:32Z | [
"python",
"windows-vista",
"ctypes"
] |
Python: how to show results on a web page? | 1,534,070 | <p>Most likely it's a dumb question for those who knows the answer, but I'm a beginner, and here it goes:</p>
<p>I have a Python script which I run in a command-line with some parameter, and it prints me some results. Let's say results are some HTML code.</p>
<p>I never done any Python programming for web, and couldn... | 6 | 2009-10-07T20:40:37Z | 1,534,088 | <p>Sorry to say it, but HTTP web services <em>are</em> what you're looking for. Think of it this way - you put a form on a webpage, and a submit button. That goes to a web service that accepts the <em>request</em> and it chews on that request, and returns a <em>response</em> - which is a page of html. You never have to... | 1 | 2009-10-07T20:43:55Z | [
"python"
] |
Python: how to show results on a web page? | 1,534,070 | <p>Most likely it's a dumb question for those who knows the answer, but I'm a beginner, and here it goes:</p>
<p>I have a Python script which I run in a command-line with some parameter, and it prints me some results. Let's say results are some HTML code.</p>
<p>I never done any Python programming for web, and couldn... | 6 | 2009-10-07T20:40:37Z | 1,534,091 | <p>For such a simple task, you probably don't need more than CGI. Luckily Python has a built-in <code>cgi</code> module which should do what you want.</p>
<p>Or you could look into some of the minimal web frameworks, such as <a href="http://webpy.org/" rel="nofollow">web.py</a>.</p>
| 4 | 2009-10-07T20:44:09Z | [
"python"
] |
Python: how to show results on a web page? | 1,534,070 | <p>Most likely it's a dumb question for those who knows the answer, but I'm a beginner, and here it goes:</p>
<p>I have a Python script which I run in a command-line with some parameter, and it prints me some results. Let's say results are some HTML code.</p>
<p>I never done any Python programming for web, and couldn... | 6 | 2009-10-07T20:40:37Z | 1,534,133 | <p>Sounds like you just need to enable <a href="http://www.modpython.org/" rel="nofollow">CGI on apache</a>, which pretty much will redirect your output to the webserver output.</p>
<p>Python does have <a href="http://docs.python.org/library/cgi.html" rel="nofollow">CGI library</a> you may take a look at it.</p>
<p>H... | 2 | 2009-10-07T20:55:03Z | [
"python"
] |
Python: how to show results on a web page? | 1,534,070 | <p>Most likely it's a dumb question for those who knows the answer, but I'm a beginner, and here it goes:</p>
<p>I have a Python script which I run in a command-line with some parameter, and it prints me some results. Let's say results are some HTML code.</p>
<p>I never done any Python programming for web, and couldn... | 6 | 2009-10-07T20:40:37Z | 1,534,137 | <p>I agree completely with Matt -- Django is what you want. Django provides a complete solution, and really wonderful documentation that will help you get something going. If your application grows and becomes more complicated, Django can still work; Django works even for very large and very complicated web sites.</p... | 0 | 2009-10-07T20:55:42Z | [
"python"
] |
Python: how to show results on a web page? | 1,534,070 | <p>Most likely it's a dumb question for those who knows the answer, but I'm a beginner, and here it goes:</p>
<p>I have a Python script which I run in a command-line with some parameter, and it prints me some results. Let's say results are some HTML code.</p>
<p>I never done any Python programming for web, and couldn... | 6 | 2009-10-07T20:40:37Z | 1,534,138 | <p>I've not read DIVE INTO PYTHON, so maybe what I'm saying is redundant. As Daniel said, CGI may work for you. These days this would only the case for simple stuff with a fairly low number of hits. The Python CGI module is documented <a href="http://docs.python.org/library/cgi.html" rel="nofollow">here</a>. I have... | 0 | 2009-10-07T20:55:58Z | [
"python"
] |
Python: how to show results on a web page? | 1,534,070 | <p>Most likely it's a dumb question for those who knows the answer, but I'm a beginner, and here it goes:</p>
<p>I have a Python script which I run in a command-line with some parameter, and it prints me some results. Let's say results are some HTML code.</p>
<p>I never done any Python programming for web, and couldn... | 6 | 2009-10-07T20:40:37Z | 1,534,192 | <p>I think Django is overkill. If you are wanting to learn about this stuff, start from something very simple like this:</p>
<p><a href="http://www.islascruz.org/html/index.php/blog/show/Python:-Simple-HTTP-Server-on-python..html" rel="nofollow">http://www.islascruz.org/html/index.php/blog/show/Python:-Simple-HTTP-Ser... | 0 | 2009-10-07T21:06:48Z | [
"python"
] |
Python: how to show results on a web page? | 1,534,070 | <p>Most likely it's a dumb question for those who knows the answer, but I'm a beginner, and here it goes:</p>
<p>I have a Python script which I run in a command-line with some parameter, and it prints me some results. Let's say results are some HTML code.</p>
<p>I never done any Python programming for web, and couldn... | 6 | 2009-10-07T20:40:37Z | 1,536,548 | <p>A <em>current</em> method of creating simple (one-of )<code>Python</code> web page server is the <a href="http://docs.python.org/library/wsgiref.html#module-wsgiref" rel="nofollow"><code>wsgiref</code> module</a>.</p>
<blockquote>
<p>wsgiref is a reference implementation of the WSGI specification that can be use... | 0 | 2009-10-08T08:57:43Z | [
"python"
] |
Python: how to show results on a web page? | 1,534,070 | <p>Most likely it's a dumb question for those who knows the answer, but I'm a beginner, and here it goes:</p>
<p>I have a Python script which I run in a command-line with some parameter, and it prints me some results. Let's say results are some HTML code.</p>
<p>I never done any Python programming for web, and couldn... | 6 | 2009-10-07T20:40:37Z | 1,537,103 | <p>Whose web server? If it is a web server provided by a web hosting company or someone else and you don't have control over it, you need to ascertain in what way they support the use of Python for writing web applications. It isn't enough to know just that they have Python available.</p>
<p>As pointed out by others, ... | 2 | 2009-10-08T11:04:21Z | [
"python"
] |
Use different Python version with virtualenv | 1,534,210 | <p>I have a Debian system currently running with python 2.5.4. I got virtualenv properly installed, everything is working fine. Is there a possibility that I can use a virtualenv with a different version of Python?</p>
<p>I compiled Python 2.6.2 and would like to use it with some virtualenv. Is it enough to overwrite ... | 501 | 2009-10-07T21:11:22Z | 1,534,343 | <p>Just use the -p flag when creating your virtualenv instance to specify the Python executable you want to use, e.g.:</p>
<pre><code>virtualenv -p /usr/bin/python2.6 <path/to/new/virtualenv/>
</code></pre>
| 753 | 2009-10-07T21:33:12Z | [
"python",
"virtualenv",
"virtualenvwrapper"
] |
Use different Python version with virtualenv | 1,534,210 | <p>I have a Debian system currently running with python 2.5.4. I got virtualenv properly installed, everything is working fine. Is there a possibility that I can use a virtualenv with a different version of Python?</p>
<p>I compiled Python 2.6.2 and would like to use it with some virtualenv. Is it enough to overwrite ... | 501 | 2009-10-07T21:11:22Z | 1,674,444 | <pre><code>virtualenv --python=/usr/bin/python2.6 <path/to/myvirtualenv>
</code></pre>
| 74 | 2009-11-04T15:15:15Z | [
"python",
"virtualenv",
"virtualenvwrapper"
] |
Use different Python version with virtualenv | 1,534,210 | <p>I have a Debian system currently running with python 2.5.4. I got virtualenv properly installed, everything is working fine. Is there a possibility that I can use a virtualenv with a different version of Python?</p>
<p>I compiled Python 2.6.2 and would like to use it with some virtualenv. Is it enough to overwrite ... | 501 | 2009-10-07T21:11:22Z | 6,892,302 | <p>Under Windows for me this works:</p>
<pre><code>virtualenv --python=c:\Python25\python.exe envname
</code></pre>
<p>without the <code>python.exe</code> I got <code>WindowsError: [Error 5] Access is denied</code>
I have Python2.7.1 installed with virtualenv 1.6.1, and I wanted python 2.5.2.</p>
| 49 | 2011-07-31T21:04:32Z | [
"python",
"virtualenv",
"virtualenvwrapper"
] |
Use different Python version with virtualenv | 1,534,210 | <p>I have a Debian system currently running with python 2.5.4. I got virtualenv properly installed, everything is working fine. Is there a possibility that I can use a virtualenv with a different version of Python?</p>
<p>I compiled Python 2.6.2 and would like to use it with some virtualenv. Is it enough to overwrite ... | 501 | 2009-10-07T21:11:22Z | 11,301,911 | <p>These are steps when you are on shared hosting environment and need to install & complie Python from source and then create venv from your Python version. For Python 2.7.9 you would do something along these lines:</p>
<pre><code>mkdir ~/src
wget http://www.python.org/ftp/python/2.7.9/Python-2.7.9.tgz
tar -zxvf ... | 119 | 2012-07-02T22:17:14Z | [
"python",
"virtualenv",
"virtualenvwrapper"
] |
Use different Python version with virtualenv | 1,534,210 | <p>I have a Debian system currently running with python 2.5.4. I got virtualenv properly installed, everything is working fine. Is there a possibility that I can use a virtualenv with a different version of Python?</p>
<p>I compiled Python 2.6.2 and would like to use it with some virtualenv. Is it enough to overwrite ... | 501 | 2009-10-07T21:11:22Z | 20,834,097 | <p>Suppose you currently have python 2.7 installed in your virtualenv. But want to make use of python3.2. You would have to update this with:</p>
<pre><code>virtualenv --python=/usr/bin/python3.2 name_of_your_virtualenv
</code></pre>
<p>Then activate your virtualenv and type <code>python --version</code> in shell to ... | 9 | 2013-12-30T05:51:49Z | [
"python",
"virtualenv",
"virtualenvwrapper"
] |
Use different Python version with virtualenv | 1,534,210 | <p>I have a Debian system currently running with python 2.5.4. I got virtualenv properly installed, everything is working fine. Is there a possibility that I can use a virtualenv with a different version of Python?</p>
<p>I compiled Python 2.6.2 and would like to use it with some virtualenv. Is it enough to overwrite ... | 501 | 2009-10-07T21:11:22Z | 27,972,633 | <p>Mac OSX 10.6.8 (Snow Leopard):</p>
<p>1) When you do <code>pip install virtualenv</code>, the pip command is associated with one of your python versions, and <code>virtualenv</code> gets installed into that version of python (you can do</p>
<pre><code> $ which pip
</code></pre>
<p>to see what version of python... | 16 | 2015-01-15T20:43:25Z | [
"python",
"virtualenv",
"virtualenvwrapper"
] |
Use different Python version with virtualenv | 1,534,210 | <p>I have a Debian system currently running with python 2.5.4. I got virtualenv properly installed, everything is working fine. Is there a possibility that I can use a virtualenv with a different version of Python?</p>
<p>I compiled Python 2.6.2 and would like to use it with some virtualenv. Is it enough to overwrite ... | 501 | 2009-10-07T21:11:22Z | 32,363,907 | <p>On the mac I use pyenv and virtualenvwrapper. I had to create a new virtualenv. You need homebrew which I'll assume you've installed if you're on a mac, but just for fun:</p>
<pre><code>ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
brew install pyenv
pyenv install 2.7.1... | 2 | 2015-09-02T22:04:10Z | [
"python",
"virtualenv",
"virtualenvwrapper"
] |
Use different Python version with virtualenv | 1,534,210 | <p>I have a Debian system currently running with python 2.5.4. I got virtualenv properly installed, everything is working fine. Is there a possibility that I can use a virtualenv with a different version of Python?</p>
<p>I compiled Python 2.6.2 and would like to use it with some virtualenv. Is it enough to overwrite ... | 501 | 2009-10-07T21:11:22Z | 34,246,092 | <p>You can call <code>virtualenv</code> with python version you want. For example:</p>
<pre><code>python3 -m virtualenv venv
</code></pre>
<p>Or alternatively directly point to your virtualenv path. e.g. for windows:</p>
<pre><code>c:\Python34\Scripts\virtualenv.exe venv
</code></pre>
<p>And by running:</p>
<pre><... | 5 | 2015-12-12T23:11:12Z | [
"python",
"virtualenv",
"virtualenvwrapper"
] |
Use different Python version with virtualenv | 1,534,210 | <p>I have a Debian system currently running with python 2.5.4. I got virtualenv properly installed, everything is working fine. Is there a possibility that I can use a virtualenv with a different version of Python?</p>
<p>I compiled Python 2.6.2 and would like to use it with some virtualenv. Is it enough to overwrite ... | 501 | 2009-10-07T21:11:22Z | 37,607,811 | <p><strong>It worked for me</strong></p>
<pre><code>sudo apt-get install python3-minimal
virtualenv --no-site-packages --distribute -p /usr/bin/python3 ~/.virtualenvs/py3
</code></pre>
| 0 | 2016-06-03T06:53:41Z | [
"python",
"virtualenv",
"virtualenvwrapper"
] |
Use different Python version with virtualenv | 1,534,210 | <p>I have a Debian system currently running with python 2.5.4. I got virtualenv properly installed, everything is working fine. Is there a possibility that I can use a virtualenv with a different version of Python?</p>
<p>I compiled Python 2.6.2 and would like to use it with some virtualenv. Is it enough to overwrite ... | 501 | 2009-10-07T21:11:22Z | 38,797,664 | <p>The <code>-p</code> approach works well, but you do have to remember to use it every time. If your goal is to switch to a newer version of Python generally, that's a pain and can also lead to mistakes.</p>
<p>Your other option is to set an environment variable that does the same thing as <code>-p</code>. Set this ... | 0 | 2016-08-05T20:57:44Z | [
"python",
"virtualenv",
"virtualenvwrapper"
] |
Use different Python version with virtualenv | 1,534,210 | <p>I have a Debian system currently running with python 2.5.4. I got virtualenv properly installed, everything is working fine. Is there a possibility that I can use a virtualenv with a different version of Python?</p>
<p>I compiled Python 2.6.2 and would like to use it with some virtualenv. Is it enough to overwrite ... | 501 | 2009-10-07T21:11:22Z | 39,574,443 | <p>Even easier, by using command substitution to find python2 for you:</p>
<p><code>virtualenv -p $(which python2) <path/to/new/virtualenv/></code></p>
<p>Or when using virtualenvwrapper : </p>
<p><code>mkvirtualenv -p $(which python2) <env_name></code></p>
| 1 | 2016-09-19T13:28:50Z | [
"python",
"virtualenv",
"virtualenvwrapper"
] |
Use different Python version with virtualenv | 1,534,210 | <p>I have a Debian system currently running with python 2.5.4. I got virtualenv properly installed, everything is working fine. Is there a possibility that I can use a virtualenv with a different version of Python?</p>
<p>I compiled Python 2.6.2 and would like to use it with some virtualenv. Is it enough to overwrite ... | 501 | 2009-10-07T21:11:22Z | 39,713,544 | <p>For python3 (3.5.2), use the <a href="https://docs.python.org/3/library/venv.html" rel="nofollow">new</a> <code>pyvenv</code> command.</p>
<pre><code>pyvenv /path/to/new/virtual/environment
</code></pre>
| 1 | 2016-09-26T22:46:36Z | [
"python",
"virtualenv",
"virtualenvwrapper"
] |
Is there any way to affect locals at runtime? | 1,534,368 | <p>I actually want to create a new local. I know it sounds dubious, but I think I have a nice use case for this. Essentially my problem is that this code throws "NameError: global name 'eggs' is not defined" when I try to print eggs:</p>
<pre><code>def f():
import inspect
frame_who_called = inspect.stack()[1][... | 0 | 2009-10-07T21:38:37Z | 1,534,421 | <p>I am highly curious as to your use case. Why on Earth are you trying to poke a new local into the caller's frame, rather than simply doing something like this:</p>
<pre><code>def f():
return 123
def g():
eggs = f()
print(eggs)
</code></pre>
<p>After all, you can return a tuple with as many values as ... | 3 | 2009-10-07T21:47:27Z | [
"python",
"python-3.x",
"locals"
] |
Is there any way to affect locals at runtime? | 1,534,368 | <p>I actually want to create a new local. I know it sounds dubious, but I think I have a nice use case for this. Essentially my problem is that this code throws "NameError: global name 'eggs' is not defined" when I try to print eggs:</p>
<pre><code>def f():
import inspect
frame_who_called = inspect.stack()[1][... | 0 | 2009-10-07T21:38:37Z | 1,534,989 | <p>As Greg Hewgill mentioned in a comment on the question, I answered <a href="http://stackoverflow.com/questions/1463306/how-does-exec-work-with-locals">another question</a> about modifying <code>locals</code> in Python 3, and I'll give a bit of a recap here.</p>
<p>There is a <a href="http://bugs.python.org/issue483... | 2 | 2009-10-08T00:32:52Z | [
"python",
"python-3.x",
"locals"
] |
Is there any way to affect locals at runtime? | 1,534,368 | <p>I actually want to create a new local. I know it sounds dubious, but I think I have a nice use case for this. Essentially my problem is that this code throws "NameError: global name 'eggs' is not defined" when I try to print eggs:</p>
<pre><code>def f():
import inspect
frame_who_called = inspect.stack()[1][... | 0 | 2009-10-07T21:38:37Z | 1,535,195 | <p>In Python 2.*, you can get such code to work by defeating the normal optimization of locals:</p>
<pre><code>>>> def g():
... exec 'pass'
... f()
... print(eggs)
</code></pre>
<p>The presence of an <code>exec</code> statement causes Python 2 to compile <code>g</code> in a totally non-optimized fashio... | 1 | 2009-10-08T01:47:40Z | [
"python",
"python-3.x",
"locals"
] |
Editing MP3 metadata on a file-like object in Python? | 1,534,374 | <p>We're generating MP3 files on the fly in Python, and need to edit the ID3 headers in-memory using a file-like object. </p>
<p>All the ID3 libraries on <a href="http://pypi.python.org/pypi?%3Aaction=search&term=id3&submit=search" rel="nofollow">PyPI</a> <em>appear</em> to require you to pass a filesystem pa... | 3 | 2009-10-07T21:39:49Z | 1,534,398 | <p>AFAIR tags are appended to the end of file. You might want to study the format and make a simple library yourself, that should not be very difficult.</p>
<p>Also, you could consider storing them temporary on a filesystem like tmpfs (ramdisk). </p>
| -1 | 2009-10-07T21:43:54Z | [
"python",
"mp3",
"metadata",
"id3"
] |
Editing MP3 metadata on a file-like object in Python? | 1,534,374 | <p>We're generating MP3 files on the fly in Python, and need to edit the ID3 headers in-memory using a file-like object. </p>
<p>All the ID3 libraries on <a href="http://pypi.python.org/pypi?%3Aaction=search&term=id3&submit=search" rel="nofollow">PyPI</a> <em>appear</em> to require you to pass a filesystem pa... | 3 | 2009-10-07T21:39:49Z | 1,534,458 | <p>Does StringIO help? <a href="http://docs.python.org/library/stringio.html" rel="nofollow">http://docs.python.org/library/stringio.html</a></p>
| 0 | 2009-10-07T21:54:47Z | [
"python",
"mp3",
"metadata",
"id3"
] |
Editing MP3 metadata on a file-like object in Python? | 1,534,374 | <p>We're generating MP3 files on the fly in Python, and need to edit the ID3 headers in-memory using a file-like object. </p>
<p>All the ID3 libraries on <a href="http://pypi.python.org/pypi?%3Aaction=search&term=id3&submit=search" rel="nofollow">PyPI</a> <em>appear</em> to require you to pass a filesystem pa... | 3 | 2009-10-07T21:39:49Z | 1,541,482 | <p>Well, the answer seems to be that no such animal exists. The advantages of programming to an interface are apparently lost on the python MP3 frame hackers. We solved the problem by modifying an existing library.</p>
| 0 | 2009-10-09T02:02:28Z | [
"python",
"mp3",
"metadata",
"id3"
] |
Python object initialization bug. Or am I misunderstanding how objects work? | 1,534,407 | <pre><code> 1 import sys
2
3 class dummy(object):
4 def __init__(self, val):
5 self.val = val
6
7 class myobj(object):
8 def __init__(self, resources):
9 self._resources = resources
10
11 class ext(myobj):
12 def __init__(self, resources=[]):
13 #myobj.__init_... | 1 | 2009-10-07T21:45:18Z | 1,534,443 | <p>You should change</p>
<pre><code>def __init__(self, resources=[]):
self._resources = resources
</code></pre>
<p>to</p>
<pre><code>def __init__(self, resources=None):
if resources is None:
resources = []
self._resources = resources
</code></pre>
<p>and all will be better. This is a detail in t... | 7 | 2009-10-07T21:51:46Z | [
"python",
"mutable",
"arguments"
] |
Python object initialization bug. Or am I misunderstanding how objects work? | 1,534,407 | <pre><code> 1 import sys
2
3 class dummy(object):
4 def __init__(self, val):
5 self.val = val
6
7 class myobj(object):
8 def __init__(self, resources):
9 self._resources = resources
10
11 class ext(myobj):
12 def __init__(self, resources=[]):
13 #myobj.__init_... | 1 | 2009-10-07T21:45:18Z | 1,534,444 | <p>Your problem is that the default value is evaluated at function definition time. This means that the same list object is shared between instances. See the answer <a href="http://stackoverflow.com/questions/1132941/least-astonishment-in-python-the-mutable-default-argument">to this question</a> for more discussion.</p... | 6 | 2009-10-07T21:51:54Z | [
"python",
"mutable",
"arguments"
] |
Python object initialization bug. Or am I misunderstanding how objects work? | 1,534,407 | <pre><code> 1 import sys
2
3 class dummy(object):
4 def __init__(self, val):
5 self.val = val
6
7 class myobj(object):
8 def __init__(self, resources):
9 self._resources = resources
10
11 class ext(myobj):
12 def __init__(self, resources=[]):
13 #myobj.__init_... | 1 | 2009-10-07T21:45:18Z | 1,534,448 | <p>From <a href="http://docs.python.org/3.1/tutorial/controlflow.html" rel="nofollow">http://docs.python.org/3.1/tutorial/controlflow.html</a>:</p>
<blockquote>
<p>The default value is evaluated only
once. This makes a difference when the
default is a mutable object such as a
list, dictionary, or instances of ... | 1 | 2009-10-07T21:52:40Z | [
"python",
"mutable",
"arguments"
] |
Python object initialization bug. Or am I misunderstanding how objects work? | 1,534,407 | <pre><code> 1 import sys
2
3 class dummy(object):
4 def __init__(self, val):
5 self.val = val
6
7 class myobj(object):
8 def __init__(self, resources):
9 self._resources = resources
10
11 class ext(myobj):
12 def __init__(self, resources=[]):
13 #myobj.__init_... | 1 | 2009-10-07T21:45:18Z | 1,534,461 | <p>Please read <a href="http://stackoverflow.com/questions/1495666/how-to-define-a-class-in-python/1495740#1495740">this answer</a> for a discussion of how to setup a class from <code>__init__()</code>. You have encountered a well-known quirk of Python: you are trying to set up a mutable, and your mutable is being eva... | 2 | 2009-10-07T21:55:07Z | [
"python",
"mutable",
"arguments"
] |
Python object initialization bug. Or am I misunderstanding how objects work? | 1,534,407 | <pre><code> 1 import sys
2
3 class dummy(object):
4 def __init__(self, val):
5 self.val = val
6
7 class myobj(object):
8 def __init__(self, resources):
9 self._resources = resources
10
11 class ext(myobj):
12 def __init__(self, resources=[]):
13 #myobj.__init_... | 1 | 2009-10-07T21:45:18Z | 1,534,515 | <p>This is a <a href="http://www.ferg.org/projects/python%5Fgotchas.html#contents%5Fitem%5F6" rel="nofollow">known</a> Python <a href="http://eli.thegreenplace.net/2009/01/16/python-insight-beware-of-mutable-default-values-for-arguments/" rel="nofollow">gotcha</a>.</p>
<p>You have to avoid using a mutable object on th... | 0 | 2009-10-07T22:08:08Z | [
"python",
"mutable",
"arguments"
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.