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 |
|---|---|---|---|---|---|---|---|---|---|
How to redirect the output of .exe to a file in python? | 880,918 | <p>In a script , I want to run a .exe with some command line parameters as "-a",and then</p>
<p>redirect the standard output of the program to a file?</p>
<p>How can I implement that?</p>
| 12 | 2009-05-19T04:03:32Z | 880,929 | <p>Easiest is <code>os.system("the.exe -a >thefile.txt")</code>, but there are many other ways, for example with the <code>subprocess</code> module in the standard library.</p>
| 7 | 2009-05-19T04:07:35Z | [
"python",
"redirect",
"io"
] |
How to redirect the output of .exe to a file in python? | 880,918 | <p>In a script , I want to run a .exe with some command line parameters as "-a",and then</p>
<p>redirect the standard output of the program to a file?</p>
<p>How can I implement that?</p>
| 12 | 2009-05-19T04:03:32Z | 881,501 | <p>You can do something like this
e.g. to read output of ls -l (or any other command)</p>
<pre><code>p = subprocess.Popen(["ls","-l"],stdout=subprocess.PIPE)
print p.stdout.read() # or put it in a file
</code></pre>
<p>you can do similar thing for stderr/stdin</p>
<p>but as Alex mentioned if you just want it in a fi... | 3 | 2009-05-19T08:05:29Z | [
"python",
"redirect",
"io"
] |
How to redirect the output of .exe to a file in python? | 880,918 | <p>In a script , I want to run a .exe with some command line parameters as "-a",and then</p>
<p>redirect the standard output of the program to a file?</p>
<p>How can I implement that?</p>
| 12 | 2009-05-19T04:03:32Z | 881,552 | <p>If you just want to run the executable and wait for the results, Anurag's solution is probably the best. I needed to respond to each line of output as it arrived, and found the following worked:</p>
<p>1) Create an object with a write(text) method. Redirect stdout to it (sys.stdout = obj). In your write method, dea... | 0 | 2009-05-19T08:21:20Z | [
"python",
"redirect",
"io"
] |
How to redirect the output of .exe to a file in python? | 880,918 | <p>In a script , I want to run a .exe with some command line parameters as "-a",and then</p>
<p>redirect the standard output of the program to a file?</p>
<p>How can I implement that?</p>
| 12 | 2009-05-19T04:03:32Z | 881,686 | <p>You can redirect directly to a file using subprocess.</p>
<pre><code>import subprocess
with open('output.txt', 'w') as output_f:
p = subprocess.Popen('Text/to/execute with-arg',
stdout=output_f,
stderr=output_f)
</code></pre>
| 21 | 2009-05-19T09:02:05Z | [
"python",
"redirect",
"io"
] |
How to redirect the output of .exe to a file in python? | 880,918 | <p>In a script , I want to run a .exe with some command line parameters as "-a",and then</p>
<p>redirect the standard output of the program to a file?</p>
<p>How can I implement that?</p>
| 12 | 2009-05-19T04:03:32Z | 14,994,325 | <p>Although the title (.exe) sounds like it's a problem on Windows.
I had to share that the accepted answer (subprocess.Popen() with stdout/stderr arguments) didn't work for me on Mac OS X (10.8) with python 2.7.</p>
<p>I had to use subprocess.check_output() (python 2.7 and above) to make it work. Example:</p>
<pre>... | 0 | 2013-02-21T04:02:35Z | [
"python",
"redirect",
"io"
] |
Pythonic URL Parsing | 880,988 | <p>There are a number of questions about how to parse a URL in Python, this question is about the best or most Pythonic way to do it. </p>
<p>In my parsing I need 4 parts: the network location, the first part of the URL, the path and the filename and querystring parts.</p>
<p><a href="http://www.somesite.com/base/f... | 0 | 2009-05-19T04:36:31Z | 880,995 | <p>Since your requirements on what parts you want are different from what urlparse gives you, that's as good as it's going to get. You could, however, replace this:</p>
<pre><code>partCount = len(pathParts) - 1
path = "/"
for i in range(2, partCount):
path += pathParts[i] + "/"
</code></pre>
<p>With this:</p>
<... | 6 | 2009-05-19T04:44:12Z | [
"url",
"python"
] |
Pythonic URL Parsing | 880,988 | <p>There are a number of questions about how to parse a URL in Python, this question is about the best or most Pythonic way to do it. </p>
<p>In my parsing I need 4 parts: the network location, the first part of the URL, the path and the filename and querystring parts.</p>
<p><a href="http://www.somesite.com/base/f... | 0 | 2009-05-19T04:36:31Z | 881,314 | <p>I'd be inclined to start out with <code>urlparse</code>. Also, you can use <code>rsplit</code>, and the <code>maxsplit</code> parameter of <code>split</code> and <code>rsplit</code> to simplify things a bit:</p>
<pre><code>_, netloc, path, _, q, _ = urlparse(url)
_, base, path = path.split('/', 2) # 1st component w... | 2 | 2009-05-19T06:55:31Z | [
"url",
"python"
] |
Error when trying to migrate django application with south | 880,989 | <p>I am getting this error when running "./manage.py migrate app_name"</p>
<pre><code>While loading migration 'whatever.0001_initial':
Traceback (most recent call last):
File "manage.py", line 14, in <module> execute_manager(settings)
...tons of other stuff..
raise KeyError("The model '%s' from the app '%s... | 0 | 2009-05-19T04:36:40Z | 885,716 | <p>The problem seemed to be with the order of models in the 0001_initial.py file. There was a class which derived from AppUser. When I re-created the migration on Mac OS with</p>
<pre><code>manage.py startmigration app --initial
</code></pre>
<p>and compared that to one generated on Ubuntu the order of models was dif... | 2 | 2009-05-20T00:53:37Z | [
"python",
"database",
"django",
"migration"
] |
Apple Event Handler Failure (Python/AppScript) | 881,041 | <p>I have written the following really simple python script to change the desktop wallpaper on my mac (based on this <a href="http://stackoverflow.com/questions/431205/how-can-i-programatically-change-the-background-in-mac-os-x">thread</a>):</p>
<pre><code>from appscript import app, mactypes
import sys
fileName = sy... | 1 | 2009-05-19T05:06:55Z | 881,328 | <p>fileName = sys.argv[1]
instead of
fileName = sys.argv[1:]</p>
<p>mactypes.File(u"/Users/Daniel/Pictures/['test.jpg']")
See the square brackets and quotes around the filename?</p>
| 2 | 2009-05-19T06:59:03Z | [
"python",
"debugging",
"osx",
"appscript"
] |
Apple Event Handler Failure (Python/AppScript) | 881,041 | <p>I have written the following really simple python script to change the desktop wallpaper on my mac (based on this <a href="http://stackoverflow.com/questions/431205/how-can-i-programatically-change-the-background-in-mac-os-x">thread</a>):</p>
<pre><code>from appscript import app, mactypes
import sys
fileName = sy... | 1 | 2009-05-19T05:06:55Z | 2,568,439 | <p>In the above, what would be the format for copying one file to another folder?</p>
<p>IS it something like app('Finder').copy (mactypes.File(u"/Users/Daniel/Pictures/['test.jpg']")) to_folder (mactypes.File(u"/Users/Daniel/OLD_PIX/))</p>
<p>Thanks for the help,
Frank</p>
| 0 | 2010-04-02T18:35:42Z | [
"python",
"debugging",
"osx",
"appscript"
] |
Google App Engine self.redirect post | 881,086 | <p>I have a form that POSTs information to one of my handlers. My handler verifies the information and then needs to POST this information to a third party AND redirect the user to that page.</p>
<p>Example of the </p>
<pre><code> class ExampleHandler(BaseRequestHandler):
"""DocString here...
"""
def post(se... | 2 | 2009-05-19T05:24:40Z | 881,171 | <p>You can POST the form and redirect the user to a page, but they'll have to be separate operations.</p>
<p>The <code>urlfetch.fetch()</code> method lets you set the method to POST like so:</p>
<pre><code>import urllib
form_fields = {
"first_name": "Albert",
"last_name": "Johnson",
"email_address": "Albert.Jo... | 1 | 2009-05-19T06:03:42Z | [
"python",
"google-app-engine"
] |
How to suppress the carriage return in python 2? | 881,160 | <pre><code> myfile = open("wrsu"+str(i)+'_'+str(j)+'_'+str(TimesToExec)+".txt",'w')
sys.stdout = myfile
p1 = subprocess.Popen([pathname,"r", "s","u",str(i),str(j),str(runTime)],stdout=subprocess.PIPE)
output = p1.communicate()[0]
print output,
</code></pre>
<p>When I use this to ... | 2 | 2009-05-19T05:59:39Z | 881,182 | <p>Here's how I removed the carriage return:</p>
<pre><code> p = Popen([vmrun_cmd, list_arg], stdout=PIPE).communicate()[0]
for line in p.splitlines():
if line.strip():
print line
</code></pre>
| 2 | 2009-05-19T06:08:30Z | [
"python",
"io"
] |
How to suppress the carriage return in python 2? | 881,160 | <pre><code> myfile = open("wrsu"+str(i)+'_'+str(j)+'_'+str(TimesToExec)+".txt",'w')
sys.stdout = myfile
p1 = subprocess.Popen([pathname,"r", "s","u",str(i),str(j),str(runTime)],stdout=subprocess.PIPE)
output = p1.communicate()[0]
print output,
</code></pre>
<p>When I use this to ... | 2 | 2009-05-19T05:59:39Z | 881,231 | <pre><code>def Popenstrip(self):
p = Popen([vmrun_cmd, list_arg], stdout=PIPE).communicate()[0]
return (line for line in p.splitlines() if line.strip())
</code></pre>
| 1 | 2009-05-19T06:25:12Z | [
"python",
"io"
] |
How to suppress the carriage return in python 2? | 881,160 | <pre><code> myfile = open("wrsu"+str(i)+'_'+str(j)+'_'+str(TimesToExec)+".txt",'w')
sys.stdout = myfile
p1 = subprocess.Popen([pathname,"r", "s","u",str(i),str(j),str(runTime)],stdout=subprocess.PIPE)
output = p1.communicate()[0]
print output,
</code></pre>
<p>When I use this to ... | 2 | 2009-05-19T05:59:39Z | 9,459,105 | <pre><code>print line.rstrip('\r\n')
</code></pre>
<p>will do fine.</p>
| 0 | 2012-02-27T01:44:35Z | [
"python",
"io"
] |
how to send email in python | 881,184 | <pre><code>import smtplib
SERVER = "localhost"
FROM = "sender@example.com"
TO = ["user@example.com"]
SUBJECT = "Hello!"
TEXT = "This message was sent with Python's smtplib."
server = smtplib.SMTP(SERVER)
server.sendmail(FROM, TO, message)
server.quit()
</code></pre>
<p>This is giving the error:</p>
<pre><code>'**... | 2 | 2009-05-19T06:08:51Z | 881,200 | <p>Rename your file to something other than email.py. Also get rid of any email.pyc file left over. Problem solved.</p>
| 12 | 2009-05-19T06:14:45Z | [
"python"
] |
how to send email in python | 881,184 | <pre><code>import smtplib
SERVER = "localhost"
FROM = "sender@example.com"
TO = ["user@example.com"]
SUBJECT = "Hello!"
TEXT = "This message was sent with Python's smtplib."
server = smtplib.SMTP(SERVER)
server.sendmail(FROM, TO, message)
server.quit()
</code></pre>
<p>This is giving the error:</p>
<pre><code>'**... | 2 | 2009-05-19T06:08:51Z | 881,318 | <p>This happens because email is a <a href="http://docs.python.org/library/email" rel="nofollow">built-in library</a> that comes standard with python. If you rename your program to something else (as suggested above), that should do the trick.</p>
| 5 | 2009-05-19T06:56:17Z | [
"python"
] |
Error occurs when I connect with socket in Python | 881,332 | <p>Nice to meet you.
A socket makes a program in Python by Linux (the transmission of a message) â Windows (the reception), b
ut the following errors occur and cannot connect now.
Linux, Windows are network connection together, and there is the authority to cut.</p>
<p>socket.error: (111, 'Connection refused')</p>
... | 0 | 2009-05-19T07:00:35Z | 881,349 | <p>111 means the listener is down/not accepting connections - restart the Windows app that should be listening for connections, or disconnect any already-bound clients.</p>
| 2 | 2009-05-19T07:06:03Z | [
"python",
"sockets"
] |
What is the reason for performing a double fork when creating a daemon? | 881,388 | <p>I'm trying to create a daemon in python. I've found the <a href="http://stackoverflow.com/questions/473620/how-do-you-create-a-daemon-in-python">following question</a>, which has some good resources in it which I am currently following, but I'm curious as to why a double fork is necessary. I've scratched around goog... | 109 | 2009-05-19T07:25:18Z | 881,408 | <p>Taken from <a href="http://blog.charcoalphile.com/2008/05/03/python-tips-for-writing-daemons/">Bad CTK</a>:</p>
<p>"On some flavors of Unix, you are forced to do a double-fork on startup, in order to go into daemon mode. This is because single forking isnât guaranteed to detach from the controlling terminal."</p>... | 11 | 2009-05-19T07:32:26Z | [
"python",
"unix"
] |
What is the reason for performing a double fork when creating a daemon? | 881,388 | <p>I'm trying to create a daemon in python. I've found the <a href="http://stackoverflow.com/questions/473620/how-do-you-create-a-daemon-in-python">following question</a>, which has some good resources in it which I am currently following, but I'm curious as to why a double fork is necessary. I've scratched around goog... | 109 | 2009-05-19T07:25:18Z | 881,412 | <p>The daemon() call has the parent call _exit() if it succeeds. The original motivation may have been to allow the parent to do some extra work while the child is daemonizing.</p>
<p>It may also be based on a mistaken belief that it's necessary in order to ensure the daemon has no parent process and is reparented to ... | 2 | 2009-05-19T07:33:16Z | [
"python",
"unix"
] |
What is the reason for performing a double fork when creating a daemon? | 881,388 | <p>I'm trying to create a daemon in python. I've found the <a href="http://stackoverflow.com/questions/473620/how-do-you-create-a-daemon-in-python">following question</a>, which has some good resources in it which I am currently following, but I'm curious as to why a double fork is necessary. I've scratched around goog... | 109 | 2009-05-19T07:25:18Z | 881,415 | <p>According to "Advanced Programming in the Unix Environment", by Stephens and Rago, the second fork is more a recommendation, and it is done to guarantee that the daemon does not acquire a controlling terminal on System V-based systems. </p>
| 8 | 2009-05-19T07:33:54Z | [
"python",
"unix"
] |
What is the reason for performing a double fork when creating a daemon? | 881,388 | <p>I'm trying to create a daemon in python. I've found the <a href="http://stackoverflow.com/questions/473620/how-do-you-create-a-daemon-in-python">following question</a>, which has some good resources in it which I am currently following, but I'm curious as to why a double fork is necessary. I've scratched around goog... | 109 | 2009-05-19T07:25:18Z | 881,434 | <p>Looking at the code referenced in the question, the justification is:</p>
<pre><code># Fork a second child and exit immediately to prevent zombies. This
# causes the second child process to be orphaned, making the init
# process responsible for its cleanup. And, since the first child is
# a session leader without... | 75 | 2009-05-19T07:42:54Z | [
"python",
"unix"
] |
What is the reason for performing a double fork when creating a daemon? | 881,388 | <p>I'm trying to create a daemon in python. I've found the <a href="http://stackoverflow.com/questions/473620/how-do-you-create-a-daemon-in-python">following question</a>, which has some good resources in it which I am currently following, but I'm curious as to why a double fork is necessary. I've scratched around goog... | 109 | 2009-05-19T07:25:18Z | 881,435 | <p>One reason is that the parent process can immediately wait_pid() for the child, and then forget about it. When then grand-child dies, it's parent is init, and it will wait() for it - and taking it out of the zombie state. </p>
<p>The result is that the parent process doesn't need to be aware of the forked childre... | 3 | 2009-05-19T07:43:39Z | [
"python",
"unix"
] |
What is the reason for performing a double fork when creating a daemon? | 881,388 | <p>I'm trying to create a daemon in python. I've found the <a href="http://stackoverflow.com/questions/473620/how-do-you-create-a-daemon-in-python">following question</a>, which has some good resources in it which I am currently following, but I'm curious as to why a double fork is necessary. I've scratched around goog... | 109 | 2009-05-19T07:25:18Z | 881,470 | <p>A decent discussion of it appear to be at <a href="http://www.developerweb.net/forum/showthread.php?t=3025" rel="nofollow">http://www.developerweb.net/forum/showthread.php?t=3025</a></p>
<p>Quoting mlampkin from there:</p>
<blockquote>
<p>...think of the setsid( ) call as the "new" way to do thing (disassociate ... | 2 | 2009-05-19T07:56:23Z | [
"python",
"unix"
] |
What is the reason for performing a double fork when creating a daemon? | 881,388 | <p>I'm trying to create a daemon in python. I've found the <a href="http://stackoverflow.com/questions/473620/how-do-you-create-a-daemon-in-python">following question</a>, which has some good resources in it which I am currently following, but I'm curious as to why a double fork is necessary. I've scratched around goog... | 109 | 2009-05-19T07:25:18Z | 5,386,753 | <p>I was trying to understand the double fork and stumbled upon this question here. After a lot of research this is what I figured out. Hopefully it will help clarify things better for anyone who has the same question.</p>
<p>In Unix every process belongs to a group which in turn belongs to a session. Here is the hier... | 111 | 2011-03-22T04:19:44Z | [
"python",
"unix"
] |
What is the reason for performing a double fork when creating a daemon? | 881,388 | <p>I'm trying to create a daemon in python. I've found the <a href="http://stackoverflow.com/questions/473620/how-do-you-create-a-daemon-in-python">following question</a>, which has some good resources in it which I am currently following, but I'm curious as to why a double fork is necessary. I've scratched around goog... | 109 | 2009-05-19T07:25:18Z | 16,317,668 | <p>Strictly speaking, the double-fork has nothing to do with re-parenting the daemon as a child of <code>init</code>. All that is necessary to re-parent the child is that the parent must exit. This can be done with only a single fork. Also, doing a double-fork by itself doesn't re-parent the daemon process to <code>ini... | 65 | 2013-05-01T11:54:52Z | [
"python",
"unix"
] |
SQLAlchemy - Database hits on every request? | 881,517 | <p>I'm currently working with a web application written in Python (and using SQLAlchemy). In order to handle authentication, the app first checks for a user ID in the session, and providing it exists, pulls that whole user record out of the database and stores it for the rest of that request. Another query is also run ... | 0 | 2009-05-19T08:11:21Z | 881,535 | <p>It's a Database, so often it's fairly common to "hit" the Database to pull the required data. You can reduce single queries if you build up Joins or Stored Procedures.</p>
| 1 | 2009-05-19T08:17:02Z | [
"python",
"sqlalchemy"
] |
SQLAlchemy - Database hits on every request? | 881,517 | <p>I'm currently working with a web application written in Python (and using SQLAlchemy). In order to handle authentication, the app first checks for a user ID in the session, and providing it exists, pulls that whole user record out of the database and stores it for the rest of that request. Another query is also run ... | 0 | 2009-05-19T08:11:21Z | 882,021 | <p>"hitting the database for something like this on every request isn't efficient."</p>
<p>False. And, you've assumed that there's no caching, which is also false.</p>
<p>Most ORM layers are perfectly capable of caching rows, saving some DB queries.</p>
<p>Most RDBMS's have extensive caching, resulting in remarkabl... | 3 | 2009-05-19T10:44:05Z | [
"python",
"sqlalchemy"
] |
SQLAlchemy - Database hits on every request? | 881,517 | <p>I'm currently working with a web application written in Python (and using SQLAlchemy). In order to handle authentication, the app first checks for a user ID in the session, and providing it exists, pulls that whole user record out of the database and stores it for the rest of that request. Another query is also run ... | 0 | 2009-05-19T08:11:21Z | 882,171 | <p>You are basically talking about caching data as a performance optimization. As always, premature optimization is a bad idea. It's hard to know where the bottlenecks are beforehand, even more so if the application domain is new to you. Optimization adds complexity and if you optimize the wrong things, you not only ha... | 2 | 2009-05-19T11:25:43Z | [
"python",
"sqlalchemy"
] |
SQLAlchemy - Database hits on every request? | 881,517 | <p>I'm currently working with a web application written in Python (and using SQLAlchemy). In order to handle authentication, the app first checks for a user ID in the session, and providing it exists, pulls that whole user record out of the database and stores it for the rest of that request. Another query is also run ... | 0 | 2009-05-19T08:11:21Z | 890,202 | <p>For a user login and basic permission tokens in a <em>simple</em> web application I will definitely store that in a cookie-based session. It's true that a few SELECTs per request is not a big deal at all, but then again if you can get some/all of your web requests to execute from cached data with no DB hits at all... | 3 | 2009-05-20T20:53:57Z | [
"python",
"sqlalchemy"
] |
Auto-tab between fields on Django admin site | 881,536 | <p>I have an inline on a model with data with a fixed length, that has to be entered very fast, so I was thinking about a way of "tabbing" through fields automatically when the field is filled...</p>
<p>Could that be possible?</p>
| 0 | 2009-05-19T08:17:10Z | 881,692 | <p>Sure it's possible, but it will need some javascript. You'd want to bind an event to the keypress event on each field, and when it fires test the length of the text entered so far - if it matches, move the focus onto the next field.</p>
| 1 | 2009-05-19T09:04:29Z | [
"python",
"django",
"django-admin",
"field"
] |
Auto-tab between fields on Django admin site | 881,536 | <p>I have an inline on a model with data with a fixed length, that has to be entered very fast, so I was thinking about a way of "tabbing" through fields automatically when the field is filled...</p>
<p>Could that be possible?</p>
| 0 | 2009-05-19T08:17:10Z | 1,283,042 | <p>I can recommend the following links:</p>
<ul>
<li><a href="http://www.lousyllama.com/sandbox/jquery-autotab" rel="nofollow">JQuery AutoTab</a></li>
</ul>
| 1 | 2009-08-15T22:41:02Z | [
"python",
"django",
"django-admin",
"field"
] |
In print statements, what determines whether python shell prints null character or waits for input | 881,564 | <p>Recently I was trying some practice programs in python and I came across this small problem.</p>
<p>when I typed</p>
<pre><code>print ""
</code></pre>
<p>in IDLE, the python shell printed a null character.</p>
<p>If I typed </p>
<pre><code>print """"""
</code></pre>
<p>in IDLE, the python shell printed a null ... | 2 | 2009-05-19T08:24:55Z | 881,576 | <p>In python you can have strings enclosed with either 1 or 3 quotes.</p>
<pre><code>print "a"
print """a"""
</code></pre>
<p>In your case, the interpreter is waiting for the last triple quote.</p>
| 11 | 2009-05-19T08:26:58Z | [
"python"
] |
In print statements, what determines whether python shell prints null character or waits for input | 881,564 | <p>Recently I was trying some practice programs in python and I came across this small problem.</p>
<p>when I typed</p>
<pre><code>print ""
</code></pre>
<p>in IDLE, the python shell printed a null character.</p>
<p>If I typed </p>
<pre><code>print """"""
</code></pre>
<p>in IDLE, the python shell printed a null ... | 2 | 2009-05-19T08:24:55Z | 881,591 | <p>I suspect you mean that python printed an empty line -- this is not the same as a null character.</p>
<p>When you <code>print """"""</code>, python finds an empty, triple-quoted string.</p>
<p>When you <code>print """"</code>, python finds the start of a triple-quoted string, and waits for you to input the rest (e... | 4 | 2009-05-19T08:30:52Z | [
"python"
] |
Python imports: importing a module without .py extension? | 881,639 | <p>In a Python system for which I develop, we usually have this module structure.</p>
<pre><code>mymodule/
mymodule/mymodule/feature.py
mymodule/test/feature.py
</code></pre>
<p>This allows our little testing framework to easily import test/feature.py and run unit tests. However, we now have the need for some shell s... | 3 | 2009-05-19T08:50:15Z | 881,647 | <p>Check out imp module:</p>
<p><a href="http://docs.python.org/library/imp.html" rel="nofollow">http://docs.python.org/library/imp.html</a></p>
<p>This will allow you to load a module by filename. But I think your symbolic link is a more elegant solution.</p>
| 1 | 2009-05-19T08:53:46Z | [
"python",
"debian"
] |
Python imports: importing a module without .py extension? | 881,639 | <p>In a Python system for which I develop, we usually have this module structure.</p>
<pre><code>mymodule/
mymodule/mymodule/feature.py
mymodule/test/feature.py
</code></pre>
<p>This allows our little testing framework to easily import test/feature.py and run unit tests. However, we now have the need for some shell s... | 3 | 2009-05-19T08:50:15Z | 881,658 | <p>The <a href="http://docs.python.org/library/imp.html">imp module</a> is used for this: </p>
<pre><code>daniel@purplehaze:/tmp/test$ cat mymodule
print "woho!"
daniel@purplehaze:/tmp/test$ cat test.py
import imp
imp.load_source("apanapansson", "mymodule")
daniel@purplehaze:/tmp/test$ python test.py
woho!
daniel@pur... | 8 | 2009-05-19T08:55:32Z | [
"python",
"debian"
] |
Python imports: importing a module without .py extension? | 881,639 | <p>In a Python system for which I develop, we usually have this module structure.</p>
<pre><code>mymodule/
mymodule/mymodule/feature.py
mymodule/test/feature.py
</code></pre>
<p>This allows our little testing framework to easily import test/feature.py and run unit tests. However, we now have the need for some shell s... | 3 | 2009-05-19T08:50:15Z | 881,669 | <p>You could most likely use some tricker by using import <a href="http://www.python.org/dev/peps/pep-0302/" rel="nofollow">hooks</a>, I wouldn't recommend it though. On the other hand I would also probably do it the other way around , have your .py scripts somewhere, and make '.py'less symbolic links to the .py files.... | 1 | 2009-05-19T08:59:37Z | [
"python",
"debian"
] |
Python imports: importing a module without .py extension? | 881,639 | <p>In a Python system for which I develop, we usually have this module structure.</p>
<pre><code>mymodule/
mymodule/mymodule/feature.py
mymodule/test/feature.py
</code></pre>
<p>This allows our little testing framework to easily import test/feature.py and run unit tests. However, we now have the need for some shell s... | 3 | 2009-05-19T08:50:15Z | 24,603,569 | <p>Another option would be to use setuptools:</p>
<blockquote>
<p>"...thereâs no easy way to have a scriptâs filename match local conventions on both Windows and POSIX platforms. For another, you often have to create a separate file just for the âmainâ script, when your actual âmainâ is a function in a m... | 0 | 2014-07-07T05:30:10Z | [
"python",
"debian"
] |
How to tell if a class is descended from another class | 881,676 | <p>I have a function that accepts a class (not an instance) and, depending on whether or not it's a specific class <em>or a subclass of that</em>, I need to pass it in to one of two other (third-party) factory functions.</p>
<p>(To forestall any objections, I'm aware this is not very Pythonic, but I'm dependent on wha... | 11 | 2009-05-19T09:00:23Z | 881,689 | <blockquote>
<p>issubclass only works for instances, not class objects themselves.</p>
</blockquote>
<p>It works fine for me:</p>
<pre><code>>>> class test(object):pass
...
>>> issubclass(test,object)
True
</code></pre>
| 27 | 2009-05-19T09:03:33Z | [
"python"
] |
How to use dynamic foreignkey in Django? | 881,792 | <p>I want to connect a single <code>ForeignKey</code> to two different models.</p>
<p>For example:</p>
<p>I have two models named <code>Casts</code> and <code>Articles</code>, and a third model, <code>Faves</code>, for favoriting either of the other models. How can I make the <code>ForeignKey</code> dynamic?</p>
<pr... | 22 | 2009-05-19T09:27:30Z | 881,874 | <p>Here is how I do it:</p>
<pre><code>from django.contrib.contenttypes.models import ContentType
from django.contrib.contenttypes import fields
class Photo(models.Model):
picture = models.ImageField(null=True, upload_to='./images/')
caption = models.CharField(_("Optional caption"),max_length=100,null=True, ... | 33 | 2009-05-19T09:59:09Z | [
"python",
"django",
"foreign-keys"
] |
How to use dynamic foreignkey in Django? | 881,792 | <p>I want to connect a single <code>ForeignKey</code> to two different models.</p>
<p>For example:</p>
<p>I have two models named <code>Casts</code> and <code>Articles</code>, and a third model, <code>Faves</code>, for favoriting either of the other models. How can I make the <code>ForeignKey</code> dynamic?</p>
<pr... | 22 | 2009-05-19T09:27:30Z | 881,912 | <p>Here's an approach. (Note that the models are singular, Django automatically pluralizes for you.)</p>
<pre><code>class Article(models.Model):
title = models.CharField(max_length=100)
body = models.TextField()
class Cast(models.Model):
title = models.CharField(max_length=100)
body = models.TextFiel... | 12 | 2009-05-19T10:11:44Z | [
"python",
"django",
"foreign-keys"
] |
Rendering JSON objects using a Django template after an Ajax call | 882,215 | <p>I've been trying to understand what's the optimal way to do <a href="http://en.wikipedia.org/wiki/Ajax%5F%28programming%29">Ajax</a> in <a href="http://en.wikipedia.org/wiki/Django%5F%28web%5Fframework%29">Django</a>. By reading stuff here and there I gathered that the common process is: </p>
<ol>
<li><p>formulate ... | 58 | 2009-05-19T11:36:21Z | 882,245 | <p>When you are doing Ajax I don't think you have any use for templates.
Template is there so that you can generate dynamic HTML on the server side easily and hence it provides few programming hooks inside HTML.</p>
<p>In case of Ajax you are passing JSON data and you can format it as you want in Python.
and HTML/docu... | 6 | 2009-05-19T11:43:22Z | [
"python",
"ajax",
"django",
"json",
"templates"
] |
Rendering JSON objects using a Django template after an Ajax call | 882,215 | <p>I've been trying to understand what's the optimal way to do <a href="http://en.wikipedia.org/wiki/Ajax%5F%28programming%29">Ajax</a> in <a href="http://en.wikipedia.org/wiki/Django%5F%28web%5Fframework%29">Django</a>. By reading stuff here and there I gathered that the common process is: </p>
<ol>
<li><p>formulate ... | 58 | 2009-05-19T11:36:21Z | 882,254 | <p>Templates are for the purpose of <em>presentation</em>. Responding with data in format X (JSON, <a href="http://en.wikipedia.org/wiki/JSON#JSONP" rel="nofollow">JSONP</a>, XML, <a href="http://en.wikipedia.org/wiki/YAML" rel="nofollow">YAML</a>, *ml, etc.) is not presentation, so you don't need templates. Just seria... | 3 | 2009-05-19T11:47:12Z | [
"python",
"ajax",
"django",
"json",
"templates"
] |
Rendering JSON objects using a Django template after an Ajax call | 882,215 | <p>I've been trying to understand what's the optimal way to do <a href="http://en.wikipedia.org/wiki/Ajax%5F%28programming%29">Ajax</a> in <a href="http://en.wikipedia.org/wiki/Django%5F%28web%5Fframework%29">Django</a>. By reading stuff here and there I gathered that the common process is: </p>
<ol>
<li><p>formulate ... | 58 | 2009-05-19T11:36:21Z | 882,648 | <p>There's no reason you can't return a rendered bit of HTML using Ajax, and insert that into the existing page at the point you want. Obviously you can use Django's templates to render this HTML, if you want.</p>
| 8 | 2009-05-19T13:06:40Z | [
"python",
"ajax",
"django",
"json",
"templates"
] |
Rendering JSON objects using a Django template after an Ajax call | 882,215 | <p>I've been trying to understand what's the optimal way to do <a href="http://en.wikipedia.org/wiki/Ajax%5F%28programming%29">Ajax</a> in <a href="http://en.wikipedia.org/wiki/Django%5F%28web%5Fframework%29">Django</a>. By reading stuff here and there I gathered that the common process is: </p>
<ol>
<li><p>formulate ... | 58 | 2009-05-19T11:36:21Z | 883,743 | <p>Here is how I use the same template for traditional rendering and Ajax-response rendering.</p>
<p>Template:</p>
<pre><code><div id="sortable">
{% include "admin/app/model/subtemplate.html" %}
</div>
</code></pre>
<p>Included template (aka: subtemplate):</p>
<pre><code><div id="results_listing"&g... | 13 | 2009-05-19T16:19:13Z | [
"python",
"ajax",
"django",
"json",
"templates"
] |
Rendering JSON objects using a Django template after an Ajax call | 882,215 | <p>I've been trying to understand what's the optimal way to do <a href="http://en.wikipedia.org/wiki/Ajax%5F%28programming%29">Ajax</a> in <a href="http://en.wikipedia.org/wiki/Django%5F%28web%5Fframework%29">Django</a>. By reading stuff here and there I gathered that the common process is: </p>
<ol>
<li><p>formulate ... | 58 | 2009-05-19T11:36:21Z | 884,339 | <p>Hey thanks vikingosegundo! </p>
<p>I like using decorators too :-).
But in the meanwhile I've been following the approach suggested by the snippet I was mentioning above. Only thing, use instead <a href="http://www.djangosnippets.org/snippets/942/">the snippet n. 942</a> cause it's an improved version of the origin... | 24 | 2009-05-19T18:29:24Z | [
"python",
"ajax",
"django",
"json",
"templates"
] |
Rendering JSON objects using a Django template after an Ajax call | 882,215 | <p>I've been trying to understand what's the optimal way to do <a href="http://en.wikipedia.org/wiki/Ajax%5F%28programming%29">Ajax</a> in <a href="http://en.wikipedia.org/wiki/Django%5F%28web%5Fframework%29">Django</a>. By reading stuff here and there I gathered that the common process is: </p>
<ol>
<li><p>formulate ... | 58 | 2009-05-19T11:36:21Z | 3,067,558 | <p>Unfortunately, Django templates are designed to be executed server side only. There is <a href="http://ajaxian.com/archives/django-template-language-in-javascript" rel="nofollow">at least one project to render</a> Django templates using Javascript, but I haven't used it and so I don't know how fast, well supported o... | 0 | 2010-06-18T06:15:13Z | [
"python",
"ajax",
"django",
"json",
"templates"
] |
Rendering JSON objects using a Django template after an Ajax call | 882,215 | <p>I've been trying to understand what's the optimal way to do <a href="http://en.wikipedia.org/wiki/Ajax%5F%28programming%29">Ajax</a> in <a href="http://en.wikipedia.org/wiki/Django%5F%28web%5Fframework%29">Django</a>. By reading stuff here and there I gathered that the common process is: </p>
<ol>
<li><p>formulate ... | 58 | 2009-05-19T11:36:21Z | 3,674,621 | <p>While templates are indeed just for presentation purposes, it shouldn't matter if you are doing it on the serverside or client side. It all comes down to separating the control logic that is performing an action, from the view logic that is just responsible for creating the markup. If your javascript control logic i... | 3 | 2010-09-09T07:36:48Z | [
"python",
"ajax",
"django",
"json",
"templates"
] |
Rendering JSON objects using a Django template after an Ajax call | 882,215 | <p>I've been trying to understand what's the optimal way to do <a href="http://en.wikipedia.org/wiki/Ajax%5F%28programming%29">Ajax</a> in <a href="http://en.wikipedia.org/wiki/Django%5F%28web%5Fframework%29">Django</a>. By reading stuff here and there I gathered that the common process is: </p>
<ol>
<li><p>formulate ... | 58 | 2009-05-19T11:36:21Z | 5,176,014 | <p>you can use jquery.load() or similar to good effect, generating the html on the server and loading it into the dom with js. I think someone has called this AJAH.</p>
| 1 | 2011-03-03T02:30:34Z | [
"python",
"ajax",
"django",
"json",
"templates"
] |
How to hide "cgi-bin", ".py", etc from my URLs? | 882,430 | <p>Brand new to web design, using python. Got Apache up and running, test python script working in cgi-bin directory. Get valid results when I type in the URL explicitly: ".../cgi-bin/showenv.py"</p>
<p>But I don't want the URL to look that way. Here at stackoverflow, for example, the URLs that display in my addre... | 11 | 2009-05-19T12:24:38Z | 882,439 | <p>I think you can do this by rewriting URL through Apache configuration. You can see the Apache documentation for rewriting <a href="http://httpd.apache.org/docs/2.0/misc/rewriteguide.html">here</a>.</p>
| 5 | 2009-05-19T12:27:48Z | [
"python",
"cgi"
] |
How to hide "cgi-bin", ".py", etc from my URLs? | 882,430 | <p>Brand new to web design, using python. Got Apache up and running, test python script working in cgi-bin directory. Get valid results when I type in the URL explicitly: ".../cgi-bin/showenv.py"</p>
<p>But I don't want the URL to look that way. Here at stackoverflow, for example, the URLs that display in my addre... | 11 | 2009-05-19T12:24:38Z | 882,442 | <p>You have to use URL Rewriting.</p>
<p>It is not a noob question, it can be quite tricky :)</p>
<p><a href="http://httpd.apache.org/docs/2.0/misc/rewriteguide.html" rel="nofollow">http://httpd.apache.org/docs/2.0/misc/rewriteguide.html</a></p>
<p>Hope you find it helpful</p>
| 4 | 2009-05-19T12:28:22Z | [
"python",
"cgi"
] |
How to hide "cgi-bin", ".py", etc from my URLs? | 882,430 | <p>Brand new to web design, using python. Got Apache up and running, test python script working in cgi-bin directory. Get valid results when I type in the URL explicitly: ".../cgi-bin/showenv.py"</p>
<p>But I don't want the URL to look that way. Here at stackoverflow, for example, the URLs that display in my addre... | 11 | 2009-05-19T12:24:38Z | 882,444 | <p>Just use some good web framework e.g. django and you can have such URLs
more than URLs you will have a better infrastructure, templates, db orm etc</p>
| 4 | 2009-05-19T12:28:23Z | [
"python",
"cgi"
] |
How to hide "cgi-bin", ".py", etc from my URLs? | 882,430 | <p>Brand new to web design, using python. Got Apache up and running, test python script working in cgi-bin directory. Get valid results when I type in the URL explicitly: ".../cgi-bin/showenv.py"</p>
<p>But I don't want the URL to look that way. Here at stackoverflow, for example, the URLs that display in my addre... | 11 | 2009-05-19T12:24:38Z | 882,510 | <p>this is an excerpt from a .htaccess that I use to achieve such a thing, this for example redirects all requests that were not to index.php to that file, of course you then have to check the server-variables within the file you redirect to to see, what was requested.</p>
<p>Or you simply make a rewrite rule, where y... | 3 | 2009-05-19T12:39:56Z | [
"python",
"cgi"
] |
How to hide "cgi-bin", ".py", etc from my URLs? | 882,430 | <p>Brand new to web design, using python. Got Apache up and running, test python script working in cgi-bin directory. Get valid results when I type in the URL explicitly: ".../cgi-bin/showenv.py"</p>
<p>But I don't want the URL to look that way. Here at stackoverflow, for example, the URLs that display in my addre... | 11 | 2009-05-19T12:24:38Z | 882,664 | <p>The python way of writing web applications is not cgi-bin. It is by using <a href="http://wsgi.org">WSGI</a>.</p>
<p>WSGI is a standard interface between web servers and Python web applications or frameworks. The <a href="http://www.python.org/dev/peps/pep-0333/">PEP 0333</a> defines it.</p>
<p>There are no disadv... | 12 | 2009-05-19T13:09:58Z | [
"python",
"cgi"
] |
How to hide "cgi-bin", ".py", etc from my URLs? | 882,430 | <p>Brand new to web design, using python. Got Apache up and running, test python script working in cgi-bin directory. Get valid results when I type in the URL explicitly: ".../cgi-bin/showenv.py"</p>
<p>But I don't want the URL to look that way. Here at stackoverflow, for example, the URLs that display in my addre... | 11 | 2009-05-19T12:24:38Z | 882,671 | <p>You'll find the <code>ScriptAlias</code> directive helpful. Using</p>
<pre><code>ScriptAlias /urlpath /your/cgi-bin/script.py
</code></pre>
<p>you can access your script via <code>http://yourserver/urlpath</code>.</p>
<p>You also might want to look into <a href="http://modrails.com" rel="nofollow"><code>mod_passe... | 3 | 2009-05-19T13:11:46Z | [
"python",
"cgi"
] |
Sending HTML email using Python | 882,712 | <p>How can I send the HTML content in an email using Python? I can send simple text.</p>
| 148 | 2009-05-19T13:20:18Z | 882,770 | <p>From <a href="http://docs.python.org/library/email-examples.html#id4">Python v2.6.2 documentation - 19.1.11. email: Examples</a>:</p>
<blockquote>
<p>Hereâs an example of how to create an HTML message with an alternative plain text version:</p>
</blockquote>
<pre class="lang-python prettyprint-override"><code>... | 225 | 2009-05-19T13:30:55Z | [
"python",
"html-email"
] |
Sending HTML email using Python | 882,712 | <p>How can I send the HTML content in an email using Python? I can send simple text.</p>
| 148 | 2009-05-19T13:20:18Z | 882,804 | <p>Here's sample code. This is inspired from code found on the <a href="http://code.activestate.com/recipes/langs/python/">Python Cookbook</a> site (can't find the exact link)</p>
<pre><code>def createhtmlmail (html, text, subject, fromEmail):
"""Create a mime-message that will render HTML in popular
MUAs, tex... | 7 | 2009-05-19T13:37:02Z | [
"python",
"html-email"
] |
Sending HTML email using Python | 882,712 | <p>How can I send the HTML content in an email using Python? I can send simple text.</p>
| 148 | 2009-05-19T13:20:18Z | 883,269 | <p>You might try using my <a href="http://pypi.python.org/pypi/mailer/">mailer</a> module.</p>
<pre class="lang-python prettyprint-override"><code>from mailer import Mailer
from mailer import Message
message = Message(From="me@example.com",
To="you@example.com")
message.Subject = "An HTML Email"
mes... | 46 | 2009-05-19T14:55:23Z | [
"python",
"html-email"
] |
Sending HTML email using Python | 882,712 | <p>How can I send the HTML content in an email using Python? I can send simple text.</p>
| 148 | 2009-05-19T13:20:18Z | 1,901,298 | <p>Just a big fat warning. If you are sending non-<a href="http://en.wikipedia.org/wiki/ASCII" rel="nofollow">ASCII</a> email using Python < 3.0, consider using the email in <a href="http://en.wikipedia.org/wiki/Django_%28web_framework%29" rel="nofollow">Django</a>. It wraps <a href="http://en.wikipedia.org/wiki/UTF... | 5 | 2009-12-14T14:42:05Z | [
"python",
"html-email"
] |
Sending HTML email using Python | 882,712 | <p>How can I send the HTML content in an email using Python? I can send simple text.</p>
| 148 | 2009-05-19T13:20:18Z | 26,369,282 | <p>Here is a <a href="http://en.wikipedia.org/wiki/Gmail">Gmail</a> implementation of the accepted answer:</p>
<pre><code>import smtplib
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
# me == my email address
# you == recipient's email address
me = "my@email.com"
you = "your@emai... | 21 | 2014-10-14T19:59:15Z | [
"python",
"html-email"
] |
Sending HTML email using Python | 882,712 | <p>How can I send the HTML content in an email using Python? I can send simple text.</p>
| 148 | 2009-05-19T13:20:18Z | 32,129,736 | <p>Here is a simple way to send an HTML email, just by specifying the Content-Type header as 'text/html':</p>
<pre><code>import email.message
import smtplib
msg = email.message.Message()
msg['Subject'] = 'foo'
msg['From'] = 'sender@test.com'
msg['To'] = 'recipient@test.com'
msg.add_header('Content-Type','text/html')
... | 16 | 2015-08-20T22:52:22Z | [
"python",
"html-email"
] |
Sending HTML email using Python | 882,712 | <p>How can I send the HTML content in an email using Python? I can send simple text.</p>
| 148 | 2009-05-19T13:20:18Z | 36,682,833 | <p>Actually, <a href="https://github.com/kootenpv/yagmail" rel="nofollow">yagmail</a> took a bit different approach. </p>
<p>It will <strong>by default</strong> send HTML, with automatic fallback for incapable email-readers. It is not the 17th century anymore.</p>
<p>Of course, it can be overridden, but here goes:</p... | 0 | 2016-04-17T22:18:14Z | [
"python",
"html-email"
] |
Sending HTML email using Python | 882,712 | <p>How can I send the HTML content in an email using Python? I can send simple text.</p>
| 148 | 2009-05-19T13:20:18Z | 39,517,007 | <p>Here is my answer for AWS using boto3</p>
<pre><code> subject = "Hello"
html = "<b>Hello Consumer</b>"
client = boto3.client('ses', region_name='us-east-1', aws_access_key_id="your_key",
aws_secret_access_key="your_secret")
client.send_email(
Source='ACME <do-no... | 0 | 2016-09-15T17:27:25Z | [
"python",
"html-email"
] |
Is there a way to poll a file handle returned from subprocess.Popen? | 883,152 | <p>Say I write this:</p>
<pre><code>from subprocessing import Popen, STDOUT, PIPE
p = Popen(["myproc"], stderr=STDOUT, stdout=PIPE)
</code></pre>
<p>Now if I do</p>
<pre><code>line = p.stdout.readline()
</code></pre>
<p>my program waits until the subprocess outputs the next line. </p>
<p>Is there any magic I can d... | 4 | 2009-05-19T14:33:15Z | 883,166 | <p>Use <code>p.stdout.read(1)</code> this will read character by character</p>
<p>And here is a full example:</p>
<pre><code>import subprocess
import sys
process = subprocess.Popen(
cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE
)
while True:
out = process.stdout.read(1)
if out == '' and process.po... | 9 | 2009-05-19T14:36:21Z | [
"python",
"pipe",
"subprocess"
] |
Is there a way to poll a file handle returned from subprocess.Popen? | 883,152 | <p>Say I write this:</p>
<pre><code>from subprocessing import Popen, STDOUT, PIPE
p = Popen(["myproc"], stderr=STDOUT, stdout=PIPE)
</code></pre>
<p>Now if I do</p>
<pre><code>line = p.stdout.readline()
</code></pre>
<p>my program waits until the subprocess outputs the next line. </p>
<p>Is there any magic I can d... | 4 | 2009-05-19T14:33:15Z | 883,204 | <p>Use the <code>select</code> module in Python's standard library, see <a href="http://docs.python.org/library/select.html">http://docs.python.org/library/select.html</a> . <code>select.select([p.stdout.fileno()], [], [], 0)</code> immediately returns a tuple whose items are three lists: the first one is going to be ... | 6 | 2009-05-19T14:42:41Z | [
"python",
"pipe",
"subprocess"
] |
Calling python from python - persistence of module imports? | 883,211 | <p>So I have some Python scripts, and I've got a BaseHTTPServer to serve up their responses. If the requested file is a .py then I'll run that script using execfile(script.py).</p>
<p>The question is this: are there any special rules about imports? One script needs to run just once, and it would be good to keep the ob... | 2 | 2009-05-19T14:43:39Z | 883,471 | <p>The documentation for the execfile method is <a href="http://docs.python.org/library/functions.html" rel="nofollow">here</a>. Since no particular version of python was specified, I'm going to assume we're talking about 2.6.2.</p>
<p>The documentation for execfile specifies it takes three arguments: the filename, a ... | 2 | 2009-05-19T15:30:16Z | [
"python",
"import",
"module"
] |
Calling python from python - persistence of module imports? | 883,211 | <p>So I have some Python scripts, and I've got a BaseHTTPServer to serve up their responses. If the requested file is a .py then I'll run that script using execfile(script.py).</p>
<p>The question is this: are there any special rules about imports? One script needs to run just once, and it would be good to keep the ob... | 2 | 2009-05-19T14:43:39Z | 883,478 | <p>I recommend not using <code>execfile</code>. Instead, you can dynamically import the python file they request as a module using the builtin <code>__import__</code> function. Here's a complete, working example that I just wrote and tested:</p>
<pre><code>from BaseHTTPServer import BaseHTTPRequestHandler, HTTPServe... | 1 | 2009-05-19T15:31:04Z | [
"python",
"import",
"module"
] |
django excel xlwt | 883,313 | <p>On a django site, I want to generate an excel file based on some data in the database.</p>
<p>I'm thinking of using <a href="http://pypi.python.org/pypi/xlwt">xlwt</a>, but it only has a method to save the data to a file. How can get the file to the HttpResponse object? Or maybe do you know a better library?</p>
<... | 30 | 2009-05-19T15:04:14Z | 883,351 | <p>neat package! i didn't know about this</p>
<p>According to the doc, the <code>save(filename_or_stream)</code> method takes either a filename to save on, or a file-like stream to write on.</p>
<p>And a Django response object happens to be a file-like stream! so just do <code>xls.save(response)</code>. Look the Dj... | 50 | 2009-05-19T15:09:44Z | [
"python",
"django",
"excel",
"xlwt"
] |
django excel xlwt | 883,313 | <p>On a django site, I want to generate an excel file based on some data in the database.</p>
<p>I'm thinking of using <a href="http://pypi.python.org/pypi/xlwt">xlwt</a>, but it only has a method to save the data to a file. How can get the file to the HttpResponse object? Or maybe do you know a better library?</p>
<... | 30 | 2009-05-19T15:04:14Z | 883,379 | <p>If your data result doesn't need formulas or exact presentation styles, you can always use CSV. any spreadsheet program would directly read it. I've even seen some webapps that generate CSV but name it as .XSL just to be sure that Excel opens it</p>
| 0 | 2009-05-19T15:15:40Z | [
"python",
"django",
"excel",
"xlwt"
] |
django excel xlwt | 883,313 | <p>On a django site, I want to generate an excel file based on some data in the database.</p>
<p>I'm thinking of using <a href="http://pypi.python.org/pypi/xlwt">xlwt</a>, but it only has a method to save the data to a file. How can get the file to the HttpResponse object? Or maybe do you know a better library?</p>
<... | 30 | 2009-05-19T15:04:14Z | 884,543 | <p>You can save your XLS file to a <a href="http://docs.python.org/library/stringio.html" rel="nofollow">StringIO</a> object, which is file-like.</p>
<p>You can return the StringIO object's <code>getvalue()</code> in the response. Be sure to add headers to mark it as a downloadable spreadsheet.</p>
| 2 | 2009-05-19T19:17:54Z | [
"python",
"django",
"excel",
"xlwt"
] |
django excel xlwt | 883,313 | <p>On a django site, I want to generate an excel file based on some data in the database.</p>
<p>I'm thinking of using <a href="http://pypi.python.org/pypi/xlwt">xlwt</a>, but it only has a method to save the data to a file. How can get the file to the HttpResponse object? Or maybe do you know a better library?</p>
<... | 30 | 2009-05-19T15:04:14Z | 1,362,637 | <p>You might want to check <a href="https://cybernetics.hudora.biz/projects/wiki/huDjango" rel="nofollow">huDjango</a> which comes fith a function called <code>serializers.queryset_to_xls()</code> do convert a queryset into an downloadable Excel Sheet.</p>
| 2 | 2009-09-01T13:56:18Z | [
"python",
"django",
"excel",
"xlwt"
] |
django excel xlwt | 883,313 | <p>On a django site, I want to generate an excel file based on some data in the database.</p>
<p>I'm thinking of using <a href="http://pypi.python.org/pypi/xlwt">xlwt</a>, but it only has a method to save the data to a file. How can get the file to the HttpResponse object? Or maybe do you know a better library?</p>
<... | 30 | 2009-05-19T15:04:14Z | 2,152,627 | <p>***UPDATE: django-excel-templates no longer being maintained, instead try Marmir <a href="http://brianray.github.com/mm/" rel="nofollow">http://brianray.github.com/mm/</a></p>
<p>Still in development as I type this but <a href="http://code.google.com/p/django-excel-templates/" rel="nofollow">http://code.google.com/... | 6 | 2010-01-28T06:05:15Z | [
"python",
"django",
"excel",
"xlwt"
] |
django excel xlwt | 883,313 | <p>On a django site, I want to generate an excel file based on some data in the database.</p>
<p>I'm thinking of using <a href="http://pypi.python.org/pypi/xlwt">xlwt</a>, but it only has a method to save the data to a file. How can get the file to the HttpResponse object? Or maybe do you know a better library?</p>
<... | 30 | 2009-05-19T15:04:14Z | 7,675,018 | <p>Use <a href="https://bitbucket.org/kmike/django-excel-response" rel="nofollow">https://bitbucket.org/kmike/django-excel-response</a></p>
| 1 | 2011-10-06T13:36:50Z | [
"python",
"django",
"excel",
"xlwt"
] |
wxPython + multiprocessing: Checking if a color string is legitimate | 883,348 | <p>I have a wxPython program with two processes: A primary and a secondary one (I'm using the multiprocessing module.) The primary one runs the wxPython GUI, the secondary one does not. However, there is something I would like to do from the secondary process: Given a string that describes a color, to check whether thi... | 0 | 2009-05-19T15:09:05Z | 883,451 | <p>You could make two Queues between the two processes and have the second one delegate wx-related functionality to the first one (by pushing on the first queue the parameters of the task to perform, and waiting for the result on the second one).</p>
| 1 | 2009-05-19T15:26:43Z | [
"python",
"wxpython",
"multiprocessing"
] |
Python unittest: how do I test the argument in an Exceptions? | 883,357 | <p>I am testing for Exceptions using unittest, for example:</p>
<pre><code>self.assertRaises(UnrecognizedAirportError, func, arg1, arg2)
</code></pre>
<p>and my code raises:</p>
<pre><code>raise UnrecognizedAirportError('From')
</code></pre>
<p>Which works well.</p>
<p>How do I test that the argument in the except... | 5 | 2009-05-19T15:10:36Z | 883,401 | <p>Like this.</p>
<pre><code>>>> try:
... raise UnrecognizedAirportError("func","arg1","arg2")
... except UnrecognizedAirportError, e:
... print e.args
...
('func', 'arg1', 'arg2')
>>>
</code></pre>
<p>Your arguments are in <code>args</code>, if you simply subclass <code>Exception</code>. </... | 11 | 2009-05-19T15:19:27Z | [
"python",
"unit-testing"
] |
Python unittest: how do I test the argument in an Exceptions? | 883,357 | <p>I am testing for Exceptions using unittest, for example:</p>
<pre><code>self.assertRaises(UnrecognizedAirportError, func, arg1, arg2)
</code></pre>
<p>and my code raises:</p>
<pre><code>raise UnrecognizedAirportError('From')
</code></pre>
<p>Which works well.</p>
<p>How do I test that the argument in the except... | 5 | 2009-05-19T15:10:36Z | 883,433 | <p><code>assertRaises</code> is a bit simplistic, and doesn't let you test the details of the raised exception beyond it belonging to a specified class. For finer-grained testing of exceptions, you need to "roll your own" with a <code>try/except/else</code> block (you can do it once and for all in a <code>def assertDet... | 1 | 2009-05-19T15:23:55Z | [
"python",
"unit-testing"
] |
Python Multiprocessing atexit Error "Error in atexit._run_exitfuncs" | 883,370 | <p>I am trying to run a simple multiple processes application in Python. The main thread spawns 1 to N processes and waits until they all done processing. The processes each run an infinite loop, so they can potentially run forever without some user interruption, so I put in some code to handle a KeyboardInterrupt:</p>... | 7 | 2009-05-19T15:13:33Z | 883,500 | <p>Rather then just forcing <code>sys.exit()</code>, you want to send a signal to your threads to tell them to stop. Look into using <a href="http://docs.python.org/library/signal.html" rel="nofollow">signal handlers</a> and threads in Python.</p>
<p>You could potentially do this by changing your <code>while True:</c... | 2 | 2009-05-19T15:36:09Z | [
"python",
"process",
"interrupt",
"atexit"
] |
Regex for finding date in Apache access log | 883,520 | <p>I'm writing a python script to extract data out of our 2GB Apache access log. Here's one line from the log.</p>
<pre><code>81.52.143.15 - - [01/Apr/2008:00:07:20 -0600] "GET /robots.txt HTTP/1.1" 200 29 "-" "Mozilla/5.0 (Windows; U; Windows NT 5.1; fr; rv:1.8.1) VoilaBot BETA 1.2 (http://www.voila.com/)"
</code></... | 1 | 2009-05-19T15:39:41Z | 883,552 | <p><code>match()</code> tries to match the entire string. Try <a href="http://docs.python.org/library/re.html#re.search" rel="nofollow"><code>search()</code></a> instead.</p>
<p>See also the <a href="http://docs.python.org/howto/regex.html" rel="nofollow">Python Regular Expression HOWTO</a>, and the <a href="http://ww... | 0 | 2009-05-19T15:45:19Z | [
"python",
"regex"
] |
Regex for finding date in Apache access log | 883,520 | <p>I'm writing a python script to extract data out of our 2GB Apache access log. Here's one line from the log.</p>
<pre><code>81.52.143.15 - - [01/Apr/2008:00:07:20 -0600] "GET /robots.txt HTTP/1.1" 200 29 "-" "Mozilla/5.0 (Windows; U; Windows NT 5.1; fr; rv:1.8.1) VoilaBot BETA 1.2 (http://www.voila.com/)"
</code></... | 1 | 2009-05-19T15:39:41Z | 883,553 | <p>match() looks for a match at the beginning of the string. Use search() to look for a match anywhere in the string. More info here: <a href="http://docs.python.org/library/re.html#matching-vs-searching" rel="nofollow">http://docs.python.org/library/re.html#matching-vs-searching</a></p>
| 5 | 2009-05-19T15:46:07Z | [
"python",
"regex"
] |
Regex for finding date in Apache access log | 883,520 | <p>I'm writing a python script to extract data out of our 2GB Apache access log. Here's one line from the log.</p>
<pre><code>81.52.143.15 - - [01/Apr/2008:00:07:20 -0600] "GET /robots.txt HTTP/1.1" 200 29 "-" "Mozilla/5.0 (Windows; U; Windows NT 5.1; fr; rv:1.8.1) VoilaBot BETA 1.2 (http://www.voila.com/)"
</code></... | 1 | 2009-05-19T15:39:41Z | 885,019 | <p>Rather than using regular expressions to get the date, it might be easier to just split the line on spaces and extract the date:</p>
<pre><code> l = '81.52.143.15 - - [01/Apr/2008:00:07:20 -0600] "GET /robots.txt HTTP/1.1" 200 29 "-" Mozilla/5.0 (Windows; U; Windows NT 5.1; fr; rv:1.8.1) VoilaBot BETA 1.2 (http://w... | 0 | 2009-05-19T21:04:31Z | [
"python",
"regex"
] |
Regex for finding date in Apache access log | 883,520 | <p>I'm writing a python script to extract data out of our 2GB Apache access log. Here's one line from the log.</p>
<pre><code>81.52.143.15 - - [01/Apr/2008:00:07:20 -0600] "GET /robots.txt HTTP/1.1" 200 29 "-" "Mozilla/5.0 (Windows; U; Windows NT 5.1; fr; rv:1.8.1) VoilaBot BETA 1.2 (http://www.voila.com/)"
</code></... | 1 | 2009-05-19T15:39:41Z | 3,969,728 | <p>Or you can use one of already available python apache log parsers like :</p>
<ul>
<li>Apachelogs</li>
<li>Logtools</li>
<li>Logrep (Wtop package)</li>
</ul>
| 1 | 2010-10-19T14:59:11Z | [
"python",
"regex"
] |
Custom ordering in Django | 883,575 | <p>How do you define a specific ordering in Django <code>QuerySet</code>s?</p>
<p>Specifically, if I have a <code>QuerySet</code> like so: <code>['a10', 'a1', 'a2']</code>.</p>
<p>Regular order (using <code>Whatever.objects.order_by('someField')</code>) will give me <code>['a1', 'a10', 'a2']</code>, while I am lookin... | 20 | 2009-05-19T15:49:31Z | 883,641 | <p>As far as I'm aware, there's no way to specify database-side ordering in this way as it would be too backend-specific. You may wish to resort to good old-fashioned Python sorting:</p>
<pre><code>class Foo(models.Model):
name = models.CharField(max_length=128)
Foo.objects.create(name='a10')
Foo.objects.create(n... | 37 | 2009-05-19T16:03:55Z | [
"python",
"django",
"django-models"
] |
Custom ordering in Django | 883,575 | <p>How do you define a specific ordering in Django <code>QuerySet</code>s?</p>
<p>Specifically, if I have a <code>QuerySet</code> like so: <code>['a10', 'a1', 'a2']</code>.</p>
<p>Regular order (using <code>Whatever.objects.order_by('someField')</code>) will give me <code>['a1', 'a10', 'a2']</code>, while I am lookin... | 20 | 2009-05-19T15:49:31Z | 883,645 | <p>It depends on where you want to use it. </p>
<p>If you want to use it in your own templates, I would suggest to write a template-tag, that will do the ordering for you
In it, you could use any sorting algorithm you want to use.</p>
<p>In admin I do custom sorting by extending the templates to my needs and loading ... | 0 | 2009-05-19T16:04:56Z | [
"python",
"django",
"django-models"
] |
Custom ordering in Django | 883,575 | <p>How do you define a specific ordering in Django <code>QuerySet</code>s?</p>
<p>Specifically, if I have a <code>QuerySet</code> like so: <code>['a10', 'a1', 'a2']</code>.</p>
<p>Regular order (using <code>Whatever.objects.order_by('someField')</code>) will give me <code>['a1', 'a10', 'a2']</code>, while I am lookin... | 20 | 2009-05-19T15:49:31Z | 889,445 | <p>@Jarret's answer (do the sort in Python) works great for simple cases. As soon as you have a large table and want to, say, pull only the first page of results sorted in a certain way, this approach breaks (you have to pull every single row from the database before you can do the sort). At that point I would look i... | 21 | 2009-05-20T18:20:33Z | [
"python",
"django",
"django-models"
] |
Custom ordering in Django | 883,575 | <p>How do you define a specific ordering in Django <code>QuerySet</code>s?</p>
<p>Specifically, if I have a <code>QuerySet</code> like so: <code>['a10', 'a1', 'a2']</code>.</p>
<p>Regular order (using <code>Whatever.objects.order_by('someField')</code>) will give me <code>['a1', 'a10', 'a2']</code>, while I am lookin... | 20 | 2009-05-19T15:49:31Z | 26,731,696 | <p>If you have larger data sets and additionally use a SOLR backend (e.g. with Haystack):</p>
<p>Use <code>solr.ICUCollationField</code> with the <code>numeric=true</code> option as type for the sort fields. This will sort according to language and if numbers are present will sort the number part according to numeric ... | 0 | 2014-11-04T09:31:39Z | [
"python",
"django",
"django-models"
] |
Given a date range how to calculate the number of weekends partially or wholly within that range? | 883,615 | <p>Given a date range how to calculate the number of weekends partially or wholly within that range?</p>
<p>(A few definitions as requested:
take 'weekend' to mean Saturday and Sunday.
The date range is inclusive i.e. the end date is part of the range
'wholly or partially' means that any part of the weekend falling wi... | 1 | 2009-05-19T15:58:57Z | 883,669 | <p>You would need external logic beside raw math. You need to have a calendar library (or if you have a decent amount of time implement it yourself) to define what a weekend, what day of the week you start on, end on, etc.</p>
<p>Take a look at <a href="http://docs.python.org/library/calendar.html" rel="nofollow">Pyth... | 0 | 2009-05-19T16:09:02Z | [
"python",
"date",
"date-arithmetic"
] |
Given a date range how to calculate the number of weekends partially or wholly within that range? | 883,615 | <p>Given a date range how to calculate the number of weekends partially or wholly within that range?</p>
<p>(A few definitions as requested:
take 'weekend' to mean Saturday and Sunday.
The date range is inclusive i.e. the end date is part of the range
'wholly or partially' means that any part of the weekend falling wi... | 1 | 2009-05-19T15:58:57Z | 883,744 | <p>General approach for this kind of thing:</p>
<p>For each day of the week, figure out how many days are required before a period starting on that day "contains a weekend". For instance, if "contains a weekend" means "contains both the Saturday and the Sunday", then we have the following table:</p>
<p>Sunday: 8
Mond... | 5 | 2009-05-19T16:19:16Z | [
"python",
"date",
"date-arithmetic"
] |
Given a date range how to calculate the number of weekends partially or wholly within that range? | 883,615 | <p>Given a date range how to calculate the number of weekends partially or wholly within that range?</p>
<p>(A few definitions as requested:
take 'weekend' to mean Saturday and Sunday.
The date range is inclusive i.e. the end date is part of the range
'wholly or partially' means that any part of the weekend falling wi... | 1 | 2009-05-19T15:58:57Z | 884,037 | <p>To count whole weekends, just adjust the number of days so that you start on a Monday, then divide by seven. (Note that if the start day is a weekday, add days to move to the previous Monday, and if it is on a weekend, subtract days to move to the next Monday since you already missed this weekend.)</p>
<pre><code>... | 1 | 2009-05-19T17:20:36Z | [
"python",
"date",
"date-arithmetic"
] |
Given a date range how to calculate the number of weekends partially or wholly within that range? | 883,615 | <p>Given a date range how to calculate the number of weekends partially or wholly within that range?</p>
<p>(A few definitions as requested:
take 'weekend' to mean Saturday and Sunday.
The date range is inclusive i.e. the end date is part of the range
'wholly or partially' means that any part of the weekend falling wi... | 1 | 2009-05-19T15:58:57Z | 2,815,480 | <p>My general approach for this sort of thing: don't start messing around trying to reimplement your own date logic - it's hard, ie. you'll screw it up for the edge cases and look bad. <strong>Hint:</strong> if you have mod 7 arithmetic anywhere in your program, or are treating dates as integers anywhere in your progra... | 2 | 2010-05-12T00:59:02Z | [
"python",
"date",
"date-arithmetic"
] |
Optparse: Usage on variable arg callback action does not indicate that extra params are needed | 883,679 | <p>I have implemented in my python code a callback for variable arguments similar to what can be found here:<br />
hxxp://docs.python.org/library/optparse.html#callback-example-6-variable-arguments</p>
<p>Adding the option like this: </p>
<pre><code>parser.add_option("-c", "--callback", dest="vararg_attr", action="c... | 3 | 2009-05-19T16:10:00Z | 883,734 | <p>user the <code>metavar</code> keyword argument:</p>
<pre><code>parser.add_option("-c", "--callback", dest="vararg_attr", action="callback", callback=vararg_callback, metavar='LIST')
</code></pre>
<p>Reference: <a href="http://docs.python.org/library/optparse.html" rel="nofollow">http://docs.python.org/library/optp... | 1 | 2009-05-19T16:17:24Z | [
"python",
"callback",
"optparse"
] |
Optparse: Usage on variable arg callback action does not indicate that extra params are needed | 883,679 | <p>I have implemented in my python code a callback for variable arguments similar to what can be found here:<br />
hxxp://docs.python.org/library/optparse.html#callback-example-6-variable-arguments</p>
<p>Adding the option like this: </p>
<pre><code>parser.add_option("-c", "--callback", dest="vararg_attr", action="c... | 3 | 2009-05-19T16:10:00Z | 884,606 | <p>This involves monkeypatching and might not be the best solution. On the other hand, it seems to work.</p>
<pre><code>from optparse import OptionParser, Option
# Complete hack.
Option.ALWAYS_TYPED_ACTIONS += ('callback',)
def dostuff(*a):
pass
parser = OptionParser()
parser.add_option("-c",
... | 2 | 2009-05-19T19:30:51Z | [
"python",
"callback",
"optparse"
] |
Optparse: Usage on variable arg callback action does not indicate that extra params are needed | 883,679 | <p>I have implemented in my python code a callback for variable arguments similar to what can be found here:<br />
hxxp://docs.python.org/library/optparse.html#callback-example-6-variable-arguments</p>
<p>Adding the option like this: </p>
<pre><code>parser.add_option("-c", "--callback", dest="vararg_attr", action="c... | 3 | 2009-05-19T16:10:00Z | 32,220,734 | <p>optparse does not display the indication for an additional argument if the type is None (default). If you specify type and metavar it is displayed in the help:</p>
<pre><code>parser.add_option("-c", "--callback",
dest="vararg_attr",
type="string",
metavar="LIST... | 0 | 2015-08-26T07:43:25Z | [
"python",
"callback",
"optparse"
] |
Custom implementation of "tail -f" functionality in C | 883,784 | <p><strong>EDIT:</strong> I used, finally, inotify. As stefanB says, inotify is the thing to use. I found a tail clone that uses inotify to implement the -f mode, <a href="http://distanz.ch/inotail/" rel="nofollow">inotail</a>.</p>
<p>Original question text:</p>
<p>I'm trying to implement the "tail -f" logic in a C p... | 2 | 2009-05-19T16:27:08Z | 883,829 | <p>Once a FILE * has seen an error or eof, it has its internal status set so that it continues to return error or eof on subsequent calls. You need to call <code>clearerr(f);</code> after the sleep returns to clear the eof setting and get it to try to read more data from the file.</p>
| 3 | 2009-05-19T16:35:20Z | [
"python",
"c"
] |
Custom implementation of "tail -f" functionality in C | 883,784 | <p><strong>EDIT:</strong> I used, finally, inotify. As stefanB says, inotify is the thing to use. I found a tail clone that uses inotify to implement the -f mode, <a href="http://distanz.ch/inotail/" rel="nofollow">inotail</a>.</p>
<p>Original question text:</p>
<p>I'm trying to implement the "tail -f" logic in a C p... | 2 | 2009-05-19T16:27:08Z | 883,831 | <p>From the <code>tail</code> <a href="http://www.monkey.org/cgi-bin/man2html?tail" rel="nofollow">man page</a>:</p>
<blockquote>
<p>-f Do not stop when end-of-file is reached, but rather to wait for
additional data to be appended to the
input. If the file is replaced (i.e.,
the inode number changes), tail ... | 2 | 2009-05-19T16:35:27Z | [
"python",
"c"
] |
Custom implementation of "tail -f" functionality in C | 883,784 | <p><strong>EDIT:</strong> I used, finally, inotify. As stefanB says, inotify is the thing to use. I found a tail clone that uses inotify to implement the -f mode, <a href="http://distanz.ch/inotail/" rel="nofollow">inotail</a>.</p>
<p>Original question text:</p>
<p>I'm trying to implement the "tail -f" logic in a C p... | 2 | 2009-05-19T16:27:08Z | 883,843 | <p><strong>EDIT</strong>:
Seems like <a href="http://www.linuxjournal.com/article/8478" rel="nofollow">inotify</a> is the thing to use. It should be included in linux kernel since 2.6.13 . <a href="http://www.ibm.com/developerworks/linux/library/l-ubuntu-inotify/index.html?ca=drs-" rel="nofollow">An article from IBM de... | 3 | 2009-05-19T16:39:54Z | [
"python",
"c"
] |
datetime.now() in Django application goes bad | 883,823 | <p>I've had some problems with a Django application after I deployed it. I use a Apache + mod-wsgi on a ubuntu server. A while after I reboot the server the time goes foobar, it's wrong by around -10 hours. I made a Django view that looks like:</p>
<pre><code>def servertime():
return HttpResponse( datetime.now() )
<... | 5 | 2009-05-19T16:34:03Z | 883,873 | <p>Can I see your urls.py as well?</p>
<p>Similar behaviors stumped me once before...</p>
<p>What it turned out to be was the way that my urls.py called the view. Python ran the datetime.now() once and stored that for future calls, never really calling it again. This is why django devs had to implement the ability to... | 6 | 2009-05-19T16:48:05Z | [
"python",
"django",
"apache",
"datetime",
"mod-wsgi"
] |
datetime.now() in Django application goes bad | 883,823 | <p>I've had some problems with a Django application after I deployed it. I use a Apache + mod-wsgi on a ubuntu server. A while after I reboot the server the time goes foobar, it's wrong by around -10 hours. I made a Django view that looks like:</p>
<pre><code>def servertime():
return HttpResponse( datetime.now() )
<... | 5 | 2009-05-19T16:34:03Z | 885,871 | <p>you may need to specify the content type like so</p>
<pre><code>def servertime():
return HttpResponse( datetime.now(), content_type="text/plain" )
</code></pre>
<p>another idea:</p>
<p>it may not be working because datetime.now() returns a datetime object. Try this:</p>
<pre><code>def servertime():
return Ht... | 0 | 2009-05-20T02:12:41Z | [
"python",
"django",
"apache",
"datetime",
"mod-wsgi"
] |
datetime.now() in Django application goes bad | 883,823 | <p>I've had some problems with a Django application after I deployed it. I use a Apache + mod-wsgi on a ubuntu server. A while after I reboot the server the time goes foobar, it's wrong by around -10 hours. I made a Django view that looks like:</p>
<pre><code>def servertime():
return HttpResponse( datetime.now() )
<... | 5 | 2009-05-19T16:34:03Z | 890,876 | <p>Maybe the server is evaluating the datetime.now() at server start, try making it lazy through a template or use a variable in your view.</p>
<p>Take a look at this <a href="http://paltman.com/2008/may/07/a-default-bug-in-django/" rel="nofollow">blog post</a>.</p>
| 1 | 2009-05-21T00:20:08Z | [
"python",
"django",
"apache",
"datetime",
"mod-wsgi"
] |
datetime.now() in Django application goes bad | 883,823 | <p>I've had some problems with a Django application after I deployed it. I use a Apache + mod-wsgi on a ubuntu server. A while after I reboot the server the time goes foobar, it's wrong by around -10 hours. I made a Django view that looks like:</p>
<pre><code>def servertime():
return HttpResponse( datetime.now() )
<... | 5 | 2009-05-19T16:34:03Z | 1,075,389 | <p>I found that putting wsgi in daemon mode works. Not sure why, but it did. Seems like some of the newly created processes gets the time screwed up.</p>
| 5 | 2009-07-02T16:32:36Z | [
"python",
"django",
"apache",
"datetime",
"mod-wsgi"
] |
datetime.now() in Django application goes bad | 883,823 | <p>I've had some problems with a Django application after I deployed it. I use a Apache + mod-wsgi on a ubuntu server. A while after I reboot the server the time goes foobar, it's wrong by around -10 hours. I made a Django view that looks like:</p>
<pre><code>def servertime():
return HttpResponse( datetime.now() )
<... | 5 | 2009-05-19T16:34:03Z | 2,817,400 | <p>Django sets the system time zone based on your settings variable TIME_ZONE. This may lead to all kinds of confusion when running multiple Django instances with different TIME_ZONE settings.</p>
<p>This is what Django does:</p>
<pre><code>os.environ['TZ'] = self.TIME_ZONE
</code></pre>
<p>The above answer:</p>
<b... | 1 | 2010-05-12T09:18:48Z | [
"python",
"django",
"apache",
"datetime",
"mod-wsgi"
] |
datetime.now() in Django application goes bad | 883,823 | <p>I've had some problems with a Django application after I deployed it. I use a Apache + mod-wsgi on a ubuntu server. A while after I reboot the server the time goes foobar, it's wrong by around -10 hours. I made a Django view that looks like:</p>
<pre><code>def servertime():
return HttpResponse( datetime.now() )
<... | 5 | 2009-05-19T16:34:03Z | 8,403,828 | <p>datetime.now() is probably being evaluated once, when your class is instantiated. Try removing the parenthesis so that the function datetime.now is returned and THEN evaluated. I had a similar issue with setting default values for my DateTimeFields and wrote up my solution <a href="http://david.feinzeig.com/blog/2... | 2 | 2011-12-06T17:06:24Z | [
"python",
"django",
"apache",
"datetime",
"mod-wsgi"
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.