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 |
|---|---|---|---|---|---|---|---|---|---|
mapping two list | 1,957,877 | <p>I have two list like this:</p>
<pre><code>list1 = [{'id':1, 'name':'foo', 'age':20}, {'id':2, 'name':'foo', 'age':20}]
list2 = [{'id':2, 'created':'2004-12-23'}, {'id':12, 'created':'2004-12-23'},
{'id':1, 'created':'2004-12-23'}]
list1 = [{'id':1, 'name':'foo', 'age':20, 'match':True},
{'id':... | 0 | 2009-12-24T10:59:52Z | 1,957,917 | <pre><code>set2 = set(x['id'] for x in list2)
for entry in list1:
if entry['id'] in set2:
entry['match'] = True
</code></pre>
<p>OR</p>
<pre><code>set2 = set(x['id'] for x in list2)
for entry in list1:
entry['match'] = entry['id'] in set2
</code></pre>
| 5 | 2009-12-24T11:13:07Z | [
"python"
] |
functions not executing python | 1,958,134 | <p>I have a program that runs when the functions have not been defined. When I put code into a function it does not execute the code it contains. Does anyone know why? Some of the code is:</p>
<pre><code>def new_directory():
if not os.path.exists(current_sandbox):
os.mkdir(current_sandbox)
</code></pre>
<p... | 1 | 2009-12-24T12:15:29Z | 1,958,161 | <p>Your code is actually a definition of a <code>new_directory</code> function. It won't be executed unless you make a call to <code>new_directory()</code>.
So, when you want to execute the code from your post, just add a function call like this:</p>
<pre><code>def new_directory():
if not os.path.exists(current_sa... | 4 | 2009-12-24T12:21:19Z | [
"python"
] |
functions not executing python | 1,958,134 | <p>I have a program that runs when the functions have not been defined. When I put code into a function it does not execute the code it contains. Does anyone know why? Some of the code is:</p>
<pre><code>def new_directory():
if not os.path.exists(current_sandbox):
os.mkdir(current_sandbox)
</code></pre>
<p... | 1 | 2009-12-24T12:15:29Z | 1,958,162 | <pre><code>def new_directory():
if not os.path.exists(current_sandbox):
os.mkdir(current_sandbox)
new_directory()
</code></pre>
| 1 | 2009-12-24T12:21:31Z | [
"python"
] |
functions not executing python | 1,958,134 | <p>I have a program that runs when the functions have not been defined. When I put code into a function it does not execute the code it contains. Does anyone know why? Some of the code is:</p>
<pre><code>def new_directory():
if not os.path.exists(current_sandbox):
os.mkdir(current_sandbox)
</code></pre>
<p... | 1 | 2009-12-24T12:15:29Z | 1,958,253 | <p>Problem 1 is that you define a function ("def" is an abbreviation of "define"), but you don't call it.</p>
<pre><code>def new_directory(): # define the function
if not os.path.exists(current_sandbox):
os.mkdir(current_sandbox)
new_directory() # call the function
</code></pre>
<p>Problem 2 (which hasn't hi... | 3 | 2009-12-24T12:56:44Z | [
"python"
] |
Convert sqlalchemy row object to python dict | 1,958,219 | <p>Is there a simple way to iterate over column name and value pairs?</p>
<p>My version of sqlalchemy is 0.5.6</p>
<p>Here is the sample code where I tried using dict(row), but it throws exception , TypeError: 'User' object is not iterable</p>
<pre><code>import sqlalchemy
from sqlalchemy import *
from sqlalchemy.ext... | 91 | 2009-12-24T12:42:34Z | 1,958,228 | <pre><code>for row in resultproxy:
row_as_dict = dict(row)
</code></pre>
| 11 | 2009-12-24T12:45:04Z | [
"python",
"sqlalchemy"
] |
Convert sqlalchemy row object to python dict | 1,958,219 | <p>Is there a simple way to iterate over column name and value pairs?</p>
<p>My version of sqlalchemy is 0.5.6</p>
<p>Here is the sample code where I tried using dict(row), but it throws exception , TypeError: 'User' object is not iterable</p>
<pre><code>import sqlalchemy
from sqlalchemy import *
from sqlalchemy.ext... | 91 | 2009-12-24T12:42:34Z | 1,960,546 | <p>I couldn't get a good answer so I use this:</p>
<pre><code>def row2dict(row):
d = {}
for column in row.__table__.columns:
d[column.name] = str(getattr(row, column.name))
return d
</code></pre>
<p>Edit: if above function is too long and not suited for some tastes here is a one liner (python 2.7... | 84 | 2009-12-25T05:20:20Z | [
"python",
"sqlalchemy"
] |
Convert sqlalchemy row object to python dict | 1,958,219 | <p>Is there a simple way to iterate over column name and value pairs?</p>
<p>My version of sqlalchemy is 0.5.6</p>
<p>Here is the sample code where I tried using dict(row), but it throws exception , TypeError: 'User' object is not iterable</p>
<pre><code>import sqlalchemy
from sqlalchemy import *
from sqlalchemy.ext... | 91 | 2009-12-24T12:42:34Z | 1,960,571 | <p>The expression you are iterating through evaluates to list of model <em>objects</em>, not rows. So the following is correct usage of them:</p>
<pre><code>for u in session.query(User).all():
print u.id, u.name
</code></pre>
<p>Do you realy need to convert them to dicts? Sure, there is a lot of ways, but then yo... | 4 | 2009-12-25T05:42:11Z | [
"python",
"sqlalchemy"
] |
Convert sqlalchemy row object to python dict | 1,958,219 | <p>Is there a simple way to iterate over column name and value pairs?</p>
<p>My version of sqlalchemy is 0.5.6</p>
<p>Here is the sample code where I tried using dict(row), but it throws exception , TypeError: 'User' object is not iterable</p>
<pre><code>import sqlalchemy
from sqlalchemy import *
from sqlalchemy.ext... | 91 | 2009-12-24T12:42:34Z | 2,237,320 | <pre><code>class User(object):
def to_dict(self):
return dict([(k, getattr(self, k)) for k in self.__dict__.keys() if not k.startswith("_")])
</code></pre>
<p>That should work.</p>
| -1 | 2010-02-10T14:07:02Z | [
"python",
"sqlalchemy"
] |
Convert sqlalchemy row object to python dict | 1,958,219 | <p>Is there a simple way to iterate over column name and value pairs?</p>
<p>My version of sqlalchemy is 0.5.6</p>
<p>Here is the sample code where I tried using dict(row), but it throws exception , TypeError: 'User' object is not iterable</p>
<pre><code>import sqlalchemy
from sqlalchemy import *
from sqlalchemy.ext... | 91 | 2009-12-24T12:42:34Z | 2,454,618 | <pre><code>from sqlalchemy.orm import class_mapper
def asdict(obj):
return dict((col.name, getattr(obj, col.name))
for col in class_mapper(obj.__class__).mapped_table.c)
</code></pre>
| 13 | 2010-03-16T13:24:01Z | [
"python",
"sqlalchemy"
] |
Convert sqlalchemy row object to python dict | 1,958,219 | <p>Is there a simple way to iterate over column name and value pairs?</p>
<p>My version of sqlalchemy is 0.5.6</p>
<p>Here is the sample code where I tried using dict(row), but it throws exception , TypeError: 'User' object is not iterable</p>
<pre><code>import sqlalchemy
from sqlalchemy import *
from sqlalchemy.ext... | 91 | 2009-12-24T12:42:34Z | 3,355,665 | <p>I have a variation on Marco Mariani's answer, expressed as a decorator. The main difference is that it'll handle <em>lists</em> of entities, as well as safely ignoring some other types of return values (which is very useful when writing tests using mocks):</p>
<pre><code>@decorator
def to_dict(f, *args, **kwargs):
... | 1 | 2010-07-28T17:32:21Z | [
"python",
"sqlalchemy"
] |
Convert sqlalchemy row object to python dict | 1,958,219 | <p>Is there a simple way to iterate over column name and value pairs?</p>
<p>My version of sqlalchemy is 0.5.6</p>
<p>Here is the sample code where I tried using dict(row), but it throws exception , TypeError: 'User' object is not iterable</p>
<pre><code>import sqlalchemy
from sqlalchemy import *
from sqlalchemy.ext... | 91 | 2009-12-24T12:42:34Z | 9,969,155 | <p>Here is how Elixir does it. The value of this solution is that it allows recursively including the dictionary representation of relations.</p>
<pre class="lang-python prettyprint-override"><code>def to_dict(self, deep={}, exclude=[]):
"""Generate a JSON-style nested dict/list structure from an object."""
co... | 2 | 2012-04-01T23:09:53Z | [
"python",
"sqlalchemy"
] |
Convert sqlalchemy row object to python dict | 1,958,219 | <p>Is there a simple way to iterate over column name and value pairs?</p>
<p>My version of sqlalchemy is 0.5.6</p>
<p>Here is the sample code where I tried using dict(row), but it throws exception , TypeError: 'User' object is not iterable</p>
<pre><code>import sqlalchemy
from sqlalchemy import *
from sqlalchemy.ext... | 91 | 2009-12-24T12:42:34Z | 10,370,224 | <p>You may access the internal <code>__dict__</code> of a SQLAlchemy object, like the following::</p>
<pre><code>for u in session.query(User).all():
print u.__dict__
</code></pre>
| 102 | 2012-04-29T06:31:44Z | [
"python",
"sqlalchemy"
] |
Convert sqlalchemy row object to python dict | 1,958,219 | <p>Is there a simple way to iterate over column name and value pairs?</p>
<p>My version of sqlalchemy is 0.5.6</p>
<p>Here is the sample code where I tried using dict(row), but it throws exception , TypeError: 'User' object is not iterable</p>
<pre><code>import sqlalchemy
from sqlalchemy import *
from sqlalchemy.ext... | 91 | 2009-12-24T12:42:34Z | 11,810,214 | <p>I've found this post because I was looking for a way to convert a SQLAlchemy row into a dict. I'm using SqlSoup... but the answer was built by myself, so, if it could helps someone here's my two cents:</p>
<pre><code>a = db.execute('select * from acquisizioni_motes')
b = a.fetchall()
c = b[0]
# and now, finally...... | 6 | 2012-08-04T16:31:49Z | [
"python",
"sqlalchemy"
] |
Convert sqlalchemy row object to python dict | 1,958,219 | <p>Is there a simple way to iterate over column name and value pairs?</p>
<p>My version of sqlalchemy is 0.5.6</p>
<p>Here is the sample code where I tried using dict(row), but it throws exception , TypeError: 'User' object is not iterable</p>
<pre><code>import sqlalchemy
from sqlalchemy import *
from sqlalchemy.ext... | 91 | 2009-12-24T12:42:34Z | 16,880,876 | <p>Here is a super simple way of doing it</p>
<pre><code>row2dict = lambda r: dict(r.items())
</code></pre>
| -1 | 2013-06-02T07:54:19Z | [
"python",
"sqlalchemy"
] |
Convert sqlalchemy row object to python dict | 1,958,219 | <p>Is there a simple way to iterate over column name and value pairs?</p>
<p>My version of sqlalchemy is 0.5.6</p>
<p>Here is the sample code where I tried using dict(row), but it throws exception , TypeError: 'User' object is not iterable</p>
<pre><code>import sqlalchemy
from sqlalchemy import *
from sqlalchemy.ext... | 91 | 2009-12-24T12:42:34Z | 21,029,850 | <p>rows have an <code>_asdict()</code> function which gives a dict</p>
<pre><code>In [8]: r1 = db.session.query(Topic.name).first()
In [9]: r1
Out[9]: (u'blah')
In [10]: r1.name
Out[10]: u'blah'
In [11]: r1._asdict()
Out[11]: {'name': u'blah'}
</code></pre>
| 7 | 2014-01-09T19:53:55Z | [
"python",
"sqlalchemy"
] |
Convert sqlalchemy row object to python dict | 1,958,219 | <p>Is there a simple way to iterate over column name and value pairs?</p>
<p>My version of sqlalchemy is 0.5.6</p>
<p>Here is the sample code where I tried using dict(row), but it throws exception , TypeError: 'User' object is not iterable</p>
<pre><code>import sqlalchemy
from sqlalchemy import *
from sqlalchemy.ext... | 91 | 2009-12-24T12:42:34Z | 21,992,899 | <p>The easiest way I found (using sqla 0.7.8):</p>
<pre><code>dictlist = [dict(row) for row in somequery.execute().fetchall()]
</code></pre>
| 0 | 2014-02-24T16:11:03Z | [
"python",
"sqlalchemy"
] |
Convert sqlalchemy row object to python dict | 1,958,219 | <p>Is there a simple way to iterate over column name and value pairs?</p>
<p>My version of sqlalchemy is 0.5.6</p>
<p>Here is the sample code where I tried using dict(row), but it throws exception , TypeError: 'User' object is not iterable</p>
<pre><code>import sqlalchemy
from sqlalchemy import *
from sqlalchemy.ext... | 91 | 2009-12-24T12:42:34Z | 24,748,320 | <p>as @balki mentioned:</p>
<p>The <code>_asdict()</code> method can be used if you're querying a specific field because it is returned as a <a href="http://docs.sqlalchemy.org/en/rel_0_9/orm/query.html#sqlalchemy.util.KeyedTuple">KeyedTuple</a>.</p>
<pre><code>In [1]: foo = db.session.query(Topic.name).first()
In [2... | 7 | 2014-07-15T00:47:36Z | [
"python",
"sqlalchemy"
] |
Convert sqlalchemy row object to python dict | 1,958,219 | <p>Is there a simple way to iterate over column name and value pairs?</p>
<p>My version of sqlalchemy is 0.5.6</p>
<p>Here is the sample code where I tried using dict(row), but it throws exception , TypeError: 'User' object is not iterable</p>
<pre><code>import sqlalchemy
from sqlalchemy import *
from sqlalchemy.ext... | 91 | 2009-12-24T12:42:34Z | 25,446,105 | <p>Following @balki answer, <strong>since SQLAlchemy 0.8</strong> you can use _asdict(), available for KeyedTuple objects. This renders a pretty straightforward answer to the original question. Just, change in your example the last two lines (the for loop) for this one:</p>
<pre><code>for u in session.query(User).all(... | 4 | 2014-08-22T11:37:49Z | [
"python",
"sqlalchemy"
] |
Convert sqlalchemy row object to python dict | 1,958,219 | <p>Is there a simple way to iterate over column name and value pairs?</p>
<p>My version of sqlalchemy is 0.5.6</p>
<p>Here is the sample code where I tried using dict(row), but it throws exception , TypeError: 'User' object is not iterable</p>
<pre><code>import sqlalchemy
from sqlalchemy import *
from sqlalchemy.ext... | 91 | 2009-12-24T12:42:34Z | 30,280,750 | <p>Assuming the following functions will be added to the <code>class User</code> the following will return all key-value pairs of all columns:</p>
<pre><code>def columns_to_dict(self):
dict_ = {}
for key in self.__mapper__.c.keys():
dict_[key] = getattr(self, key)
return dict_
</code></pre>
<p>unl... | 3 | 2015-05-16T21:03:31Z | [
"python",
"sqlalchemy"
] |
Convert sqlalchemy row object to python dict | 1,958,219 | <p>Is there a simple way to iterate over column name and value pairs?</p>
<p>My version of sqlalchemy is 0.5.6</p>
<p>Here is the sample code where I tried using dict(row), but it throws exception , TypeError: 'User' object is not iterable</p>
<pre><code>import sqlalchemy
from sqlalchemy import *
from sqlalchemy.ext... | 91 | 2009-12-24T12:42:34Z | 31,330,688 | <p>In most scenarios, column name is fit for them. But maybe you write the code like follows:</p>
<pre><code>class UserModel(BaseModel):
user_id = Column("user_id", INT, primary_key=True)
email = Column("user_email", STRING)
</code></pre>
<p>the column.name "user_email" while the field name is "email", the co... | -1 | 2015-07-10T00:46:15Z | [
"python",
"sqlalchemy"
] |
Convert sqlalchemy row object to python dict | 1,958,219 | <p>Is there a simple way to iterate over column name and value pairs?</p>
<p>My version of sqlalchemy is 0.5.6</p>
<p>Here is the sample code where I tried using dict(row), but it throws exception , TypeError: 'User' object is not iterable</p>
<pre><code>import sqlalchemy
from sqlalchemy import *
from sqlalchemy.ext... | 91 | 2009-12-24T12:42:34Z | 33,897,982 | <p>I am a newly minted Python programmer and ran into problems getting to JSON with Joined tables. Using information from the answers here I built a function to return reasonable results to JSON where the table names are included avoiding having to alias, or have fields collide.</p>
<p>Simply pass the result of a ses... | 0 | 2015-11-24T15:45:49Z | [
"python",
"sqlalchemy"
] |
Convert sqlalchemy row object to python dict | 1,958,219 | <p>Is there a simple way to iterate over column name and value pairs?</p>
<p>My version of sqlalchemy is 0.5.6</p>
<p>Here is the sample code where I tried using dict(row), but it throws exception , TypeError: 'User' object is not iterable</p>
<pre><code>import sqlalchemy
from sqlalchemy import *
from sqlalchemy.ext... | 91 | 2009-12-24T12:42:34Z | 37,307,369 | <p>I don't have much experience with this, but the following seems to work for what I'm doing:</p>
<pre><code>dict(row)
</code></pre>
<p>This seems too simple (compared to the other answers here). What am I missing?</p>
| -2 | 2016-05-18T18:21:58Z | [
"python",
"sqlalchemy"
] |
Convert sqlalchemy row object to python dict | 1,958,219 | <p>Is there a simple way to iterate over column name and value pairs?</p>
<p>My version of sqlalchemy is 0.5.6</p>
<p>Here is the sample code where I tried using dict(row), but it throws exception , TypeError: 'User' object is not iterable</p>
<pre><code>import sqlalchemy
from sqlalchemy import *
from sqlalchemy.ext... | 91 | 2009-12-24T12:42:34Z | 37,350,445 | <h1>This is the corrrect answer for modern SQLAlchemy.</h1>
<p>Use the <a href="http://docs.sqlalchemy.org/en/latest/core/inspection.html">inspection system</a>.</p>
<pre><code>from sqlalchemy import inspect
def object_as_dict(obj):
return {c.key: getattr(obj, c.key)
for c in inspect(obj).mapper.colu... | 5 | 2016-05-20T15:32:50Z | [
"python",
"sqlalchemy"
] |
Convert sqlalchemy row object to python dict | 1,958,219 | <p>Is there a simple way to iterate over column name and value pairs?</p>
<p>My version of sqlalchemy is 0.5.6</p>
<p>Here is the sample code where I tried using dict(row), but it throws exception , TypeError: 'User' object is not iterable</p>
<pre><code>import sqlalchemy
from sqlalchemy import *
from sqlalchemy.ext... | 91 | 2009-12-24T12:42:34Z | 37,704,970 | <p>A solution that works with inherited classes too:</p>
<pre><code>from itertools import chain
from sqlalchemy.ext.declarative import declarative_base
Base = declarative_base()
class Mixin(object):
def as_dict(self):
tables = [base.__table__ for base in self.__class__.__bases__ if base not in [Base, Mix... | -1 | 2016-06-08T14:11:54Z | [
"python",
"sqlalchemy"
] |
Convert sqlalchemy row object to python dict | 1,958,219 | <p>Is there a simple way to iterate over column name and value pairs?</p>
<p>My version of sqlalchemy is 0.5.6</p>
<p>Here is the sample code where I tried using dict(row), but it throws exception , TypeError: 'User' object is not iterable</p>
<pre><code>import sqlalchemy
from sqlalchemy import *
from sqlalchemy.ext... | 91 | 2009-12-24T12:42:34Z | 37,706,490 | <p>My take utilizing (too many?) dictionaries:</p>
<pre><code>def serialize(_query):
#d = dictionary written to per row
#D = dictionary d is written to each time, then reset
#Master = dictionary of dictionaries; the id Key (int, unique from database) from D is used as the Key for the dictionary D entry in Master
Maste... | -2 | 2016-06-08T15:13:18Z | [
"python",
"sqlalchemy"
] |
django templatetags template , combine {{ }} method call with template tag context variable | 1,958,286 | <p>i m trying to make the result of a template tag dependent from another template tag. the use case is the following. i have a headers list which contains all the columns i want to show in a table + the column of the model they are showing +whether they are visible or not.</p>
<pre><code>LIST_HEADERS = (
('Title... | 0 | 2009-12-24T13:16:13Z | 1,958,342 | <p>I would do this as a filter, as they provide an easy way to render a result dependent on the value of a variable.</p>
<pre><code>@register.filter
def field_from_name(instance, field_name):
return getattr(instance, field_name, None)
</code></pre>
<p>and then in the template:</p>
<pre><code>{{ model_instance|fi... | 2 | 2009-12-24T13:36:33Z | [
"python",
"django"
] |
django templatetags template , combine {{ }} method call with template tag context variable | 1,958,286 | <p>i m trying to make the result of a template tag dependent from another template tag. the use case is the following. i have a headers list which contains all the columns i want to show in a table + the column of the model they are showing +whether they are visible or not.</p>
<pre><code>LIST_HEADERS = (
('Title... | 0 | 2009-12-24T13:16:13Z | 1,958,358 | <p>Simplify this.</p>
<p>First, read about the things the Django template language actually <em>can</em> do. It's not much. It can deference variables, lists and dictionaries.</p>
<p>It's simpler if you do all the "work" in your view function.</p>
<pre><code>show = [ ]
for title, field_name, visible in LIST_HEAD... | 2 | 2009-12-24T13:40:32Z | [
"python",
"django"
] |
Why are there dummy modules in sys.modules? | 1,958,417 | <p>Importing the standard "logging" module pollutes sys.modules with a bunch of dummy entries:</p>
<pre><code>Python 2.5.4 (r254:67916, Dec 23 2008, 15:10:54) [MSC v.1310 32 bit (Intel)] on win32
>>> import sys
>>> import logging
>>> sorted(x for x in sys.modules.keys() if 'log' in x)
['logg... | 13 | 2009-12-24T13:58:46Z | 1,958,474 | <p><code>None</code> values in <code>sys.modules</code> are cached failures of relative lookups.</p>
<p>So when you're in package <code>foo</code> and you <code>import sys</code>, Python looks first for a <code>foo.sys</code> module, and if that fails goes to the top-level <code>sys</code> module. To avoid having to c... | 20 | 2009-12-24T14:15:36Z | [
"python",
"import"
] |
Why are there dummy modules in sys.modules? | 1,958,417 | <p>Importing the standard "logging" module pollutes sys.modules with a bunch of dummy entries:</p>
<pre><code>Python 2.5.4 (r254:67916, Dec 23 2008, 15:10:54) [MSC v.1310 32 bit (Intel)] on win32
>>> import sys
>>> import logging
>>> sorted(x for x in sys.modules.keys() if 'log' in x)
['logg... | 13 | 2009-12-24T13:58:46Z | 1,958,476 | <p>I'm not sure why it happens but <code>encodings</code> exhibits the same references to <code>None</code>.</p>
<pre><code>Python 2.6.2 (r262:71600, May 24 2009, 00:12:54)
[GCC 4.0.1 (Apple Inc. build 5465)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>... | 0 | 2009-12-24T14:16:09Z | [
"python",
"import"
] |
Django manytomany signals? | 1,958,540 | <p>Let's say I have such model</p>
<pre><code>class Event(models.Model)
users_count = models.IntegerField(default=0)
users = models.ManyToManyField(User)
</code></pre>
<p>How would you recommend to update users_count value if Event add/delete some users ?</p>
| 6 | 2009-12-24T14:38:29Z | 1,958,548 | <p>There is a <a href="http://uswaretech.com/books/djangodesignpatterns/models.html#working-with-denormalised-fields" rel="nofollow">"design pattern" for that</a>.</p>
<p>Pretty much, override <code>save()</code> and <code>delete()</code>.</p>
<p>As they mention, using listeners is also an option, but for this scenar... | -4 | 2009-12-24T14:40:04Z | [
"python",
"django",
"django-models",
"django-signals"
] |
Django manytomany signals? | 1,958,540 | <p>Let's say I have such model</p>
<pre><code>class Event(models.Model)
users_count = models.IntegerField(default=0)
users = models.ManyToManyField(User)
</code></pre>
<p>How would you recommend to update users_count value if Event add/delete some users ?</p>
| 6 | 2009-12-24T14:38:29Z | 1,958,814 | <p>Overriding save() may not help you because the update to the M2M is not atomic and happens <em>after</em> the save of the Event instance (I haven't studied the delete() semantics but they are probably similar). This was discussed in <a href="http://stackoverflow.com/questions/1925383/issue-with-manytomany-relationsh... | 2 | 2009-12-24T15:57:10Z | [
"python",
"django",
"django-models",
"django-signals"
] |
Django manytomany signals? | 1,958,540 | <p>Let's say I have such model</p>
<pre><code>class Event(models.Model)
users_count = models.IntegerField(default=0)
users = models.ManyToManyField(User)
</code></pre>
<p>How would you recommend to update users_count value if Event add/delete some users ?</p>
| 6 | 2009-12-24T14:38:29Z | 1,959,929 | <p>If possible in your case, you could introduce <code>Participation</code> model which would join Event and User:</p>
<pre><code>class Participation(models.Model):
user = models.ForeignKey(User)
event = models.ForeignKey(Event)
class Event(models.Model):
users = models.ManyToManyField(User, through='Part... | 8 | 2009-12-24T22:26:28Z | [
"python",
"django",
"django-models",
"django-signals"
] |
Django manytomany signals? | 1,958,540 | <p>Let's say I have such model</p>
<pre><code>class Event(models.Model)
users_count = models.IntegerField(default=0)
users = models.ManyToManyField(User)
</code></pre>
<p>How would you recommend to update users_count value if Event add/delete some users ?</p>
| 6 | 2009-12-24T14:38:29Z | 6,047,637 | <p>I have a fixed the problem using the built-in signal <strong>django.db.models.signals.m2m_changed</strong>.</p>
<p>In my case, I have to update a related instance of another model each time the ManyToMany change and as you know, overriding Model.save() does not works.</p>
<p>Here my (french & simplified) model... | 4 | 2011-05-18T16:02:47Z | [
"python",
"django",
"django-models",
"django-signals"
] |
pygtk: how to force message dialogs to show up in the center of the screen? | 1,958,757 | <p>I have a glade GUI and i'm using dome gtk.MessageDialog widgets created with pygtk for user interaction. My problem is that whenever I throw a dialog message on the screen, they show up all over the place. One might show up on the top right corner, the next on the bottom left, top left, mid left etc...</p>
<p>Is th... | 3 | 2009-12-24T15:43:23Z | 1,958,815 | <p>Check out the reference material at <a href="http://library.gnome.org/devel/pygtk/2.16/" rel="nofollow">PyGTK 2.0 Reference Manual</a></p>
<p>I have not had a chance to try this but MessageDialog seems to be derived from Window which has a <a href="http://library.gnome.org/devel/pygtk/stable/class-gtkwindow.html#me... | 2 | 2009-12-24T15:57:30Z | [
"python",
"pygtk",
"dialog"
] |
pygtk: how to force message dialogs to show up in the center of the screen? | 1,958,757 | <p>I have a glade GUI and i'm using dome gtk.MessageDialog widgets created with pygtk for user interaction. My problem is that whenever I throw a dialog message on the screen, they show up all over the place. One might show up on the top right corner, the next on the bottom left, top left, mid left etc...</p>
<p>Is th... | 3 | 2009-12-24T15:43:23Z | 1,958,832 | <p>Never mind. Found the solution.</p>
<p>For others who might wander about the same thing, the solution to this problem lies in specifying a parent value to the gtk.MessageDialog construct.
If you are using a glade gui, in your class, and your glade xml is loaded in to a variable named 'gui', it would look like this:... | 5 | 2009-12-24T16:01:46Z | [
"python",
"pygtk",
"dialog"
] |
Absolute import failing in subpackage that shadows a stdlib package name | 1,959,188 | <p>Basically I have a subpackage with the same name as a standard library package ("logging") and I'd like it to be able to absolute-import the standard one no matter how I run it, but this fails when I'm in the parent package.</p>
<p>It really looks like either a bug, or an undocumented behaviour of the new "absolute... | 8 | 2009-12-24T17:46:34Z | 1,959,215 | <p><code>sys.path[0]</code> is by default <code>''</code>, which means "current directory". So if you are sitting in a directory with <code>logging</code> in it, that will be chosen first.</p>
<p>I ran into this recently, until I realized that I was actually sitting in that directory and that <code>sys.path</code> wa... | 9 | 2009-12-24T17:53:54Z | [
"python",
"import"
] |
Python scientific notation using D instead of E | 1,959,210 | <p>Some results file produced by Fortran programs report double precision numbers (in scientific notation) using the letter <code>D</code> instead of <code>E</code>, for instance:</p>
<pre><code>1.2345D+02
# instead of
1.2345E+02
</code></pre>
<p>I need to process huge amounts of this data using Python, and I just re... | 8 | 2009-12-24T17:52:22Z | 1,959,239 | <p>The simplest way, from your Python program, would be just to add a step before you interpret each entry:</p>
<pre><code>>>> val = "1.5698D+03" # 1,569.8
>>> print float(val.replace('D', 'E'))
1569.8
</code></pre>
| 8 | 2009-12-24T18:00:58Z | [
"python",
"locale",
"scientific-notation"
] |
Python scientific notation using D instead of E | 1,959,210 | <p>Some results file produced by Fortran programs report double precision numbers (in scientific notation) using the letter <code>D</code> instead of <code>E</code>, for instance:</p>
<pre><code>1.2345D+02
# instead of
1.2345E+02
</code></pre>
<p>I need to process huge amounts of this data using Python, and I just re... | 8 | 2009-12-24T17:52:22Z | 1,959,312 | <p>If you are dealing with lots of data and/or are doing a lot computations with that data, you might consider using the fortran-friendly <a href="http://numpy.scipy.org/">numpy</a> module which supports double-precision fortran format out of the box.</p>
<pre><code>>>> numpy.float('1.5698D+03')
1569.8
</code... | 14 | 2009-12-24T18:31:11Z | [
"python",
"locale",
"scientific-notation"
] |
Python scientific notation using D instead of E | 1,959,210 | <p>Some results file produced by Fortran programs report double precision numbers (in scientific notation) using the letter <code>D</code> instead of <code>E</code>, for instance:</p>
<pre><code>1.2345D+02
# instead of
1.2345E+02
</code></pre>
<p>I need to process huge amounts of this data using Python, and I just re... | 8 | 2009-12-24T17:52:22Z | 6,657,771 | <p>Another option is the <a href="https://bitbucket.org/brendanarnold/py-fortranformat/wiki/Home">fortranformat</a> library for Python. It will read strings and interpret them according to a FORTRAN format statement. i.e.</p>
<pre><code>>>> import fortranformat as ff
>>> line = ff.FortranRecordReader('(F10.0)')
>>> li... | 6 | 2011-07-11T23:11:35Z | [
"python",
"locale",
"scientific-notation"
] |
get many pages with pycurl? | 1,959,240 | <p>I want to get many pages from a website, like</p>
<pre><code>curl "http://farmsubsidy.org/DE/browse?page=[0000-3603]" -o "de.#1"
</code></pre>
<p>but get the pages' data in python, not disk files.
Can someone please post <code>pycurl</code> code to do this,<br>
or fast <code>urllib2</code> (not one-at-a-time) if t... | 3 | 2009-12-24T18:01:23Z | 1,959,412 | <p>You can just put that into a bash script inside a for loop.</p>
<p>However you may have better success at parsing each page using python.
<a href="http://www.securitytube.net/Crawling-the-Web-for-Fun-and-Profit-video.aspx" rel="nofollow">http://www.securitytube.net/Crawling-the-Web-for-Fun-and-Profit-video.aspx</a>... | 1 | 2009-12-24T19:06:19Z | [
"python",
"curl",
"urllib2",
"pycurl"
] |
get many pages with pycurl? | 1,959,240 | <p>I want to get many pages from a website, like</p>
<pre><code>curl "http://farmsubsidy.org/DE/browse?page=[0000-3603]" -o "de.#1"
</code></pre>
<p>but get the pages' data in python, not disk files.
Can someone please post <code>pycurl</code> code to do this,<br>
or fast <code>urllib2</code> (not one-at-a-time) if t... | 3 | 2009-12-24T18:01:23Z | 1,959,962 | <p>here is a solution based on urllib2 and threads.</p>
<pre><code>import urllib2
from threading import Thread
BASE_URL = 'http://farmsubsidy.org/DE/browse?page='
NUM_RANGE = range(0000, 3603)
THREADS = 2
def main():
for nums in split_seq(NUM_RANGE, THREADS):
t = Spider(BASE_URL, nums)
t.start()
... | 3 | 2009-12-24T22:40:54Z | [
"python",
"curl",
"urllib2",
"pycurl"
] |
get many pages with pycurl? | 1,959,240 | <p>I want to get many pages from a website, like</p>
<pre><code>curl "http://farmsubsidy.org/DE/browse?page=[0000-3603]" -o "de.#1"
</code></pre>
<p>but get the pages' data in python, not disk files.
Can someone please post <code>pycurl</code> code to do this,<br>
or fast <code>urllib2</code> (not one-at-a-time) if t... | 3 | 2009-12-24T18:01:23Z | 3,528,383 | <p>So you have 2 problem and let me show you in one example. Notice the pycurl already did the multithreading/not one-at-a-time w/o your hardwork.</p>
<pre><code>#! /usr/bin/env python
import sys, select, time
import pycurl,StringIO
c1 = pycurl.Curl()
c2 = pycurl.Curl()
c3 = pycurl.Curl()
c1.setopt(c1.URL, "http://w... | 5 | 2010-08-20T05:23:24Z | [
"python",
"curl",
"urllib2",
"pycurl"
] |
get many pages with pycurl? | 1,959,240 | <p>I want to get many pages from a website, like</p>
<pre><code>curl "http://farmsubsidy.org/DE/browse?page=[0000-3603]" -o "de.#1"
</code></pre>
<p>but get the pages' data in python, not disk files.
Can someone please post <code>pycurl</code> code to do this,<br>
or fast <code>urllib2</code> (not one-at-a-time) if t... | 3 | 2009-12-24T18:01:23Z | 4,913,045 | <p>If you want to crawl a website using python, you should have a look to scrapy <a href="http://scrapy.org" rel="nofollow">http://scrapy.org</a></p>
| 1 | 2011-02-06T11:40:45Z | [
"python",
"curl",
"urllib2",
"pycurl"
] |
get many pages with pycurl? | 1,959,240 | <p>I want to get many pages from a website, like</p>
<pre><code>curl "http://farmsubsidy.org/DE/browse?page=[0000-3603]" -o "de.#1"
</code></pre>
<p>but get the pages' data in python, not disk files.
Can someone please post <code>pycurl</code> code to do this,<br>
or fast <code>urllib2</code> (not one-at-a-time) if t... | 3 | 2009-12-24T18:01:23Z | 10,458,671 | <p>Using <a href="http://www.crummy.com/software/BeautifulSoup/" rel="nofollow">BeautifulSoup4</a> and <a href="http://docs.python-requests.org/en/latest/" rel="nofollow">requests</a> -</p>
<p>Grab head page:</p>
<pre><code>page = Soup(requests.get(url='http://rootpage.htm').text)
</code></pre>
<p>Create an array of... | 1 | 2012-05-05T03:47:08Z | [
"python",
"curl",
"urllib2",
"pycurl"
] |
get many pages with pycurl? | 1,959,240 | <p>I want to get many pages from a website, like</p>
<pre><code>curl "http://farmsubsidy.org/DE/browse?page=[0000-3603]" -o "de.#1"
</code></pre>
<p>but get the pages' data in python, not disk files.
Can someone please post <code>pycurl</code> code to do this,<br>
or fast <code>urllib2</code> (not one-at-a-time) if t... | 3 | 2009-12-24T18:01:23Z | 12,772,358 | <p>I can recommend you to user async module of <a href="http://github.com/Lispython/human_curl" rel="nofollow">human_curl</a></p>
<p>Look example:</p>
<pre><code>from urlparse import urljoin
from datetime import datetime
from human_curl.async import AsyncClient
from human_curl.utils import stdout_debug
def succes... | 1 | 2012-10-07T19:57:22Z | [
"python",
"curl",
"urllib2",
"pycurl"
] |
Self-contained egg installs: turbogears and pythonpath | 1,959,286 | <p>I have a TG 1.0 application (not 1.1 -- I'm not sure I can convince the admin to upgrade) running. I have my own checkout of the project from cvs that I'm developing with, and it's come time to integrate xlwt (http://www.python-excel.org/) into the web app. </p>
<p>However, I don't have administrator access and it'... | 0 | 2009-12-24T18:18:19Z | 1,992,345 | <p>So, if anyone wants an easy answer for this: I inspected sys.path at run-time of my program and it turns out the root of the project (not the directory with templates/ and controllers in it, but its parent) is on it. So I added the directories to there and... voila! So I would suggest this as opposed to mucking abou... | 0 | 2010-01-02T18:26:55Z | [
"python",
"path",
"easy-install",
"egg",
"pythonpath"
] |
Self-contained egg installs: turbogears and pythonpath | 1,959,286 | <p>I have a TG 1.0 application (not 1.1 -- I'm not sure I can convince the admin to upgrade) running. I have my own checkout of the project from cvs that I'm developing with, and it's come time to integrate xlwt (http://www.python-excel.org/) into the web app. </p>
<p>However, I don't have administrator access and it'... | 0 | 2009-12-24T18:18:19Z | 1,992,386 | <p>Why don't you use just <a href="http://pypi.python.org/pypi/virtualenv" rel="nofollow">Virtualenv</a>, create a Python installation which you (as a user own) and install the TG egg inside that? This would make it convenient for you to install non-standard packages as well. I did this since I couldn't get my admin to... | 1 | 2010-01-02T18:38:15Z | [
"python",
"path",
"easy-install",
"egg",
"pythonpath"
] |
Best way to add common date_added, date_modified to many models in Django | 1,959,311 | <p>I am adding date_added and date_modified fields to a bunch of common models in my current project. I am subclassing models.Model and adding the appropriate fields, but I want to add automated save behavior (i.e: evey time anyone calls MyModel.save(), the date_modified field gets updated. I see two approaches: overri... | 4 | 2009-12-24T18:30:50Z | 1,959,322 | <p>You can define these in an <a href="http://docs.djangoproject.com/en/dev/topics/db/models/#id6" rel="nofollow">Abstract Base Class</a> and then inherit from that. It's sort of like having a MixIn that also defines model fields.</p>
| 2 | 2009-12-24T18:35:22Z | [
"python",
"django",
"django-models",
"save",
"django-signals"
] |
Best way to add common date_added, date_modified to many models in Django | 1,959,311 | <p>I am adding date_added and date_modified fields to a bunch of common models in my current project. I am subclassing models.Model and adding the appropriate fields, but I want to add automated save behavior (i.e: evey time anyone calls MyModel.save(), the date_modified field gets updated. I see two approaches: overri... | 4 | 2009-12-24T18:30:50Z | 1,959,402 | <p>Did you try looking at <code>DateTimeField</code>'s <code>auto_now=True</code> and <code>auto_now_add=True</code>? They do just what you need automatically. Otherwise, there is no real difference between doing save override and signal handling - in fact, pre_save signal is being called from django model's save metho... | 4 | 2009-12-24T19:02:17Z | [
"python",
"django",
"django-models",
"save",
"django-signals"
] |
Best way to add common date_added, date_modified to many models in Django | 1,959,311 | <p>I am adding date_added and date_modified fields to a bunch of common models in my current project. I am subclassing models.Model and adding the appropriate fields, but I want to add automated save behavior (i.e: evey time anyone calls MyModel.save(), the date_modified field gets updated. I see two approaches: overri... | 4 | 2009-12-24T18:30:50Z | 1,959,921 | <p>Since you're new to Django, you might find the Django Command Extensions useful:</p>
<p><a href="http://code.google.com/p/django-command-extensions/" rel="nofollow">http://code.google.com/p/django-command-extensions/</a></p>
<p>... which conveniently includes a TimeStampedModel you can derive your models from:</p>... | 4 | 2009-12-24T22:23:53Z | [
"python",
"django",
"django-models",
"save",
"django-signals"
] |
Best way to add common date_added, date_modified to many models in Django | 1,959,311 | <p>I am adding date_added and date_modified fields to a bunch of common models in my current project. I am subclassing models.Model and adding the appropriate fields, but I want to add automated save behavior (i.e: evey time anyone calls MyModel.save(), the date_modified field gets updated. I see two approaches: overri... | 4 | 2009-12-24T18:30:50Z | 14,454,552 | <p>Note that <code>auto_now_add</code> and <code>auto_now</code> uses <code>pre_save</code>, which not working when <code>bulk_create</code> or <code>update</code>. Thus in your MySQL, for example, date_added field will be '0000-00-00 00:00:00' and it is possible to get warning: 'Warning: Column 'date_added' cannot be ... | 1 | 2013-01-22T08:43:10Z | [
"python",
"django",
"django-models",
"save",
"django-signals"
] |
str.format() problem | 1,959,364 | <p>So I made this class that outputs '{0}' when x=0 or '{1}' for every other value of x.</p>
<pre><code>class offset(str):
def __init__(self,x):
self.x=x
def__repr__(self):
return repr(str({int(bool(self.x))}))
def end(self,end_of_loop):
#ignore this def it works fine
if s... | 3 | 2009-12-24T18:48:01Z | 1,959,388 | <p>Your subclass of <code>str</code> does not override <code>format</code>, so when you call <code>format</code> on one of its instances it just uses the one inherited from <code>str</code> which uses <code>self</code>'s "intrinsic value as <code>str</code>", i.e., the string form of whatever you passed to <code>offset... | 4 | 2009-12-24T18:57:07Z | [
"python"
] |
Django JSON Serialization with Mixed Django models and a Dictionary | 1,959,375 | <p>I can't seem to find a good way to serialize both Django Models and Python dictionaries together, its pretty common for me to return a json response that looks like</p>
<pre><code>{
"modified":updated_object,
"success":true
... some additional data...
}
</code></pre>
<p>Its simple enough to use either simple... | 4 | 2009-12-24T18:53:03Z | 1,959,408 | <p>Can't you just convert the model instance to a dict, join the other dict and then serialize?</p>
<pre><code>from django.forms import model_to_dict
dict = model_to_dict(instance)
dict.update(dict2)
... Then serialize here ...
</code></pre>
<p>Don't know about being "better"... :-)</p>
| 10 | 2009-12-24T19:05:40Z | [
"python",
"django",
"json",
"serialization"
] |
Django JSON Serialization with Mixed Django models and a Dictionary | 1,959,375 | <p>I can't seem to find a good way to serialize both Django Models and Python dictionaries together, its pretty common for me to return a json response that looks like</p>
<pre><code>{
"modified":updated_object,
"success":true
... some additional data...
}
</code></pre>
<p>Its simple enough to use either simple... | 4 | 2009-12-24T18:53:03Z | 17,973,616 | <p>I'm using this (where <code>products</code> is queryset):</p>
<pre><code>response = {}
products_list = list(products.values('id', 'name', 'description'))
response['products'] = products_list
response['more_data'] = 'more, more, more, things'
json_data = json.dumps(response)
</code></pre>
<p>Using this method you ... | 2 | 2013-07-31T14:46:53Z | [
"python",
"django",
"json",
"serialization"
] |
How do you sort a list in Jinja2? | 1,959,386 | <p>I am trying to do this:</p>
<pre><code> {% for movie in movie_list | sort(movie.rating) %}
</code></pre>
<p>But that's not right...the documentation is vague...how do you do this in Jinja2?</p>
| 35 | 2009-12-24T18:56:31Z | 1,959,413 | <p>Usually we sort the list before giving it to Jinja2. There's no way to specify a key in Jinja's <code>sort</code> filter.</p>
<p>However, you can always try <code>{% for movie in movie_list|sort %}</code>. That's the syntax. You don't get to provide any sort of key information for the sorting.</p>
<p>You can al... | 10 | 2009-12-24T19:06:26Z | [
"python",
"sorting",
"jinja2"
] |
How do you sort a list in Jinja2? | 1,959,386 | <p>I am trying to do this:</p>
<pre><code> {% for movie in movie_list | sort(movie.rating) %}
</code></pre>
<p>But that's not right...the documentation is vague...how do you do this in Jinja2?</p>
| 35 | 2009-12-24T18:56:31Z | 5,490,174 | <p>As of version 2.6, Jinja2's built-in sort filter allows you to specify an attribute to sort by:</p>
<pre><code>{% for movie in movie_list|sort(attribute='rating') %}
</code></pre>
<p>See <a href="http://jinja.pocoo.org/docs/templates/#sort">http://jinja.pocoo.org/docs/templates/#sort</a></p>
| 66 | 2011-03-30T17:55:47Z | [
"python",
"sorting",
"jinja2"
] |
How do you sort a list in Jinja2? | 1,959,386 | <p>I am trying to do this:</p>
<pre><code> {% for movie in movie_list | sort(movie.rating) %}
</code></pre>
<p>But that's not right...the documentation is vague...how do you do this in Jinja2?</p>
| 35 | 2009-12-24T18:56:31Z | 39,051,279 | <p>If you want to sort in ascending order</p>
<pre><code>{% for movie in movie_list|sort(attribute='rating') %}
</code></pre>
<p>If you want to sort in descending order</p>
<pre><code>{% for movie in movie_list|sort(attribute='rating', reverse = True) %}
</code></pre>
| 0 | 2016-08-20T06:41:16Z | [
"python",
"sorting",
"jinja2"
] |
Django uploading image error | 1,959,447 | <p>I'm trying to upload an image using normal form for normal admin for normal model with normal image field.</p>
<pre><code>thumb = fields.ThumbnailField(upload_to=make_upload_path, sizes=settings.VIDEO_THUMB_SIZE, blank=True, null=True)
</code></pre>
<p>But I'm getting an error:</p>
<pre><code>Upload a valid image... | 0 | 2009-12-24T19:20:53Z | 1,959,765 | <p>You probably have PIL (Python Imaging Library) installed without JPEG support. If you don't have the libjpeg header files it'll happily compile and install, just with no JPEG support. You need to uninstall PIL, make sure you install libjpeg and the libjpeg development header files, and then reinstall PIL. How you do... | 3 | 2009-12-24T21:05:19Z | [
"python",
"django"
] |
Django-registration, template | 1,959,511 | <p>where can I find good templates for django-registration? I've found one, but the activation isn't work properly - when user click on activation link he gets:</p>
<blockquote>
<p>Hello !
Check your e-mail to confirm registration. 7 days left.</p>
</blockquote>
<p>Instead of ~"Activation succesfull/fail".</p>
| 15 | 2009-12-24T19:41:01Z | 1,960,085 | <p>Some templates can be found here: <a href="http://devdoodles.wordpress.com/2009/02/16/user-authentication-with-django-registration/" rel="nofollow">http://devdoodles.wordpress.com/2009/02/16/user-authentication-with-django-registration/</a></p>
<pre><code>$ tree
.
|-- [ 981] base.html
|-- [ ... | 17 | 2009-12-24T23:47:51Z | [
"python",
"django"
] |
Django-registration, template | 1,959,511 | <p>where can I find good templates for django-registration? I've found one, but the activation isn't work properly - when user click on activation link he gets:</p>
<blockquote>
<p>Hello !
Check your e-mail to confirm registration. 7 days left.</p>
</blockquote>
<p>Instead of ~"Activation succesfull/fail".</p>
| 15 | 2009-12-24T19:41:01Z | 4,295,551 | <p>I found the templates here to be a good starting point:</p>
<p><a href="https://github.com/yourcelf/django-registration-defaults">https://github.com/yourcelf/django-registration-defaults</a></p>
<p>(Note that you need to a base.html for them to include)</p>
| 14 | 2010-11-28T05:34:22Z | [
"python",
"django"
] |
Django-registration, template | 1,959,511 | <p>where can I find good templates for django-registration? I've found one, but the activation isn't work properly - when user click on activation link he gets:</p>
<blockquote>
<p>Hello !
Check your e-mail to confirm registration. 7 days left.</p>
</blockquote>
<p>Instead of ~"Activation succesfull/fail".</p>
| 15 | 2009-12-24T19:41:01Z | 5,646,091 | <p><a href="http://agiliq.com/books/djenofdjango/chapter5.html#reusable-apps" rel="nofollow">the djen of django book</a> has some templates for django-registration with some explanations.</p>
| 2 | 2011-04-13T07:57:54Z | [
"python",
"django"
] |
Django-registration, template | 1,959,511 | <p>where can I find good templates for django-registration? I've found one, but the activation isn't work properly - when user click on activation link he gets:</p>
<blockquote>
<p>Hello !
Check your e-mail to confirm registration. 7 days left.</p>
</blockquote>
<p>Instead of ~"Activation succesfull/fail".</p>
| 15 | 2009-12-24T19:41:01Z | 38,577,039 | <p>Make sure you are using the latest version of Django-registration-redux. Current version is 1.4. Also go to <a href="https://github.com/macropin/django-registration/tree/master/registration/templates/registration" rel="nofollow">this</a> link and download django-registration app manually. After its downloaded just d... | 1 | 2016-07-25T20:39:06Z | [
"python",
"django"
] |
best way to deal with python pdb flakiness re/stdout? | 1,959,662 | <p>If I have a program where <code>stdout</code> is redirected, my pdb prompts all go to the redirection, because the library was written to write to <code>stdout</code>.</p>
<p>Oftentimes this problem is subtle, causing me to think a program is hanging when it's really waiting for input. </p>
<p>How do people work a... | 4 | 2009-12-24T20:28:52Z | 1,959,794 | <p>If you are invoking pdb in code, you can pass your own stdout into the constructor. <code>sys.__stdout__</code> might be a good choice.</p>
<p>If you are invoking pdb from the command line, you could copy the <code>main()</code> function from pdb.py into your own sane_pdb.py. Then change the Pdb() initialization ... | 2 | 2009-12-24T21:17:28Z | [
"python",
"pdb"
] |
best way to deal with python pdb flakiness re/stdout? | 1,959,662 | <p>If I have a program where <code>stdout</code> is redirected, my pdb prompts all go to the redirection, because the library was written to write to <code>stdout</code>.</p>
<p>Oftentimes this problem is subtle, causing me to think a program is hanging when it's really waiting for input. </p>
<p>How do people work a... | 4 | 2009-12-24T20:28:52Z | 1,960,351 | <p>This answer is just to supplement Ned's, as a way of wrapping the pdb.py <code>main()</code> function in a manner which doesn't require copying 40 lines just to change one of them:</p>
<pre><code># sane_pdb.py: launch Pdb with stdout on original
import sys, pdb
def fixed_pdb(Pdb=pdb.Pdb):
'''make Pdb() tied to ... | 4 | 2009-12-25T02:58:11Z | [
"python",
"pdb"
] |
best way to deal with python pdb flakiness re/stdout? | 1,959,662 | <p>If I have a program where <code>stdout</code> is redirected, my pdb prompts all go to the redirection, because the library was written to write to <code>stdout</code>.</p>
<p>Oftentimes this problem is subtle, causing me to think a program is hanging when it's really waiting for input. </p>
<p>How do people work a... | 4 | 2009-12-24T20:28:52Z | 26,899,968 | <p>The problem here is that PDB uses Cmd class where by default:</p>
<pre><code>use_rawinput = 1
</code></pre>
<p>It means that Cmd will use <code>raw_input()</code> method by default instead of <code>sys.stdout.readline()</code> to read from the console . This is done because <code>raw_input()</code> supports histor... | 1 | 2014-11-13T01:44:38Z | [
"python",
"pdb"
] |
Python list problem | 1,959,744 | <p>python:</p>
<pre><code>m=[[0]*3]*2
for i in range(3):
m[0][i]=1
print m
</code></pre>
<p>I expect that this code should print</p>
<pre><code>[[1, 1, 1], [0, 0, 0]]
</code></pre>
<p>but it prints</p>
<pre><code>[[1, 1, 1], [1, 1, 1]]
</code></pre>
| 9 | 2009-12-24T20:57:24Z | 1,959,756 | <p>This is by design. When you use multiplication on elements of a list, you are reproducing the references.</p>
<p>See <a href="http://en.wikibooks.org/wiki/Python%5FProgramming/Lists#List%5Fcreation%5Fshortcuts">the section "List creation shortcuts" on the Python Programming/Lists wikibook</a> which goes into detai... | 13 | 2009-12-24T21:02:00Z | [
"python",
"list"
] |
Python list problem | 1,959,744 | <p>python:</p>
<pre><code>m=[[0]*3]*2
for i in range(3):
m[0][i]=1
print m
</code></pre>
<p>I expect that this code should print</p>
<pre><code>[[1, 1, 1], [0, 0, 0]]
</code></pre>
<p>but it prints</p>
<pre><code>[[1, 1, 1], [1, 1, 1]]
</code></pre>
| 9 | 2009-12-24T20:57:24Z | 1,959,763 | <p>This is a bit devilish, but quite obvious when you understand what you're doing. when you're doing the <code>[[0]*3]*2</code> bit, you're first creating a list with 3 zeros, then you copy that to make two elements. But when you do that copy, you do not create new lists with the same contents, but rather reference th... | 6 | 2009-12-24T21:04:41Z | [
"python",
"list"
] |
Windows Server cannot execute a py2exe-generated app | 1,959,811 | <p>A simple python script needs to run on a windows server with no python installed.</p>
<p>I used py2exe, which generated a healthy dist subdirectory, with script.exe that runs fine on the local machine.<br>
However, when I run it on the server (Windows Server 2003 R2), it produces this:<br>
<em>The system cannot exe... | 5 | 2009-12-24T21:26:29Z | 1,959,886 | <p>It could be missing some required DLLs. Try using <a href="http://dependencywalker.com/" rel="nofollow">depends.exe</a> to identify what might be missing. It's probably an msvc-something-something.dll</p>
| 2 | 2009-12-24T22:06:51Z | [
"python",
"windows",
"py2exe"
] |
Windows Server cannot execute a py2exe-generated app | 1,959,811 | <p>A simple python script needs to run on a windows server with no python installed.</p>
<p>I used py2exe, which generated a healthy dist subdirectory, with script.exe that runs fine on the local machine.<br>
However, when I run it on the server (Windows Server 2003 R2), it produces this:<br>
<em>The system cannot exe... | 5 | 2009-12-24T21:26:29Z | 1,962,069 | <p>I did not find the cause to the problem, but using python 2.5 with py2exe on the same script worked fine on the server. </p>
<p>I guess there is something wrong with py2exe under 2.6. </p>
| 1 | 2009-12-25T22:14:25Z | [
"python",
"windows",
"py2exe"
] |
Windows Server cannot execute a py2exe-generated app | 1,959,811 | <p>A simple python script needs to run on a windows server with no python installed.</p>
<p>I used py2exe, which generated a healthy dist subdirectory, with script.exe that runs fine on the local machine.<br>
However, when I run it on the server (Windows Server 2003 R2), it produces this:<br>
<em>The system cannot exe... | 5 | 2009-12-24T21:26:29Z | 2,678,877 | <p>Because Python 2.6 is built against Visual Studio 2008, the target machine must also have the Visual Studio 2008 libraries, available from the <a href="http://www.microsoft.com/downloads/details.aspx?familyid=A5C84275-3B97-4AB7-A40D-3802B2AF5FC2&displaylang=en" rel="nofollow">Visual C++ 2008 Redistributable pack... | 1 | 2010-04-20T21:42:39Z | [
"python",
"windows",
"py2exe"
] |
Windows Server cannot execute a py2exe-generated app | 1,959,811 | <p>A simple python script needs to run on a windows server with no python installed.</p>
<p>I used py2exe, which generated a healthy dist subdirectory, with script.exe that runs fine on the local machine.<br>
However, when I run it on the server (Windows Server 2003 R2), it produces this:<br>
<em>The system cannot exe... | 5 | 2009-12-24T21:26:29Z | 3,212,695 | <p>For py2exe to work, you have to include the correct version of the Microsoft C runtime DLL with your application.</p>
<p>For Python2.6, this is MSVCR90.dll version 9.0.21022.8, which can be obtained from the Microsoft Visual C++ 2008 Redistributable Package:</p>
<p><a href="http://www.microsoft.com/downloads/detai... | 6 | 2010-07-09T12:49:57Z | [
"python",
"windows",
"py2exe"
] |
Python if else micro-optimization | 1,959,944 | <p>In pondering optimization of code, I was wondering which was more expensive in python:</p>
<pre><code>if x:
d = 1
else:
d = 2
</code></pre>
<p>or</p>
<pre><code>d = 2
if x:
d = 1
</code></pre>
<p>Any thoughts? I like the reduced line count in the second but wondered if reassignment was more costly t... | 3 | 2009-12-24T22:33:35Z | 1,959,950 | <p>The second one should obviously be more expensive, it does the same operations if <code>x</code> is false and twice the assignments if <code>x</code> is true.</p>
<p>Assumption: assignment is more expensive in python than a conditional jump, which makes sense since its interpreted and it has to read a run time hash... | 2 | 2009-12-24T22:36:42Z | [
"python",
"micro-optimization"
] |
Python if else micro-optimization | 1,959,944 | <p>In pondering optimization of code, I was wondering which was more expensive in python:</p>
<pre><code>if x:
d = 1
else:
d = 2
</code></pre>
<p>or</p>
<pre><code>d = 2
if x:
d = 1
</code></pre>
<p>Any thoughts? I like the reduced line count in the second but wondered if reassignment was more costly t... | 3 | 2009-12-24T22:33:35Z | 1,959,953 | <p>You should probably benchmark this, but there's also a third form that uses the ternary operator:</p>
<pre><code>d = 1 if x else 2
</code></pre>
| 5 | 2009-12-24T22:37:59Z | [
"python",
"micro-optimization"
] |
Python if else micro-optimization | 1,959,944 | <p>In pondering optimization of code, I was wondering which was more expensive in python:</p>
<pre><code>if x:
d = 1
else:
d = 2
</code></pre>
<p>or</p>
<pre><code>d = 2
if x:
d = 1
</code></pre>
<p>Any thoughts? I like the reduced line count in the second but wondered if reassignment was more costly t... | 3 | 2009-12-24T22:33:35Z | 1,960,000 | <p>Don't ponder, don't wonder, <strong>measure</strong> -- with <code>timeit</code> <strong>at the shell command line</strong> (by far the best, simplest way to use it!). Python 2.5.4 on Mac OSX 10.5 on a laptop...:</p>
<pre><code>$ python -mtimeit -s'x=0' 'if x: d=1' 'else: d=2'
10000000 loops, best of 3: 0.0748 usec... | 19 | 2009-12-24T22:57:06Z | [
"python",
"micro-optimization"
] |
Python if else micro-optimization | 1,959,944 | <p>In pondering optimization of code, I was wondering which was more expensive in python:</p>
<pre><code>if x:
d = 1
else:
d = 2
</code></pre>
<p>or</p>
<pre><code>d = 2
if x:
d = 1
</code></pre>
<p>Any thoughts? I like the reduced line count in the second but wondered if reassignment was more costly t... | 3 | 2009-12-24T22:33:35Z | 1,960,017 | <p>I would argue that the one that is most readable is the most optimized (for readability at least).</p>
<p>The if...else construct makes it clear that you are dealing with an either/or case.</p>
<p>The assignment construct might make more sense if (d==2) is the usual value and your if tests for an unusual case. Th... | 1 | 2009-12-24T23:08:14Z | [
"python",
"micro-optimization"
] |
GAE template code to check is item in the list | 1,960,022 | <p>How to use "in" statement to check is item in the list or not. If I use:</p>
<pre><code>{% for picture in pictures %}
{% if picture in article.pictures %}
<input type="checkbox" checked="true" name="picture" value="{{ picture.key }}" />
{% else %}
<input type="checkbox" name="picture" va... | 0 | 2009-12-24T23:11:14Z | 1,960,111 | <p>I've not worked with GAE, but the code for a custom "ifin" Django tag can be found in the patch <a href="http://code.djangoproject.com/attachment/ticket/8087/django-ifin-templatetag.patch" rel="nofollow">here</a>. As mentioned in my comment, it looks like that functionality may be implemented in Django 1.2</p>
| 1 | 2009-12-24T23:58:33Z | [
"python",
"google-app-engine",
"templates"
] |
GAE template code to check is item in the list | 1,960,022 | <p>How to use "in" statement to check is item in the list or not. If I use:</p>
<pre><code>{% for picture in pictures %}
{% if picture in article.pictures %}
<input type="checkbox" checked="true" name="picture" value="{{ picture.key }}" />
{% else %}
<input type="checkbox" name="picture" va... | 0 | 2009-12-24T23:11:14Z | 1,960,138 | <p>By default, Django templates do not support full conditional expressions. You can check if one value is "true" with if, or you can check whether two values are equal with <code>ifequal</code>, etc.</p>
<p>Perhaps you can decorate your <code>picture</code>s in the view before you render the template.</p>
<pre><code... | 2 | 2009-12-25T00:16:49Z | [
"python",
"google-app-engine",
"templates"
] |
Start a "throwaway" MySQL session for testing code? | 1,960,155 | <p>If I want to be able to test my application against a empty MySQL database each time my application's testsuite is run, how can I start up a server as a non-root user which refers to a empty (not saved anywhere, or in saved to <code>/tmp</code>) MySQL database?</p>
<p>My application is in Python, and I'm using <cod... | 2 | 2009-12-25T00:25:16Z | 1,960,160 | <p>--datadir for just the data or --basedir</p>
| 1 | 2009-12-25T00:33:36Z | [
"python",
"mysql",
"unit-testing",
"ubuntu"
] |
Start a "throwaway" MySQL session for testing code? | 1,960,155 | <p>If I want to be able to test my application against a empty MySQL database each time my application's testsuite is run, how can I start up a server as a non-root user which refers to a empty (not saved anywhere, or in saved to <code>/tmp</code>) MySQL database?</p>
<p>My application is in Python, and I'm using <cod... | 2 | 2009-12-25T00:25:16Z | 1,960,164 | <p>You can try the Blackhole and Memory table types in MySQL.</p>
| 0 | 2009-12-25T00:37:28Z | [
"python",
"mysql",
"unit-testing",
"ubuntu"
] |
How does this class implement the "__iter__" method without implementing "next"? | 1,960,309 | <p>I have the following code in django.template:</p>
<pre><code>class Template(object):
def __init__(self, template_string, origin=None, name='<Unknown Template>'):
try:
template_string = smart_unicode(template_string)
except UnicodeDecodeError:
raise TemplateEncodingE... | 13 | 2009-12-25T02:35:50Z | 1,960,325 | <p>That <code>__iter__</code>method returns a python <strong>generator</strong> (see the <a href="http://docs.python.org/tutorial/classes.html#generators">documentation</a>), as it uses the <code>yield</code> keyword.
The generator will provide the next() method automatically; quoting the documentation:</p>
<blockquot... | 9 | 2009-12-25T02:44:12Z | [
"python",
"iterator",
"yield"
] |
How does this class implement the "__iter__" method without implementing "next"? | 1,960,309 | <p>I have the following code in django.template:</p>
<pre><code>class Template(object):
def __init__(self, template_string, origin=None, name='<Unknown Template>'):
try:
template_string = smart_unicode(template_string)
except UnicodeDecodeError:
raise TemplateEncodingE... | 13 | 2009-12-25T02:35:50Z | 1,960,330 | <p>From the <a href="http://docs.python.org/library/stdtypes.html#generator-types">docs</a>: </p>
<blockquote>
<p>If a container objectâs <code>__iter__()</code>
method is implemented as a generator,
it will automatically return an
iterator object (technically, a
generator object) supplying the
<code>__i... | 27 | 2009-12-25T02:47:23Z | [
"python",
"iterator",
"yield"
] |
Python JSON serialize a Decimal object | 1,960,516 | <p>I have a <code>Decimal('3.9')</code> as part of an object, and wish to encode this to a JSON string which should look like <code>{'x': 3.9}</code>. I don't care about precision on the client side, so a float is fine.</p>
<p>Is there a good way to serialize this? JSONDecoder doesn't accept Decimal objects, and conve... | 87 | 2009-12-25T05:00:12Z | 1,960,553 | <p><code>3.9</code> can not be exactly represented in IEEE floats, it will always come as <code>3.8999999999999999</code>, e.g. try <code>print repr(3.9)</code>, you can read more about it here: </p>
<p><a href="http://en.wikipedia.org/wiki/Floating_point">http://en.wikipedia.org/wiki/Floating_point</a><br>
<a href=... | 9 | 2009-12-25T05:29:17Z | [
"python",
"json"
] |
Python JSON serialize a Decimal object | 1,960,516 | <p>I have a <code>Decimal('3.9')</code> as part of an object, and wish to encode this to a JSON string which should look like <code>{'x': 3.9}</code>. I don't care about precision on the client side, so a float is fine.</p>
<p>Is there a good way to serialize this? JSONDecoder doesn't accept Decimal objects, and conve... | 87 | 2009-12-25T05:00:12Z | 1,960,564 | <p>this can be done by adding </p>
<pre><code> elif isinstance(o, decimal.Decimal):
yield str(o)
</code></pre>
<p>in <code>\Lib\json\encoder.py:JSONEncoder._iterencode</code>, but I was hoping for a better solution</p>
| -2 | 2009-12-25T05:37:41Z | [
"python",
"json"
] |
Python JSON serialize a Decimal object | 1,960,516 | <p>I have a <code>Decimal('3.9')</code> as part of an object, and wish to encode this to a JSON string which should look like <code>{'x': 3.9}</code>. I don't care about precision on the client side, so a float is fine.</p>
<p>Is there a good way to serialize this? JSONDecoder doesn't accept Decimal objects, and conve... | 87 | 2009-12-25T05:00:12Z | 1,960,649 | <p>How about subclassing <code>json.JSONEncoder</code>?</p>
<pre><code>class DecimalEncoder(json.JSONEncoder):
def _iterencode(self, o, markers=None):
if isinstance(o, decimal.Decimal):
# wanted a simple yield str(o) in the next line,
# but that would mean a yield on the line with s... | 69 | 2009-12-25T06:43:22Z | [
"python",
"json"
] |
Python JSON serialize a Decimal object | 1,960,516 | <p>I have a <code>Decimal('3.9')</code> as part of an object, and wish to encode this to a JSON string which should look like <code>{'x': 3.9}</code>. I don't care about precision on the client side, so a float is fine.</p>
<p>Is there a good way to serialize this? JSONDecoder doesn't accept Decimal objects, and conve... | 87 | 2009-12-25T05:00:12Z | 3,148,376 | <p><a href="http://code.google.com/p/simplejson/">Simplejson 2.1</a> and higher has native support for Decimal type:</p>
<pre><code>>>> json.dumps(Decimal('3.9'), use_decimal=True)
'3.9'
</code></pre>
<p>Note that <code>use_decimal</code> is <code>True</code> by default:</p>
<pre><code>def dumps(obj, skipke... | 110 | 2010-06-30T10:34:21Z | [
"python",
"json"
] |
Python JSON serialize a Decimal object | 1,960,516 | <p>I have a <code>Decimal('3.9')</code> as part of an object, and wish to encode this to a JSON string which should look like <code>{'x': 3.9}</code>. I don't care about precision on the client side, so a float is fine.</p>
<p>Is there a good way to serialize this? JSONDecoder doesn't accept Decimal objects, and conve... | 87 | 2009-12-25T05:00:12Z | 3,885,198 | <p>I would like to let everyone know that I tried MichaÅ Marczyk's answer on my web server that was running Python 2.6.5 and it worked fine. However, I upgraded to Python 2.7 and it stopped working. I tried to think of some sort of way to encode Decimal objects and this is what I came up with:</p>
<pre><code>class De... | 71 | 2010-10-07T19:29:03Z | [
"python",
"json"
] |
Python JSON serialize a Decimal object | 1,960,516 | <p>I have a <code>Decimal('3.9')</code> as part of an object, and wish to encode this to a JSON string which should look like <code>{'x': 3.9}</code>. I don't care about precision on the client side, so a float is fine.</p>
<p>Is there a good way to serialize this? JSONDecoder doesn't accept Decimal objects, and conve... | 87 | 2009-12-25T05:00:12Z | 8,274,307 | <p>I tried switching from simplejson to builtin json for GAE 2.7, and had issues with the decimal. If default returned str(o) there were quotes (because _iterencode calls _iterencode on the results of default), and float(o) would remove trailing 0.</p>
<p>If default returns an object of a class that inherits from floa... | 10 | 2011-11-25T21:17:24Z | [
"python",
"json"
] |
Python JSON serialize a Decimal object | 1,960,516 | <p>I have a <code>Decimal('3.9')</code> as part of an object, and wish to encode this to a JSON string which should look like <code>{'x': 3.9}</code>. I don't care about precision on the client side, so a float is fine.</p>
<p>Is there a good way to serialize this? JSONDecoder doesn't accept Decimal objects, and conve... | 87 | 2009-12-25T05:00:12Z | 28,269,980 | <p>This is what I have, extracted from our class</p>
<pre><code>class CommonJSONEncoder(json.JSONEncoder):
"""
Common JSON Encoder
json.dumps(myString, cls=CommonJSONEncoder)
"""
def default(self, obj):
if isinstance(obj, decimal.Decimal):
return {'type{decimal}': str(obj)}
... | 3 | 2015-02-02T01:30:54Z | [
"python",
"json"
] |
Python JSON serialize a Decimal object | 1,960,516 | <p>I have a <code>Decimal('3.9')</code> as part of an object, and wish to encode this to a JSON string which should look like <code>{'x': 3.9}</code>. I don't care about precision on the client side, so a float is fine.</p>
<p>Is there a good way to serialize this? JSONDecoder doesn't accept Decimal objects, and conve... | 87 | 2009-12-25T05:00:12Z | 39,257,479 | <p>In my Flask app, Which uses python 2.7.11, flask alchemy(with 'db.decimal' types), and Flask Marshmallow ( for 'instant' serializer and deserializer), i had this error, every time i did a GET or POST. The serializer and deserializer, failed to convert Decimal types into any JSON identifiable format. </p>
<p>I did ... | 1 | 2016-08-31T19:21:54Z | [
"python",
"json"
] |
how can i use '@' by myself function like '@staticmethod' | 1,960,659 | <p>the next is my code,it can print <code>'xxx'</code>, but run wrong at last:</p>
<pre><code>def a(object):
print 'xxx'
@a
def b():
return 'bbb'
b()
</code></pre>
<p>In your answers, please try to use code examples rather than text, because my English is not very good. Thank you.</p>
| 0 | 2009-12-25T06:56:55Z | 1,960,664 | <pre><code>def a(b):
print 'xxx'
return b
@a
def b():
return 'bbb'
b()
</code></pre>
<p>This is the same as:</p>
<pre><code>def a(b):
print 'xxx'
return b
def b():
return 'bbb'
b = a(b)
b()
</code></pre>
| 1 | 2009-12-25T07:00:27Z | [
"python",
"decorator"
] |
how can i use '@' by myself function like '@staticmethod' | 1,960,659 | <p>the next is my code,it can print <code>'xxx'</code>, but run wrong at last:</p>
<pre><code>def a(object):
print 'xxx'
@a
def b():
return 'bbb'
b()
</code></pre>
<p>In your answers, please try to use code examples rather than text, because my English is not very good. Thank you.</p>
| 0 | 2009-12-25T06:56:55Z | 1,960,708 | <p>The decorator form <code>@a</code> means:</p>
<pre><code>@a
def b...
</code></pre>
<p>is <strong>exactly</strong> the same as:</p>
<pre><code>def b...
b = a(b)
</code></pre>
<p>So, write <code>a</code> as a <em>higher order function</em>, AKA <strong>HOF</strong>: specifically, a function that takes a function ... | 5 | 2009-12-25T07:31:19Z | [
"python",
"decorator"
] |
why does my 'join' function run wrong | 1,960,698 | <pre><code>b=','.join([1,2,3,4,5])
print b
</code></pre>
<p>I want it to print the string: <code>'1,2,3,4,5'</code></p>
<p>In your answers, please try to use code examples rather than text, because my English is not very good. Thank you.</p>
| 0 | 2009-12-25T07:24:55Z | 1,960,704 | <p>The join function expects strings not integers, if you did <code>b=','.join(["1","2","3","4","5"])</code> instead it works. </p>
<p>Here's the consoles output:</p>
<pre><code>>>> b=','.join(["1","2","3","4","5"])
>>> print b
1,2,3,4,5
>>>
</code></pre>
| 4 | 2009-12-25T07:29:54Z | [
"python"
] |
why does my 'join' function run wrong | 1,960,698 | <pre><code>b=','.join([1,2,3,4,5])
print b
</code></pre>
<p>I want it to print the string: <code>'1,2,3,4,5'</code></p>
<p>In your answers, please try to use code examples rather than text, because my English is not very good. Thank you.</p>
| 0 | 2009-12-25T07:24:55Z | 1,960,706 | <pre><code>b = ','.join(map(str, [1,2,3,4,5]))
# => '1,2,3,4,5'
</code></pre>
<p>Python doesn't automatically turn the ints into strings--you have to convert them to strings first, then join them.</p>
| 7 | 2009-12-25T07:30:24Z | [
"python"
] |
why does my 'join' function run wrong | 1,960,698 | <pre><code>b=','.join([1,2,3,4,5])
print b
</code></pre>
<p>I want it to print the string: <code>'1,2,3,4,5'</code></p>
<p>In your answers, please try to use code examples rather than text, because my English is not very good. Thank you.</p>
| 0 | 2009-12-25T07:24:55Z | 1,960,711 | <p><code>anystring.join</code> takes an iterable of <strong>STRINGS</strong>, <strong>not</strong> one of integers, which is what you're passing to it!</p>
<p>So, use <code>','.join(str(x) for x in range(1, 6))</code> or the like.</p>
| 7 | 2009-12-25T07:33:46Z | [
"python"
] |
Refreshing a window in Tkinter | 1,960,725 | <p>I am trying to make a GUI in Tkinter and am wondering how to refresh a window, namely if I fill in a rectangle, I want the GUI to delete it a specified time later. How would I go about doing this? Documentation on Tkinter seems to be thin...</p>
| 2 | 2009-12-25T07:42:55Z | 1,961,239 | <p>Each Tkinter widget has a <code>after</code> method, which you can use to call your rectangle delete function e.g. in the example below first I change a msg using <code>after</code>, and then destruct the window using <code>after</code></p>
<pre><code>from Tkinter import *
def changeMsg():
label.configure(text... | 5 | 2009-12-25T14:34:31Z | [
"python",
"tkinter"
] |
How to extend the Turbogears 2.1 login functionality | 1,960,747 | <p>I'm using Turbogears 2.1 and repoze.who/what and am having trouble figuring out how to extend the basic authentication functionality. I am essentially attempting to require users to activate their account via an emailed link before they can login. If they try to login without activating their account, I want to disp... | 4 | 2009-12-25T08:02:17Z | 2,159,022 | <p>It's impossible to give a really good answer without seeing your actual code, but here's one idea:</p>
<ol>
<li>Create a repoze.who metadata provider plugin that "scribbles" something that indicates whether the user has activated their account.</li>
<li>Create a "challenger decider" plugin that looks at both whethe... | 4 | 2010-01-29T00:16:54Z | [
"python",
"turbogears",
"turbogears2"
] |
Write to file as Json format? | 1,960,873 | <p>I have A method for format the ouput as json.
My keyword_filter will be pass in this this format:</p>
<pre><code><QueryDict: {u'customer_type': [u'ABC'], u'tag': [u'2']}>
<QueryDict: {u'customer_type': [u'TDO'], u'tag': [u'3']}>
<QueryDict: {u'customer_type': [u'FRI'], u'tag': [u'2,3']}>
</code></... | 0 | 2009-12-25T09:35:15Z | 1,960,902 | <p>Your question is difficult to understand. I am not sure what you need. Here is my best attempt to solve your problem.</p>
<pre><code>def save_fiter_to_JSON(self, dest, filter_name, keyword_filter):
# start with an empty list
lst = []
# I don't know where you will get your qd (QueryDict instance)
... | 2 | 2009-12-25T09:59:39Z | [
"python",
"django"
] |
Write to file as Json format? | 1,960,873 | <p>I have A method for format the ouput as json.
My keyword_filter will be pass in this this format:</p>
<pre><code><QueryDict: {u'customer_type': [u'ABC'], u'tag': [u'2']}>
<QueryDict: {u'customer_type': [u'TDO'], u'tag': [u'3']}>
<QueryDict: {u'customer_type': [u'FRI'], u'tag': [u'2,3']}>
</code></... | 0 | 2009-12-25T09:35:15Z | 1,960,915 | <p>Some tips:</p>
<ul>
<li>you can convert django's <code>QueryDict</code> to to Python dictionary with <code>dict(keyword_filter)</code> expression,</li>
<li>you can add additional record to the dictionary with <code>dict(keyword_filter, name=filter_name)</code> expression.</li>
</ul>
<p>Then use <code>json</code> m... | 3 | 2009-12-25T10:13:20Z | [
"python",
"django"
] |
Polygon touches in more than one point with shapely | 1,960,961 | <p>I have a list of shapely polygons in Python. To find out which polygon touch is easy, using the .touches() method. However, I need something that returns true only when the polygons share <em>more</em> than one point (in other words shares a border). Let me illustrate:</p>
<pre><code>IPython 0.10 -- An enhanced Int... | 5 | 2009-12-25T10:47:46Z | 1,961,010 | <p>i haven't used shapely, but have you tried seeing if the intersection of the two polygons is a line?</p>
| 4 | 2009-12-25T11:21:54Z | [
"python",
"touch",
"polygon",
"shapely"
] |
Polygon touches in more than one point with shapely | 1,960,961 | <p>I have a list of shapely polygons in Python. To find out which polygon touch is easy, using the .touches() method. However, I need something that returns true only when the polygons share <em>more</em> than one point (in other words shares a border). Let me illustrate:</p>
<pre><code>IPython 0.10 -- An enhanced Int... | 5 | 2009-12-25T10:47:46Z | 1,962,164 | <p>If you truly want to check if two polygons share more than x number of points you can simply do this:</p>
<pre><code>p0,p1,p2 = polygons
x = 2
len(set(p1.boundary.coords).intersection(p2.boundary.coords))>=x
</code></pre>
<p>But I think what you may want is to determine if two edges are colinear (and overlappin... | 2 | 2009-12-25T22:59:14Z | [
"python",
"touch",
"polygon",
"shapely"
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.