title stringlengths 10 172 | question_id int64 469 40.1M | question_body stringlengths 22 48.2k | question_score int64 -44 5.52k | question_date stringlengths 20 20 | answer_id int64 497 40.1M | answer_body stringlengths 18 33.9k | answer_score int64 -38 8.38k | answer_date stringlengths 20 20 | tags listlengths 1 5 |
|---|---|---|---|---|---|---|---|---|---|
Is there a way to reopen a socket? | 1,410,723 | <p>I create many "short-term" sockets in some code that look like that :</p>
<pre><code>nb=1000
for i in range(nb):
sck = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sck.connect((adr, prt)
sck.send('question %i'%i)
sck.shutdown(SHUT_WR)
answer=sck.recv(4096)
print 'answer %i : %s' % (%i, ... | 6 | 2009-09-11T13:00:14Z | 1,410,803 | <p>If you keep opening and closing sockets for the same port then it is better to open this socket once and keep it open, then you will have much better performance, since opening and closing will take some time.</p>
<p>If you have many short-term sockets, you may also consider datagram sockets (UDP).
Note that you do... | 1 | 2009-09-11T13:16:34Z | [
"python",
"sockets"
] |
Is there a way to reopen a socket? | 1,410,723 | <p>I create many "short-term" sockets in some code that look like that :</p>
<pre><code>nb=1000
for i in range(nb):
sck = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sck.connect((adr, prt)
sck.send('question %i'%i)
sck.shutdown(SHUT_WR)
answer=sck.recv(4096)
print 'answer %i : %s' % (%i, ... | 6 | 2009-09-11T13:00:14Z | 1,411,387 | <p>I'm not sure what the extra overhead would be like, but you could fully close and reopen the socket. You need to set SO_REUSEADDR, and bind to a specific port you can reuse.</p>
<pre><code>sck = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sck.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
</code></pre>... | 3 | 2009-09-11T14:54:12Z | [
"python",
"sockets"
] |
Is there a way to reopen a socket? | 1,410,723 | <p>I create many "short-term" sockets in some code that look like that :</p>
<pre><code>nb=1000
for i in range(nb):
sck = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sck.connect((adr, prt)
sck.send('question %i'%i)
sck.shutdown(SHUT_WR)
answer=sck.recv(4096)
print 'answer %i : %s' % (%i, ... | 6 | 2009-09-11T13:00:14Z | 1,411,602 | <p>You cannot reuse the socket but it would not help if you could, since you are running out of ports, not sockets. Each port will stay in <a href="http://www.developerweb.net/forum/showthread.php?t=2941" rel="nofollow"><code>TIME_WAIT</code> state</a> for twice the maximum segment lifetime after you initiate the shut... | 0 | 2009-09-11T15:24:41Z | [
"python",
"sockets"
] |
Bypassing buffering of subprocess output with popen in C or Python | 1,410,849 | <p>I have a general question about popen (and all related functions), applicable to all operating systems, when I write a python script or some c code and run the resulting executable from the console (win or linux), i can immediately see the output from the process. However, if I run the same executable as a forked pr... | 9 | 2009-09-11T13:25:03Z | 1,410,879 | <p>Thats correct, and applies to both Windows and Linux (and possibly other systems), with <code>popen()</code> and <code>fopen()</code>. If you want the output buffer to be dispatched before 4096 bytes, use <code>fflush()</code> (on C) or <code>sys.stdout.flush()</code> (Python).</p>
| 1 | 2009-09-11T13:30:53Z | [
"python",
"c",
"buffer",
"pipe"
] |
Bypassing buffering of subprocess output with popen in C or Python | 1,410,849 | <p>I have a general question about popen (and all related functions), applicable to all operating systems, when I write a python script or some c code and run the resulting executable from the console (win or linux), i can immediately see the output from the process. However, if I run the same executable as a forked pr... | 9 | 2009-09-11T13:25:03Z | 1,411,112 | <p>In general, the standard C runtime library (that's running on behalf of just about every program on every system, more or less;-) detects whether stdout is a terminal or not; if not, it buffers the output (which can be a huge efficiency win, compared to unbuffered output).</p>
<p>If you're in control of the program... | 10 | 2009-09-11T14:11:29Z | [
"python",
"c",
"buffer",
"pipe"
] |
Apache vs Twisted | 1,410,967 | <p>I know Twisted is a framework that allows you to do asynchronous non-blocking i/o but I still do not understand how that is different from what Apache server does. If anyone could explain the need for twisted, I would appreciate it..</p>
| 4 | 2009-09-11T13:46:13Z | 1,411,014 | <p>They are two different things, one is a pure WEB server and one is a WEB framework with a builtin event driven servers.</p>
<p>Twisted is good for constructing high-end ad-hoc network services.</p>
| 2 | 2009-09-11T13:56:19Z | [
"python",
"apache",
"twisted"
] |
Apache vs Twisted | 1,410,967 | <p>I know Twisted is a framework that allows you to do asynchronous non-blocking i/o but I still do not understand how that is different from what Apache server does. If anyone could explain the need for twisted, I would appreciate it..</p>
| 4 | 2009-09-11T13:46:13Z | 1,411,038 | <p>Twisted is a platform for developing internet applications, for handling the underlying communications and such. It doesn't "do" anything out of the box--you've got to program it.</p>
<p>Apache is an internet application, of sorts. Upon install, you have a working web server which can serve up static and dynamic we... | 10 | 2009-09-11T14:01:03Z | [
"python",
"apache",
"twisted"
] |
Apache vs Twisted | 1,410,967 | <p>I know Twisted is a framework that allows you to do asynchronous non-blocking i/o but I still do not understand how that is different from what Apache server does. If anyone could explain the need for twisted, I would appreciate it..</p>
| 4 | 2009-09-11T13:46:13Z | 1,413,874 | <p>FYI, FriendFeed/Facebook just open sourced their custom server and framework: <a href="http://www.tornadoweb.org/" rel="nofollow">Tornado</a>. Matt Heitzenroder of Apparatus has run an initial comparison test and <a href="http://www.apparatusproject.org/blog/" rel="nofollow">looks like Tornado left twisted in the d... | 2 | 2009-09-12T00:39:51Z | [
"python",
"apache",
"twisted"
] |
Apache vs Twisted | 1,410,967 | <p>I know Twisted is a framework that allows you to do asynchronous non-blocking i/o but I still do not understand how that is different from what Apache server does. If anyone could explain the need for twisted, I would appreciate it..</p>
| 4 | 2009-09-11T13:46:13Z | 1,456,513 | <p>@alphazero You read that Twisted vs. Tornado benchmark wrong (or you didn't read it at all). Quote from the article: " Lower mean response time is better." Twisted is <em>lower</em>. People want their webservers to respond with lower (faster) times.</p>
<p>Twisted leaves Tornado in the dust... or, in reality, the... | 2 | 2009-09-21T19:57:58Z | [
"python",
"apache",
"twisted"
] |
Equivalent of Bash Backticks in Python | 1,410,976 | <p>What is the equivalent of the backticks found in Ruby and Perl in Python? That is, in Ruby I can do this:</p>
<pre><code>foo = `cat /tmp/baz`
</code></pre>
<p>What does the equivalent statement look like in Python? I've tried <code>os.system("cat /tmp/baz")</code> but that puts the result to standard out and retur... | 67 | 2009-09-11T13:47:53Z | 1,410,997 | <p>The most flexible way is to use the <a href="http://docs.python.org/library/subprocess.html"><code>subprocess</code></a> module:</p>
<pre><code>import subprocess
proc = subprocess.Popen(["cat", "/tmp/baz"], stdout=subprocess.PIPE)
(out, err) = proc.communicate()
print "program output:", out
</code></pre>
<p>If yo... | 71 | 2009-09-11T13:52:17Z | [
"python",
"backticks"
] |
Equivalent of Bash Backticks in Python | 1,410,976 | <p>What is the equivalent of the backticks found in Ruby and Perl in Python? That is, in Ruby I can do this:</p>
<pre><code>foo = `cat /tmp/baz`
</code></pre>
<p>What does the equivalent statement look like in Python? I've tried <code>os.system("cat /tmp/baz")</code> but that puts the result to standard out and retur... | 67 | 2009-09-11T13:47:53Z | 1,411,004 | <pre><code>output = os.popen('cat /tmp/baz').read()
</code></pre>
| 65 | 2009-09-11T13:53:48Z | [
"python",
"backticks"
] |
Equivalent of Bash Backticks in Python | 1,410,976 | <p>What is the equivalent of the backticks found in Ruby and Perl in Python? That is, in Ruby I can do this:</p>
<pre><code>foo = `cat /tmp/baz`
</code></pre>
<p>What does the equivalent statement look like in Python? I've tried <code>os.system("cat /tmp/baz")</code> but that puts the result to standard out and retur... | 67 | 2009-09-11T13:47:53Z | 1,411,010 | <pre><code>import os
foo = os.popen('cat /tmp/baz', 'r').read()
</code></pre>
| 2 | 2009-09-11T13:55:24Z | [
"python",
"backticks"
] |
Equivalent of Bash Backticks in Python | 1,410,976 | <p>What is the equivalent of the backticks found in Ruby and Perl in Python? That is, in Ruby I can do this:</p>
<pre><code>foo = `cat /tmp/baz`
</code></pre>
<p>What does the equivalent statement look like in Python? I've tried <code>os.system("cat /tmp/baz")</code> but that puts the result to standard out and retur... | 67 | 2009-09-11T13:47:53Z | 1,411,035 | <p><a href="http://stackoverflow.com/a/1410997/456814">sth is right</a>. You can also use os.popen(), but where available (Python 2.4+) subprocess is generally preferable.</p>
<p>However, unlike some languages that encourage it, it's generally considered bad form to spawn a subprocess where you can do the same job ins... | 23 | 2009-09-11T14:00:11Z | [
"python",
"backticks"
] |
Equivalent of Bash Backticks in Python | 1,410,976 | <p>What is the equivalent of the backticks found in Ruby and Perl in Python? That is, in Ruby I can do this:</p>
<pre><code>foo = `cat /tmp/baz`
</code></pre>
<p>What does the equivalent statement look like in Python? I've tried <code>os.system("cat /tmp/baz")</code> but that puts the result to standard out and retur... | 67 | 2009-09-11T13:47:53Z | 2,626,678 | <p>If you use subprocess.Popen, remember to specify bufsize. The default is 0, which means "unbuffered", not "choose a reasonable default".</p>
| 0 | 2010-04-13T02:55:41Z | [
"python",
"backticks"
] |
Equivalent of Bash Backticks in Python | 1,410,976 | <p>What is the equivalent of the backticks found in Ruby and Perl in Python? That is, in Ruby I can do this:</p>
<pre><code>foo = `cat /tmp/baz`
</code></pre>
<p>What does the equivalent statement look like in Python? I've tried <code>os.system("cat /tmp/baz")</code> but that puts the result to standard out and retur... | 67 | 2009-09-11T13:47:53Z | 5,279,400 | <p>I'm using</p>
<blockquote>
<p>(6:0)$ python --version
Python 2.7.1</p>
</blockquote>
<p>One of the examples above is:</p>
<pre><code>import subprocess
proc = subprocess.Popen(["cat", "/tmp/baz"], stdout=subprocess.PIPE, shell=True)
(out, err) = proc.communicate()
print "program output:", out
</code></pre>
<p... | 1 | 2011-03-11T23:13:34Z | [
"python",
"backticks"
] |
Equivalent of Bash Backticks in Python | 1,410,976 | <p>What is the equivalent of the backticks found in Ruby and Perl in Python? That is, in Ruby I can do this:</p>
<pre><code>foo = `cat /tmp/baz`
</code></pre>
<p>What does the equivalent statement look like in Python? I've tried <code>os.system("cat /tmp/baz")</code> but that puts the result to standard out and retur... | 67 | 2009-09-11T13:47:53Z | 7,469,168 | <pre><code>foo = subprocess.check_output(["cat", "/tmp/baz"])
</code></pre>
| 13 | 2011-09-19T09:58:22Z | [
"python",
"backticks"
] |
Equivalent of Bash Backticks in Python | 1,410,976 | <p>What is the equivalent of the backticks found in Ruby and Perl in Python? That is, in Ruby I can do this:</p>
<pre><code>foo = `cat /tmp/baz`
</code></pre>
<p>What does the equivalent statement look like in Python? I've tried <code>os.system("cat /tmp/baz")</code> but that puts the result to standard out and retur... | 67 | 2009-09-11T13:47:53Z | 25,001,160 | <p>Easiest way is to use commands package.</p>
<pre><code>import commands
commands.getoutput("whoami")
</code></pre>
<p>Output:</p>
<blockquote>
<p>'bganesan'</p>
</blockquote>
| 3 | 2014-07-28T17:48:01Z | [
"python",
"backticks"
] |
Equivalent of Bash Backticks in Python | 1,410,976 | <p>What is the equivalent of the backticks found in Ruby and Perl in Python? That is, in Ruby I can do this:</p>
<pre><code>foo = `cat /tmp/baz`
</code></pre>
<p>What does the equivalent statement look like in Python? I've tried <code>os.system("cat /tmp/baz")</code> but that puts the result to standard out and retur... | 67 | 2009-09-11T13:47:53Z | 29,735,004 | <p>This will not work in python3, but in python2 you can extend <code>str</code> with a custom <code>__repr__</code> method that calls your shell command and returns it like so:</p>
<pre><code>#!/usr/bin/env python
import os
class Command(str):
"""Call system commands"""
def __repr__(cmd):
return os... | 1 | 2015-04-19T19:48:17Z | [
"python",
"backticks"
] |
Equivalent of Bash Backticks in Python | 1,410,976 | <p>What is the equivalent of the backticks found in Ruby and Perl in Python? That is, in Ruby I can do this:</p>
<pre><code>foo = `cat /tmp/baz`
</code></pre>
<p>What does the equivalent statement look like in Python? I've tried <code>os.system("cat /tmp/baz")</code> but that puts the result to standard out and retur... | 67 | 2009-09-11T13:47:53Z | 36,160,224 | <p>From Python 3.5 onward, the recommended way is to use <a href="https://docs.python.org/3/library/subprocess.html#subprocess.run" rel="nofollow"><code>subprocess.run</code></a>. To get the same behaviour as you describe, you would use:</p>
<pre><code>output = subprocess.run("ls", shell=True, stdout=subprocess.PIPE)... | 1 | 2016-03-22T16:39:33Z | [
"python",
"backticks"
] |
Python - Windows Shutdown Events | 1,411,186 | <p>When using win32api.setConsoleCtrlHandler(), I'm able to receive shutdown/logoff/etc events from Windows, and cleanly shut down my app.</p>
<p>However, this only works when running the app under python.exe (i.e., it has a console window), but not under pythonw.exe (no console window).</p>
<p>Is there an equivalent... | 7 | 2009-09-11T14:21:59Z | 1,411,322 | <p>If you don't have a console, setting a console handler of course can't work. You can receive system events on a GUI (non-console) program by making another window (doesn't have to be visible), making sure you have a normal "message pump" on it serving, and handling <code>WM_QUERYENDSESSION</code> -- that's the messa... | 4 | 2009-09-11T14:43:39Z | [
"python",
"windows"
] |
Python - Windows Shutdown Events | 1,411,186 | <p>When using win32api.setConsoleCtrlHandler(), I'm able to receive shutdown/logoff/etc events from Windows, and cleanly shut down my app.</p>
<p>However, this only works when running the app under python.exe (i.e., it has a console window), but not under pythonw.exe (no console window).</p>
<p>Is there an equivalent... | 7 | 2009-09-11T14:21:59Z | 1,429,658 | <p>The problem here was that the HWND_MESSAGE window type doesn't actually receive broadcast messages - like the WM_QUERYENDSESSION and WM_ENDSESSION. </p>
<p>So instead of specifying win32con.HWND_MESSAGE for the "parent window" parameter of CreateWindowEx(), I just specified "0".</p>
<p>Basically, this creates an ... | 6 | 2009-09-15T21:13:29Z | [
"python",
"windows"
] |
Twisted - listen to multiple ports for multiple processes with one reactor | 1,411,281 | <p>i need to run multiple instances of my server app each on it's own port. It's not a problem if i start these with os.system or subprocess.Popen, but i'd like to have some process communication with multiprocessing. </p>
<p>I'd like to somehow dynamically set up listening to different port from different processes. ... | 3 | 2009-09-11T14:35:53Z | 1,417,980 | <p>I am not sure what error you are getting.
The following is an example from <a href="http://twistedmatrix.com/projects/core/documentation/howto/servers.html">twisted site</a> (modified)
And as you can see, it listen on two ports, and can listen to many more.</p>
<pre><code>from twisted.internet.protocol import Proto... | 9 | 2009-09-13T15:21:31Z | [
"python",
"process",
"twisted"
] |
Locking in sqlalchemy | 1,411,350 | <p>I'm confused about how to concurrently modify a table from several different processes. I've tried using <code>Query.with_lockmode()</code>, but it doesn't seem to be doing what I expect it to do, which would be to prevent two processes from simultaneously querying the same rows. Here's what I've tried:</p>
<pre><c... | 3 | 2009-09-11T14:48:09Z | 1,411,497 | <p>Are you by accident using MyISAM tables? This works fine with InnoDB tables, but would have the described behavior (silent failure to respect isolation) with MyISAM.</p>
| 4 | 2009-09-11T15:08:44Z | [
"python",
"sql",
"sqlalchemy",
"locking"
] |
How do I stop getting ImportError: Could not import settings 'mofin.settings' when using django with wsgi? | 1,411,417 | <p>I can't get wsgi to import my settings file for my project 'mofin'.</p>
<p>The list of errors from the apache error log are as follows</p>
<pre><code>mod_wsgi (pid=4001): Exception occurred within WSGI script '/var/www/wsgi-scripts/django.wsgi'.
Traceback (most recent call last):
File "/usr/lib/python2.5/site-pa... | 62 | 2009-09-11T14:58:37Z | 1,411,515 | <p>Possible problem:</p>
<p>you forgot the __init__.py file, which must be in your project and in all directories which you consider a python module for import.</p>
<p>Other thing you could try is to add the path directly into the manage.py file, like :</p>
<pre><code>import sys
...
...
sys.path.insert(0, '/home/d... | 4 | 2009-09-11T15:10:14Z | [
"python",
"django",
"apache",
"wsgi"
] |
How do I stop getting ImportError: Could not import settings 'mofin.settings' when using django with wsgi? | 1,411,417 | <p>I can't get wsgi to import my settings file for my project 'mofin'.</p>
<p>The list of errors from the apache error log are as follows</p>
<pre><code>mod_wsgi (pid=4001): Exception occurred within WSGI script '/var/www/wsgi-scripts/django.wsgi'.
Traceback (most recent call last):
File "/usr/lib/python2.5/site-pa... | 62 | 2009-09-11T14:58:37Z | 1,412,678 | <p>At first look I'd say the python path is wrong but compared to interactive shell it looks ok.
So maybe try this:</p>
<pre><code>from django.core.management import setup_environ
from mofin import settings
setup_environ(settings)
</code></pre>
| 0 | 2009-09-11T18:51:27Z | [
"python",
"django",
"apache",
"wsgi"
] |
How do I stop getting ImportError: Could not import settings 'mofin.settings' when using django with wsgi? | 1,411,417 | <p>I can't get wsgi to import my settings file for my project 'mofin'.</p>
<p>The list of errors from the apache error log are as follows</p>
<pre><code>mod_wsgi (pid=4001): Exception occurred within WSGI script '/var/www/wsgi-scripts/django.wsgi'.
Traceback (most recent call last):
File "/usr/lib/python2.5/site-pa... | 62 | 2009-09-11T14:58:37Z | 1,418,284 | <p>I was going to say that you can just insert/append your project directory to your sys.path in your wsgi file but if your settings file is at</p>
<pre><code>/home/django/mofin/trunk/mofin/settings.py
</code></pre>
<p>Then you should be good there.</p>
<pre><code>Is it on sys.path? Does it have syntax errors?
</cod... | 0 | 2009-09-13T17:20:53Z | [
"python",
"django",
"apache",
"wsgi"
] |
How do I stop getting ImportError: Could not import settings 'mofin.settings' when using django with wsgi? | 1,411,417 | <p>I can't get wsgi to import my settings file for my project 'mofin'.</p>
<p>The list of errors from the apache error log are as follows</p>
<pre><code>mod_wsgi (pid=4001): Exception occurred within WSGI script '/var/www/wsgi-scripts/django.wsgi'.
Traceback (most recent call last):
File "/usr/lib/python2.5/site-pa... | 62 | 2009-09-11T14:58:37Z | 1,438,381 | <p>I found the answer... file permissions. /home/django was set to 700. i.e. only django can view the contents. apache runs as Apache and so can't get past /home/django. </p>
| 8 | 2009-09-17T11:51:54Z | [
"python",
"django",
"apache",
"wsgi"
] |
How do I stop getting ImportError: Could not import settings 'mofin.settings' when using django with wsgi? | 1,411,417 | <p>I can't get wsgi to import my settings file for my project 'mofin'.</p>
<p>The list of errors from the apache error log are as follows</p>
<pre><code>mod_wsgi (pid=4001): Exception occurred within WSGI script '/var/www/wsgi-scripts/django.wsgi'.
Traceback (most recent call last):
File "/usr/lib/python2.5/site-pa... | 62 | 2009-09-11T14:58:37Z | 4,181,080 | <p>I had a similar permissions problem, and although my settings.py had the right permissions, the .pyc's did not!!! So watch out for this.</p>
| 21 | 2010-11-15T02:59:13Z | [
"python",
"django",
"apache",
"wsgi"
] |
How do I stop getting ImportError: Could not import settings 'mofin.settings' when using django with wsgi? | 1,411,417 | <p>I can't get wsgi to import my settings file for my project 'mofin'.</p>
<p>The list of errors from the apache error log are as follows</p>
<pre><code>mod_wsgi (pid=4001): Exception occurred within WSGI script '/var/www/wsgi-scripts/django.wsgi'.
Traceback (most recent call last):
File "/usr/lib/python2.5/site-pa... | 62 | 2009-09-11T14:58:37Z | 4,750,766 | <p>Hey, just adding an additional answer to this problem. I had the exact same issue, but it wasn't file permissions. I was appending "path/to/project", but not also appending "path/to". Linked is mod_wsgi's <a href="http://code.google.com/p/modwsgi/wiki/IntegrationWithDjango">Django integration explanation</a> that ... | 18 | 2011-01-20T18:04:09Z | [
"python",
"django",
"apache",
"wsgi"
] |
How do I stop getting ImportError: Could not import settings 'mofin.settings' when using django with wsgi? | 1,411,417 | <p>I can't get wsgi to import my settings file for my project 'mofin'.</p>
<p>The list of errors from the apache error log are as follows</p>
<pre><code>mod_wsgi (pid=4001): Exception occurred within WSGI script '/var/www/wsgi-scripts/django.wsgi'.
Traceback (most recent call last):
File "/usr/lib/python2.5/site-pa... | 62 | 2009-09-11T14:58:37Z | 6,949,892 | <p>This can also happen if you have an application (subdirectory to the project with an init file in it) named the same thing as the project. Your settings.py file may be in your project folder, but it seems that a part of the django system looks first for a module inside the project by the same name as the project an... | 46 | 2011-08-04T23:40:02Z | [
"python",
"django",
"apache",
"wsgi"
] |
How do I stop getting ImportError: Could not import settings 'mofin.settings' when using django with wsgi? | 1,411,417 | <p>I can't get wsgi to import my settings file for my project 'mofin'.</p>
<p>The list of errors from the apache error log are as follows</p>
<pre><code>mod_wsgi (pid=4001): Exception occurred within WSGI script '/var/www/wsgi-scripts/django.wsgi'.
Traceback (most recent call last):
File "/usr/lib/python2.5/site-pa... | 62 | 2009-09-11T14:58:37Z | 7,254,518 | <p>I had the same problem but another solution :</p>
<p>My project folder was named exactly as one of my application.</p>
<p>I had :</p>
<p>/home/myApp<br>
/home/myApp/settings.py<br>
/home/myApp/manage.py<br>
/home/myApp/rights.py<br>
/home/myApp/static/<br>
/home/myApp/static/<br>
/home/myApp/<strong>myApp</strong... | 3 | 2011-08-31T08:38:38Z | [
"python",
"django",
"apache",
"wsgi"
] |
How do I stop getting ImportError: Could not import settings 'mofin.settings' when using django with wsgi? | 1,411,417 | <p>I can't get wsgi to import my settings file for my project 'mofin'.</p>
<p>The list of errors from the apache error log are as follows</p>
<pre><code>mod_wsgi (pid=4001): Exception occurred within WSGI script '/var/www/wsgi-scripts/django.wsgi'.
Traceback (most recent call last):
File "/usr/lib/python2.5/site-pa... | 62 | 2009-09-11T14:58:37Z | 7,347,016 | <p>I think you need to have a trailing forward slash on that its what I have to do in my wsgi script in apache before I load up django.</p>
<pre><code>import os
import sys
sys.path.append('/home/django/mofin/trunk/')
sys.path.append('/home/django/mofin/trunk/mofin/')
print >> sys.stderr, sys.path
os.environ['DJA... | 7 | 2011-09-08T11:02:35Z | [
"python",
"django",
"apache",
"wsgi"
] |
How do I stop getting ImportError: Could not import settings 'mofin.settings' when using django with wsgi? | 1,411,417 | <p>I can't get wsgi to import my settings file for my project 'mofin'.</p>
<p>The list of errors from the apache error log are as follows</p>
<pre><code>mod_wsgi (pid=4001): Exception occurred within WSGI script '/var/www/wsgi-scripts/django.wsgi'.
Traceback (most recent call last):
File "/usr/lib/python2.5/site-pa... | 62 | 2009-09-11T14:58:37Z | 8,722,325 | <p>(I wrote up this same answer for <a href="http://stackoverflow.com/questions/4462276/django-deployment-problem-in-apache-mod-wsgi-importerror-could-not-import-sett">Django deployment problem in Apache/mod_wsgi. ImportError: Could not import settings 'site.settings'</a> in case someone only finds this questio... | 1 | 2012-01-04T05:15:31Z | [
"python",
"django",
"apache",
"wsgi"
] |
How do I stop getting ImportError: Could not import settings 'mofin.settings' when using django with wsgi? | 1,411,417 | <p>I can't get wsgi to import my settings file for my project 'mofin'.</p>
<p>The list of errors from the apache error log are as follows</p>
<pre><code>mod_wsgi (pid=4001): Exception occurred within WSGI script '/var/www/wsgi-scripts/django.wsgi'.
Traceback (most recent call last):
File "/usr/lib/python2.5/site-pa... | 62 | 2009-09-11T14:58:37Z | 12,176,522 | <p>Another cause of this problem is that you can't name your application the same as another python module. For example I called mine <code>site</code>, little realising that <code>site</code> is already a python module.</p>
<p>You can check this by starting python, and running <code>import site</code>, <code>help(sit... | 6 | 2012-08-29T11:06:32Z | [
"python",
"django",
"apache",
"wsgi"
] |
How do I stop getting ImportError: Could not import settings 'mofin.settings' when using django with wsgi? | 1,411,417 | <p>I can't get wsgi to import my settings file for my project 'mofin'.</p>
<p>The list of errors from the apache error log are as follows</p>
<pre><code>mod_wsgi (pid=4001): Exception occurred within WSGI script '/var/www/wsgi-scripts/django.wsgi'.
Traceback (most recent call last):
File "/usr/lib/python2.5/site-pa... | 62 | 2009-09-11T14:58:37Z | 16,637,106 | <p>Add two more lines of code </p>
<pre><code>sys.path.append('/home/django/mofin/mofin')
sys.path.append('/home/django/mofin/trunk/mofin/mofin')
</code></pre>
<p>to your wsgi file under the line:</p>
<pre><code>sys.path.append('/home/django/mofin/trunk/mofin/')
</code></pre>
| 0 | 2013-05-19T16:56:48Z | [
"python",
"django",
"apache",
"wsgi"
] |
How do I stop getting ImportError: Could not import settings 'mofin.settings' when using django with wsgi? | 1,411,417 | <p>I can't get wsgi to import my settings file for my project 'mofin'.</p>
<p>The list of errors from the apache error log are as follows</p>
<pre><code>mod_wsgi (pid=4001): Exception occurred within WSGI script '/var/www/wsgi-scripts/django.wsgi'.
Traceback (most recent call last):
File "/usr/lib/python2.5/site-pa... | 62 | 2009-09-11T14:58:37Z | 17,467,705 | <p>In my case, I had a <strong>circular import</strong> that was causing this error. From <code>settings.py</code> I was importing one function in another module, and from that module I was importing a settings variable. To fix it, instead of directly importing from settings, I did this:</p>
<pre><code>from django.con... | 1 | 2013-07-04T10:15:56Z | [
"python",
"django",
"apache",
"wsgi"
] |
How do I stop getting ImportError: Could not import settings 'mofin.settings' when using django with wsgi? | 1,411,417 | <p>I can't get wsgi to import my settings file for my project 'mofin'.</p>
<p>The list of errors from the apache error log are as follows</p>
<pre><code>mod_wsgi (pid=4001): Exception occurred within WSGI script '/var/www/wsgi-scripts/django.wsgi'.
Traceback (most recent call last):
File "/usr/lib/python2.5/site-pa... | 62 | 2009-09-11T14:58:37Z | 19,991,779 | <p>I had a similar problem, solved it with the following snippet in my python:</p>
<pre><code>ALLDIRS = ['/var/www/MarkerDB/']
import sys
import site
# Remember original sys.path.
prev_sys_path = list(sys.path)
# Add each new site-packages directory.
for directory in ALLDIRS:
site.addsitedir(directory)
# Reor... | 0 | 2013-11-15T01:19:16Z | [
"python",
"django",
"apache",
"wsgi"
] |
How do I stop getting ImportError: Could not import settings 'mofin.settings' when using django with wsgi? | 1,411,417 | <p>I can't get wsgi to import my settings file for my project 'mofin'.</p>
<p>The list of errors from the apache error log are as follows</p>
<pre><code>mod_wsgi (pid=4001): Exception occurred within WSGI script '/var/www/wsgi-scripts/django.wsgi'.
Traceback (most recent call last):
File "/usr/lib/python2.5/site-pa... | 62 | 2009-09-11T14:58:37Z | 26,113,843 | <p>Let me add and my experience for that issue. After head banging for few hours and try all from the above answers I found that few lines in settings.py file cause the problem:</p>
<pre><code>from south.modelsinspector import add_introspection_rules
add_introspection_rules([], ["^dynamicsites.fields.FolderNameField"... | 1 | 2014-09-30T06:04:48Z | [
"python",
"django",
"apache",
"wsgi"
] |
How do I stop getting ImportError: Could not import settings 'mofin.settings' when using django with wsgi? | 1,411,417 | <p>I can't get wsgi to import my settings file for my project 'mofin'.</p>
<p>The list of errors from the apache error log are as follows</p>
<pre><code>mod_wsgi (pid=4001): Exception occurred within WSGI script '/var/www/wsgi-scripts/django.wsgi'.
Traceback (most recent call last):
File "/usr/lib/python2.5/site-pa... | 62 | 2009-09-11T14:58:37Z | 31,500,959 | <p>I just had this error and the solution was to enable my virtual environment via myvenv/source/activate. </p>
| 0 | 2015-07-19T11:59:53Z | [
"python",
"django",
"apache",
"wsgi"
] |
Having problem with IronPython to instantiate a class in IronPython Console | 1,411,442 | <p>I'm trying to learn IronPython. I created an extremely simple class like this one:</p>
<pre><code>class Test:
def testMethod(self):
print "test"
</code></pre>
<p>Next I'm trying to use it in IronPython Console:</p>
<pre><code>>>> import Test
>>> t = Test()
</code></pre>
<p>After the seco... | 1 | 2009-09-11T15:01:34Z | 1,411,539 | <p>you need to <code>from filename import Test</code> where filename is a basename of file class Test is saved in.</p>
<p>e.g.: class <code>Test</code> is saved in <code>test.py</code></p>
<p>then:</p>
<pre><code>from test import Test
t = Test()
</code></pre>
<p>will run as expected.</p>
| 4 | 2009-09-11T15:13:19Z | [
"python",
"ironpython"
] |
Having problem with IronPython to instantiate a class in IronPython Console | 1,411,442 | <p>I'm trying to learn IronPython. I created an extremely simple class like this one:</p>
<pre><code>class Test:
def testMethod(self):
print "test"
</code></pre>
<p>Next I'm trying to use it in IronPython Console:</p>
<pre><code>>>> import Test
>>> t = Test()
</code></pre>
<p>After the seco... | 1 | 2009-09-11T15:01:34Z | 1,411,543 | <p><code>import Test</code> loads the module named Test, defined in a file called Test.py(c|d). This module in turn contains your class named Test. You're trying to instantiate the module called Test. To instantiate the class Test in module Test, you need to use:</p>
<p>t = Test.Test()</p>
<p>This concept can be quit... | 2 | 2009-09-11T15:13:41Z | [
"python",
"ironpython"
] |
Help with basic Python function | 1,411,553 | <p>I have a function to connect to a database. This code works:</p>
<pre><code>def connect():
return MySQLdb.connect("example.com", "username", "password", "database")
</code></pre>
<p>But this doesn't:</p>
<pre><code>def connect():
host = "example.com"
user = "username"
pass = "password"
base = ... | 4 | 2009-09-11T15:15:28Z | 1,411,569 | <p><code>pass</code> is a reserved keyword. </p>
<p>Pick different variable names and your code should work fine.<br/>
Maybe something like:</p>
<pre><code>def connect():
_host = "example.com"
_user = "username"
_pass = "password"
_base = "database"
return MySQLdb.connect(_host, _user, _pass, _base)
</... | 9 | 2009-09-11T15:17:30Z | [
"python"
] |
How to get '\x01' to 1 | 1,411,658 | <p>I am getting this:</p>
<pre><code>_format_ = "7c7sc"
print struct.unpack(self._format_, data)
</code></pre>
<p>gives</p>
<pre><code>('\x7f', 'E', 'L', 'F', '\x01', '\x01', '\x01', '\x00\x00\x00\x00\x00\x00\x00', '\x00')
</code></pre>
<p>I want to take <code>'\x01'</code> and get 1 from it, i.e., convert to ``int... | 4 | 2009-09-11T15:34:02Z | 1,411,678 | <p><code>ord("\x01")</code> will return 1.</p>
| 13 | 2009-09-11T15:37:28Z | [
"python"
] |
How to get '\x01' to 1 | 1,411,658 | <p>I am getting this:</p>
<pre><code>_format_ = "7c7sc"
print struct.unpack(self._format_, data)
</code></pre>
<p>gives</p>
<pre><code>('\x7f', 'E', 'L', 'F', '\x01', '\x01', '\x01', '\x00\x00\x00\x00\x00\x00\x00', '\x00')
</code></pre>
<p>I want to take <code>'\x01'</code> and get 1 from it, i.e., convert to ``int... | 4 | 2009-09-11T15:34:02Z | 1,411,684 | <p>Perhaps you are thinking of the <code>ord</code> function?</p>
<pre><code>>>> ord("\x01")
1
>>> ord("\x02")
2
>>> ord("\x7f")
127
</code></pre>
| 3 | 2009-09-11T15:38:52Z | [
"python"
] |
What difference it makes when I set python thread as a Deamon | 1,411,860 | <p>What difference it makes when I set python thread as a Deamon, using thread.setDaemon(True) ?</p>
| 7 | 2009-09-11T16:08:29Z | 1,412,230 | <p>A daemon thread will not prevent the application from exiting. The program ends when all non-daemon threads (main thread included) are complete.</p>
<p>So generally, if you're doing something in the background, you might want to set the thread as daemon so you don't have to explicitly have that thread's function r... | 14 | 2009-09-11T17:20:46Z | [
"python",
"multithreading",
"daemon"
] |
Python CGI returning an http status code, such as 403? | 1,411,867 | <p>How can my python cgi return a specific http status code, such as 403 or 418? </p>
<p>I tried the obvious (print "Status:403 Forbidden") but it doesn't work.</p>
| 14 | 2009-09-11T16:09:29Z | 1,411,902 | <p>I guess, you're looking for <a href="http://docs.python.org/library/basehttpserver.html#BaseHTTPServer.BaseHTTPRequestHandler.send%5Ferror" rel="nofollow"><code>send_error</code></a>. It would be located in <a href="http://docs.python.org/3.1/library/http.server.html#http.server.BaseHTTPRequestHandler.send%5Ferror" ... | 1 | 2009-09-11T16:14:22Z | [
"python",
"http",
"cgi",
"http-status-codes"
] |
Python CGI returning an http status code, such as 403? | 1,411,867 | <p>How can my python cgi return a specific http status code, such as 403 or 418? </p>
<p>I tried the obvious (print "Status:403 Forbidden") but it doesn't work.</p>
| 14 | 2009-09-11T16:09:29Z | 1,411,969 | <pre><code>print 'Status: 403 Forbidden'
print
</code></pre>
<p>Works for me. You do need the second print though, as you need a double-newline to end the HTTP response headers. Otherwise your web server may complain you aren't sending it a complete set of headers.</p>
<pre><code>sys.stdout('Status: 403 Forbidden\r\n... | 16 | 2009-09-11T16:27:50Z | [
"python",
"http",
"cgi",
"http-status-codes"
] |
Python: what's the pythonic way to perform this loop? | 1,411,943 | <p>What is the pythonic way to perform this loop. I'm trying to pick a random key that will return a subtree and not the root. Hence: 'parent == None' cannot be true. Nor can 'isRoot==True' be true.</p>
<pre><code>thekey = random.choice(tree.thedict.keys())
while (tree.thedict[thekey].parent == None)or(tree.thedict[th... | 1 | 2009-09-11T16:21:11Z | 1,411,970 | <pre><code>thekey = random.choice(tree.thedict.keys())
parent = thedict[thekey].parent
while parent is None or parent.isRoot:
thekey = random.choice(tree.thedict.keys())
parent = thedict[thekey].parent
</code></pre>
| 1 | 2009-09-11T16:27:53Z | [
"python"
] |
Python: what's the pythonic way to perform this loop? | 1,411,943 | <p>What is the pythonic way to perform this loop. I'm trying to pick a random key that will return a subtree and not the root. Hence: 'parent == None' cannot be true. Nor can 'isRoot==True' be true.</p>
<pre><code>thekey = random.choice(tree.thedict.keys())
while (tree.thedict[thekey].parent == None)or(tree.thedict[th... | 1 | 2009-09-11T16:21:11Z | 1,411,980 | <blockquote>
<p>get a random subtree that is not the
root</p>
</blockquote>
<pre><code>not_root_nodes = [key, node for key,node in tree.thedict.iteritems() if not ( node.parent is None or node.isRoot)]
item = random.choice( not_root_nodes )
</code></pre>
| 3 | 2009-09-11T16:29:30Z | [
"python"
] |
Python: what's the pythonic way to perform this loop? | 1,411,943 | <p>What is the pythonic way to perform this loop. I'm trying to pick a random key that will return a subtree and not the root. Hence: 'parent == None' cannot be true. Nor can 'isRoot==True' be true.</p>
<pre><code>thekey = random.choice(tree.thedict.keys())
while (tree.thedict[thekey].parent == None)or(tree.thedict[th... | 1 | 2009-09-11T16:21:11Z | 1,411,982 | <pre><code>key = random.choice([key for key, subtree in tree.thedict.items()
if subtree.parent and not subtree.isRoot])
</code></pre>
<p>(Corrected after comments and question edition)</p>
| 3 | 2009-09-11T16:29:47Z | [
"python"
] |
Python: what's the pythonic way to perform this loop? | 1,411,943 | <p>What is the pythonic way to perform this loop. I'm trying to pick a random key that will return a subtree and not the root. Hence: 'parent == None' cannot be true. Nor can 'isRoot==True' be true.</p>
<pre><code>thekey = random.choice(tree.thedict.keys())
while (tree.thedict[thekey].parent == None)or(tree.thedict[th... | 1 | 2009-09-11T16:21:11Z | 1,411,987 | <p>I think that's a bit better:</p>
<pre><code>theDict = tree.thedict
def getKey():
return random.choice(theDict.keys())
theKey = getKey()
while theDict[thekey].parent in (None, True):
thekey = getKey()
</code></pre>
<p>What do you think?</p>
| 1 | 2009-09-11T16:30:30Z | [
"python"
] |
Python: what's the pythonic way to perform this loop? | 1,411,943 | <p>What is the pythonic way to perform this loop. I'm trying to pick a random key that will return a subtree and not the root. Hence: 'parent == None' cannot be true. Nor can 'isRoot==True' be true.</p>
<pre><code>thekey = random.choice(tree.thedict.keys())
while (tree.thedict[thekey].parent == None)or(tree.thedict[th... | 1 | 2009-09-11T16:21:11Z | 1,412,006 | <pre><code>def is_root(v):
assert (v.parent != None) == (v.isRoot)
return v.isRoot
#note how dumb this function looks when you guarantee that assertion
def get_random_nonroot_key():
while True:
thekey = random.choice(tree.thedict.keys())
value = tree.thedict[thekey]
if not is_root(value): return k... | 0 | 2009-09-11T16:34:49Z | [
"python"
] |
Python: what's the pythonic way to perform this loop? | 1,411,943 | <p>What is the pythonic way to perform this loop. I'm trying to pick a random key that will return a subtree and not the root. Hence: 'parent == None' cannot be true. Nor can 'isRoot==True' be true.</p>
<pre><code>thekey = random.choice(tree.thedict.keys())
while (tree.thedict[thekey].parent == None)or(tree.thedict[th... | 1 | 2009-09-11T16:21:11Z | 1,412,020 | <p>I think your while condition is flawed:</p>
<p>I think you expect this: <strong><code>tree.thedict[thekey].parent == None</code></strong><br />
should be equal to this: <strong><code>tree.thedict[thekey].parent.isRoot == True</code></strong></p>
<p>When in fact, for both to mean "this node is not the root", you sh... | 0 | 2009-09-11T16:38:02Z | [
"python"
] |
Python: what's the pythonic way to perform this loop? | 1,411,943 | <p>What is the pythonic way to perform this loop. I'm trying to pick a random key that will return a subtree and not the root. Hence: 'parent == None' cannot be true. Nor can 'isRoot==True' be true.</p>
<pre><code>thekey = random.choice(tree.thedict.keys())
while (tree.thedict[thekey].parent == None)or(tree.thedict[th... | 1 | 2009-09-11T16:21:11Z | 1,412,054 | <pre><code>thekey = random.choice(tree.thedict.keys())
parent = tree.thedict[thekey].parent
while parent is None or tree.thedict[thekey].isRoot:
thekey = random.choice(tree.thedict.keys())
parent = thedict[thekey].parent
</code></pre>
| 0 | 2009-09-11T16:47:08Z | [
"python"
] |
Python: what's the pythonic way to perform this loop? | 1,411,943 | <p>What is the pythonic way to perform this loop. I'm trying to pick a random key that will return a subtree and not the root. Hence: 'parent == None' cannot be true. Nor can 'isRoot==True' be true.</p>
<pre><code>thekey = random.choice(tree.thedict.keys())
while (tree.thedict[thekey].parent == None)or(tree.thedict[th... | 1 | 2009-09-11T16:21:11Z | 1,412,844 | <p>Personally, I don't like the repetition of initializing thekey before the while loop and then again inside the loop. It's a possible source of bugs; what happens if someone edits one of the two initializations and forgets to edit the other? Even if that never happens, anyone reading the code needs to check careful... | 0 | 2009-09-11T19:27:17Z | [
"python"
] |
Reading XML using Python minidom and iterating over each node | 1,412,004 | <p>I have an XML structure that looks like the following, but on a much larger scale:</p>
<pre><code><root>
<conference name='1'>
<author>
Bob
</author>
<author>
Nigel
</author>
</conference>
<conference na... | 21 | 2009-09-11T16:34:26Z | 1,412,150 | <p>I played around with it a bit, and here's what I got to work:</p>
<pre><code># ...
authortext= a.childNodes[0].nodeValue
print authortext
</code></pre>
<p>leading to output of:</p>
<pre>
C:\temp\py>xml2.py
1
Bob
Nigel
2
Alice
Mary
</pre>
<p>I can't tell you exactly why you have to access the childNode to get the... | 0 | 2009-09-11T17:05:12Z | [
"python",
"xml",
"parsing",
"minidom"
] |
Reading XML using Python minidom and iterating over each node | 1,412,004 | <p>I have an XML structure that looks like the following, but on a much larger scale:</p>
<pre><code><root>
<conference name='1'>
<author>
Bob
</author>
<author>
Nigel
</author>
</conference>
<conference na... | 21 | 2009-09-11T16:34:26Z | 1,412,170 | <p>your <code>authortext</code> is of type 1 (<code>ELEMENT_NODE</code>), normally you need to have <code>TEXT_NODE</code> to get a string. This will work</p>
<pre><code>a.childNodes[0].nodeValue
</code></pre>
| 21 | 2009-09-11T17:10:00Z | [
"python",
"xml",
"parsing",
"minidom"
] |
Reading XML using Python minidom and iterating over each node | 1,412,004 | <p>I have an XML structure that looks like the following, but on a much larger scale:</p>
<pre><code><root>
<conference name='1'>
<author>
Bob
</author>
<author>
Nigel
</author>
</conference>
<conference na... | 21 | 2009-09-11T16:34:26Z | 1,412,173 | <p>Element nodes don't have a nodeValue. You have to look at the Text nodes inside them. If you know there's always one text node inside you can say <code>element.firstChild.data</code> (data is the same as nodeValue for text nodes).</p>
<p>Be careful: if there is no text content there will be no child Text nodes and ... | 6 | 2009-09-11T17:10:16Z | [
"python",
"xml",
"parsing",
"minidom"
] |
Reading XML using Python minidom and iterating over each node | 1,412,004 | <p>I have an XML structure that looks like the following, but on a much larger scale:</p>
<pre><code><root>
<conference name='1'>
<author>
Bob
</author>
<author>
Nigel
</author>
</conference>
<conference na... | 21 | 2009-09-11T16:34:26Z | 18,661,632 | <p>Quick access:</p>
<pre><code>node.getElementsByTagName('author')[0].childNodes[0].nodeValue
</code></pre>
| 2 | 2013-09-06T15:46:15Z | [
"python",
"xml",
"parsing",
"minidom"
] |
Reading XML using Python minidom and iterating over each node | 1,412,004 | <p>I have an XML structure that looks like the following, but on a much larger scale:</p>
<pre><code><root>
<conference name='1'>
<author>
Bob
</author>
<author>
Nigel
</author>
</conference>
<conference na... | 21 | 2009-09-11T16:34:26Z | 35,292,416 | <p>Since you always have one text data value per author you can use element.firstChild.data</p>
<pre><code>dom = parseString(document)
conferences = dom.getElementsByTagName("conference")
# Each conference here is a node
for conference in conferences:
conference_name = conference.getAttribute("name")
print
... | 0 | 2016-02-09T12:43:14Z | [
"python",
"xml",
"parsing",
"minidom"
] |
Custom QStyledItemDelegate: adding bold items | 1,412,156 | <p>So here's the story:</p>
<p>I have a QListview that uses a QSqlQueryModel to fill it up. Because some items should display in bold based on the value of a hidden column of the model, I decided to make my own custom delegate. I'm using PyQT 4.5.4 and thus inheriting from QStyledItemDelegate is the way to go accordin... | 4 | 2009-09-11T17:06:36Z | 1,466,123 | <p>I've not tested this, but I think you can do:</p>
<pre><code>class TypeSoortDelegate(QStyledItemDelegate):
def paint(self, painter, option, index):
get value...
if value:
option.font.setWeight(QFont.Bold)
QStyledItemDelegate.paint(self, painter, option, index)
</code></pre>
| 3 | 2009-09-23T13:48:35Z | [
"python",
"user-interface",
"pyqt"
] |
Twisted(asynch server) vs Django(or any other framework) | 1,412,169 | <p>I need help understanding what the advantage of using an asynch framework is. Suppose I want to develop a simple chat web app. Why cant I write python code in the Django framework that does long polling where I dont send a response back the server until someone enters a new msg. What does Twisted provide that gives ... | 13 | 2009-09-11T17:09:48Z | 1,412,226 | <p>Asynchronous servers support much larger numbers of simultaneous client connections. More conventional servers come up against thread and process limits when servicing large number of concurrent clients, particularly those with long-lived connections. Async servers can also provide better performance as they avoid t... | 14 | 2009-09-11T17:20:23Z | [
"python",
"django",
"asynchronous",
"twisted",
"real-time"
] |
Twisted(asynch server) vs Django(or any other framework) | 1,412,169 | <p>I need help understanding what the advantage of using an asynch framework is. Suppose I want to develop a simple chat web app. Why cant I write python code in the Django framework that does long polling where I dont send a response back the server until someone enters a new msg. What does Twisted provide that gives ... | 13 | 2009-09-11T17:09:48Z | 1,412,372 | <p>First off Django is a framework for writing web apps so it provides ORM, html templating, it requires running an http server etc. Twisted helps to write much lower level code than that. You could use twisted to write the http server Django runs on. If you use Django you are limited to http model, with twisted it ... | 18 | 2009-09-11T17:50:55Z | [
"python",
"django",
"asynchronous",
"twisted",
"real-time"
] |
Twisted(asynch server) vs Django(or any other framework) | 1,412,169 | <p>I need help understanding what the advantage of using an asynch framework is. Suppose I want to develop a simple chat web app. Why cant I write python code in the Django framework that does long polling where I dont send a response back the server until someone enters a new msg. What does Twisted provide that gives ... | 13 | 2009-09-11T17:09:48Z | 1,413,098 | <p>You could use <a href="http://aaron.oirt.rutgers.edu/myapp/docs/W.intro" rel="nofollow">WHIFF</a> instead of either :). Check out
<a href="http://aaron.oirt.rutgers.edu/myapp/gfChat/nucularChatRoom" rel="nofollow">http://aaron.oirt.rutgers.edu/myapp/gfChat/nucularChatRoom</a>
which uses a javascript polling loop wi... | 0 | 2009-09-11T20:26:20Z | [
"python",
"django",
"asynchronous",
"twisted",
"real-time"
] |
Twisted(asynch server) vs Django(or any other framework) | 1,412,169 | <p>I need help understanding what the advantage of using an asynch framework is. Suppose I want to develop a simple chat web app. Why cant I write python code in the Django framework that does long polling where I dont send a response back the server until someone enters a new msg. What does Twisted provide that gives ... | 13 | 2009-09-11T17:09:48Z | 1,413,820 | <p>If you'd like to look at some source for integrating Twisted and Django, have a look at <a href="http://zork.net/motd/nick/django/introducing-yardbird.html" rel="nofollow">Yardbird</a>.</p>
| 0 | 2009-09-12T00:12:24Z | [
"python",
"django",
"asynchronous",
"twisted",
"real-time"
] |
Twisted(asynch server) vs Django(or any other framework) | 1,412,169 | <p>I need help understanding what the advantage of using an asynch framework is. Suppose I want to develop a simple chat web app. Why cant I write python code in the Django framework that does long polling where I dont send a response back the server until someone enters a new msg. What does Twisted provide that gives ... | 13 | 2009-09-11T17:09:48Z | 1,417,358 | <p>In twisted you can implement protocols of your own. Django certainly can't do this.</p>
| 2 | 2009-09-13T10:07:24Z | [
"python",
"django",
"asynchronous",
"twisted",
"real-time"
] |
Twisted(asynch server) vs Django(or any other framework) | 1,412,169 | <p>I need help understanding what the advantage of using an asynch framework is. Suppose I want to develop a simple chat web app. Why cant I write python code in the Django framework that does long polling where I dont send a response back the server until someone enters a new msg. What does Twisted provide that gives ... | 13 | 2009-09-11T17:09:48Z | 1,468,718 | <p>The biggest advantage for me is that Twisted gives me an application that has state, and can communicate with many different clients using many protocols. For more information, see my blog entry on <a href="http://blog.gridspy.co.nz/2009/09/database-meet-realtime-data-logging.html">Why I choose twisted over using a ... | 5 | 2009-09-23T21:53:32Z | [
"python",
"django",
"asynchronous",
"twisted",
"real-time"
] |
Python decorate a class to change parent object type | 1,412,210 | <p>Suppose you have two classes X & Y. You want to decorate those classes by adding attributes to the class to produce new classes X1 and Y1.</p>
<p>For example:</p>
<pre><code>class X1(X):
new_attribute = 'something'
class Y1(Y):
new_attribute = 'something'
</code></pre>
<p>*new_attribute* will always be t... | 3 | 2009-09-11T17:18:05Z | 1,412,335 | <p>Why can't you use <a href="http://docs.python.org/tutorial/classes.html#multiple-inheritance" rel="nofollow">multiple inheritance</a>?</p>
<pre><code>class Origin:
new_attribute = 'something'
class X:
pass
class Y:
pass
class X1(Origin, X):
pass
class Y1(Origin, Y):
pass
</code></pre>
| 2 | 2009-09-11T17:43:37Z | [
"python",
"decorator",
"multiple-inheritance"
] |
Python decorate a class to change parent object type | 1,412,210 | <p>Suppose you have two classes X & Y. You want to decorate those classes by adding attributes to the class to produce new classes X1 and Y1.</p>
<p>For example:</p>
<pre><code>class X1(X):
new_attribute = 'something'
class Y1(Y):
new_attribute = 'something'
</code></pre>
<p>*new_attribute* will always be t... | 3 | 2009-09-11T17:18:05Z | 1,412,866 | <p>Responding to your comments on <a href="http://stackoverflow.com/questions/1412210/python-decorate-a-class-to-change-parent-object-type/1412335#1412335">voyager's answer</a>:</p>
<pre><code>from google.appengine.ext import db
class Mixin(object):
"""Mix in attributes shared by different types of models."""
... | 3 | 2009-09-11T19:33:21Z | [
"python",
"decorator",
"multiple-inheritance"
] |
Python decorate a class to change parent object type | 1,412,210 | <p>Suppose you have two classes X & Y. You want to decorate those classes by adding attributes to the class to produce new classes X1 and Y1.</p>
<p>For example:</p>
<pre><code>class X1(X):
new_attribute = 'something'
class Y1(Y):
new_attribute = 'something'
</code></pre>
<p>*new_attribute* will always be t... | 3 | 2009-09-11T17:18:05Z | 1,413,902 | <p>Use 3-arguments <a href="http://docs.python.org/library/functions.html?#type" rel="nofollow">type</a>:</p>
<pre><code>def makeSomeNicelyDecoratedSubclass(someclass):
return type('MyNiceName', (someclass,), {'new_attribute':'something'})
</code></pre>
<p>This is indeed, as you surmised, a reasonably popular idiom... | 5 | 2009-09-12T00:58:23Z | [
"python",
"decorator",
"multiple-inheritance"
] |
Modifying a GUI started with Glade | 1,412,350 | <p>I am just starting to learn Glade with pyGTK. Since Glade makes XML files instead of actual python code, is there a good way to start a project with Glade and then hand code more or tweak it? </p>
<p>Are there times or reasons it would be preferrable to hand code all of it instead of starting with glade?</p>
| 2 | 2009-09-11T17:46:41Z | 1,413,921 | <p>How much do you know about glade and pygtk? Glade creates xml files but you load these using gtk.Builder in python. You can easily tweak any widgets you created with glade in python. Read these <a href="http://live.gnome.org/Glade/Tutorials" rel="nofollow">tutorials</a> to understand how to do it better. You just ne... | 2 | 2009-09-12T01:08:05Z | [
"python",
"gtk",
"pygtk",
"glade"
] |
Modifying a GUI started with Glade | 1,412,350 | <p>I am just starting to learn Glade with pyGTK. Since Glade makes XML files instead of actual python code, is there a good way to start a project with Glade and then hand code more or tweak it? </p>
<p>Are there times or reasons it would be preferrable to hand code all of it instead of starting with glade?</p>
| 2 | 2009-09-11T17:46:41Z | 1,448,130 | <p>GUI's created with glade are accessible in the code in two way: libglade or gtkbuilder. I cannot comment much on the differences between the two, other than that gtkbuilder is newer; there are a lot of pages on google that show how to migrate from libglade to gtkbuilder.</p>
<p>Using gtkbuilder, you can create your... | 4 | 2009-09-19T08:18:04Z | [
"python",
"gtk",
"pygtk",
"glade"
] |
Python Triple Quote / Multi-line indentation | 1,412,374 | <p>I have a python editor where the user is entering a script or code, which is then put into a main method behind the scenes, while also having every line indented. The problem is that if a user has a multi line string, the indentation made to the whole script affects the string, by inserting a tab in every space. A p... | 20 | 2009-09-11T17:51:05Z | 1,412,441 | <p>The only way i see - is to strip first n tabs for each line starting with second, where n is known identation of main method. </p>
<p>If that identation is not known beforehand - you can add trailing newline before inserting it and strip number of tabs from the last line...</p>
<p>The third solution is to parse d... | 1 | 2009-09-11T18:06:21Z | [
"python",
"quotes",
"multiline"
] |
Python Triple Quote / Multi-line indentation | 1,412,374 | <p>I have a python editor where the user is entering a script or code, which is then put into a main method behind the scenes, while also having every line indented. The problem is that if a user has a multi line string, the indentation made to the whole script affects the string, by inserting a tab in every space. A p... | 20 | 2009-09-11T17:51:05Z | 1,412,480 | <p>What follows the first line of a multiline string is part of the string, and not treated as indentation by the parser. you may freely write:</p>
<pre><code>def main():
"""foo
bar
foo2"""
pass
</code></pre>
<p>and it will do the right thing.</p>
<p>On the other hand, that's not readable, and python knows ... | 13 | 2009-09-11T18:12:23Z | [
"python",
"quotes",
"multiline"
] |
Python Triple Quote / Multi-line indentation | 1,412,374 | <p>I have a python editor where the user is entering a script or code, which is then put into a main method behind the scenes, while also having every line indented. The problem is that if a user has a multi line string, the indentation made to the whole script affects the string, by inserting a tab in every space. A p... | 20 | 2009-09-11T17:51:05Z | 1,412,603 | <p>So if I get it correctly, you take whatever the user inputs, indent it properly and add it to the rest of your program (and then run that whole program).</p>
<p>So after you put the user input into your program, you could run a regex, that basically takes that forced indentation back. Something like: Within three q... | 1 | 2009-09-11T18:35:43Z | [
"python",
"quotes",
"multiline"
] |
Python Triple Quote / Multi-line indentation | 1,412,374 | <p>I have a python editor where the user is entering a script or code, which is then put into a main method behind the scenes, while also having every line indented. The problem is that if a user has a multi line string, the indentation made to the whole script affects the string, by inserting a tab in every space. A p... | 20 | 2009-09-11T17:51:05Z | 1,412,728 | <p><a href="http://docs.python.org/library/textwrap.html#textwrap.dedent">textwrap.dedent</a> from the standard library is there to automatically undo the wacky indentation. </p>
| 49 | 2009-09-11T19:02:18Z | [
"python",
"quotes",
"multiline"
] |
Django extends template | 1,412,476 | <p>i have simple django/python app and i got 1 page - create.html. So i want to extend this page to use index.html. Everything work (no errors) and when the page is loaded all data from create.html and all text from index.html present but no formating is available - images and css that must be loaded from index.html is... | 0 | 2009-09-11T18:11:19Z | 1,412,627 | <p>It looks like you are extending base.html and not index.html.</p>
| 1 | 2009-09-11T18:41:33Z | [
"python",
"django",
"extends"
] |
Django extends template | 1,412,476 | <p>i have simple django/python app and i got 1 page - create.html. So i want to extend this page to use index.html. Everything work (no errors) and when the page is loaded all data from create.html and all text from index.html present but no formating is available - images and css that must be loaded from index.html is... | 0 | 2009-09-11T18:11:19Z | 1,412,673 | <p>More specifically, look at the first line of your content.html:</p>
<pre><code> {% extends "base.html" %}
</code></pre>
<p>Change this to</p>
<pre><code> {% extends "index.html" %}
</code></pre>
<p>(or rename index.html to be base.html)</p>
| 1 | 2009-09-11T18:50:36Z | [
"python",
"django",
"extends"
] |
Django extends template | 1,412,476 | <p>i have simple django/python app and i got 1 page - create.html. So i want to extend this page to use index.html. Everything work (no errors) and when the page is loaded all data from create.html and all text from index.html present but no formating is available - images and css that must be loaded from index.html is... | 0 | 2009-09-11T18:11:19Z | 1,413,255 | <p>Ahaa find where is the problem!
MEDIA_ROOT and MEDIA_URL was not set up :-( after edit them everything work ok.</p>
<p><a href="http://stackoverflow.com/questions/1075753/django-template-cant-see-css-files">http://stackoverflow.com/questions/1075753/django-template-cant-see-css-files</a></p>
| 1 | 2009-09-11T21:02:06Z | [
"python",
"django",
"extends"
] |
How do I programmatically check whether a GIF image is animated? | 1,412,529 | <p>Here is a link to <a href="http://stackoverflow.com/questions/1401527/how-do-i-programmatically-check-whether-an-image-png-jpeg-or-gif-is-corrupted">another question</a> I asked concerning the same project I am working on. I think that bit of background will be helpful. </p>
<p>For those that are too lazy to open a... | 8 | 2009-09-11T18:21:18Z | 1,412,587 | <p>Read the GIF89A specification and extract the information.
<a href="http://www.w3.org/Graphics/GIF/spec-gif89a.txt" rel="nofollow">http://www.w3.org/Graphics/GIF/spec-gif89a.txt</a></p>
<p>Or easy and lazy and ready for a hack use the intergif program which can extract the single images out of an animated gif. Extr... | 2 | 2009-09-11T18:33:14Z | [
"php",
"python",
"image"
] |
How do I programmatically check whether a GIF image is animated? | 1,412,529 | <p>Here is a link to <a href="http://stackoverflow.com/questions/1401527/how-do-i-programmatically-check-whether-an-image-png-jpeg-or-gif-is-corrupted">another question</a> I asked concerning the same project I am working on. I think that bit of background will be helpful. </p>
<p>For those that are too lazy to open a... | 8 | 2009-09-11T18:21:18Z | 1,412,594 | <p>A few solutions are given on the <a href="http://php.net/manual/en/function.imagecreatefromgif.php#88005" rel="nofollow">PHP docs</a> page for the <code>imagecreatefromgif</code> function.</p>
<p>From the solutions I've read, this one seems the best due to its tighter memory requirements.</p>
<pre><code><?php
f... | 3 | 2009-09-11T18:34:31Z | [
"php",
"python",
"image"
] |
How do I programmatically check whether a GIF image is animated? | 1,412,529 | <p>Here is a link to <a href="http://stackoverflow.com/questions/1401527/how-do-i-programmatically-check-whether-an-image-png-jpeg-or-gif-is-corrupted">another question</a> I asked concerning the same project I am working on. I think that bit of background will be helpful. </p>
<p>For those that are too lazy to open a... | 8 | 2009-09-11T18:21:18Z | 1,412,644 | <p>I've never seen a program that will tell you this. But GIF is a block structured format and you can check if the block indicating animated GIF is present in your files. </p>
<p>From wikipedia article noted below: at offset 0x30D an Application Extension (ie: 3 byte magic number 21 FF 0B) block in the GIF file, foll... | 6 | 2009-09-11T18:45:06Z | [
"php",
"python",
"image"
] |
How do I programmatically check whether a GIF image is animated? | 1,412,529 | <p>Here is a link to <a href="http://stackoverflow.com/questions/1401527/how-do-i-programmatically-check-whether-an-image-png-jpeg-or-gif-is-corrupted">another question</a> I asked concerning the same project I am working on. I think that bit of background will be helpful. </p>
<p>For those that are too lazy to open a... | 8 | 2009-09-11T18:21:18Z | 1,412,711 | <p>I'm no GIF file format expert, but this is an interesting problem to me so I looked into it a bit. This would work only if it's always true that animated gifs have the value NETSCAPE2.0 at position 0x310 (edit)AND static gifs do not,(/edit) which was the case in my test files. This is C#, if you want I could compile... | 1 | 2009-09-11T18:58:57Z | [
"php",
"python",
"image"
] |
How do I programmatically check whether a GIF image is animated? | 1,412,529 | <p>Here is a link to <a href="http://stackoverflow.com/questions/1401527/how-do-i-programmatically-check-whether-an-image-png-jpeg-or-gif-is-corrupted">another question</a> I asked concerning the same project I am working on. I think that bit of background will be helpful. </p>
<p>For those that are too lazy to open a... | 8 | 2009-09-11T18:21:18Z | 1,413,234 | <p>If you're on Linux (or any system with <a href="http://www.imagemagick.org/">ImageMagick</a>) you can use a one-liner shell script and <code>identify</code> program:</p>
<pre><code>identify *.gif | fgrep '.gif[1] '
</code></pre>
<p>I know you said you prefer PHP and Python, but you also said you are willing to exp... | 11 | 2009-09-11T20:56:52Z | [
"php",
"python",
"image"
] |
How do I programmatically check whether a GIF image is animated? | 1,412,529 | <p>Here is a link to <a href="http://stackoverflow.com/questions/1401527/how-do-i-programmatically-check-whether-an-image-png-jpeg-or-gif-is-corrupted">another question</a> I asked concerning the same project I am working on. I think that bit of background will be helpful. </p>
<p>For those that are too lazy to open a... | 8 | 2009-09-11T18:21:18Z | 1,413,365 | <p>With Python and <a href="http://www.pythonware.com/products/pil/" rel="nofollow">PIL</a>:</p>
<pre><code>from PIL import Image
gif = Image.open('path.gif')
try:
gif.seek(1)
except EOFError:
isanimated = False
else:
isanimated = True
</code></pre>
| 13 | 2009-09-11T21:26:07Z | [
"php",
"python",
"image"
] |
How do I programmatically check whether a GIF image is animated? | 1,412,529 | <p>Here is a link to <a href="http://stackoverflow.com/questions/1401527/how-do-i-programmatically-check-whether-an-image-png-jpeg-or-gif-is-corrupted">another question</a> I asked concerning the same project I am working on. I think that bit of background will be helpful. </p>
<p>For those that are too lazy to open a... | 8 | 2009-09-11T18:21:18Z | 1,414,046 | <p>try this</p>
<pre><code>import Image
def checkAnimate():
im = Image.open('image.gif')
if not im.info['version'].__contains__('GIF'):
print "It's not a GIF file"
else:
if im.info.has_key('duration'):
if im.info['duration'] > 0:
return True
else:... | 0 | 2009-09-12T02:23:34Z | [
"php",
"python",
"image"
] |
How do I programmatically check whether a GIF image is animated? | 1,412,529 | <p>Here is a link to <a href="http://stackoverflow.com/questions/1401527/how-do-i-programmatically-check-whether-an-image-png-jpeg-or-gif-is-corrupted">another question</a> I asked concerning the same project I am working on. I think that bit of background will be helpful. </p>
<p>For those that are too lazy to open a... | 8 | 2009-09-11T18:21:18Z | 2,965,831 | <p>see if there is more than one LocalDescriptor are there in the GIF file.</p>
| 1 | 2010-06-03T12:23:38Z | [
"php",
"python",
"image"
] |
How do I programmatically check whether a GIF image is animated? | 1,412,529 | <p>Here is a link to <a href="http://stackoverflow.com/questions/1401527/how-do-i-programmatically-check-whether-an-image-png-jpeg-or-gif-is-corrupted">another question</a> I asked concerning the same project I am working on. I think that bit of background will be helpful. </p>
<p>For those that are too lazy to open a... | 8 | 2009-09-11T18:21:18Z | 36,888,169 | <pre><code>from PIL import Image
fp = open('1.gif', 'rb')
im = Image.open(fp)
is_gif = bool(im.format and im.format.upper() == 'GIF')
</code></pre>
| 0 | 2016-04-27T11:15:01Z | [
"php",
"python",
"image"
] |
Python Warning control | 1,412,575 | <p>I would like some kind of warning to be raisen as errors, but only the first occurrence. How to do that?</p>
<p>I read <a href="http://docs.python.org/library/warnings.html" rel="nofollow">http://docs.python.org/library/warnings.html</a> and I dont know how to combine this two types of behaviour.</p>
| 3 | 2009-09-11T18:31:45Z | 1,412,615 | <p>Looking at the code to warnings.py, you can't assign more than one filter action to a warning, and you can't (easily) define your own actions, like 'raise_once'.</p>
<p>However, if you want to raise a warning as an exception, but just once, that means that you are catching the exception. Why not put a line in your ... | 6 | 2009-09-11T18:39:24Z | [
"python",
"warnings"
] |
iTunes COM - How to acess Lyrics | 1,412,689 | <p>I have been messing around with iTunes COM from python.</p>
<p>However, I haven't been able to access the Lyrics of any track.</p>
<p>I have been using python for this. Here is the code:</p>
<pre><code>>>> import win32com.client
>>> itunes = win32com.client.Dispatch("iTunes.Application")
>>... | 1 | 2009-09-11T18:54:31Z | 1,412,881 | <p>Try to convert it like this (not tested):</p>
<pre><code>track_converted = win32com.client.CastTo(tracks[1], "IITFileOrCDTrack")
</code></pre>
| 3 | 2009-09-11T19:38:09Z | [
"python",
"com",
"itunes"
] |
PicklingError: Can't pickle <class 'decimal.Decimal'>: it's not the same object as decimal.Decimal | 1,412,787 | <p>This is the error I got today at filmaster.com:</p>
<blockquote>
<p>PicklingError: Can't pickle : it's not the same
object as decimal.Decimal</p>
</blockquote>
<p>What does that exactly mean? It does not seem to be making a lot of sense...
It seems to be connected with django caching. You can see the whole tra... | 6 | 2009-09-11T19:13:23Z | 1,413,299 | <p>One oddity of Pickle is that the way you import a class before you pickle one of it's instances can subtly change the pickled object. Pickle requires you to have imported the object identically both before you pickle it and before you unpickle it. </p>
<p>So for example:</p>
<pre><code>from a.b import c
C = c()
pi... | 8 | 2009-09-11T21:12:22Z | [
"python",
"django",
"pickle"
] |
PicklingError: Can't pickle <class 'decimal.Decimal'>: it's not the same object as decimal.Decimal | 1,412,787 | <p>This is the error I got today at filmaster.com:</p>
<blockquote>
<p>PicklingError: Can't pickle : it's not the same
object as decimal.Decimal</p>
</blockquote>
<p>What does that exactly mean? It does not seem to be making a lot of sense...
It seems to be connected with django caching. You can see the whole tra... | 6 | 2009-09-11T19:13:23Z | 1,964,942 | <p>Did you somehow <code>reload(decimal)</code>, or monkeypatch the decimal module to change the Decimal class? These are the two things most likely to produce such a problem.</p>
| 2 | 2009-12-27T01:57:05Z | [
"python",
"django",
"pickle"
] |
PicklingError: Can't pickle <class 'decimal.Decimal'>: it's not the same object as decimal.Decimal | 1,412,787 | <p>This is the error I got today at filmaster.com:</p>
<blockquote>
<p>PicklingError: Can't pickle : it's not the same
object as decimal.Decimal</p>
</blockquote>
<p>What does that exactly mean? It does not seem to be making a lot of sense...
It seems to be connected with django caching. You can see the whole tra... | 6 | 2009-09-11T19:13:23Z | 38,551,656 | <p>I got this error when running in an jupyter notebook. I think the problem was that I was using <code>%load_ext autoreload</code> <code>autoreload 2</code>. Restarting my kernel and rerunning solved the problem.</p>
| 1 | 2016-07-24T11:46:51Z | [
"python",
"django",
"pickle"
] |
PicklingError: Can't pickle <class 'decimal.Decimal'>: it's not the same object as decimal.Decimal | 1,412,787 | <p>This is the error I got today at filmaster.com:</p>
<blockquote>
<p>PicklingError: Can't pickle : it's not the same
object as decimal.Decimal</p>
</blockquote>
<p>What does that exactly mean? It does not seem to be making a lot of sense...
It seems to be connected with django caching. You can see the whole tra... | 6 | 2009-09-11T19:13:23Z | 39,812,728 | <p>There can be issues starting a process with <code>multiprocessing</code> by calling <code>__init__</code>. Here's a demo:</p>
<pre><code>import multiprocessing as mp
class SubProcClass:
def __init__(self, pipe, startloop=False):
self.pipe = pipe
if startloop:
self.do_loop()
def... | 0 | 2016-10-02T00:19:12Z | [
"python",
"django",
"pickle"
] |
python mysql fetch query | 1,413,057 | <pre><code>def dispcar ( self, reg ):
print ("The car information for '%s' is: "), (reg)
numrows = int(self.dbc.rowcount) #get the count of total rows
self.dbc.execute("select * from car where reg='%s'") %(reg)
for x in range(0, numrows):
car_info = self.dbc.fetchone()
print ... | 2 | 2009-09-11T20:20:39Z | 1,413,100 | <p>I think this line simply has the parens in the wrong place:</p>
<pre><code>self.dbc.execute("select * from car where reg='%s'") %(reg)
</code></pre>
<p>You are using % on the result of execute(), and reg.</p>
<p>Change it to:</p>
<pre><code>self.dbc.execute("select * from car where reg='%s'" % reg)
</code></pre>... | 3 | 2009-09-11T20:26:48Z | [
"python",
"mysql"
] |
python mysql fetch query | 1,413,057 | <pre><code>def dispcar ( self, reg ):
print ("The car information for '%s' is: "), (reg)
numrows = int(self.dbc.rowcount) #get the count of total rows
self.dbc.execute("select * from car where reg='%s'") %(reg)
for x in range(0, numrows):
car_info = self.dbc.fetchone()
print ... | 2 | 2009-09-11T20:20:39Z | 1,413,103 | <p>You got the brackets wrong:</p>
<pre><code>self.dbc.execute("select * from car where reg=%s" , (reg,))
</code></pre>
<p>Any particular reason you are looping using fetchone (in this ugly loop with a range based on a rowcount which will probably be zero as you get it before you execute the query)?</p>
<p>Just do</... | 2 | 2009-09-11T20:27:58Z | [
"python",
"mysql"
] |
python mysql fetch query | 1,413,057 | <pre><code>def dispcar ( self, reg ):
print ("The car information for '%s' is: "), (reg)
numrows = int(self.dbc.rowcount) #get the count of total rows
self.dbc.execute("select * from car where reg='%s'") %(reg)
for x in range(0, numrows):
car_info = self.dbc.fetchone()
print ... | 2 | 2009-09-11T20:20:39Z | 1,413,449 | <p>This confuses just about everyone who works with MySQLDB. You are passing arguments to the execute function, not doing python string substitution. The %s in the query string is used more like a prepared statement than a python string substitution. This also prevents SQL injection as MySQLDB will do the escaping for ... | 3 | 2009-09-11T21:49:12Z | [
"python",
"mysql"
] |
Sorting by a field of another table referenced by a foreign key in SQLObject | 1,413,101 | <p>Is it possible to sort results returned by SQLObject by a value of another table?</p>
<p>I have two tables:</p>
<pre><code> class Foo(SQLObject):
bar = ForeignKey('Bar')
class Bar(SQLObject):
name = StringCol()
foos = MultipleJoin('Foo')
</code></pre>
<p>I'd like to get <code>foo</... | 1 | 2009-09-11T20:27:08Z | 1,437,840 | <p>Below is the answer of a SQLObject maintainer (he has trouble posting it himself because captcha is not displayed):</p>
<p>Do an explicit join:</p>
<pre><code>foos = Foo.select(Foo.q.barID==Bar.q.id, orderBy=Bar.q.name)
</code></pre>
<p>This generates a query:</p>
<pre><code>SELECT foo.id, foo.bar_id FROM foo, b... | 3 | 2009-09-17T10:02:25Z | [
"python",
"sorting",
"sqlobject"
] |
Showing an image from console in Python | 1,413,540 | <p>What is the easiest way to show a <code>.jpg</code> or <code>.gif</code> image from Python console?</p>
<p>I've got a Python console program that is checking a data set which contains links to images stored locally. How should I write the script so that it would display images pop-up graphical windows?</p>
| 13 | 2009-09-11T22:22:50Z | 1,413,561 | <p>You cannot display images in a console window.
You need a graphical toolkit such as Tkinter, PyGTK, PyQt, PyKDE, wxPython, PyObjC or PyFLTK.
There are plenty of tutorial how to create siomple windows and loading images iun python.</p>
| 4 | 2009-09-11T22:31:58Z | [
"python",
"image"
] |
Showing an image from console in Python | 1,413,540 | <p>What is the easiest way to show a <code>.jpg</code> or <code>.gif</code> image from Python console?</p>
<p>I've got a Python console program that is checking a data set which contains links to images stored locally. How should I write the script so that it would display images pop-up graphical windows?</p>
| 13 | 2009-09-11T22:22:50Z | 1,413,567 | <p>Using the awesome <a href="https://pypi.python.org/pypi/Pillow/2.7.0">Pillow</a> library:</p>
<pre><code>>>> from PIL import Image
>>> img = Image.open('test.png')
>>> img.show()
</code></pre>
<p>This will o... | 22 | 2009-09-11T22:34:22Z | [
"python",
"image"
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.