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 |
|---|---|---|---|---|---|---|---|---|---|
Python, Evaluate a Variable value as a Variable | 632,856 | <p>I'd like to do something like below: particularly the 'f.eval(field)' part, such that it evaluates the value of the variable as the field name. How does one accomplish this in Python?</p>
<pre><code>def punctuated_object_list(objects, field):
field_list = [f.eval(field) for f in objects]
if len(field_list)... | 4 | 2009-03-11T00:31:50Z | 632,902 | <p>To get at a list of all the fields in a Python object you can access its <code>__dict__</code> property.</p>
<pre><code>class Testing():
def __init__(self):
self.name = "Joe"
self.age = 30
test = Testing()
print test.__dict__
</code></pre>
<p>results:</p>
<pre><code>{'age': 30, 'name': 'Joe'}... | 0 | 2009-03-11T00:43:27Z | [
"python"
] |
Python, Evaluate a Variable value as a Variable | 632,856 | <p>I'd like to do something like below: particularly the 'f.eval(field)' part, such that it evaluates the value of the variable as the field name. How does one accomplish this in Python?</p>
<pre><code>def punctuated_object_list(objects, field):
field_list = [f.eval(field) for f in objects]
if len(field_list)... | 4 | 2009-03-11T00:31:50Z | 632,911 | <pre><code>getattr( object, 'field' ) #note that field is a string
f = 'field_name'
#...
getattr( object, f )
#to get a list of fields in an object, you can use dir()
dir( object )
</code></pre>
<p>For more details, see: <a href="http://www.diveintopython.org/power_of_introspection/index.html" rel="nofollow">http:/... | 4 | 2009-03-11T00:47:08Z | [
"python"
] |
Unable to separate codes in one file to many files in AWK/Python | 632,958 | <p>I need to put different codes in one file to many files.
The file is apparantly shared by AWK's creators at their homepage.
The file is also <a href="http://dpaste.com/12282/" rel="nofollow">here</a> for easy use.</p>
<p><strong>My attempt to the problem</strong></p>
<p>I can get the lines where each code locate b... | 0 | 2009-03-11T01:06:34Z | 633,000 | <p>Are you trying to unpack a file in that format? It's a kind of shell archive. For more information, see <a href="http://en.wikipedia.org/wiki/Shar" rel="nofollow">http://en.wikipedia.org/wiki/Shar</a></p>
<p>If you execute that program with awk, awk will create all those files. You don't need to write or rewrite... | 2 | 2009-03-11T01:38:06Z | [
"python",
"awk"
] |
Unable to separate codes in one file to many files in AWK/Python | 632,958 | <p>I need to put different codes in one file to many files.
The file is apparantly shared by AWK's creators at their homepage.
The file is also <a href="http://dpaste.com/12282/" rel="nofollow">here</a> for easy use.</p>
<p><strong>My attempt to the problem</strong></p>
<p>I can get the lines where each code locate b... | 0 | 2009-03-11T01:06:34Z | 634,062 | <p>Did you try to:</p>
<ol>
<li>Create a file unbundle.awk with the following content:</li>
</ol>
<p>$1 != prev { close(prev); prev = $1 }
{ print substr($0, index($0, " ") + 1) >$1 }</p>
<ol>
<li><p>Remove the following lines form the file awkcode.txt:</p>
<p><strong># unbundle - unpack a bundle into se... | 2 | 2009-03-11T10:56:35Z | [
"python",
"awk"
] |
Unable to separate codes in one file to many files in AWK/Python | 632,958 | <p>I need to put different codes in one file to many files.
The file is apparantly shared by AWK's creators at their homepage.
The file is also <a href="http://dpaste.com/12282/" rel="nofollow">here</a> for easy use.</p>
<p><strong>My attempt to the problem</strong></p>
<p>I can get the lines where each code locate b... | 0 | 2009-03-11T01:06:34Z | 19,219,465 | <p>Awk file awkcode.txt should not contain ANY BLANK line. If any blank line is encountered, the awk program fails. There is no error check to filter out blank line in the code. This I could find out after several days of struggle. </p>
| 0 | 2013-10-07T07:47:06Z | [
"python",
"awk"
] |
detecting fullscreen on mac | 633,086 | <p>I am writing an IM client for Mac (in python, but an Objective C / Cocoa solution here is fine). I want to detect whether or not the user is currently watching a movie or playing a game in the foreground, or doing anything else that takes up the entire screen. If so, I won't play a sound when a new IM comes in, but ... | 2 | 2009-03-11T02:11:41Z | 633,164 | <p>not entirely sure how to do this, but the <a href="http://developer.apple.com/documentation/Carbon/Reference/Dock%5FManager/Reference/reference.html#//apple%5Fref/c/func/GetSystemUIMode" rel="nofollow">apple docs</a> say:</p>
<blockquote>
<p>To track changes in the login
sessionâs presentation mode, you may
... | 2 | 2009-03-11T02:46:00Z | [
"python",
"objective-c",
"cocoa",
"osx",
"fullscreen"
] |
detecting fullscreen on mac | 633,086 | <p>I am writing an IM client for Mac (in python, but an Objective C / Cocoa solution here is fine). I want to detect whether or not the user is currently watching a movie or playing a game in the foreground, or doing anything else that takes up the entire screen. If so, I won't play a sound when a new IM comes in, but ... | 2 | 2009-03-11T02:11:41Z | 633,166 | <p>To check for full-screen, call <a href="http://developer.apple.com/DOCUMENTATION/GraphicsImaging/Reference/Quartz%5FServices%5FRef/Reference/reference.html#//apple%5Fref/c/func/CGDisplayIsCaptured" rel="nofollow">CGDisplayIsCaptured(screenID)</a> on each screen.</p>
<p>But I'm not sure if you're checking the right ... | 8 | 2009-03-11T02:48:50Z | [
"python",
"objective-c",
"cocoa",
"osx",
"fullscreen"
] |
detecting fullscreen on mac | 633,086 | <p>I am writing an IM client for Mac (in python, but an Objective C / Cocoa solution here is fine). I want to detect whether or not the user is currently watching a movie or playing a game in the foreground, or doing anything else that takes up the entire screen. If so, I won't play a sound when a new IM comes in, but ... | 2 | 2009-03-11T02:11:41Z | 633,718 | <p>The two solutions posted so far apply to ârealâ full-screen, but itâs worth noting that many full-screen apps just put a window over the whole screen (or, as vasi points out, <em>a</em> whole screen). To be accurate, youâll have to check both.</p>
| 0 | 2009-03-11T08:19:39Z | [
"python",
"objective-c",
"cocoa",
"osx",
"fullscreen"
] |
detecting fullscreen on mac | 633,086 | <p>I am writing an IM client for Mac (in python, but an Objective C / Cocoa solution here is fine). I want to detect whether or not the user is currently watching a movie or playing a game in the foreground, or doing anything else that takes up the entire screen. If so, I won't play a sound when a new IM comes in, but ... | 2 | 2009-03-11T02:11:41Z | 11,965,482 | <p>In Mountain Lion (and probably earlier), you can track the presence of the menu bar by monitoring the distributed notifications com.apple.HIToolbox.hideMenuBarShown and com.apple.HIToolbox.hideMenuBarShown. No menu bar usually == fullscreen mode. This works across apps, so you can tell when, say, VLC goes fullscre... | 0 | 2012-08-15T07:23:56Z | [
"python",
"objective-c",
"cocoa",
"osx",
"fullscreen"
] |
why am i getting errors while installing pysqlite2.5.3 | 633,601 | <p>Am trying build pysqlite 2.5.3 package on SLSE 9, and am getting all sorts of compilation errors i.e.</p>
<pre><code>...
src/module.c:290: error: initializer element is not constant
src/module.c:290: error: (near initialization for `_int_constants[27].constant_value')
src/module.c:290: error: initializer element i... | 1 | 2009-03-11T07:01:54Z | 633,606 | <p>Do you have the sqlite development headers installed?</p>
<blockquote>
<p>error: SQLITE_DETACH' undeclared here </p>
</blockquote>
<p>Looks like you need sqlite3-dev (or whatever your distro named it, perhaps sqlite3-devel?)</p>
<p><strong>Edit:</strong></p>
<p>After a good natured soul cleaned up your error t... | 4 | 2009-03-11T07:04:21Z | [
"python",
"linux",
"sqlite"
] |
Scalable polling of an AppEngine application from numerous "active" clients? | 633,999 | <p>I'm working on an application that will run on Google AppEngine.</p>
<p>I plan to have the web interface of that application wait, among many other things, for notifications coming from the AppEngine server.</p>
<p>Ideally I would have liked to use an XMLHttpRequest() to make a request to the server that would be ... | 2 | 2009-03-11T10:37:08Z | 637,045 | <p>You are correct; long-running connections are prohibited on App Engine. The model is request->response->connection closed, and as quickly as possible.</p>
<p>There are certain kinds of applications that aren't feasible on App Engine due to this architecture. If you absolutely need a notification from the server wit... | 3 | 2009-03-12T01:16:53Z | [
"javascript",
"python",
"ajax",
"google-app-engine"
] |
Scalable polling of an AppEngine application from numerous "active" clients? | 633,999 | <p>I'm working on an application that will run on Google AppEngine.</p>
<p>I plan to have the web interface of that application wait, among many other things, for notifications coming from the AppEngine server.</p>
<p>Ideally I would have liked to use an XMLHttpRequest() to make a request to the server that would be ... | 2 | 2009-03-11T10:37:08Z | 640,500 | <p>OR...</p>
<p>You might be interested in some pubsub implementation. Like the venerable <a href="http://code.google.com/p/pubsubhubbub/" rel="nofollow">pubsubhubbub</a>, made by guys from Google and Jaiku.</p>
| 1 | 2009-03-12T21:12:02Z | [
"javascript",
"python",
"ajax",
"google-app-engine"
] |
Why do Python's frameworks return dictionaries from controllers? | 634,024 | <p>Why (for example web2py) do you return data from a controller in a dictionary instead of variables (see Rails)? </p>
<p>For example:</p>
<pre><code>return dict(sape=4139, guido=4127, jack=4098)
</code></pre>
<p>instead of (that's the way Rails does it)</p>
<pre><code>@var1 = "jello"
@var2 = "hihi"
</code></pre>... | 2 | 2009-03-11T10:45:28Z | 634,101 | <p>The main advantage is that this is the only way in python to return a) more than a single value <strong>and</strong> b) give that value a name. Other options would be to use a class (extra code), return a tuple (no names, so you'd have to use indexes to access the values) or allow to return only a single value which... | 5 | 2009-03-11T11:13:09Z | [
"python",
"ruby-on-rails",
"web2py"
] |
Why do Python's frameworks return dictionaries from controllers? | 634,024 | <p>Why (for example web2py) do you return data from a controller in a dictionary instead of variables (see Rails)? </p>
<p>For example:</p>
<pre><code>return dict(sape=4139, guido=4127, jack=4098)
</code></pre>
<p>instead of (that's the way Rails does it)</p>
<pre><code>@var1 = "jello"
@var2 = "hihi"
</code></pre>... | 2 | 2009-03-11T10:45:28Z | 634,120 | <p>The nice thing is that a template engine like Jinja2 treats an object and a dict similarly, so if:</p>
<pre><code>d = {'color': 'red'}
o = Color(red)
</code></pre>
<p>then these all work in the template syntax:</p>
<pre><code>d.color d['color'] o.color o['color']
</code></pre>
| -1 | 2009-03-11T11:19:50Z | [
"python",
"ruby-on-rails",
"web2py"
] |
Why do Python's frameworks return dictionaries from controllers? | 634,024 | <p>Why (for example web2py) do you return data from a controller in a dictionary instead of variables (see Rails)? </p>
<p>For example:</p>
<pre><code>return dict(sape=4139, guido=4127, jack=4098)
</code></pre>
<p>instead of (that's the way Rails does it)</p>
<pre><code>@var1 = "jello"
@var2 = "hihi"
</code></pre>... | 2 | 2009-03-11T10:45:28Z | 634,173 | <p>You can use local variables if you'd like:</p>
<pre><code>def hello():
var1 = "whatever you like"
var2 = "another value"
return locals() # or vars()
</code></pre>
<p><code>hello.html</code>:</p>
<pre><code><html><body>
<p>var1 {{=var1}}</p>
<p>var2 {{=var2}}</p>
&... | 3 | 2009-03-11T11:37:08Z | [
"python",
"ruby-on-rails",
"web2py"
] |
Python drag and drop | 634,067 | <p>Im working on a parser here that opens a file, reads it and prints data in another file.</p>
<p>The input file is determined from sys.argv[1] to both handle commandline opening and drag and drop (in windows). However, when drag and dropping a file, it gives me</p>
<pre><code>ioerror 13: Permission denied
</code></... | 0 | 2009-03-11T10:59:51Z | 634,086 | <p>You use <code>outfile = open("out.txt", "w")</code> - In the first example, this would go to c:\out.txt, which I'd imagine is the source of your error.</p>
| 4 | 2009-03-11T11:06:00Z | [
"python",
"windows",
"drag-and-drop",
"permission-denied",
"ioerror"
] |
Python drag and drop | 634,067 | <p>Im working on a parser here that opens a file, reads it and prints data in another file.</p>
<p>The input file is determined from sys.argv[1] to both handle commandline opening and drag and drop (in windows). However, when drag and dropping a file, it gives me</p>
<pre><code>ioerror 13: Permission denied
</code></... | 0 | 2009-03-11T10:59:51Z | 35,334,000 | <p>The working directory may be in <code>C:\Window\System32</code> when get error: IOError: [Errno 2] No such file or directory: or 13: Permission denied. </p>
<p>So you need to change to the script or input file directory firstly. Such as: </p>
<p><code>os.chdir(os.path.split(sys.argv[0])[0])</code></p>
<p>If you w... | 0 | 2016-02-11T08:17:03Z | [
"python",
"windows",
"drag-and-drop",
"permission-denied",
"ioerror"
] |
Writing a socket-based server in Python, recommended strategies? | 634,107 | <p>I was recently reading <a href="http://www.kegel.com/c10k.html">this document</a> which lists a number of strategies that could be employed to implement a socket server. Namely, they are:</p>
<ol>
<li>Serve many clients with each thread, and use nonblocking I/O and level-triggered readiness notification</li>
<li>Se... | 9 | 2009-03-11T11:15:27Z | 634,166 | <p><a href="http://docs.python.org/library/socketserver.html#asynchronous-mixins" rel="nofollow">http://docs.python.org/library/socketserver.html#asynchronous-mixins</a></p>
<p>As for multi-processor (multi-core) machines. With CPython due to <a href="http://docs.python.org/glossary.html#term-global-interpreter-lock" ... | 1 | 2009-03-11T11:30:19Z | [
"python",
"sockets",
"asynchronous",
"network-programming",
"c10k"
] |
Writing a socket-based server in Python, recommended strategies? | 634,107 | <p>I was recently reading <a href="http://www.kegel.com/c10k.html">this document</a> which lists a number of strategies that could be employed to implement a socket server. Namely, they are:</p>
<ol>
<li>Serve many clients with each thread, and use nonblocking I/O and level-triggered readiness notification</li>
<li>Se... | 9 | 2009-03-11T11:15:27Z | 634,237 | <p><a href="http://docs.python.org/library/asyncore.html" rel="nofollow"><code>asyncore</code></a> is basically "1" - It uses <code>select</code> internally, and you just have one thread handling all requests. According to the docs it can also use <code>poll</code>. (EDIT: Removed Twisted reference, I thought it used a... | 7 | 2009-03-11T12:07:05Z | [
"python",
"sockets",
"asynchronous",
"network-programming",
"c10k"
] |
Writing a socket-based server in Python, recommended strategies? | 634,107 | <p>I was recently reading <a href="http://www.kegel.com/c10k.html">this document</a> which lists a number of strategies that could be employed to implement a socket server. Namely, they are:</p>
<ol>
<li>Serve many clients with each thread, and use nonblocking I/O and level-triggered readiness notification</li>
<li>Se... | 9 | 2009-03-11T11:15:27Z | 634,288 | <p>I like Douglas' answer, but as an aside...</p>
<p>You could use a centralized dispatch thread/process that listens for readiness notifications using <a href="http://docs.python.org/library/select.html?highlight=select#module-select" rel="nofollow"><code>select</code></a> and delegates to a pool of worker threads/<a... | 1 | 2009-03-11T12:22:29Z | [
"python",
"sockets",
"asynchronous",
"network-programming",
"c10k"
] |
Writing a socket-based server in Python, recommended strategies? | 634,107 | <p>I was recently reading <a href="http://www.kegel.com/c10k.html">this document</a> which lists a number of strategies that could be employed to implement a socket server. Namely, they are:</p>
<ol>
<li>Serve many clients with each thread, and use nonblocking I/O and level-triggered readiness notification</li>
<li>Se... | 9 | 2009-03-11T11:15:27Z | 634,958 | <p>Can I suggest additional links?</p>
<p><a href="http://code.google.com/p/cogen/" rel="nofollow">cogen</a> is a crossplatform library for network oriented, coroutine based programming using the enhanced generators from python 2.5. On the main page of cogen project there're links to several projects with similar purp... | 2 | 2009-03-11T15:06:58Z | [
"python",
"sockets",
"asynchronous",
"network-programming",
"c10k"
] |
Writing a socket-based server in Python, recommended strategies? | 634,107 | <p>I was recently reading <a href="http://www.kegel.com/c10k.html">this document</a> which lists a number of strategies that could be employed to implement a socket server. Namely, they are:</p>
<ol>
<li>Serve many clients with each thread, and use nonblocking I/O and level-triggered readiness notification</li>
<li>Se... | 9 | 2009-03-11T11:15:27Z | 634,965 | <p>How about "fork"? (I assume that is what the ForkingMixIn does) If the requests are handled in a "shared nothing" (other than DB or file system) architecture, fork() starts pretty quickly on most *nixes, and you don't have to worry about all the silly bugs and complications from threading.</p>
<p>Threads are a de... | 3 | 2009-03-11T15:07:41Z | [
"python",
"sockets",
"asynchronous",
"network-programming",
"c10k"
] |
Writing a socket-based server in Python, recommended strategies? | 634,107 | <p>I was recently reading <a href="http://www.kegel.com/c10k.html">this document</a> which lists a number of strategies that could be employed to implement a socket server. Namely, they are:</p>
<ol>
<li>Serve many clients with each thread, and use nonblocking I/O and level-triggered readiness notification</li>
<li>Se... | 9 | 2009-03-11T11:15:27Z | 3,221,702 | <p>One sollution is gevent. <a href="http://www.gevent.org/" rel="nofollow">Gevent</a> maries a libevent based event polling with lightweight cooperative task switching implemented by greenlet.</p>
<p>What you get is all the performance and scalability of an event system with the elegance and straightforward model of ... | 3 | 2010-07-11T03:07:11Z | [
"python",
"sockets",
"asynchronous",
"network-programming",
"c10k"
] |
Need help on making the recursive parser using pyparsing | 634,432 | <p>I am trying the python pyparsing for parsing. I got stuck up while making the recursive parser. </p>
<p>Let me explain the problem </p>
<p>I want to make the Cartesian product of the elements. The syntax is </p>
<pre><code>cross({elements },{element})
</code></pre>
<p>I put in more specific way</p>
<pre><code>c... | 2 | 2009-03-11T13:07:53Z | 634,460 | <p>You should look at definitions of other languages to see how this is usually handled.</p>
<p>For example, look at how multiplication is defined.</p>
<p>It isn't</p>
<pre><code>{expression} * {expression}
</code></pre>
<p>Because the recursion is hard to deal with, and there's no implied left-to-right ordering. ... | 6 | 2009-03-11T13:14:33Z | [
"python",
"recursion",
"parsing",
"pyparsing"
] |
Need help on making the recursive parser using pyparsing | 634,432 | <p>I am trying the python pyparsing for parsing. I got stuck up while making the recursive parser. </p>
<p>Let me explain the problem </p>
<p>I want to make the Cartesian product of the elements. The syntax is </p>
<pre><code>cross({elements },{element})
</code></pre>
<p>I put in more specific way</p>
<pre><code>c... | 2 | 2009-03-11T13:07:53Z | 634,725 | <p>I agree with @S.Lott you should reconsider your grammar.</p>
<p>Recursive definitions can be introduced using <code>Forward()</code>:</p>
<pre><code>from pyparsing import (Literal, Word, OneOrMore, Forward, nums, alphas)
def BNF():
"""
element :: id
elements :: '{' element [ ',' element ]+ '}... | 3 | 2009-03-11T14:24:58Z | [
"python",
"recursion",
"parsing",
"pyparsing"
] |
Need help on making the recursive parser using pyparsing | 634,432 | <p>I am trying the python pyparsing for parsing. I got stuck up while making the recursive parser. </p>
<p>Let me explain the problem </p>
<p>I want to make the Cartesian product of the elements. The syntax is </p>
<pre><code>cross({elements },{element})
</code></pre>
<p>I put in more specific way</p>
<pre><code>c... | 2 | 2009-03-11T13:07:53Z | 1,673,407 | <p>I don't know if this is any help, but here is how you would do what you want in lepl. Since the grammar appears to be correct I assume that it would be easy to translate to pyparsing.</p>
<pre><code>from lepl import *
def compile_parser():
class Cross(Node): pass
word = Token('[a-z0-9]+')
par, en, b... | 3 | 2009-11-04T12:08:47Z | [
"python",
"recursion",
"parsing",
"pyparsing"
] |
using wsgiref.simple_server in unittests | 634,485 | <p>I have some functions like this one:</p>
<pre>
<code>
URL = 'http://localhost:8080'
def func():
response = urlopen(URL)
return process(response)
</code>
</pre>
<p>And i want to test it with unittest.</p>
<p>I did something like this:</p>
<pre><code>
from wsgiref.simple_server import make_server
def app_2... | 3 | 2009-03-11T13:22:09Z | 634,571 | <p>If you are testing a WSGI application, I can strongly recommend <a href="http://werkzeug.pocoo.org/documentation/test">werkzeug.test</a> which gets around these issues by testing the application itself without a server:</p>
<pre><code>from werkzeug.test import Client
# then in your test case
def test1(self):
c... | 7 | 2009-03-11T13:44:29Z | [
"python",
"unit-testing",
"wsgiref"
] |
using wsgiref.simple_server in unittests | 634,485 | <p>I have some functions like this one:</p>
<pre>
<code>
URL = 'http://localhost:8080'
def func():
response = urlopen(URL)
return process(response)
</code>
</pre>
<p>And i want to test it with unittest.</p>
<p>I did something like this:</p>
<pre><code>
from wsgiref.simple_server import make_server
def app_2... | 3 | 2009-03-11T13:22:09Z | 634,622 | <p>Your server must be a separate process.</p>
<p>You'll want to start it with <code>subprocess.Popen()</code></p>
<p>If you're using Python 2.6, you can then kill the subprocess during tearDown.</p>
<pre><code>def setUp( self ):
self.server= subprocess.Popen( "python","myserver","etc." )
def tearDown( self ):
... | 3 | 2009-03-11T13:59:16Z | [
"python",
"unit-testing",
"wsgiref"
] |
using wsgiref.simple_server in unittests | 634,485 | <p>I have some functions like this one:</p>
<pre>
<code>
URL = 'http://localhost:8080'
def func():
response = urlopen(URL)
return process(response)
</code>
</pre>
<p>And i want to test it with unittest.</p>
<p>I did something like this:</p>
<pre><code>
from wsgiref.simple_server import make_server
def app_2... | 3 | 2009-03-11T13:22:09Z | 634,907 | <p>My solution:</p>
<pre>
<code>
URL = 'http://localhost:8085'
def func():
response = urlopen(URL)
return response.read()
import unittest
from wsgiref.simple_server import WSGIServer, WSGIRequestHandler
import threading
from urllib2 import urlopen
from cStringIO import StringIO
def app_200_hello(environ,star... | 0 | 2009-03-11T14:58:23Z | [
"python",
"unit-testing",
"wsgiref"
] |
using wsgiref.simple_server in unittests | 634,485 | <p>I have some functions like this one:</p>
<pre>
<code>
URL = 'http://localhost:8080'
def func():
response = urlopen(URL)
return process(response)
</code>
</pre>
<p>And i want to test it with unittest.</p>
<p>I did something like this:</p>
<pre><code>
from wsgiref.simple_server import make_server
def app_2... | 3 | 2009-03-11T13:22:09Z | 635,306 | <p>You could also provide a mock version of <code>urlopen</code> that doesn't actually run the server.</p>
<p>Assuming your original code was in <code>mycode.py</code>, in your test code you'd do something like:</p>
<pre><code>
import mycode
class TestFunc(unittest.TestCase):
def setUp(self):
# patch my... | 2 | 2009-03-11T16:28:20Z | [
"python",
"unit-testing",
"wsgiref"
] |
using wsgiref.simple_server in unittests | 634,485 | <p>I have some functions like this one:</p>
<pre>
<code>
URL = 'http://localhost:8080'
def func():
response = urlopen(URL)
return process(response)
</code>
</pre>
<p>And i want to test it with unittest.</p>
<p>I did something like this:</p>
<pre><code>
from wsgiref.simple_server import make_server
def app_2... | 3 | 2009-03-11T13:22:09Z | 6,564,500 | <p>Use multiprocessing to start the server in a separate process</p>
<p>in setUp do something like: </p>
<pre><code>self.port = 8000
server = make_server('', self.port, make_my_wsgi_ap())
self.server_process = multiprocessing.Process(target=server.serve_forever)
self.server_process.start()
</code></pre>
<p>then in t... | 4 | 2011-07-03T17:49:28Z | [
"python",
"unit-testing",
"wsgiref"
] |
Django: Calling custom Model method from Form clean method. "Unbound Method"? | 634,857 | <p>I'm having a problem while trying to call a custom Model method from my Form <code>clean</code> method.</p>
<p>Here is [part of] my model:<br />
<a href="http://dpaste.com/hold/12695/" rel="nofollow">http://dpaste.com/hold/12695/</a></p>
<p>Here is my Form:<br />
<a href="http://dpaste.com/hold/12699/" rel="nofoll... | 1 | 2009-03-11T14:51:12Z | 634,885 | <p>You can't call </p>
<pre><code>nzb_data = File.get_nzb_data(nzb_absolute)
</code></pre>
<p>because your using the class, not an object.</p>
<p>You have two choices.</p>
<ol>
<li><p>Make <code>get_nzb_data</code> a <code>@classmethod</code>. See <a href="http://docs.python.org/library/functions.html#classmethod"... | 3 | 2009-03-11T14:54:39Z | [
"python",
"django"
] |
Django: Calling custom Model method from Form clean method. "Unbound Method"? | 634,857 | <p>I'm having a problem while trying to call a custom Model method from my Form <code>clean</code> method.</p>
<p>Here is [part of] my model:<br />
<a href="http://dpaste.com/hold/12695/" rel="nofollow">http://dpaste.com/hold/12695/</a></p>
<p>Here is my Form:<br />
<a href="http://dpaste.com/hold/12699/" rel="nofoll... | 1 | 2009-03-11T14:51:12Z | 634,902 | <p>I may be missing something here, but I think that your method ´get_nzb_data´ should have a @classmethod decorator. Otherwise, it expects the ´self´ argument of the type File, and this gives that error.</p>
| 1 | 2009-03-11T14:57:20Z | [
"python",
"django"
] |
svg diagrams using python | 634,964 | <p>I am looking for a library to generate svg diagrams in python (I fetch data from a sql database). I have found <a href="http://newcenturycomputers.net/projects/gdmodule.html">python-gd</a>, but it has not much documentation and last update was in 2005 so I wonder if there are any other libraries that are good for th... | 20 | 2009-03-11T15:07:39Z | 634,998 | <p>Here's a general purpose SVG library in Python: <a href="http://codeboje.de/pysvg/">pySVG</a>.</p>
| 7 | 2009-03-11T15:15:47Z | [
"python",
"svg",
"diagram"
] |
svg diagrams using python | 634,964 | <p>I am looking for a library to generate svg diagrams in python (I fetch data from a sql database). I have found <a href="http://newcenturycomputers.net/projects/gdmodule.html">python-gd</a>, but it has not much documentation and last update was in 2005 so I wonder if there are any other libraries that are good for th... | 20 | 2009-03-11T15:07:39Z | 635,001 | <p>Try using <a href="http://matplotlib.sourceforge.net/">matplotlib</a>. You can configure it with a SVG <a href="http://matplotlib.sourceforge.net/faq/installing%5Ffaq.html#what-is-a-backend">backend</a>.</p>
| 9 | 2009-03-11T15:16:51Z | [
"python",
"svg",
"diagram"
] |
svg diagrams using python | 634,964 | <p>I am looking for a library to generate svg diagrams in python (I fetch data from a sql database). I have found <a href="http://newcenturycomputers.net/projects/gdmodule.html">python-gd</a>, but it has not much documentation and last update was in 2005 so I wonder if there are any other libraries that are good for th... | 20 | 2009-03-11T15:07:39Z | 635,002 | <p><a href="http://home.gna.org/pychart/">PyChart</a> <em>"is a Python library for creating high quality Encapsulated Postscript, PDF, PNG, or <strong>SVG</strong> charts."</em></p>
| 9 | 2009-03-11T15:16:53Z | [
"python",
"svg",
"diagram"
] |
svg diagrams using python | 634,964 | <p>I am looking for a library to generate svg diagrams in python (I fetch data from a sql database). I have found <a href="http://newcenturycomputers.net/projects/gdmodule.html">python-gd</a>, but it has not much documentation and last update was in 2005 so I wonder if there are any other libraries that are good for th... | 20 | 2009-03-11T15:07:39Z | 635,096 | <p><a href="http://cairographics.org/pycairo/">pyCairo</a> is an option worth looking at.</p>
| 8 | 2009-03-11T15:36:41Z | [
"python",
"svg",
"diagram"
] |
svg diagrams using python | 634,964 | <p>I am looking for a library to generate svg diagrams in python (I fetch data from a sql database). I have found <a href="http://newcenturycomputers.net/projects/gdmodule.html">python-gd</a>, but it has not much documentation and last update was in 2005 so I wonder if there are any other libraries that are good for th... | 20 | 2009-03-11T15:07:39Z | 635,149 | <p>As you're looking for simple line graphics, probably, <a href="http://linil.wordpress.com/2008/09/16/cairoplot-11/">CairoPlot</a> will fit your needs as it can generate svg output files out of the box. Take a look at <a href="http://linil.files.wordpress.com/2008/06/cairoplot%5Fdotlineplot.png">this</a>.</p>
<p><im... | 10 | 2009-03-11T15:50:55Z | [
"python",
"svg",
"diagram"
] |
svg diagrams using python | 634,964 | <p>I am looking for a library to generate svg diagrams in python (I fetch data from a sql database). I have found <a href="http://newcenturycomputers.net/projects/gdmodule.html">python-gd</a>, but it has not much documentation and last update was in 2005 so I wonder if there are any other libraries that are good for th... | 20 | 2009-03-11T15:07:39Z | 635,259 | <p>You can use <a href="http://www.graphviz.org/" rel="nofollow">Graphviz</a> to generate diagrams in SVG format. There are Python bindings to Graphviz e.g., <a href="http://code.google.com/p/pydot/" rel="nofollow">pydot</a> -- Python interface to Graphviz's Dot language.</p>
| 6 | 2009-03-11T16:16:54Z | [
"python",
"svg",
"diagram"
] |
svg diagrams using python | 634,964 | <p>I am looking for a library to generate svg diagrams in python (I fetch data from a sql database). I have found <a href="http://newcenturycomputers.net/projects/gdmodule.html">python-gd</a>, but it has not much documentation and last update was in 2005 so I wonder if there are any other libraries that are good for th... | 20 | 2009-03-11T15:07:39Z | 2,937,225 | <p>svgfig is worth a look:</p>
<p><a href="http://code.google.com/p/svgfig/" rel="nofollow">http://code.google.com/p/svgfig/</a></p>
| 3 | 2010-05-30T01:36:32Z | [
"python",
"svg",
"diagram"
] |
svg diagrams using python | 634,964 | <p>I am looking for a library to generate svg diagrams in python (I fetch data from a sql database). I have found <a href="http://newcenturycomputers.net/projects/gdmodule.html">python-gd</a>, but it has not much documentation and last update was in 2005 so I wonder if there are any other libraries that are good for th... | 20 | 2009-03-11T15:07:39Z | 7,419,825 | <p>Being not exactly related to SVG plots, but searching for the same thing I have found a good source of carefully collected useful info to answer your question:
<a href="http://wiki.python.org/moin/NumericAndScientific/Plotting" rel="nofollow">http://wiki.python.org/moin/NumericAndScientific/Plotting</a></p>
| 0 | 2011-09-14T16:36:11Z | [
"python",
"svg",
"diagram"
] |
svg diagrams using python | 634,964 | <p>I am looking for a library to generate svg diagrams in python (I fetch data from a sql database). I have found <a href="http://newcenturycomputers.net/projects/gdmodule.html">python-gd</a>, but it has not much documentation and last update was in 2005 so I wonder if there are any other libraries that are good for th... | 20 | 2009-03-11T15:07:39Z | 7,831,808 | <p>I have tried to collate a list of available charting libraries(its an ongoing work, wherein i keep updating the list) : <a href="http://blizzardzblogs.blogspot.com/2010/12/data-visualization-charts-and.html" rel="nofollow">http://blizzardzblogs.blogspot.com/2010/12/data-visualization-charts-and.html</a></p>
<p>I fe... | 0 | 2011-10-20T06:11:43Z | [
"python",
"svg",
"diagram"
] |
svg diagrams using python | 634,964 | <p>I am looking for a library to generate svg diagrams in python (I fetch data from a sql database). I have found <a href="http://newcenturycomputers.net/projects/gdmodule.html">python-gd</a>, but it has not much documentation and last update was in 2005 so I wonder if there are any other libraries that are good for th... | 20 | 2009-03-11T15:07:39Z | 10,662,071 | <p>Consider svgwrite <a href="http://packages.python.org/svgwrite/" rel="nofollow">http://packages.python.org/svgwrite/</a></p>
| 1 | 2012-05-19T03:27:07Z | [
"python",
"svg",
"diagram"
] |
Django Admin | 635,048 | <p>I am using Django admin for managing my data.
I have a Users, Groups and Domains tables
Users table has many to many relationship with Groups and Domains tables.
Domains table has one to many relationship with Groups table.
and when I save the User data through admin I also need some addtional database updates in t... | 0 | 2009-03-11T15:28:10Z | 635,087 | <p>I think you are looking for <a href="http://docs.djangoproject.com/en/dev/ref/contrib/admin/#inlinemodeladmin-objects" rel="nofollow">InlineModels</a>. They allow you to edit related models in the same page as the parent model. If you are looking for greater control than this, you can override the ModelAdmin <a href... | 2 | 2009-03-11T15:33:25Z | [
"python",
"django",
"django-admin"
] |
Django Admin | 635,048 | <p>I am using Django admin for managing my data.
I have a Users, Groups and Domains tables
Users table has many to many relationship with Groups and Domains tables.
Domains table has one to many relationship with Groups table.
and when I save the User data through admin I also need some addtional database updates in t... | 0 | 2009-03-11T15:28:10Z | 638,957 | <p>The best way to update other database tables is to perform the necessary get and save operations. However, if you have a many-to-many relationship, by default, both sides of the relationship are accessible from a _set parameter. That is, user.group_set.all() will give you all Group objects associated with a user, ... | 0 | 2009-03-12T14:45:48Z | [
"python",
"django",
"django-admin"
] |
Python urllib2, basic HTTP authentication, and tr.im | 635,113 | <p>I'm playing around, trying to write some code to use the <a href="http://www.programmableweb.com/api/tr.im">tr.im</a>
APIs to shorten a URL.</p>
<p>After reading <a href="http://docs.python.org/library/urllib2.html">http://docs.python.org/library/urllib2.html</a>, I tried:</p>
<pre><code> TRIM_API_URL = 'http://... | 62 | 2009-03-11T15:43:10Z | 635,146 | <p>Really cheap solution:</p>
<pre><code>urllib.urlopen('http://user:xxxx@api.tr.im/api')
</code></pre>
<p>(which you may decide is not suitable for a number of reasons, like security of the url) </p>
<p><a href="https://developer.github.com/v3/auth/#via-oauth-tokens">Github API example</a>:</p>
<pre><code>>>... | 16 | 2009-03-11T15:50:08Z | [
"python",
"http",
"authentication"
] |
Python urllib2, basic HTTP authentication, and tr.im | 635,113 | <p>I'm playing around, trying to write some code to use the <a href="http://www.programmableweb.com/api/tr.im">tr.im</a>
APIs to shorten a URL.</p>
<p>After reading <a href="http://docs.python.org/library/urllib2.html">http://docs.python.org/library/urllib2.html</a>, I tried:</p>
<pre><code> TRIM_API_URL = 'http://... | 62 | 2009-03-11T15:43:10Z | 4,188,709 | <p>This seems to work really well (taken from another thread)</p>
<pre><code>import urllib2, base64
request = urllib2.Request("http://api.foursquare.com/v1/user")
base64string = base64.encodestring('%s:%s' % (username, password)).replace('\n', '')
request.add_header("Authorization", "Basic %s" % base64string)
resu... | 210 | 2010-11-15T20:52:54Z | [
"python",
"http",
"authentication"
] |
Python urllib2, basic HTTP authentication, and tr.im | 635,113 | <p>I'm playing around, trying to write some code to use the <a href="http://www.programmableweb.com/api/tr.im">tr.im</a>
APIs to shorten a URL.</p>
<p>After reading <a href="http://docs.python.org/library/urllib2.html">http://docs.python.org/library/urllib2.html</a>, I tried:</p>
<pre><code> TRIM_API_URL = 'http://... | 62 | 2009-03-11T15:43:10Z | 9,698,319 | <p>Take a look at <a href="http://stackoverflow.com/a/7755057/1020470">this SO post answer</a> and also look at this <a href="http://www.voidspace.org.uk/python/articles/authentication.shtml">basic authentication tutorial</a> from the <a href="http://www.voidspace.org.uk/python/articles/urllib2.shtml">urllib2 missing m... | 11 | 2012-03-14T08:35:25Z | [
"python",
"http",
"authentication"
] |
Python urllib2, basic HTTP authentication, and tr.im | 635,113 | <p>I'm playing around, trying to write some code to use the <a href="http://www.programmableweb.com/api/tr.im">tr.im</a>
APIs to shorten a URL.</p>
<p>After reading <a href="http://docs.python.org/library/urllib2.html">http://docs.python.org/library/urllib2.html</a>, I tried:</p>
<pre><code> TRIM_API_URL = 'http://... | 62 | 2009-03-11T15:43:10Z | 13,328,157 | <p>Try <a href="http://docs.python-requests.org/en/latest/" rel="nofollow">python-request</a> or <a href="https://bitbucket.org/lorien/grab" rel="nofollow">python-grab</a></p>
| 1 | 2012-11-11T02:44:58Z | [
"python",
"http",
"authentication"
] |
Python urllib2, basic HTTP authentication, and tr.im | 635,113 | <p>I'm playing around, trying to write some code to use the <a href="http://www.programmableweb.com/api/tr.im">tr.im</a>
APIs to shorten a URL.</p>
<p>After reading <a href="http://docs.python.org/library/urllib2.html">http://docs.python.org/library/urllib2.html</a>, I tried:</p>
<pre><code> TRIM_API_URL = 'http://... | 62 | 2009-03-11T15:43:10Z | 24,049,022 | <p>Same solutions as <a href="http://stackoverflow.com/questions/2407126/python-urllib2-basic-auth-problem">Python urllib2 Basic Auth Problem</a> apply.</p>
<p>see <a href="http://stackoverflow.com/a/24048852/1733117">http://stackoverflow.com/a/24048852/1733117</a>; you can subclass <code>urllib2.HTTPBasicAuthHandler<... | 2 | 2014-06-04T23:02:31Z | [
"python",
"http",
"authentication"
] |
Python urllib2, basic HTTP authentication, and tr.im | 635,113 | <p>I'm playing around, trying to write some code to use the <a href="http://www.programmableweb.com/api/tr.im">tr.im</a>
APIs to shorten a URL.</p>
<p>After reading <a href="http://docs.python.org/library/urllib2.html">http://docs.python.org/library/urllib2.html</a>, I tried:</p>
<pre><code> TRIM_API_URL = 'http://... | 62 | 2009-03-11T15:43:10Z | 25,775,523 | <p>I would suggest that the current solution is to use my package <a href="https://pypi.python.org/pypi/urllib2_prior_auth/" rel="nofollow">urllib2_prior_auth</a> which solves this pretty nicely (I work on <a href="http://bugs.python.org/issue19494" rel="nofollow">inclusion</a> to the standard lib.</p>
| 2 | 2014-09-10T21:38:56Z | [
"python",
"http",
"authentication"
] |
Python urllib2, basic HTTP authentication, and tr.im | 635,113 | <p>I'm playing around, trying to write some code to use the <a href="http://www.programmableweb.com/api/tr.im">tr.im</a>
APIs to shorten a URL.</p>
<p>After reading <a href="http://docs.python.org/library/urllib2.html">http://docs.python.org/library/urllib2.html</a>, I tried:</p>
<pre><code> TRIM_API_URL = 'http://... | 62 | 2009-03-11T15:43:10Z | 33,509,568 | <p><a href="https://docs.python.org/3/library/urllib.request.html#module-urllib.request" rel="nofollow">The recommended way</a> is to use <a href="http://docs.python-requests.org/en/latest/" rel="nofollow"><code>requests</code> module</a>: </p>
<pre><code>#!/usr/bin/env python
import requests # $ python -m pip install... | 4 | 2015-11-03T21:39:08Z | [
"python",
"http",
"authentication"
] |
Web frameworks performance comparison | 635,159 | <p>I'm looking for real life benchmarks comparing web frameworks based on dynamic languages (Python, Ruby, Groovy and Lua). Even better if they're compared up against classic solutions based on PHP, Java, ASP.NET maybe even Perl. I'm particularly interested in:</p>
<ul>
<li>Django</li>
<li>Ruby on Rails</li>
<li>Grail... | 0 | 2009-03-11T15:52:26Z | 636,427 | <p>If your project has a serious, identifiable, need for speed, to the point where your framework is a consideration, taking a general-purpose framework is a bad idea to begin with. They're all going to be too slow, by virtue of being high-level, general purpose & extensible.</p>
<p>If your project does not have ... | 15 | 2009-03-11T21:19:36Z | [
"java",
"php",
"python",
"performance"
] |
Web frameworks performance comparison | 635,159 | <p>I'm looking for real life benchmarks comparing web frameworks based on dynamic languages (Python, Ruby, Groovy and Lua). Even better if they're compared up against classic solutions based on PHP, Java, ASP.NET maybe even Perl. I'm particularly interested in:</p>
<ul>
<li>Django</li>
<li>Ruby on Rails</li>
<li>Grail... | 0 | 2009-03-11T15:52:26Z | 16,544,086 | <p><strong>Techempower benchmark:</strong> </p>
<p><a href="http://www.techempower.com/benchmarks" rel="nofollow">http://www.techempower.com/benchmarks</a></p>
<p>They are comparing a lot of frameworks and accept new frameworks for comparison. Interface very intuitive. In my view, it is the best benchmark now. </p>
... | 2 | 2013-05-14T13:09:00Z | [
"java",
"php",
"python",
"performance"
] |
Visual Studio 2005 Build of Python with Debug .lib | 635,200 | <p>I am looking for the Visual Studio 2005 build of Python 2.4, 2.5 or 2.6, I also need the python2x_d.lib (the debug version of the .lib) since I embed the interpreter into my app and the python libs implicitly link to the python2x_d.lib with pragmas (grrr).</p>
<p>Any hints where I can find those builds ?</p>
<p>Re... | 0 | 2009-03-11T16:00:22Z | 635,239 | <p>I would recommend that you <a href="http://python.org/download/" rel="nofollow">download the Python source</a> (tgz and tar.bz2 zipped versions available) and compile it yourself. It comes with a VS2005 solution so it isn't difficult. I had to do this for a SWIG project I was working on.</p>
| 1 | 2009-03-11T16:10:09Z | [
"python",
"visual-studio-2005"
] |
Visual Studio 2005 Build of Python with Debug .lib | 635,200 | <p>I am looking for the Visual Studio 2005 build of Python 2.4, 2.5 or 2.6, I also need the python2x_d.lib (the debug version of the .lib) since I embed the interpreter into my app and the python libs implicitly link to the python2x_d.lib with pragmas (grrr).</p>
<p>Any hints where I can find those builds ?</p>
<p>Re... | 0 | 2009-03-11T16:00:22Z | 635,245 | <p>If you have trouble finding the debug builds, you can try and build your own. Browse the <a href="http://svn.python.org/view/python/trunk/PCbuild/" rel="nofollow">build directory</a>, for project files like <code>python.vcproj</code> - to locate versions that will work with Visual Studio 2005.</p>
| 0 | 2009-03-11T16:13:56Z | [
"python",
"visual-studio-2005"
] |
Visual Studio 2005 Build of Python with Debug .lib | 635,200 | <p>I am looking for the Visual Studio 2005 build of Python 2.4, 2.5 or 2.6, I also need the python2x_d.lib (the debug version of the .lib) since I embed the interpreter into my app and the python libs implicitly link to the python2x_d.lib with pragmas (grrr).</p>
<p>Any hints where I can find those builds ?</p>
<p>Re... | 0 | 2009-03-11T16:00:22Z | 635,266 | <p>I recall, some time ago, giving IronPython a 'whirl' in VS2005. I ran into all kinds of 'esoteric' errors until I figured out that to compile and run I had to add the C++ libraries and tools of VS2005 as well (add/remove).
Maybe this is something similar ?</p>
| 0 | 2009-03-11T16:18:53Z | [
"python",
"visual-studio-2005"
] |
code documentation for python | 635,419 | <p>What is out there on conventions and tools for documenting python source code?</p>
| 16 | 2009-03-11T16:54:41Z | 635,428 | <p>Conventions: <a href="http://www.python.org/dev/peps/pep-0257/">PEP 257</a> and <a href="http://www.python.org/dev/peps/pep-0008/">PEP 8</a>.
Note, that docstrings can be written in <a href="http://docutils.sourceforge.net/rst.html">reStructuredText</a></p>
<p>Tools for generating documentation: for example <a hre... | 33 | 2009-03-11T16:56:58Z | [
"python",
"documentation",
"documentation-generation"
] |
code documentation for python | 635,419 | <p>What is out there on conventions and tools for documenting python source code?</p>
| 16 | 2009-03-11T16:54:41Z | 635,445 | <p>It's very nice to put code documentation in the code itself. See:</p>
<ul>
<li><a href="http://www.python.org/dev/peps/pep-0257/">PEP 257 -- Docstring Conventions </a></li>
<li><a href="http://www.python.org/dev/peps/pep-0008/">PEP 8 -- Style Guide for Python Code</a></li>
</ul>
| 6 | 2009-03-11T17:00:23Z | [
"python",
"documentation",
"documentation-generation"
] |
code documentation for python | 635,419 | <p>What is out there on conventions and tools for documenting python source code?</p>
| 16 | 2009-03-11T16:54:41Z | 635,473 | <p><a href="http://epydoc.sourceforge.net/">Epydoc</a> is also a good tool for documenting source code, and handles cross-referencing classes, modules, variables, etc, into HTML, PDF, LaTeX. Draws some nice class inheritance diagrams too. It's used by a number of open-source projects, so it's fairly actively developed.... | 8 | 2009-03-11T17:06:07Z | [
"python",
"documentation",
"documentation-generation"
] |
code documentation for python | 635,419 | <p>What is out there on conventions and tools for documenting python source code?</p>
| 16 | 2009-03-11T16:54:41Z | 635,482 | <p>First, put comments in your docstrings using RestructuredText format.</p>
<p>Second, get <a href="http://sphinx.pocoo.org/">sphinx</a>.</p>
<p>Third, create an index that uses the <a href="http://sphinx.pocoo.org/ext/autodoc.html">autodoc extension</a>.</p>
<p>Then, run Sphinx to get really nice documentation.</p... | 14 | 2009-03-11T17:08:39Z | [
"python",
"documentation",
"documentation-generation"
] |
code documentation for python | 635,419 | <p>What is out there on conventions and tools for documenting python source code?</p>
| 16 | 2009-03-11T16:54:41Z | 22,247,361 | <p>using doxypy filter with doxygen is a good thing also</p>
| 1 | 2014-03-07T10:20:16Z | [
"python",
"documentation",
"documentation-generation"
] |
What is the best way to implement nested dictionaries in Python? | 635,483 | <p>I have a data structure which essentially amounts to a nested dictionary. Let's say it looks like this:</p>
<pre><code>{'new jersey': {'mercer county': {'plumbers': 3,
'programmers': 81},
'middlesex county': {'programmers': 81,
'... | 149 | 2009-03-11T17:09:21Z | 635,498 | <p>I find <code>setdefault</code> quite useful; It checks if a key is present and adds it if not:</p>
<pre><code>d = {}
d.setdefault('new jersey', {}).setdefault('mercer county', {})['plumbers'] = 3
</code></pre>
<p><code>setdefault</code> always returns the relevant key, so you are actually updating the values of '<... | 7 | 2009-03-11T17:14:19Z | [
"python",
"data-structures",
"dictionary",
"mapping",
"autovivification"
] |
What is the best way to implement nested dictionaries in Python? | 635,483 | <p>I have a data structure which essentially amounts to a nested dictionary. Let's say it looks like this:</p>
<pre><code>{'new jersey': {'mercer county': {'plumbers': 3,
'programmers': 81},
'middlesex county': {'programmers': 81,
'... | 149 | 2009-03-11T17:09:21Z | 635,512 | <p>As for "obnoxious try/catch blocks":</p>
<pre><code>d = {}
d.setdefault('key',{}).setdefault('inner key',{})['inner inner key'] = 'value'
print d
</code></pre>
<p>yields</p>
<pre><code>{'key': {'inner key': {'inner inner key': 'value'}}}
</code></pre>
<p>You can use this to convert from your flat dictionary form... | 4 | 2009-03-11T17:17:40Z | [
"python",
"data-structures",
"dictionary",
"mapping",
"autovivification"
] |
What is the best way to implement nested dictionaries in Python? | 635,483 | <p>I have a data structure which essentially amounts to a nested dictionary. Let's say it looks like this:</p>
<pre><code>{'new jersey': {'mercer county': {'plumbers': 3,
'programmers': 81},
'middlesex county': {'programmers': 81,
'... | 149 | 2009-03-11T17:09:21Z | 635,522 | <p>I like the idea of wrapping this in a class and implementing <code>__getitem__</code> and <code>__setitem__</code> such that they implemented a simple query language:</p>
<pre><code>>>> d['new jersey/mercer county/plumbers'] = 3
>>> d['new jersey/mercer county/programmers'] = 81
>>> d['ne... | 1 | 2009-03-11T17:19:27Z | [
"python",
"data-structures",
"dictionary",
"mapping",
"autovivification"
] |
What is the best way to implement nested dictionaries in Python? | 635,483 | <p>I have a data structure which essentially amounts to a nested dictionary. Let's say it looks like this:</p>
<pre><code>{'new jersey': {'mercer county': {'plumbers': 3,
'programmers': 81},
'middlesex county': {'programmers': 81,
'... | 149 | 2009-03-11T17:09:21Z | 635,557 | <p>Since you have a star-schema design, you might want to structure it more like a relational table and less like a dictionary.</p>
<pre><code>import collections
class Jobs( object ):
def __init__( self, state, county, title, count ):
self.state= state
self.count= county
self.title= title
... | 17 | 2009-03-11T17:29:12Z | [
"python",
"data-structures",
"dictionary",
"mapping",
"autovivification"
] |
What is the best way to implement nested dictionaries in Python? | 635,483 | <p>I have a data structure which essentially amounts to a nested dictionary. Let's say it looks like this:</p>
<pre><code>{'new jersey': {'mercer county': {'plumbers': 3,
'programmers': 81},
'middlesex county': {'programmers': 81,
'... | 149 | 2009-03-11T17:09:21Z | 635,857 | <pre><code>class JobDb(object):
def __init__(self):
self.data = []
self.all = set()
self.free = []
self.index1 = {}
self.index2 = {}
self.index3 = {}
def _indices(self,(key1,key2,key3)):
indices = self.all.copy()
wild = False
for index,key... | 1 | 2009-03-11T18:52:03Z | [
"python",
"data-structures",
"dictionary",
"mapping",
"autovivification"
] |
What is the best way to implement nested dictionaries in Python? | 635,483 | <p>I have a data structure which essentially amounts to a nested dictionary. Let's say it looks like this:</p>
<pre><code>{'new jersey': {'mercer county': {'plumbers': 3,
'programmers': 81},
'middlesex county': {'programmers': 81,
'... | 149 | 2009-03-11T17:09:21Z | 636,109 | <p>If the number of nesting levels is small, I use <code>collections.defaultdict</code> for this:</p>
<pre><code>from collections import defaultdict
def nested_dict_factory():
return defaultdict(int)
def nested_dict_factory2():
return defaultdict(nested_dict_factory)
db = defaultdict(nested_dict_factory2)
db['... | 12 | 2009-03-11T20:02:11Z | [
"python",
"data-structures",
"dictionary",
"mapping",
"autovivification"
] |
What is the best way to implement nested dictionaries in Python? | 635,483 | <p>I have a data structure which essentially amounts to a nested dictionary. Let's say it looks like this:</p>
<pre><code>{'new jersey': {'mercer county': {'plumbers': 3,
'programmers': 81},
'middlesex county': {'programmers': 81,
'... | 149 | 2009-03-11T17:09:21Z | 636,125 | <p>For easy iterating over your nested dictionary, why not just write a simple generator?</p>
<pre><code>def each_job(my_dict):
for state, a in my_dict.items():
for county, b in a.items():
for job, value in b.items():
yield {
'state' : state,
... | 3 | 2009-03-11T20:05:32Z | [
"python",
"data-structures",
"dictionary",
"mapping",
"autovivification"
] |
What is the best way to implement nested dictionaries in Python? | 635,483 | <p>I have a data structure which essentially amounts to a nested dictionary. Let's say it looks like this:</p>
<pre><code>{'new jersey': {'mercer county': {'plumbers': 3,
'programmers': 81},
'middlesex county': {'programmers': 81,
'... | 149 | 2009-03-11T17:09:21Z | 636,138 | <p>You could create a YAML file and read it in using <a href="http://pyyaml.org/">PyYaml</a>.</p>
<p>Step 1: Create a YAML file, "employment.yml":</p>
<pre><code>new jersey:
mercer county:
pumbers: 3
programmers: 81
middlesex county:
salesmen: 62
programmers: 81
new york:
queens county:
plu... | 21 | 2009-03-11T20:08:17Z | [
"python",
"data-structures",
"dictionary",
"mapping",
"autovivification"
] |
What is the best way to implement nested dictionaries in Python? | 635,483 | <p>I have a data structure which essentially amounts to a nested dictionary. Let's say it looks like this:</p>
<pre><code>{'new jersey': {'mercer county': {'plumbers': 3,
'programmers': 81},
'middlesex county': {'programmers': 81,
'... | 149 | 2009-03-11T17:09:21Z | 636,234 | <p>Unless your dataset is going to stay pretty small, you might want to consider using a relational database. It will do exactly what you want: make it easy to add counts, selecting subsets of counts, and even aggregate counts by state, county, occupation, or any combination of these.</p>
| 1 | 2009-03-11T20:30:20Z | [
"python",
"data-structures",
"dictionary",
"mapping",
"autovivification"
] |
What is the best way to implement nested dictionaries in Python? | 635,483 | <p>I have a data structure which essentially amounts to a nested dictionary. Let's say it looks like this:</p>
<pre><code>{'new jersey': {'mercer county': {'plumbers': 3,
'programmers': 81},
'middlesex county': {'programmers': 81,
'... | 149 | 2009-03-11T17:09:21Z | 637,569 | <p><code>collections.defaultdict</code> can be sub-classed to make a nested dict. Then add any useful iteration methods to that class.</p>
<pre><code>>>> from collections import defaultdict
>>> class nesteddict(defaultdict):
def __init__(self):
defaultdict.__init__(self, nesteddict)
... | 5 | 2009-03-12T06:27:52Z | [
"python",
"data-structures",
"dictionary",
"mapping",
"autovivification"
] |
What is the best way to implement nested dictionaries in Python? | 635,483 | <p>I have a data structure which essentially amounts to a nested dictionary. Let's say it looks like this:</p>
<pre><code>{'new jersey': {'mercer county': {'plumbers': 3,
'programmers': 81},
'middlesex county': {'programmers': 81,
'... | 149 | 2009-03-11T17:09:21Z | 644,500 | <p>As others have suggested, a relational database could be more useful to you. You can use a in-memory sqlite3 database as a data structure to create tables and then query them.</p>
<pre><code>import sqlite3
c = sqlite3.Connection(':memory:')
c.execute('CREATE TABLE jobs (state, county, title, count)')
c.executema... | 6 | 2009-03-13T20:24:47Z | [
"python",
"data-structures",
"dictionary",
"mapping",
"autovivification"
] |
What is the best way to implement nested dictionaries in Python? | 635,483 | <p>I have a data structure which essentially amounts to a nested dictionary. Let's say it looks like this:</p>
<pre><code>{'new jersey': {'mercer county': {'plumbers': 3,
'programmers': 81},
'middlesex county': {'programmers': 81,
'... | 149 | 2009-03-11T17:09:21Z | 652,284 | <pre><code>class AutoVivification(dict):
"""Implementation of perl's autovivification feature."""
def __getitem__(self, item):
try:
return dict.__getitem__(self, item)
except KeyError:
value = self[item] = type(self)()
return value
</code></pre>
<p>Testing:</... | 178 | 2009-03-16T21:53:36Z | [
"python",
"data-structures",
"dictionary",
"mapping",
"autovivification"
] |
What is the best way to implement nested dictionaries in Python? | 635,483 | <p>I have a data structure which essentially amounts to a nested dictionary. Let's say it looks like this:</p>
<pre><code>{'new jersey': {'mercer county': {'plumbers': 3,
'programmers': 81},
'middlesex county': {'programmers': 81,
'... | 149 | 2009-03-11T17:09:21Z | 5,222,457 | <p><code>defaultdict()</code> is your friend!</p>
<p>I didn't come up with this (see "<a href="http://slacy.com/blog/2010/05/python-multi-dimensional-dicts-using-defaultdict/">Python Multi-dimensional dicts using defaultdict</a>") but for a two dimensional dictionary you can do:</p>
<pre><code>d = defaultdict(defaul... | 6 | 2011-03-07T16:48:34Z | [
"python",
"data-structures",
"dictionary",
"mapping",
"autovivification"
] |
What is the best way to implement nested dictionaries in Python? | 635,483 | <p>I have a data structure which essentially amounts to a nested dictionary. Let's say it looks like this:</p>
<pre><code>{'new jersey': {'mercer county': {'plumbers': 3,
'programmers': 81},
'middlesex county': {'programmers': 81,
'... | 149 | 2009-03-11T17:09:21Z | 7,476,491 | <p>Just because I haven't seen one this small, here's a dict that gets as nested as you like, no sweat:</p>
<pre><code># yo dawg, i heard you liked dicts
def yodict():
return defaultdict(yodict)
</code></pre>
| 25 | 2011-09-19T19:51:07Z | [
"python",
"data-structures",
"dictionary",
"mapping",
"autovivification"
] |
What is the best way to implement nested dictionaries in Python? | 635,483 | <p>I have a data structure which essentially amounts to a nested dictionary. Let's say it looks like this:</p>
<pre><code>{'new jersey': {'mercer county': {'plumbers': 3,
'programmers': 81},
'middlesex county': {'programmers': 81,
'... | 149 | 2009-03-11T17:09:21Z | 12,980,572 | <p>I have a similar thing going. I have a lot of cases where I do:</p>
<pre><code>thedict = {}
for item in ('foo', 'bar', 'baz'):
mydict = thedict.get(item, {})
mydict = get_value_for(item)
thedict[item] = mydict
</code></pre>
<p>But going many levels deep. It's the ".get(item, {})" that's the key as it'll ma... | 0 | 2012-10-19T18:47:35Z | [
"python",
"data-structures",
"dictionary",
"mapping",
"autovivification"
] |
What is the best way to implement nested dictionaries in Python? | 635,483 | <p>I have a data structure which essentially amounts to a nested dictionary. Let's say it looks like this:</p>
<pre><code>{'new jersey': {'mercer county': {'plumbers': 3,
'programmers': 81},
'middlesex county': {'programmers': 81,
'... | 149 | 2009-03-11T17:09:21Z | 19,829,714 | <blockquote>
<h1>What is the best way to implement nested dictionaries in Python?</h1>
</blockquote>
<p>Implement <code>__missing__</code> on a <code>dict</code> subclass to set and return a new instance!</p>
<p>Here is a more elegant approach that has been available <a href="http://docs.python.org/2/library/stdtyp... | 88 | 2013-11-07T06:53:24Z | [
"python",
"data-structures",
"dictionary",
"mapping",
"autovivification"
] |
What is the best way to implement nested dictionaries in Python? | 635,483 | <p>I have a data structure which essentially amounts to a nested dictionary. Let's say it looks like this:</p>
<pre><code>{'new jersey': {'mercer county': {'plumbers': 3,
'programmers': 81},
'middlesex county': {'programmers': 81,
'... | 149 | 2009-03-11T17:09:21Z | 22,737,965 | <p>This is a function that returns a nested dictionary of arbitrary depth:</p>
<pre><code>from collections import defaultdict
def make_dict():
return defaultdict(make_dict)
</code></pre>
<p>Use it like this:</p>
<pre><code>d=defaultdict(make_dict)
d["food"]["meat"]="beef"
d["food"]["veggie"]="corn"
d["food"]["sw... | 8 | 2014-03-29T22:53:36Z | [
"python",
"data-structures",
"dictionary",
"mapping",
"autovivification"
] |
What is the best way to implement nested dictionaries in Python? | 635,483 | <p>I have a data structure which essentially amounts to a nested dictionary. Let's say it looks like this:</p>
<pre><code>{'new jersey': {'mercer county': {'plumbers': 3,
'programmers': 81},
'middlesex county': {'programmers': 81,
'... | 149 | 2009-03-11T17:09:21Z | 34,931,958 | <p>You can use Addict: <a href="https://github.com/mewwts/addict" rel="nofollow">https://github.com/mewwts/addict</a></p>
<pre><code>>>> from addict import Dict
>>> my_new_shiny_dict = Dict()
>>> my_new_shiny_dict.a.b.c.d.e = 2
>>> my_new_shiny_dict
{'a': {'b': {'c': {'d': {'e': 2}}... | 1 | 2016-01-21T18:50:09Z | [
"python",
"data-structures",
"dictionary",
"mapping",
"autovivification"
] |
What is the best way to implement nested dictionaries in Python? | 635,483 | <p>I have a data structure which essentially amounts to a nested dictionary. Let's say it looks like this:</p>
<pre><code>{'new jersey': {'mercer county': {'plumbers': 3,
'programmers': 81},
'middlesex county': {'programmers': 81,
'... | 149 | 2009-03-11T17:09:21Z | 36,512,749 | <p>You can use recursion in lambdas and defaultdict, no need to define names:</p>
<pre><code>a = defaultdict((lambda f: f(f))(lambda g: lambda:defaultdict(g(g))))
</code></pre>
<p>Here's an example:</p>
<pre><code>>>> a['new jersey']['mercer county']['plumbers']=3
>>> a['new jersey']['middlesex cou... | 1 | 2016-04-09T04:25:21Z | [
"python",
"data-structures",
"dictionary",
"mapping",
"autovivification"
] |
Django: Open uploaded file while still in memory; In the Form Clean method? | 635,524 | <p>I need to validate the contents of an uploaded XML file in my Form clean method, but I'm unable to open the file for validation. It seams, in the clean method, the file hasn't yet been moved from memory (or the temporary directory) to the destination directory.</p>
<p>For example the following code doesn't work bec... | 7 | 2009-03-11T17:20:30Z | 635,559 | <p>I'm assuming that you've bound your form to the files using:</p>
<pre><code>my_form = MyFormClass(request.POST, request.FILES)
</code></pre>
<p>If you have, once the form has been validated, you can access the file content itself using the request.FILES dictionary:</p>
<pre><code>if my_form.is_valid():
data =... | 12 | 2009-03-11T17:29:45Z | [
"python",
"django"
] |
Inserting A Heading Into A Django Form | 635,583 | <p>I would like my form to output something like this:</p>
<pre><code>Name: ___________
Company: ___________
Interested in
-------------
Foo: [ ]
Bar: [ ]
Baz: [ ]
</code></pre>
<p>That is to say, I would like to have the 'Interested In' title inserted in the middle of my form output.</p>
<p>One way of doing this w... | 2 | 2009-03-11T17:37:13Z | 636,160 | <p>With <a href="http://github.com/muhuk/django-formfieldset/tree/master" rel="nofollow"><code>FieldsetMixin</code></a> you get Admin-like fieldsets. You create your form like this:</p>
<pre><code>from django.forms import Form
from formfieldset.forms import FieldsetMixin
class MyForm(Form, FieldsetMixin):
fields... | 3 | 2009-03-11T20:13:24Z | [
"python",
"django",
"forms"
] |
Inserting A Heading Into A Django Form | 635,583 | <p>I would like my form to output something like this:</p>
<pre><code>Name: ___________
Company: ___________
Interested in
-------------
Foo: [ ]
Bar: [ ]
Baz: [ ]
</code></pre>
<p>That is to say, I would like to have the 'Interested In' title inserted in the middle of my form output.</p>
<p>One way of doing this w... | 2 | 2009-03-11T17:37:13Z | 636,164 | <p>The form fields retain the order with which you defined the form class or model if it's form for model. In the template you can iterate thru all the fields specifying how they are rendered, you can check for the one you are looking for with the ifequal tag and specify the different rendering.</p>
<p>See:</p>
<p><a... | 0 | 2009-03-11T20:14:44Z | [
"python",
"django",
"forms"
] |
Inserting A Heading Into A Django Form | 635,583 | <p>I would like my form to output something like this:</p>
<pre><code>Name: ___________
Company: ___________
Interested in
-------------
Foo: [ ]
Bar: [ ]
Baz: [ ]
</code></pre>
<p>That is to say, I would like to have the 'Interested In' title inserted in the middle of my form output.</p>
<p>One way of doing this w... | 2 | 2009-03-11T17:37:13Z | 636,200 | <p>Django formsets are not the way to go: They are used if you need to edit multiple objects at the same time. HTML fieldsets are more like the correct way. I imagine you could group the name and company fields into one fieldset, and then the interest fields into another.</p>
<p>On DjangoSnippets you can find a <a hre... | 3 | 2009-03-11T20:22:21Z | [
"python",
"django",
"forms"
] |
Inserting A Heading Into A Django Form | 635,583 | <p>I would like my form to output something like this:</p>
<pre><code>Name: ___________
Company: ___________
Interested in
-------------
Foo: [ ]
Bar: [ ]
Baz: [ ]
</code></pre>
<p>That is to say, I would like to have the 'Interested In' title inserted in the middle of my form output.</p>
<p>One way of doing this w... | 2 | 2009-03-11T17:37:13Z | 24,209,246 | <p>It's a bit of a hack, but you could define a <code>HeaderWidget</code> that just renders its value:</p>
<pre><code>from django.forms.util import flatatt
from django.utils.html import format_html
class HeaderWidget(forms.widgets.Widget):
def render(self, name, value, attrs=None):
attrs.update(self.attrs... | 0 | 2014-06-13T15:43:05Z | [
"python",
"django",
"forms"
] |
tell whether a character is a combining diacritic mark | 635,643 | <p>if you're looping though the chars a unicode string in python (2.x), say:</p>
<blockquote>
<p>ak.sÉp.tÉÌ</p>
</blockquote>
<p>How can you tell whether the current char is a combining diacritic mark?</p>
<p>For instance, the last char in the above string is actually a combining mark:</p>
<blockquote>
<p>ak... | 3 | 2009-03-11T17:55:57Z | 635,716 | <p>Use the unicodedata module:</p>
<pre><code>import unicodedata
if unicodedata.combining(u'a'):
print "is combining character"
else:
print "is not combining"
</code></pre>
<p>these posts are also relevant</p>
<p><a href="http://stackoverflow.com/questions/446222/how-do-i-reverse-unicode-decomposition-using-... | 7 | 2009-03-11T18:15:22Z | [
"python",
"unicode",
"diacritics"
] |
python: problem using call.subprocess to use a file after writing it | 635,946 | <p>In python I am trying to write a script that will edit text files and then run executables that use those text files. It basically entails 1)opening and reading/writing to a text file, and 2)using the file I just wrote in a bash command. Here is a simple example:</p>
<pre><code>import subprocess
# write file
a =... | 0 | 2009-03-11T19:14:37Z | 635,961 | <p>Close the file by actually calling the close() method. This will implicitly flush the buffers to disk.</p>
<pre><code>f.close()
</code></pre>
<p>rather than</p>
<pre><code>f.close #this probably doesn't do anything, but if there was no close method it would raise an error.
</code></pre>
| 9 | 2009-03-11T19:18:45Z | [
"python",
"subprocess"
] |
python: problem using call.subprocess to use a file after writing it | 635,946 | <p>In python I am trying to write a script that will edit text files and then run executables that use those text files. It basically entails 1)opening and reading/writing to a text file, and 2)using the file I just wrote in a bash command. Here is a simple example:</p>
<pre><code>import subprocess
# write file
a =... | 0 | 2009-03-11T19:14:37Z | 20,544,443 | <p>Although the first answer is most definitely correct and proper, you could also just set f to None instead of was was done as follows:</p>
<pre><code>import subprocess
# write file
a = ['1\n','2\n','3\n','4\n','5th and final line\n']
f = open('junk01.txt', 'wb')
f.writelines(a)
f = None
# show file
subprocess.call... | 0 | 2013-12-12T13:08:19Z | [
"python",
"subprocess"
] |
What's different between Python and Javascript regular expressions? | 636,485 | <p>Are Python and JavaScript regular expression syntax identical? </p>
<p>If not, then: </p>
<ol>
<li>What are the important differences between them</li>
<li>Is there a python library that "implements" JavaScript regexps?</li>
</ol>
| 25 | 2009-03-11T21:36:56Z | 636,501 | <p>There is a comparison table here:</p>
<p><a href="http://www.regular-expressions.info/refflavors.html">Regex Flavor Comparison</a></p>
| 25 | 2009-03-11T21:42:55Z | [
"javascript",
"python",
"regex"
] |
What's different between Python and Javascript regular expressions? | 636,485 | <p>Are Python and JavaScript regular expression syntax identical? </p>
<p>If not, then: </p>
<ol>
<li>What are the important differences between them</li>
<li>Is there a python library that "implements" JavaScript regexps?</li>
</ol>
| 25 | 2009-03-11T21:36:56Z | 636,506 | <p><a href="http://www.regular-expressions.info/javascript.html" rel="nofollow">http://www.regular-expressions.info/javascript.html</a> vs <a href="http://www.regular-expressions.info/python.html" rel="nofollow">http://www.regular-expressions.info/python.html</a></p>
| 2 | 2009-03-11T21:44:12Z | [
"javascript",
"python",
"regex"
] |
What's different between Python and Javascript regular expressions? | 636,485 | <p>Are Python and JavaScript regular expression syntax identical? </p>
<p>If not, then: </p>
<ol>
<li>What are the important differences between them</li>
<li>Is there a python library that "implements" JavaScript regexps?</li>
</ol>
| 25 | 2009-03-11T21:36:56Z | 636,523 | <p><strong>Part 1</strong><br />
They are different; One difference is Python supports Unicode and Javascript doesn't. </p>
<p><strong>Part 2</strong><br />
Read <a href="http://oreilly.com/catalog/9780596528126/" rel="nofollow">Mastering Regular Expressions</a>. It gives information on how to identify the back-end ... | 5 | 2009-03-11T21:48:57Z | [
"javascript",
"python",
"regex"
] |
SELECT * in sqlalchemy? | 636,548 | <p>Is it possible to do <code>SELECT *</code> in sqlalchemy?</p>
<p>Edit: Specifically, <code>SELECT * WHERE foo=1</code></p>
| 12 | 2009-03-11T21:56:49Z | 636,571 | <p>If you don't list any columns, you get all of them.</p>
<pre><code>query = users.select()
query = query.where(users.c.name=='jack')
result = conn.execute(query)
for row in result:
print row
</code></pre>
<p>Should work.</p>
| 3 | 2009-03-11T22:05:48Z | [
"python",
"sqlalchemy"
] |
SELECT * in sqlalchemy? | 636,548 | <p>Is it possible to do <code>SELECT *</code> in sqlalchemy?</p>
<p>Edit: Specifically, <code>SELECT * WHERE foo=1</code></p>
| 12 | 2009-03-11T21:56:49Z | 636,596 | <p>Turns out you can do:</p>
<pre><code>sa.select('*', ...)
</code></pre>
| 1 | 2009-03-11T22:13:53Z | [
"python",
"sqlalchemy"
] |
SELECT * in sqlalchemy? | 636,548 | <p>Is it possible to do <code>SELECT *</code> in sqlalchemy?</p>
<p>Edit: Specifically, <code>SELECT * WHERE foo=1</code></p>
| 12 | 2009-03-11T21:56:49Z | 636,631 | <p>Is no one feeling the ORM love of SQLALchemy today? The presented answers correctly describe the lower level interface that SQLAlchemy provides. Just for completeness this is the more-likely <em>(for me)</em> real-world situation where you have a session instance and a User class that is orm mapped to the users tabl... | 19 | 2009-03-11T22:27:31Z | [
"python",
"sqlalchemy"
] |
SELECT * in sqlalchemy? | 636,548 | <p>Is it possible to do <code>SELECT *</code> in sqlalchemy?</p>
<p>Edit: Specifically, <code>SELECT * WHERE foo=1</code></p>
| 12 | 2009-03-11T21:56:49Z | 636,709 | <p>Where <strong>Bar</strong> is the class mapped to your table and <strong>session</strong> is your sa session:</p>
<pre><code>bars = session.query(Bar).filter(Bar.foo == 1)</code></pre>
| 7 | 2009-03-11T23:02:32Z | [
"python",
"sqlalchemy"
] |
SELECT * in sqlalchemy? | 636,548 | <p>Is it possible to do <code>SELECT *</code> in sqlalchemy?</p>
<p>Edit: Specifically, <code>SELECT * WHERE foo=1</code></p>
| 12 | 2009-03-11T21:56:49Z | 12,632,528 | <p>If you're using the ORM, you can build a query using the normal ORM constructs and then execute it directly to get raw column values:</p>
<pre><code>query = session.query(User).filter_by(name='jack')
for cols in session.connection().execute(query):
print cols
</code></pre>
| 1 | 2012-09-28T01:50:06Z | [
"python",
"sqlalchemy"
] |
SELECT * in sqlalchemy? | 636,548 | <p>Is it possible to do <code>SELECT *</code> in sqlalchemy?</p>
<p>Edit: Specifically, <code>SELECT * WHERE foo=1</code></p>
| 12 | 2009-03-11T21:56:49Z | 16,064,769 | <p>You can always use a raw SQL too:</p>
<pre><code>str_sql = sql.text("YOUR STRING SQL")
#if you have some args:
args = {
'myarg1': yourarg1
'myarg2': yourarg2}
#then call the execute method from your connection
results = conn.execute(str_sql,args).fetchall()
</code></pre>
| 2 | 2013-04-17T15:56:37Z | [
"python",
"sqlalchemy"
] |
SELECT * in sqlalchemy? | 636,548 | <p>Is it possible to do <code>SELECT *</code> in sqlalchemy?</p>
<p>Edit: Specifically, <code>SELECT * WHERE foo=1</code></p>
| 12 | 2009-03-11T21:56:49Z | 19,514,773 | <p>For joins if columns are not defined manually, only columns of target table are returned. To get all columns for joins(User table joined with Group Table:</p>
<pre class="lang-py prettyprint-override"><code>sql = User.select(from_obj(Group, User.c.group_id == Group.c.id))
# Add all coumns of Group table to select
s... | 3 | 2013-10-22T10:05:49Z | [
"python",
"sqlalchemy"
] |
SELECT * in sqlalchemy? | 636,548 | <p>Is it possible to do <code>SELECT *</code> in sqlalchemy?</p>
<p>Edit: Specifically, <code>SELECT * WHERE foo=1</code></p>
| 12 | 2009-03-11T21:56:49Z | 23,228,825 | <p>The following selection works for me in the core expression language (returning a <a href="http://docs.sqlalchemy.org/en/latest/core/connections.html#sqlalchemy.engine.RowProxy" rel="nofollow">RowProxy object</a>):</p>
<pre><code>foo_col = sqlalchemy.sql.column('foo')
s = sqlalchemy.sql.select(['*']).where(foo_col ... | 6 | 2014-04-22T19:48:44Z | [
"python",
"sqlalchemy"
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.