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 |
|---|---|---|---|---|---|---|---|---|---|
Why doesn't os.system('set foo=bar') work? | 1,506,579 | <p>Possibly a stupid question: Why can't I set an environment variable with this?</p>
<pre><code>os.system('set foo=bar') # on windows
</code></pre>
<p>I'm aware of <code>os.environ</code>, and that works for me. I'm just confused about why the former doesn't work. </p>
| 0 | 2009-10-01T21:21:19Z | 1,506,594 | <p>See the discussion <a href="http://stackoverflow.com/questions/1506010/how-to-use-export-with-python-on-linux">here</a> -- <code>export</code> and <code>set</code> are both shell commands, and whether on Windows or Unix, they're still inevitably being addressed to a <strong>child process</strong> running the shell (... | 11 | 2009-10-01T21:24:44Z | [
"python",
"environment-variables",
"environment"
] |
Matplotlib square boxplot | 1,506,647 | <p>I have a plot of two boxplots in the same figure. Due to style reasons, the axis should have the same length, so that the graphic box is squared.
I tried to use the set_aspect method, but the axis are too different by means of range
and the result is terrific.</p>
<p>Is it possible to have 1:1 axis even if they hav... | 4 | 2009-10-01T21:37:37Z | 1,506,741 | <p>Try <code>axis('equal')</code>. It's been a while since I worked with matplotlib, but I seem to remember typing that command a lot.</p>
| 4 | 2009-10-01T21:58:00Z | [
"python",
"matplotlib",
"square"
] |
Matplotlib square boxplot | 1,506,647 | <p>I have a plot of two boxplots in the same figure. Due to style reasons, the axis should have the same length, so that the graphic box is squared.
I tried to use the set_aspect method, but the axis are too different by means of range
and the result is terrific.</p>
<p>Is it possible to have 1:1 axis even if they hav... | 4 | 2009-10-01T21:37:37Z | 1,506,925 | <p>You can use <a href="http://matplotlib.sourceforge.net/api/axes%5Fapi.html?highlight=set%5Faspect#matplotlib.axes.Axes.set%5Faspect" rel="nofollow">Axes.set_aspect</a> to do this if you set the aspect to the ratio of axes limits. Here's an example:
<img src="http://i37.tinypic.com/b6u9zs.png" alt="alt text" /></p>
... | 3 | 2009-10-01T22:53:40Z | [
"python",
"matplotlib",
"square"
] |
Matplotlib square boxplot | 1,506,647 | <p>I have a plot of two boxplots in the same figure. Due to style reasons, the axis should have the same length, so that the graphic box is squared.
I tried to use the set_aspect method, but the axis are too different by means of range
and the result is terrific.</p>
<p>Is it possible to have 1:1 axis even if they hav... | 4 | 2009-10-01T21:37:37Z | 8,930,451 | <p>For loglog plots ( <code>loglog()</code> ) don't forget to use</p>
<pre><code>ax1.set_aspect(log10(xmax/xmin)/log10(ymax/ymin))
</code></pre>
| 1 | 2012-01-19T17:23:32Z | [
"python",
"matplotlib",
"square"
] |
How to use Sphinx auto-documentation when Python file won't compile | 1,506,673 | <p>This question is even harder today because I haven't had any luck using the search function on the Sphinx homepage today.</p>
<p>I have a group of modules that I want to be documented from the docstrings. However, these are not pure Python scripts. They won't compile as is, because they are run from a C# applicatio... | 1 | 2009-10-01T21:41:14Z | 1,506,824 | <p>Perhaps you could define injected_method as a empty function so that the documentation will work. You'll need to make sure that the definition of injected_method that you're injecting happens after the new injected_method stub.</p>
<pre><code>#By empty function I mean a function that looks like this
def injected_m... | 0 | 2009-10-01T22:20:24Z | [
"python",
"ironpython",
"python-sphinx"
] |
How to use Sphinx auto-documentation when Python file won't compile | 1,506,673 | <p>This question is even harder today because I haven't had any luck using the search function on the Sphinx homepage today.</p>
<p>I have a group of modules that I want to be documented from the docstrings. However, these are not pure Python scripts. They won't compile as is, because they are run from a C# applicatio... | 1 | 2009-10-01T21:41:14Z | 1,506,908 | <p>Well, you could try:</p>
<ul>
<li>Wrapping the usage of injected_method in a try/except.</li>
<li>Writing a script that filters out all python-code that is run on import time, and feeds the result into Sphinx.</li>
<li>You could....ok, I have no more ideas. :)</li>
</ul>
| 3 | 2009-10-01T22:47:24Z | [
"python",
"ironpython",
"python-sphinx"
] |
How to use Sphinx auto-documentation when Python file won't compile | 1,506,673 | <p>This question is even harder today because I haven't had any luck using the search function on the Sphinx homepage today.</p>
<p>I have a group of modules that I want to be documented from the docstrings. However, these are not pure Python scripts. They won't compile as is, because they are run from a C# applicatio... | 1 | 2009-10-01T21:41:14Z | 1,510,499 | <p>Okay, I found a way to get around the Errors.</p>
<p>When setting up the embedded scripting environment, instead of using:</p>
<pre><code>ScriptScope.SetVariable("injected_method", myMethod);
</code></pre>
<p>I am now using:</p>
<pre><code>ScriptRuntime.Globals.SetVariable("injected_method", myMethod);
</code></... | 0 | 2009-10-02T16:10:21Z | [
"python",
"ironpython",
"python-sphinx"
] |
How to arrange the source code of an application made with SQLAlchemy and a graphic interface? | 1,506,887 | <p>I'm developing an application using SQLAlchemy and wxPython that I'm trying to keep distributed in separated modules consisting of Business logic, ORM and GUI.</p>
<p>I'm not completely sure how to do this in a pythonic way.</p>
<p>Given that <code>mapping()</code> has to be called in orther for the objects to be ... | 6 | 2009-10-01T22:39:03Z | 1,509,612 | <p>I find <a href="http://jcalderone.livejournal.com/39794.html">this document</a> by Jp Calderone to be a great tip on how to (not) structure your python project. Following it you won't have issues. I'll reproduce the entire text here:</p>
<blockquote>
<h1>Filesystem structure of a Python project</h1>
<p><stro... | 5 | 2009-10-02T13:48:36Z | [
"python",
"sqlalchemy",
"directory-structure",
"version-control"
] |
Cleanest and most Pythonic way to get tomorrow's date? | 1,506,901 | <p>What is the cleanest and most Pythonic way to get tomorrow's date? There must be a better way than to add one to the day, handle days at the end of the month, etc.</p>
| 43 | 2009-10-01T22:45:11Z | 1,506,916 | <p><code>datetime.date.today() + datetime.timedelta(days=1)</code> should do the trick</p>
| 90 | 2009-10-01T22:49:11Z | [
"python",
"datetime",
"date",
"time"
] |
Cleanest and most Pythonic way to get tomorrow's date? | 1,506,901 | <p>What is the cleanest and most Pythonic way to get tomorrow's date? There must be a better way than to add one to the day, handle days at the end of the month, etc.</p>
| 43 | 2009-10-01T22:45:11Z | 1,506,917 | <p><a href="http://docs.python.org/library/datetime.html#timedelta-objects"><code>timedelta</code></a> can handle adding days, seconds, microseconds, milliseconds, minutes, hours, or weeks.</p>
<pre><code>>>> import datetime
>>> today = datetime.date.today()
>>> today
datetime.date(2009, 10,... | 23 | 2009-10-01T22:49:24Z | [
"python",
"datetime",
"date",
"time"
] |
Cleanest and most Pythonic way to get tomorrow's date? | 1,506,901 | <p>What is the cleanest and most Pythonic way to get tomorrow's date? There must be a better way than to add one to the day, handle days at the end of the month, etc.</p>
| 43 | 2009-10-01T22:45:11Z | 1,507,077 | <p>No handling of <a href="http://en.wikipedia.org/wiki/Leap%5Fsecond">leap seconds</a> tho:</p>
<pre><code>>>> from datetime import datetime, timedelta
>>> dt = datetime(2008,12,31,23,59,59)
>>> str(dt)
'2008-12-31 23:59:59'
>>> # leap second was added at the end of 2008,
>>... | 5 | 2009-10-01T23:45:34Z | [
"python",
"datetime",
"date",
"time"
] |
Cleanest and most Pythonic way to get tomorrow's date? | 1,506,901 | <p>What is the cleanest and most Pythonic way to get tomorrow's date? There must be a better way than to add one to the day, handle days at the end of the month, etc.</p>
| 43 | 2009-10-01T22:45:11Z | 1,507,121 | <p>Even the basic <code>time</code> module can handle this:</p>
<pre><code>import time
time.localtime(time.time() + 24*3600)
</code></pre>
| 4 | 2009-10-01T23:58:15Z | [
"python",
"datetime",
"date",
"time"
] |
How do I get fluent in Python? | 1,507,041 | <p>Once you have learned the basic commands in Python, you are often able to solve most programming problem you face. But the way in which this is done is not really <em>Python-ic</em>.
What is common is to use the classical c++ or Java mentality to solve problems. But Python is more than that. It has functional progr... | 10 | 2009-10-01T23:32:12Z | 1,507,045 | <p>Have you read the <a href="http://rads.stackoverflow.com/amzn/click/0596007973" rel="nofollow">Python Cookbook</a>? It's a pretty good source for Pythonic.</p>
<p>Plus you'll find <a href="http://stackoverflow.com/search?q=user%3a95810%20%5Bpython%5D&tab=votes">much more from Alex Martelli on Stack Overflow</a>... | 8 | 2009-10-01T23:33:25Z | [
"python"
] |
How do I get fluent in Python? | 1,507,041 | <p>Once you have learned the basic commands in Python, you are often able to solve most programming problem you face. But the way in which this is done is not really <em>Python-ic</em>.
What is common is to use the classical c++ or Java mentality to solve problems. But Python is more than that. It has functional progr... | 10 | 2009-10-01T23:32:12Z | 1,507,054 | <p>Read other people's code. Write some of your own code. Repeat for a year or two.</p>
<p>Study the Python documentation and learn the built-in modules.</p>
<p>Read Python in a Nutshell.</p>
<p>Subscribe your RSS reader to the Python tag on Stack Overflow.</p>
| 10 | 2009-10-01T23:35:48Z | [
"python"
] |
How do I get fluent in Python? | 1,507,041 | <p>Once you have learned the basic commands in Python, you are often able to solve most programming problem you face. But the way in which this is done is not really <em>Python-ic</em>.
What is common is to use the classical c++ or Java mentality to solve problems. But Python is more than that. It has functional progr... | 10 | 2009-10-01T23:32:12Z | 1,507,058 | <p>I guess becoming fluent in any programming language is the same as becoming fluent in a spoken/written language. You do that by speaking and listening to the language, a lot.</p>
<p>So my advice is to do some projects using python, and you will soon become fluent in it. You can complement this by reading other peop... | 2 | 2009-10-01T23:36:15Z | [
"python"
] |
How do I get fluent in Python? | 1,507,041 | <p>Once you have learned the basic commands in Python, you are often able to solve most programming problem you face. But the way in which this is done is not really <em>Python-ic</em>.
What is common is to use the classical c++ or Java mentality to solve problems. But Python is more than that. It has functional progr... | 10 | 2009-10-01T23:32:12Z | 1,507,068 | <p>The same way you get fluent in any language - program a lot.</p>
<p>I'd recommend working on a project (hopefully something you'll actually use later). While working on the project, every time you need some basic piece of functionality, try writing it yourself, and <strong>then</strong> checking online how other pe... | 3 | 2009-10-01T23:41:36Z | [
"python"
] |
How do I get fluent in Python? | 1,507,041 | <p>Once you have learned the basic commands in Python, you are often able to solve most programming problem you face. But the way in which this is done is not really <em>Python-ic</em>.
What is common is to use the classical c++ or Java mentality to solve problems. But Python is more than that. It has functional progr... | 10 | 2009-10-01T23:32:12Z | 1,507,101 | <p>There are some Python textbooks that not only teach you the language, they teach you the philosophy of the language (why it is the way it is) and teach you common idioms. I learned from the book <a href="http://www.rmi.net/~lutz/about-lp4e.html" rel="nofollow">Learning Python</a> by <a href="http://www.rmi.net/~lut... | 3 | 2009-10-01T23:52:38Z | [
"python"
] |
How do I get fluent in Python? | 1,507,041 | <p>Once you have learned the basic commands in Python, you are often able to solve most programming problem you face. But the way in which this is done is not really <em>Python-ic</em>.
What is common is to use the classical c++ or Java mentality to solve problems. But Python is more than that. It has functional progr... | 10 | 2009-10-01T23:32:12Z | 1,507,169 | <p>More Pythonic? Start with a simple import.</p>
<pre><code>import this
</code></pre>
<p>And add practice.</p>
| 5 | 2009-10-02T00:16:09Z | [
"python"
] |
How do I get fluent in Python? | 1,507,041 | <p>Once you have learned the basic commands in Python, you are often able to solve most programming problem you face. But the way in which this is done is not really <em>Python-ic</em>.
What is common is to use the classical c++ or Java mentality to solve problems. But Python is more than that. It has functional progr... | 10 | 2009-10-01T23:32:12Z | 1,507,504 | <p>I can tell you what I've done.</p>
<ol>
<li><a href="http://python.net/~goodger/projects/pycon/2007/idiomatic/handout.html">Idiomatic Python</a></li>
<li>Bookmark SO with the python keyword.</li>
<li>Read other's <em>good</em> python code.</li>
<li><a href="http://www.pythonchallenge.com/">The Python Challenge</a><... | 7 | 2009-10-02T02:31:13Z | [
"python"
] |
How do I get fluent in Python? | 1,507,041 | <p>Once you have learned the basic commands in Python, you are often able to solve most programming problem you face. But the way in which this is done is not really <em>Python-ic</em>.
What is common is to use the classical c++ or Java mentality to solve problems. But Python is more than that. It has functional progr... | 10 | 2009-10-01T23:32:12Z | 1,509,575 | <p>Read existing projects known for technical excelence.</p>
<p>Some of the ones I'd recommend are:</p>
<ul>
<li><a href="http://code.djangoproject.com/browser/django" rel="nofollow">Django</a></li>
<li><a href="http://svn.sqlalchemy.org/sqlalchemy/" rel="nofollow">SQLAlchemy</a></li>
<li>Python's <a href="http://doc... | 2 | 2009-10-02T13:41:41Z | [
"python"
] |
wx.TextCtrl.LoadFile() | 1,507,075 | <p>I am trying to display search result data quickly. I have all absolute file paths for files on my network drive(s) in a single, ~50MB text file. The python script makes a single pass over every line in this file [kept on the local drive] in a second or less, and that is acceptable. That is the time it takes to gath... | 0 | 2009-10-01T23:44:31Z | 1,507,087 | <p>Are people really going to read (or need) all 10MB in a text control? Probably not.</p>
<p>Suggest that, you load on demand by paging in portions of the data.</p>
<p>Or better still, provide some user search functionality that narrows down the results to the information of interest.</p>
| 0 | 2009-10-01T23:49:32Z | [
"python",
"file-io",
"wxpython",
"wxwidgets",
"mmap"
] |
wx.TextCtrl.LoadFile() | 1,507,075 | <p>I am trying to display search result data quickly. I have all absolute file paths for files on my network drive(s) in a single, ~50MB text file. The python script makes a single pass over every line in this file [kept on the local drive] in a second or less, and that is acceptable. That is the time it takes to gath... | 0 | 2009-10-01T23:44:31Z | 1,512,903 | <p>You can load all the data at once with AppendText, why you need to do it line by line, but still it will take seconds as 10MB is huge. If you use wx.RichTextCtrl it is bit faster
in my test it loaded 10 MB in 6 secs instead of 9 sec for TextCtrl.</p>
<p>I do not see the reason why you need to set all the data at on... | 0 | 2009-10-03T05:32:18Z | [
"python",
"file-io",
"wxpython",
"wxwidgets",
"mmap"
] |
Python: is it bad form to raise exceptions within __init__? | 1,507,082 | <p>Is it considered bad form to raise exceptions within __init_? If so, then what is the accepted method of throwing an error when certain class variables are initialized as None or of an incorrect type?</p>
| 59 | 2009-10-01T23:47:38Z | 1,507,112 | <p>I should think it is the perfect case for the built-in <code>ValueError</code> exception.</p>
| 3 | 2009-10-01T23:55:38Z | [
"python",
"exception"
] |
Python: is it bad form to raise exceptions within __init__? | 1,507,082 | <p>Is it considered bad form to raise exceptions within __init_? If so, then what is the accepted method of throwing an error when certain class variables are initialized as None or of an incorrect type?</p>
| 59 | 2009-10-01T23:47:38Z | 1,507,120 | <p>The standard library says:</p>
<pre><code>>>> f = file("notexisting.txt")
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
IOError: [Errno 2] No such file or directory: 'notexisting.txt'
</code></pre>
<p>Also I don't really see any reason why it should be considered bad... | 3 | 2009-10-01T23:58:13Z | [
"python",
"exception"
] |
Python: is it bad form to raise exceptions within __init__? | 1,507,082 | <p>Is it considered bad form to raise exceptions within __init_? If so, then what is the accepted method of throwing an error when certain class variables are initialized as None or of an incorrect type?</p>
| 59 | 2009-10-01T23:47:38Z | 1,507,127 | <p>Raising exceptions within <code>__init__()</code> is absolutely fine. There's no other good way to indicate an error condition within a constructor, and there are many hundreds of examples in the standard library where building an object can raise an exception.</p>
<p>The error class to raise, of course, is up to y... | 82 | 2009-10-01T23:59:26Z | [
"python",
"exception"
] |
Python: is it bad form to raise exceptions within __init__? | 1,507,082 | <p>Is it considered bad form to raise exceptions within __init_? If so, then what is the accepted method of throwing an error when certain class variables are initialized as None or of an incorrect type?</p>
| 59 | 2009-10-01T23:47:38Z | 1,507,130 | <p>I don't see any reason that it should be bad form.</p>
<p>On the contrary, one of the things exceptions are known for doing well, as opposed to returning error codes, is that error codes usually <strong>can't</strong> be returned by constructors. So at least in languages like C++, raising exceptions is the only way... | 8 | 2009-10-02T00:01:01Z | [
"python",
"exception"
] |
Python: is it bad form to raise exceptions within __init__? | 1,507,082 | <p>Is it considered bad form to raise exceptions within __init_? If so, then what is the accepted method of throwing an error when certain class variables are initialized as None or of an incorrect type?</p>
| 59 | 2009-10-01T23:47:38Z | 1,507,245 | <p>I concur with all of the above.</p>
<p>There's really no other way to signal that something went wrong in the initialisation of an object other than raising an exception. </p>
<p>In most programs classes where the state of a class is wholly dependant on the inputs to that class we might expect some kind of ValueEr... | 2 | 2009-10-02T00:46:58Z | [
"python",
"exception"
] |
Python: is it bad form to raise exceptions within __init__? | 1,507,082 | <p>Is it considered bad form to raise exceptions within __init_? If so, then what is the accepted method of throwing an error when certain class variables are initialized as None or of an incorrect type?</p>
| 59 | 2009-10-01T23:47:38Z | 7,501,167 | <p>It's true that the only proper way to indicate an error in a constructor is raising an exception. That is why in C++ and in other object-oriented languages that have been designed with exception safety in mind, the destructor is not called if an exception is thrown in the constructor of an object (meaning that the i... | 8 | 2011-09-21T14:04:02Z | [
"python",
"exception"
] |
Python: is it bad form to raise exceptions within __init__? | 1,507,082 | <p>Is it considered bad form to raise exceptions within __init_? If so, then what is the accepted method of throwing an error when certain class variables are initialized as None or of an incorrect type?</p>
| 59 | 2009-10-01T23:47:38Z | 18,825,585 | <p>Raising errors from init is unavoidable in some cases, but doing too much work in init is a bad style. You should consider making a factory or a pseudo-factory - a simple classmethod that returns setted up object.</p>
| 1 | 2013-09-16T10:18:01Z | [
"python",
"exception"
] |
How to check dimensions of all images in a directory using python? | 1,507,084 | <p>I need to check the dimensions of images in a directory. Currently it has ~700 images.
I just need to check the sizes, and if the size does not match a given dimension, it will be moved to a different folder. How do I get started? </p>
| 10 | 2009-10-01T23:47:48Z | 1,507,110 | <p>You can use the <a href="http://www.pythonware.com/products/pil/" rel="nofollow">Python Imaging Library</a> (aka PIL) to read the image headers and query the dimensions.</p>
<p>One way to approach it would be to write yourself a function that takes a filename and returns the dimensions (using PIL). Then use the <c... | 4 | 2009-10-01T23:55:11Z | [
"python",
"image",
"directory"
] |
How to check dimensions of all images in a directory using python? | 1,507,084 | <p>I need to check the dimensions of images in a directory. Currently it has ~700 images.
I just need to check the sizes, and if the size does not match a given dimension, it will be moved to a different folder. How do I get started? </p>
| 10 | 2009-10-01T23:47:48Z | 1,507,142 | <p>One common way is to use <a href="http://www.pythonware.com/products/pil/">PIL</a>, the python imaging library to get the dimensions:</p>
<pre><code>from PIL import Image
import os.path
filename = os.path.join('path', 'to', 'image', 'file')
img = Image.open(filename)
print img.size
</code></pre>
<p>Then you need ... | 5 | 2009-10-02T00:06:21Z | [
"python",
"image",
"directory"
] |
How to check dimensions of all images in a directory using python? | 1,507,084 | <p>I need to check the dimensions of images in a directory. Currently it has ~700 images.
I just need to check the sizes, and if the size does not match a given dimension, it will be moved to a different folder. How do I get started? </p>
| 10 | 2009-10-01T23:47:48Z | 3,175,473 | <p>If you don't need the rest of PIL and just want image dimensions of PNG, JPEG and GIF then this small function (BSD license) does the job nicely:</p>
<p><a href="http://code.google.com/p/bfg-pages/source/browse/trunk/pages/getimageinfo.py" rel="nofollow">http://code.google.com/p/bfg-pages/source/browse/trunk/pages/... | 13 | 2010-07-04T17:01:48Z | [
"python",
"image",
"directory"
] |
How to check dimensions of all images in a directory using python? | 1,507,084 | <p>I need to check the dimensions of images in a directory. Currently it has ~700 images.
I just need to check the sizes, and if the size does not match a given dimension, it will be moved to a different folder. How do I get started? </p>
| 10 | 2009-10-01T23:47:48Z | 34,704,634 | <pre><code>#!/usr/bin/env python
"""
Get information about images in a folder.
"""
from os import listdir
from os.path import isfile, join
from PIL import Image
def print_data(data):
"""
Parameters
----------
data : dict
"""
for k, v in data.items():
print("%s:\t%s" % (k, v))
pr... | 1 | 2016-01-10T11:02:30Z | [
"python",
"image",
"directory"
] |
python MySQLDB query timeout | 1,507,091 | <p>I'm trying to enforce a time limit on queries in python MySQLDB. I have a situation where I have no control over the queries, but need to ensure that they do not run over a set time limit. I've tried using signal.SIGALRM to interrupt the call to execute, but this does not seem to work. The signal gets sent, but does... | 7 | 2009-10-01T23:51:06Z | 1,507,116 | <blockquote>
<p>Why do I not get the signal until after execute finishes?</p>
</blockquote>
<p>The query is executed through a C function, which blocks the Python VM from executing until it returns.</p>
<blockquote>
<p>Is there another reliable way to limit query execution time?</p>
</blockquote>
<p>This is (IMO... | 1 | 2009-10-01T23:56:40Z | [
"python",
"timeout",
"mysql"
] |
python MySQLDB query timeout | 1,507,091 | <p>I'm trying to enforce a time limit on queries in python MySQLDB. I have a situation where I have no control over the queries, but need to ensure that they do not run over a set time limit. I've tried using signal.SIGALRM to interrupt the call to execute, but this does not seem to work. The signal gets sent, but does... | 7 | 2009-10-01T23:51:06Z | 1,507,370 | <p>Use <a href="http://twistedmatrix.com/documents/current/api/twisted.enterprise.adbapi.html" rel="nofollow">adbapi</a>. It allows you to do a db call asynchronously.</p>
<pre><code>from twisted.internet import reactor
from twisted.enterprise import adbapi
def bogusQuery():
return dbpool.runQuery("SELECT SLEEP(1... | 1 | 2009-10-02T01:29:34Z | [
"python",
"timeout",
"mysql"
] |
python MySQLDB query timeout | 1,507,091 | <p>I'm trying to enforce a time limit on queries in python MySQLDB. I have a situation where I have no control over the queries, but need to ensure that they do not run over a set time limit. I've tried using signal.SIGALRM to interrupt the call to execute, but this does not seem to work. The signal gets sent, but does... | 7 | 2009-10-01T23:51:06Z | 1,508,287 | <blockquote>
<p>Why do I not get the signal until after execute finishes?</p>
</blockquote>
<p>The process waiting for network I/O is in an uninterruptible state (UNIX thing, not related to Python or MySQL). It gets the signal after the system call finishes (probably as <code>EINTR</code> error code, although I am n... | -1 | 2009-10-02T08:17:49Z | [
"python",
"timeout",
"mysql"
] |
python MySQLDB query timeout | 1,507,091 | <p>I'm trying to enforce a time limit on queries in python MySQLDB. I have a situation where I have no control over the queries, but need to ensure that they do not run over a set time limit. I've tried using signal.SIGALRM to interrupt the call to execute, but this does not seem to work. The signal gets sent, but does... | 7 | 2009-10-01T23:51:06Z | 1,510,167 | <p>@nosklo's twisted-based solution is elegant and workable, but if you want to avoid the dependency on twisted, the task is still doable, e.g....:</p>
<pre><code>import multiprocessing
def query_with_timeout(dbc, timeout, query, *a, **k):
conn1, conn2 = multiprocessing.Pipe(False)
subproc = multiprocessing.Proce... | 7 | 2009-10-02T15:14:05Z | [
"python",
"timeout",
"mysql"
] |
python MySQLDB query timeout | 1,507,091 | <p>I'm trying to enforce a time limit on queries in python MySQLDB. I have a situation where I have no control over the queries, but need to ensure that they do not run over a set time limit. I've tried using signal.SIGALRM to interrupt the call to execute, but this does not seem to work. The signal gets sent, but does... | 7 | 2009-10-01T23:51:06Z | 1,609,603 | <blockquote>
<p>I've tried using signal.SIGALRM to interrupt the call to execute, but this does not seem to work. The signal gets sent, but does not get caught until after the call to execute finishes.</p>
</blockquote>
<p>mysql library handles interrupted systems calls internally so you won't see side effects of SI... | 2 | 2009-10-22T19:58:56Z | [
"python",
"timeout",
"mysql"
] |
python MySQLDB query timeout | 1,507,091 | <p>I'm trying to enforce a time limit on queries in python MySQLDB. I have a situation where I have no control over the queries, but need to ensure that they do not run over a set time limit. I've tried using signal.SIGALRM to interrupt the call to execute, but this does not seem to work. The signal gets sent, but does... | 7 | 2009-10-01T23:51:06Z | 18,083,281 |
<h3>Generic notes</h3>
<p>I've experienced the same issue lately with several conditions I had to met:</p>
<ul>
<li>solution must be thread safe</li>
<li>multiple connections to database from the same machine may be active at the same time, kill the exact one connection/query</li>
<li>application contains connectio... | 1 | 2013-08-06T14:41:09Z | [
"python",
"timeout",
"mysql"
] |
urllib2: submitting a form and then redirecting | 1,507,170 | <p>My goal is to come up with a portable urllib2 solution that would POST a form and then redirect the user to what comes out.
The POSTing part is simple:</p>
<pre><code>request = urllib2.Request('https://some.site/page', data=urllib.urlencode({'key':'value'}))
response = urllib2.urlopen(request)
</code></pre>
<p>Pro... | 1 | 2009-10-02T00:16:10Z | 1,507,415 | <p>I suspect this will almost always fail. When you POST a form, the URL you end up at is just the URL you posted to. Sending someone else to this URL, or even visiting it again with the same browser that just POSTed, is going to do a GET and the page won't have the form data that was POSTed. The only way this would ... | 2 | 2009-10-02T01:51:37Z | [
"python",
"google-app-engine",
"urllib2"
] |
urllib2: submitting a form and then redirecting | 1,507,170 | <p>My goal is to come up with a portable urllib2 solution that would POST a form and then redirect the user to what comes out.
The POSTing part is simple:</p>
<pre><code>request = urllib2.Request('https://some.site/page', data=urllib.urlencode({'key':'value'}))
response = urllib2.urlopen(request)
</code></pre>
<p>Pro... | 1 | 2009-10-02T00:16:10Z | 1,507,434 | <p>The standard way to follow redirects with urllib2 is to use the <a href="http://docs.python.org/library/urllib2.html#httpredirecthandler-objects" rel="nofollow">HTTPRedirectHandler</a>.
(Not sure what you mean by 'what comes out' but I'm assuming a standard http redirect here, javascript redirect is a different beas... | 2 | 2009-10-02T01:57:40Z | [
"python",
"google-app-engine",
"urllib2"
] |
urllib2: submitting a form and then redirecting | 1,507,170 | <p>My goal is to come up with a portable urllib2 solution that would POST a form and then redirect the user to what comes out.
The POSTing part is simple:</p>
<pre><code>request = urllib2.Request('https://some.site/page', data=urllib.urlencode({'key':'value'}))
response = urllib2.urlopen(request)
</code></pre>
<p>Pro... | 1 | 2009-10-02T00:16:10Z | 1,507,721 | <p>You will find using mechanize much easier than using urllib2 directly</p>
<p><a href="http://wwwsearch.sourceforge.net/mechanize/" rel="nofollow">http://wwwsearch.sourceforge.net/mechanize/</a></p>
| 0 | 2009-10-02T04:22:42Z | [
"python",
"google-app-engine",
"urllib2"
] |
What are the advantages of faster server side scripting languages? | 1,507,175 | <p>Typical performance of Python scripts are about <a href="http://blog.dhananjaynene.com/2008/07/performance-comparison-c-java-python-ruby-jython-jruby-groovy/" rel="nofollow">5 times faster</a> than PHP. What are the advantages of using faster server side scripting languages? Will the speed ever be felt by website vi... | 1 | 2009-10-02T00:17:15Z | 1,507,183 | <p>How about <a href="http://code.google.com/appengine/docs/quotas.html#Resources" rel="nofollow">when you get charged for CPU time</a>? </p>
<blockquote>
<p>I just saved a ton of money by switching to Python!</p>
</blockquote>
| 9 | 2009-10-02T00:21:51Z | [
"php",
"python",
"performance",
"scripting",
"webserver"
] |
What are the advantages of faster server side scripting languages? | 1,507,175 | <p>Typical performance of Python scripts are about <a href="http://blog.dhananjaynene.com/2008/07/performance-comparison-c-java-python-ruby-jython-jruby-groovy/" rel="nofollow">5 times faster</a> than PHP. What are the advantages of using faster server side scripting languages? Will the speed ever be felt by website vi... | 1 | 2009-10-02T00:17:15Z | 1,507,186 | <p>According to Andy B. King, in <em>Website Optimization</em>:</p>
<blockquote>
<p>For Google an increase in page load time from 0.4 second to 0.9 seconds decreased traffic and ad revenues by 20%. For Amazon every 100 ms increase in load times decreased sales with 1%.</p>
</blockquote>
<p><a href="http://www.svenn... | 12 | 2009-10-02T00:23:48Z | [
"php",
"python",
"performance",
"scripting",
"webserver"
] |
What are the advantages of faster server side scripting languages? | 1,507,175 | <p>Typical performance of Python scripts are about <a href="http://blog.dhananjaynene.com/2008/07/performance-comparison-c-java-python-ruby-jython-jruby-groovy/" rel="nofollow">5 times faster</a> than PHP. What are the advantages of using faster server side scripting languages? Will the speed ever be felt by website vi... | 1 | 2009-10-02T00:17:15Z | 1,507,192 | <p>Increasing the execution speed of web request handlers usually translates to handling more requests/second with the same hardware. This is valuable in a number of cases; maintaining one server is much easier than maintaining two.</p>
<p>BTW, why Python and not Haskell? Haskell is 100x faster than PHP in some benc... | 1 | 2009-10-02T00:26:02Z | [
"php",
"python",
"performance",
"scripting",
"webserver"
] |
What are the advantages of faster server side scripting languages? | 1,507,175 | <p>Typical performance of Python scripts are about <a href="http://blog.dhananjaynene.com/2008/07/performance-comparison-c-java-python-ruby-jython-jruby-groovy/" rel="nofollow">5 times faster</a> than PHP. What are the advantages of using faster server side scripting languages? Will the speed ever be felt by website vi... | 1 | 2009-10-02T00:17:15Z | 1,507,200 | <p>For typical web apps, the difference in speed won't usually be felt within the request itself (the network latency dwarfs your compute time for a typical script that runs inside an HTTP request).</p>
<p>There are plenty of <em>other</em> things that affect scalability, but the processing needs to handle an average ... | 4 | 2009-10-02T00:31:06Z | [
"php",
"python",
"performance",
"scripting",
"webserver"
] |
How and when to appropriately use weakref in Python | 1,507,566 | <p>I have some code where instances of classes have parent<->child references to each other, e.g.:</p>
<pre><code>class Node(object):
def __init__(self):
self.parent = None
self.children = {}
def AddChild(self, name, child):
child.parent = self
self.children[name] = child
def Run():
root, c1,... | 38 | 2009-10-02T03:03:40Z | 1,507,578 | <p>Yep, weakref's excellent here. Specifically, instead of:</p>
<pre><code>self.children = {}
</code></pre>
<p>use:</p>
<pre><code>self.children = weakref.WeakValueDictionary()
</code></pre>
<p>Nothing else needs change in your code. This way, when a child has no other differences, it just goes away -- and so does ... | 23 | 2009-10-02T03:10:11Z | [
"python",
"circular-reference"
] |
How and when to appropriately use weakref in Python | 1,507,566 | <p>I have some code where instances of classes have parent<->child references to each other, e.g.:</p>
<pre><code>class Node(object):
def __init__(self):
self.parent = None
self.children = {}
def AddChild(self, name, child):
child.parent = self
self.children[name] = child
def Run():
root, c1,... | 38 | 2009-10-02T03:03:40Z | 1,508,284 | <p>I suggest using <code>child.parent = weakref.proxy(self)</code>. This is good solution to avoid circular references in case when lifetime of (external references to) <code>parent</code> covers lifetime of <code>child</code>. Contrary, use <code>weakref</code> for <code>child</code> (as Alex suggested) when lifetime ... | 11 | 2009-10-02T08:17:00Z | [
"python",
"circular-reference"
] |
How and when to appropriately use weakref in Python | 1,507,566 | <p>I have some code where instances of classes have parent<->child references to each other, e.g.:</p>
<pre><code>class Node(object):
def __init__(self):
self.parent = None
self.children = {}
def AddChild(self, name, child):
child.parent = self
self.children[name] = child
def Run():
root, c1,... | 38 | 2009-10-02T03:03:40Z | 9,834,694 | <p>I wanted to clarify which references can be weak. The following approach is general, but I use the doubly-linked tree in all examples. </p>
<p>Logical Step 1.</p>
<p>You need to ensure that there are strong references to keep all the objects alive as long as you need them. It could be done in many ways, for exampl... | 0 | 2012-03-23T05:48:28Z | [
"python",
"circular-reference"
] |
How does Smalltalk (Pharo for example) compare to Python? | 1,508,256 | <p>I've seen some comparisons between <strong>Smalltalk and Ruby</strong> on the one hand and <strong>Ruby and Python</strong> on the other, but <strong>not between Python and Smalltalk</strong>. I'd especially like to know what the fundamental differences in Implementation, Syntax, Extensiabillity and Philosophy are. ... | 6 | 2009-10-02T08:09:36Z | 1,508,306 | <p>According to <a href="http://en.wikipedia.org/wiki/Dynamic%5Fdispatch" rel="nofollow">Wikipedia</a>'s page on dynamic method dispatch:</p>
<blockquote>
<p><strong>Smalltalk Implementation</strong></p>
<p>Smalltalk uses a type based message
dispatcher. Each instance has a single
type whose definition cont... | 1 | 2009-10-02T08:25:04Z | [
"python",
"comparison",
"language-features",
"smalltalk",
"language-comparisons"
] |
How does Smalltalk (Pharo for example) compare to Python? | 1,508,256 | <p>I've seen some comparisons between <strong>Smalltalk and Ruby</strong> on the one hand and <strong>Ruby and Python</strong> on the other, but <strong>not between Python and Smalltalk</strong>. I'd especially like to know what the fundamental differences in Implementation, Syntax, Extensiabillity and Philosophy are. ... | 6 | 2009-10-02T08:09:36Z | 1,508,309 | <p>I've been reading <a href="http://rads.stackoverflow.com/amzn/click/1430219483" rel="nofollow">coders at work</a> which is a really nice book full of interviews with top programmers. Anyhow, one of them is the inventor of smalltalk and he talks in length on his language and how it relates to python (he likes python ... | 2 | 2009-10-02T08:26:31Z | [
"python",
"comparison",
"language-features",
"smalltalk",
"language-comparisons"
] |
How does Smalltalk (Pharo for example) compare to Python? | 1,508,256 | <p>I've seen some comparisons between <strong>Smalltalk and Ruby</strong> on the one hand and <strong>Ruby and Python</strong> on the other, but <strong>not between Python and Smalltalk</strong>. I'd especially like to know what the fundamental differences in Implementation, Syntax, Extensiabillity and Philosophy are. ... | 6 | 2009-10-02T08:09:36Z | 1,508,312 | <p>Python certainly does have metaclasses.</p>
<p>Smalltalk has some unusual features:</p>
<ul>
<li>Has a rather simple syntax and only about 6 (!) keywords. Everything else (including defining new classes) is accomplished by calling methods (sending messages in Smalltalk). This allows you to create some DSL within t... | 7 | 2009-10-02T08:26:55Z | [
"python",
"comparison",
"language-features",
"smalltalk",
"language-comparisons"
] |
How does Smalltalk (Pharo for example) compare to Python? | 1,508,256 | <p>I've seen some comparisons between <strong>Smalltalk and Ruby</strong> on the one hand and <strong>Ruby and Python</strong> on the other, but <strong>not between Python and Smalltalk</strong>. I'd especially like to know what the fundamental differences in Implementation, Syntax, Extensiabillity and Philosophy are. ... | 6 | 2009-10-02T08:09:36Z | 1,510,402 | <blockquote>
<p>For example Python does not seem to
have Metaclasses.</p>
</blockquote>
<p>It sure does -- it just doesn't implicitly generate a new metaclass for every class: it uses the same metaclass as the parent class, or <code>type</code> by default. Python's design philosophy, aka "The Zen of Python", can ... | 9 | 2009-10-02T15:54:15Z | [
"python",
"comparison",
"language-features",
"smalltalk",
"language-comparisons"
] |
How does Smalltalk (Pharo for example) compare to Python? | 1,508,256 | <p>I've seen some comparisons between <strong>Smalltalk and Ruby</strong> on the one hand and <strong>Ruby and Python</strong> on the other, but <strong>not between Python and Smalltalk</strong>. I'd especially like to know what the fundamental differences in Implementation, Syntax, Extensiabillity and Philosophy are. ... | 6 | 2009-10-02T08:09:36Z | 1,883,218 | <blockquote>
<p>Smalltalk has no concept of
generators.</p>
</blockquote>
<p>True, but they can be implemented in most Smalltalk dialects from within the language. GNU Smalltalk comes with Generators as part of its <a href="http://smalltalk.gnu.org/faq/47" rel="nofollow">stream library</a>.</p>
| 2 | 2009-12-10T19:01:12Z | [
"python",
"comparison",
"language-features",
"smalltalk",
"language-comparisons"
] |
Why is it that my thumbnail PIL function won't work the 2nd time? | 1,508,355 | <blockquote>
<pre><code>def create_thumbnail(f, width=200, height=100):
im = Image.open(f)
im.thumbnail((width, height), Image.ANTIALIAS)
thumbnail_file = StringIO()
im.save(thumbnail_file, 'JPEG')
thumbnail_file.seek(0)
return thumbnail_file
</code></pre>
</blockquote>
<p>It seems that my erro... | 0 | 2009-10-02T08:42:22Z | 1,508,826 | <p>The only thing I can think of is that you are running on Windows, in which case <code>Image.open()</code> will open a file handler but does not close it. (That behaviour does not occur on Linux/Unix - the file is closed by the end of your code, and it doesn't matter if it isn't anyway).</p>
| 2 | 2009-10-02T10:43:59Z | [
"python",
"python-imaging-library"
] |
Mod_python produces no output | 1,508,406 | <p>Just installed and configured mod_python 3.2.8 on a CentOS 5 (Apache 2.2.3) server with Python 2.4.3. It is loaded fine by Apache.</p>
<p>I activated the mpinfo test page and it works. So I wrote a simple "Hello World" with the following code:</p>
<pre><code>from mod_python import apache
def handler(req):
req... | 1 | 2009-10-02T08:51:43Z | 1,508,747 | <p>Don't use <code>mod_python</code>. </p>
<p>A common mistake is to take <code>mod_python</code> as "<em><code>mod_php</code>, but for python</em>" and that is <strong>not true</strong>. <code>mod_python</code> is more suited to writing apache extensions, not web applications. </p>
<p>The <a href="http://www.python.... | 2 | 2009-10-02T10:18:17Z | [
"python",
"apache",
"mod-python"
] |
Mod_python produces no output | 1,508,406 | <p>Just installed and configured mod_python 3.2.8 on a CentOS 5 (Apache 2.2.3) server with Python 2.4.3. It is loaded fine by Apache.</p>
<p>I activated the mpinfo test page and it works. So I wrote a simple "Hello World" with the following code:</p>
<pre><code>from mod_python import apache
def handler(req):
req... | 1 | 2009-10-02T08:51:43Z | 1,509,008 | <p>I make a complete new answer for clarity...</p>
<p>I decided to install mod_wsgi instead. So I've set it up and when I go to my testfile I just see the page source. I haven't been spending any time on finding the issue yet, so I'll get back to you when I either solve the problem or decide that I need more help :)</... | 0 | 2009-10-02T11:35:19Z | [
"python",
"apache",
"mod-python"
] |
Mod_python produces no output | 1,508,406 | <p>Just installed and configured mod_python 3.2.8 on a CentOS 5 (Apache 2.2.3) server with Python 2.4.3. It is loaded fine by Apache.</p>
<p>I activated the mpinfo test page and it works. So I wrote a simple "Hello World" with the following code:</p>
<pre><code>from mod_python import apache
def handler(req):
req... | 1 | 2009-10-02T08:51:43Z | 1,512,233 | <p>Your original problem is that mod_python.cgihandler is being called to handle the request. This means your Python script file is being interpreted as a CGI script. Thus, no wonder it doesn't return anything.</p>
<p>You likely have conflicting definition in your Apache configuration which is enabling the mod_python.... | 1 | 2009-10-02T23:08:41Z | [
"python",
"apache",
"mod-python"
] |
fast string modification in python | 1,508,464 | <p>This is partially a theoretical question:</p>
<p>I have a string (say UTF-8), and I need to modify it so that each character (not byte) becomes 2 characters, for instance:</p>
<pre><code>"Nissim" becomes "N-i-s-s-i-m-"
"01234" becomes "0a1b2c3d4e"
</code></pre>
<p>and so on.
I would suspect that naive concatena... | 4 | 2009-10-02T09:06:17Z | 1,508,508 | <p>have you tested how slow it is or how fast you need, i think something like this will be fast enough</p>
<pre><code>s = u"\u0960\u0961"
ss = ''.join(sum(map(list,zip(s,"anurag")),[]))
</code></pre>
<p>So try with simplest and if it doesn't suffice then try to improve upon it, C module should be last option</p>
<p... | 1 | 2009-10-02T09:15:59Z | [
"python",
"string"
] |
fast string modification in python | 1,508,464 | <p>This is partially a theoretical question:</p>
<p>I have a string (say UTF-8), and I need to modify it so that each character (not byte) becomes 2 characters, for instance:</p>
<pre><code>"Nissim" becomes "N-i-s-s-i-m-"
"01234" becomes "0a1b2c3d4e"
</code></pre>
<p>and so on.
I would suspect that naive concatena... | 4 | 2009-10-02T09:06:17Z | 1,508,550 | <p>Try to build the result with the <a href="http://docs.python.org/library/re.html" rel="nofollow"><code>re</code> module</a>. It will do the nasty concatenation under the hood, so performance should be OK. Example:</p>
<pre><code> import re
re.sub(r'(.)', r'\1-', u'Nissim')
count = 1
def repl(m):
global cou... | 2 | 2009-10-02T09:23:34Z | [
"python",
"string"
] |
fast string modification in python | 1,508,464 | <p>This is partially a theoretical question:</p>
<p>I have a string (say UTF-8), and I need to modify it so that each character (not byte) becomes 2 characters, for instance:</p>
<pre><code>"Nissim" becomes "N-i-s-s-i-m-"
"01234" becomes "0a1b2c3d4e"
</code></pre>
<p>and so on.
I would suspect that naive concatena... | 4 | 2009-10-02T09:06:17Z | 1,508,551 | <p>this might be a python effective solution:</p>
<pre><code>s1="Nissim"
s2="------"
s3=''.join([''.join(list(x)) for x in zip(s1,s2)])
</code></pre>
| 2 | 2009-10-02T09:24:39Z | [
"python",
"string"
] |
fast string modification in python | 1,508,464 | <p>This is partially a theoretical question:</p>
<p>I have a string (say UTF-8), and I need to modify it so that each character (not byte) becomes 2 characters, for instance:</p>
<pre><code>"Nissim" becomes "N-i-s-s-i-m-"
"01234" becomes "0a1b2c3d4e"
</code></pre>
<p>and so on.
I would suspect that naive concatena... | 4 | 2009-10-02T09:06:17Z | 1,508,858 | <p>Use Reduce.</p>
<pre><code>>>> str = "Nissim"
>>> reduce(lambda x, y : x+y+'-', str, '')
'N-i-s-s-i-m-'
</code></pre>
<p>The same with numbers too as long as you know which char maps to which. [dict can be handy]</p>
<pre><code>>>> mapper = dict([(repr(i), chr(i+ord('a'))) for i in rang... | 0 | 2009-10-02T10:50:55Z | [
"python",
"string"
] |
fast string modification in python | 1,508,464 | <p>This is partially a theoretical question:</p>
<p>I have a string (say UTF-8), and I need to modify it so that each character (not byte) becomes 2 characters, for instance:</p>
<pre><code>"Nissim" becomes "N-i-s-s-i-m-"
"01234" becomes "0a1b2c3d4e"
</code></pre>
<p>and so on.
I would suspect that naive concatena... | 4 | 2009-10-02T09:06:17Z | 1,509,659 | <p>here are my timings. Note, it's py3.1</p>
<pre><code>>>> s1
'Nissim'
>>> s2 = '-' * len(s1)
>>> timeit.timeit("''.join(i+j for i, j in zip(s1, s2))", "from __main__ import s1, s2")
3.5249209707199043
>>> timeit.timeit("''.join(sum(map(list,zip(s1,s2)),[]))", "from __main__ import... | 1 | 2009-10-02T13:55:54Z | [
"python",
"string"
] |
fast string modification in python | 1,508,464 | <p>This is partially a theoretical question:</p>
<p>I have a string (say UTF-8), and I need to modify it so that each character (not byte) becomes 2 characters, for instance:</p>
<pre><code>"Nissim" becomes "N-i-s-s-i-m-"
"01234" becomes "0a1b2c3d4e"
</code></pre>
<p>and so on.
I would suspect that naive concatena... | 4 | 2009-10-02T09:06:17Z | 1,510,030 | <pre><code>string="â¢Â¡â¢Â©â¬"
unicode(string,"utf-8")
s2='-'*len(s1)
''.join(sum(map(list,zip(s1,s2)),[])).encode("utf-8")
</code></pre>
| 0 | 2009-10-02T14:54:20Z | [
"python",
"string"
] |
fast string modification in python | 1,508,464 | <p>This is partially a theoretical question:</p>
<p>I have a string (say UTF-8), and I need to modify it so that each character (not byte) becomes 2 characters, for instance:</p>
<pre><code>"Nissim" becomes "N-i-s-s-i-m-"
"01234" becomes "0a1b2c3d4e"
</code></pre>
<p>and so on.
I would suspect that naive concatena... | 4 | 2009-10-02T09:06:17Z | 1,510,511 | <p>@gnosis, beware of all the well-intentioned responders saying you should measure the times: yes, you should (because programmers' instincts are often off-base about performance), <strong>but</strong> measuring a single case, as in all the <code>timeit</code> examples proffered so far, misses a crucial consideration ... | 9 | 2009-10-02T16:12:59Z | [
"python",
"string"
] |
Log exception with traceback | 1,508,467 | <p>How can I log my Python errors?</p>
<pre><code>try:
do_something()
except:
# How can I log my exception here, complete with its traceback?
</code></pre>
| 56 | 2009-10-02T09:07:15Z | 1,508,485 | <p>Heres a simple example taken from the <a href="http://docs.python.org/library/logging.html" rel="nofollow">python 2.6 documentation</a>:</p>
<pre><code>import logging
LOG_FILENAME = '/tmp/logging_example.out'
logging.basicConfig(filename=LOG_FILENAME,level=logging.DEBUG,)
logging.debug('This message should go to t... | -1 | 2009-10-02T09:10:58Z | [
"python",
"exception",
"logging",
"error-handling"
] |
Log exception with traceback | 1,508,467 | <p>How can I log my Python errors?</p>
<pre><code>try:
do_something()
except:
# How can I log my exception here, complete with its traceback?
</code></pre>
| 56 | 2009-10-02T09:07:15Z | 1,508,761 | <p>Use <a href="https://docs.python.org/library/logging.html#logging.exception"><code>logging.exception</code></a> from with an <code>except:</code> handler to log the current exception, prepended with a message.</p>
<pre><code>import logging
LOG_FILENAME = '/tmp/logging_example.out'
logging.basicConfig(filename=LOG_F... | 84 | 2009-10-02T10:24:09Z | [
"python",
"exception",
"logging",
"error-handling"
] |
Log exception with traceback | 1,508,467 | <p>How can I log my Python errors?</p>
<pre><code>try:
do_something()
except:
# How can I log my exception here, complete with its traceback?
</code></pre>
| 56 | 2009-10-02T09:07:15Z | 9,929,970 | <p>My job recently tasked me with logging all the tracebacks/exceptions from our application. I tried numerous techniques that others had posted online such as the one above but settled on a different approach. Overriding <code>traceback.print_exception</code>. </p>
<p>I have a write up at <a href="http://www.bbarrows... | 31 | 2012-03-29T16:58:57Z | [
"python",
"exception",
"logging",
"error-handling"
] |
Log exception with traceback | 1,508,467 | <p>How can I log my Python errors?</p>
<pre><code>try:
do_something()
except:
# How can I log my exception here, complete with its traceback?
</code></pre>
| 56 | 2009-10-02T09:07:15Z | 11,844,359 | <p>maybe not as stylish, but easier:</p>
<pre><code>#!/bin/bash
log="/var/log/yourlog"
/path/to/your/script.py 2>&1 | (while read; do echo "$REPLY" >> $log; done)
</code></pre>
| -1 | 2012-08-07T10:52:20Z | [
"python",
"exception",
"logging",
"error-handling"
] |
Log exception with traceback | 1,508,467 | <p>How can I log my Python errors?</p>
<pre><code>try:
do_something()
except:
# How can I log my exception here, complete with its traceback?
</code></pre>
| 56 | 2009-10-02T09:07:15Z | 29,556,246 | <p>Use exc_info options may be better, remains warning or error title: </p>
<pre><code>try:
# coode in here
except Exception, e:
logging.error(e, exc_info=True)
</code></pre>
| 16 | 2015-04-10T08:00:52Z | [
"python",
"exception",
"logging",
"error-handling"
] |
Log exception with traceback | 1,508,467 | <p>How can I log my Python errors?</p>
<pre><code>try:
do_something()
except:
# How can I log my exception here, complete with its traceback?
</code></pre>
| 56 | 2009-10-02T09:07:15Z | 36,633,733 | <p>Uncaught exception messages go to STDERR, so instead of implementing your logging in Python itself you could send STDERR to a file using whatever shell you're using to run your Python script. In a Bash script, you can do this with output redirection, as <a href="http://tldp.org/HOWTO/Bash-Prog-Intro-HOWTO-3.html" re... | 0 | 2016-04-14T20:50:28Z | [
"python",
"exception",
"logging",
"error-handling"
] |
Log exception with traceback | 1,508,467 | <p>How can I log my Python errors?</p>
<pre><code>try:
do_something()
except:
# How can I log my exception here, complete with its traceback?
</code></pre>
| 56 | 2009-10-02T09:07:15Z | 36,635,362 | <p>You can log all uncaught exceptions on the main thread by assigning a handler to <a href="https://docs.python.org/library/sys.html#sys.excepthook" rel="nofollow"><code>sys.excepthook</code></a>, perhaps using the <a href="https://docs.python.org/3/library/logging.html#logging.debug" rel="nofollow"><code>exc_info</co... | 0 | 2016-04-14T22:51:04Z | [
"python",
"exception",
"logging",
"error-handling"
] |
Is there anything like Project Sprouts but implemented in Python? | 1,508,743 | <p>Since our entire build system is written in Python, I'm wondering if there is anything like <a href="http://projectsprouts.org/" rel="nofollow">Sprouts</a> that I could leverage to integrate Flex builds / development into our codebase? </p>
<p>Sprouts looks nice and all, but I don't want to introduce another build... | 1 | 2009-10-02T10:17:56Z | 1,509,678 | <p>No, I don't believe there is anything similar for Python.</p>
<p>It looks like Sprouts is made up of a lot of <a href="http://rake.rubyforge.org/" rel="nofollow">Rake</a> build files, so you could try to roll your own build system in Python using tools like <a href="http://www.blueskyonmars.com/projects/paver/" rel... | 3 | 2009-10-02T13:58:17Z | [
"python",
"ruby",
"flex"
] |
python 2.6 or python 3.1? | 1,508,906 | <p>I am about to learn Python and was wondering what is recommended, learning python 2.6 or 3.1? (any tips on learning python is welcomed as well =)</p>
<p><hr /></p>
<p>edit: Is the difference really big between the two? If I learn python 2 will i have trouble learning python 3?</p>
| 6 | 2009-10-02T11:03:38Z | 1,508,919 | <p>You really want to stick with the later version. Python 2.6 and the rest of the 2.x versions that come out are really for compatibility. However, this is not true if you want to use a framework like Django right away because it is incompatible with the 3.x series at the moment.</p>
<p>A tip for learning Python? Jus... | 5 | 2009-10-02T11:08:53Z | [
"python"
] |
python 2.6 or python 3.1? | 1,508,906 | <p>I am about to learn Python and was wondering what is recommended, learning python 2.6 or 3.1? (any tips on learning python is welcomed as well =)</p>
<p><hr /></p>
<p>edit: Is the difference really big between the two? If I learn python 2 will i have trouble learning python 3?</p>
| 6 | 2009-10-02T11:03:38Z | 1,508,921 | <p>If you're looking to learn python: <a href="http://diveintopython3.org/" rel="nofollow">http://diveintopython3.org/</a> was recently finished and can be read completely free online or you can buy the hardcopy. It's a great tutorial and introduction to the language.</p>
| 4 | 2009-10-02T11:10:34Z | [
"python"
] |
python 2.6 or python 3.1? | 1,508,906 | <p>I am about to learn Python and was wondering what is recommended, learning python 2.6 or 3.1? (any tips on learning python is welcomed as well =)</p>
<p><hr /></p>
<p>edit: Is the difference really big between the two? If I learn python 2 will i have trouble learning python 3?</p>
| 6 | 2009-10-02T11:03:38Z | 1,508,929 | <p>I would go with 2.6 for a couple of reasons.</p>
<ol>
<li><p>There's so much more material (books, examples, etc) based on 2.6. Some things might not work under 3.x, and you'll be able to get some good second-hand deals on 2.4-6 books.</p></li>
<li><p>The majority of libraries you'll want to pull in are still aimed... | 10 | 2009-10-02T11:12:05Z | [
"python"
] |
python 2.6 or python 3.1? | 1,508,906 | <p>I am about to learn Python and was wondering what is recommended, learning python 2.6 or 3.1? (any tips on learning python is welcomed as well =)</p>
<p><hr /></p>
<p>edit: Is the difference really big between the two? If I learn python 2 will i have trouble learning python 3?</p>
| 6 | 2009-10-02T11:03:38Z | 1,508,931 | <p>If you want to use existing libraries and modules written in C/C++ or use SWIG, you'll have to use python2, otherwise I don't really see a reason to stick with python2.</p>
| -1 | 2009-10-02T11:12:56Z | [
"python"
] |
python 2.6 or python 3.1? | 1,508,906 | <p>I am about to learn Python and was wondering what is recommended, learning python 2.6 or 3.1? (any tips on learning python is welcomed as well =)</p>
<p><hr /></p>
<p>edit: Is the difference really big between the two? If I learn python 2 will i have trouble learning python 3?</p>
| 6 | 2009-10-02T11:03:38Z | 1,509,018 | <ul>
<li>If you're looking to <strong>develop software
right now</strong> stick with Python 2.6. </li>
<li>If
you're looking to <strong>learn the language
and experiment</strong> go with Python
3.1.</li>
</ul>
<p>Python 3.1 doesn't have the same library support (yet!) as Python 2.6, so you'll encounter difficulties wo... | 15 | 2009-10-02T11:37:37Z | [
"python"
] |
python 2.6 or python 3.1? | 1,508,906 | <p>I am about to learn Python and was wondering what is recommended, learning python 2.6 or 3.1? (any tips on learning python is welcomed as well =)</p>
<p><hr /></p>
<p>edit: Is the difference really big between the two? If I learn python 2 will i have trouble learning python 3?</p>
| 6 | 2009-10-02T11:03:38Z | 1,509,308 | <p>You would want to go with 2.6 today.</p>
<p>Why? Because there is no library support for 3.1. We've just finished porting setuptools (under the name Distribute) to Python 3, so hopefully library support for Python 3 will increase dramatically during the next year, but it's not there yet.</p>
<p>And it's not so har... | 5 | 2009-10-02T12:47:33Z | [
"python"
] |
python 2.6 or python 3.1? | 1,508,906 | <p>I am about to learn Python and was wondering what is recommended, learning python 2.6 or 3.1? (any tips on learning python is welcomed as well =)</p>
<p><hr /></p>
<p>edit: Is the difference really big between the two? If I learn python 2 will i have trouble learning python 3?</p>
| 6 | 2009-10-02T11:03:38Z | 1,509,378 | <p>As for tips on learning Python, I would work through the main tutorial (<a href="http://docs.python.org/3.1/tutorial/" rel="nofollow">http://docs.python.org/3.1/tutorial/</a>) and then explore the Beginner's Guide. O'Reilly's Learning Python is pretty handy if you prefer using a book.</p>
| 0 | 2009-10-02T13:06:25Z | [
"python"
] |
Parsing large pseudo-xml files in python | 1,508,938 | <p>I'm trying to parse* a large file (> 5GB) of structured markup data. The data format is essentially XML but there is no explicit root element. What's the most efficient way to do that?</p>
<p>The problem with SAX parsers is that they require a root element, so either I've to add a pseudo element to the data stream ... | 4 | 2009-10-02T11:15:49Z | 1,508,976 | <p><a href="http://docs.python.org/library/xml.sax.html" rel="nofollow">http://docs.python.org/library/xml.sax.html</a></p>
<p>Note, that you can pass a 'stream' object to <code>xml.sax.parse</code>. This means you can probably pass any object that has file-like methods (like <code>read</code>) to the <code>parse</cod... | 10 | 2009-10-02T11:26:55Z | [
"python",
"xml"
] |
Parsing large pseudo-xml files in python | 1,508,938 | <p>I'm trying to parse* a large file (> 5GB) of structured markup data. The data format is essentially XML but there is no explicit root element. What's the most efficient way to do that?</p>
<p>The problem with SAX parsers is that they require a root element, so either I've to add a pseudo element to the data stream ... | 4 | 2009-10-02T11:15:49Z | 1,509,024 | <p>The quick and dirty answer would be adding a root element (as String) so it would be a valid XML.</p>
<p>Regards.</p>
| 1 | 2009-10-02T11:39:00Z | [
"python",
"xml"
] |
Parsing large pseudo-xml files in python | 1,508,938 | <p>I'm trying to parse* a large file (> 5GB) of structured markup data. The data format is essentially XML but there is no explicit root element. What's the most efficient way to do that?</p>
<p>The problem with SAX parsers is that they require a root element, so either I've to add a pseudo element to the data stream ... | 4 | 2009-10-02T11:15:49Z | 1,510,957 | <p>Add root element and use SAX, STax or VTD-XML ..</p>
| 1 | 2009-10-02T17:49:17Z | [
"python",
"xml"
] |
Parsing large pseudo-xml files in python | 1,508,938 | <p>I'm trying to parse* a large file (> 5GB) of structured markup data. The data format is essentially XML but there is no explicit root element. What's the most efficient way to do that?</p>
<p>The problem with SAX parsers is that they require a root element, so either I've to add a pseudo element to the data stream ... | 4 | 2009-10-02T11:15:49Z | 1,511,070 | <p>xml.parsers.expat -- Fast XML parsing using Expat
The xml.parsers.expat module is a Python interface to the Expat non-validating XML parser. The module provides a single extension type, xmlparser, that represents the current state of an XML parser. After an xmlparser object has been created, various attributes of th... | 0 | 2009-10-02T18:17:01Z | [
"python",
"xml"
] |
KeyError with dict.fromkeys() and dict-like object | 1,509,153 | <p>In Python, you can use a dictionary as the first argument to <code>dict.fromkeys()</code>, e.g.:</p>
<pre><code>In [1]: d = {'a': 1, 'b': 2}
In [2]: dict.fromkeys(d)
Out[2]: {'a': None, 'b': None}
</code></pre>
<p>I tried to do the same with a dict-like object, but that always raises a <code>KeyError</code>, e.g.... | 3 | 2009-10-02T12:09:48Z | 1,509,183 | <p>instance of <code>SemiDict</code> is not a sequence. I'd imagine the most obvious solution would be to inherit from <code>dict</code>, why don't you do it?</p>
| 1 | 2009-10-02T12:14:51Z | [
"python",
"dictionary"
] |
KeyError with dict.fromkeys() and dict-like object | 1,509,153 | <p>In Python, you can use a dictionary as the first argument to <code>dict.fromkeys()</code>, e.g.:</p>
<pre><code>In [1]: d = {'a': 1, 'b': 2}
In [2]: dict.fromkeys(d)
Out[2]: {'a': None, 'b': None}
</code></pre>
<p>I tried to do the same with a dict-like object, but that always raises a <code>KeyError</code>, e.g.... | 3 | 2009-10-02T12:09:48Z | 1,509,208 | <p>To create the dict, <code>fromkeys</code> iterates over its argument. So it must be an iterator. One way to make it work is to add an <code>__iter__</code> method to your <code>dict</code>-like:</p>
<pre><code>def __iter__(self):
return iter(self.d)
</code></pre>
| 6 | 2009-10-02T12:23:33Z | [
"python",
"dictionary"
] |
How to search XPath inside Python ClientForm object? | 1,509,404 | <p>I've got a form, returned by Python mechanize Browser and got via forms() method. How can I perform XPath search inside form node, that is, among descendant nodes of the HTML form node? TIA</p>
<p>Upd:
How to save html code of the form?</p>
| 0 | 2009-10-02T13:10:26Z | 1,509,434 | <p>By parsing the browser contents with lxml, which has xpath support.</p>
| 1 | 2009-10-02T13:15:43Z | [
"python",
"mechanize"
] |
Zero results in Query/GqlQuery | 1,509,407 | <p>How do I know if the results of my query either using the Query interface or the GqlQuery interface returned zero results? Would using <code>.get()</code> on zero results produce an error? If yes, what's the best way to handle it?</p>
| 2 | 2009-10-02T13:11:01Z | 1,509,421 | <p>when doing a get() if there are no results you will have an object containing None</p>
<p>I normally do </p>
<pre><code>result = query.get()
if result is None:
#do the following
</code></pre>
<p>or if you want to check that its not none then</p>
<pre><code>if result is not None:
#do the following
</code></pr... | 5 | 2009-10-02T13:14:09Z | [
"python",
"google-app-engine",
"gql",
"gqlquery",
"queryinterface"
] |
Zero results in Query/GqlQuery | 1,509,407 | <p>How do I know if the results of my query either using the Query interface or the GqlQuery interface returned zero results? Would using <code>.get()</code> on zero results produce an error? If yes, what's the best way to handle it?</p>
| 2 | 2009-10-02T13:11:01Z | 1,543,842 | <p>if a query returns no results, <code>fetch()</code> returns an empty list <code>[]</code> and <code>get()</code> returns <code>None</code></p>
<p>in either case you can use the following:</p>
<pre><code>if result:
#handle the result
else:
#no results were returned
</code></pre>
| 2 | 2009-10-09T13:41:57Z | [
"python",
"google-app-engine",
"gql",
"gqlquery",
"queryinterface"
] |
RESTful APIs in Django for GETTING information from a server | 1,509,621 | <p>Any idea of a RESTful APIs in Django for GETTING information from a server?</p>
<p>What I want to do is fetch the errors from the server into a database. </p>
<p>For example:</p>
<p>The Live server has examplewebsite.com, any thing goes wrong with that website should POST the error, where the Django app GET the e... | 1 | 2009-10-02T13:50:19Z | 1,509,650 | <p>Are you just trying to fetch data over HTTP? If so, what about <a href="http://docs.python.org/library/urllib2.html" rel="nofollow">urllib2</a>?</p>
| 0 | 2009-10-02T13:54:35Z | [
"python",
"django",
"rest",
"api"
] |
RESTful APIs in Django for GETTING information from a server | 1,509,621 | <p>Any idea of a RESTful APIs in Django for GETTING information from a server?</p>
<p>What I want to do is fetch the errors from the server into a database. </p>
<p>For example:</p>
<p>The Live server has examplewebsite.com, any thing goes wrong with that website should POST the error, where the Django app GET the e... | 1 | 2009-10-02T13:50:19Z | 1,510,582 | <p>Take a look at <a href="http://bitbucket.org/jespern/django-piston/wiki/Home" rel="nofollow">Piston</a>, which calls itself a 'mini-framework for Django for creating RESTful APIs.'</p>
| 2 | 2009-10-02T16:24:06Z | [
"python",
"django",
"rest",
"api"
] |
Catch contents of PHP session under Apache with Python (mod_wsgi)? | 1,509,641 | <p>Is there a way to catch the contents of the PHP session variable <code>$_SESSION['user_id']</code> with a <code>mod_wsgi</code> Python script? I'm running a script in the background that will decide whether or not the user may proceed to view the document.</p>
<p>I would like to do something like this:</p>
<pre><c... | 0 | 2009-10-02T13:53:44Z | 1,509,778 | <p>If it's possible, it's not easy; apache stores session variables in files in a special format.</p>
<p>Your best option might be to write a php page that prints all session variables. (Hard-code it to only serve to localhost.) Open the url to that page from within your python script. Add a header to the url reques... | 3 | 2009-10-02T14:14:07Z | [
"python",
"apache",
"mod-wsgi"
] |
Catch contents of PHP session under Apache with Python (mod_wsgi)? | 1,509,641 | <p>Is there a way to catch the contents of the PHP session variable <code>$_SESSION['user_id']</code> with a <code>mod_wsgi</code> Python script? I'm running a script in the background that will decide whether or not the user may proceed to view the document.</p>
<p>I would like to do something like this:</p>
<pre><c... | 0 | 2009-10-02T13:53:44Z | 1,509,807 | <p>please don't do this:</p>
<pre><code>if allow_access:
return True
else:
return False
</code></pre>
<p>when you can do: <code>return allow_access</code>.</p>
| 2 | 2009-10-02T14:19:11Z | [
"python",
"apache",
"mod-wsgi"
] |
Compound UniqueConstraint with a function | 1,510,018 | <p><br />
A quick SQLAlchemy question... </p>
<p>I have a class "Document" with attributes "Number" and "Date". I need to ensure that there's no duplicated number <em>for the same year</em>, is
there a way to have a UniqueConstraint on "Number + year(Date)"? Should I use a unique Index instead? How would I declare t... | 3 | 2009-10-02T14:52:57Z | 1,510,137 | <p>I'm pretty sure that unique constraints can only be applied on columns that already have data in them, and not on runtime-calculated expressions. Hence, you would need to create an extra column which contains the <code>year</code> part of your <code>date</code>, over which you could create a unique constraint togeth... | 0 | 2009-10-02T15:08:51Z | [
"python",
"sqlalchemy",
"constraints"
] |
Compound UniqueConstraint with a function | 1,510,018 | <p><br />
A quick SQLAlchemy question... </p>
<p>I have a class "Document" with attributes "Number" and "Date". I need to ensure that there's no duplicated number <em>for the same year</em>, is
there a way to have a UniqueConstraint on "Number + year(Date)"? Should I use a unique Index instead? How would I declare t... | 3 | 2009-10-02T14:52:57Z | 1,517,153 | <p>You should use a functional unique index to apply this constraint. Unfortunately the database generic database independent schema definition machinery in SQLAlchemy doesn't abstract functional indexes yet. You'll have to use the DDL construct to register custom schema definition clauses. If you are using the declara... | 3 | 2009-10-04T19:11:39Z | [
"python",
"sqlalchemy",
"constraints"
] |
Is there any framework like RoR on Python 3000? | 1,510,084 | <p>One of the feature I like in RoR is the db management, it can hide all the sql statement, also, it is very easy to change different db in RoR, is there any similar framework in Python 3000?</p>
| 1 | 2009-10-02T15:01:41Z | 1,510,161 | <p>There's Django but <a href="http://docs.djangoproject.com/en/dev/faq/install/#can-i-use-django-with-python-3-0" rel="nofollow">it works with Python 2.3+ only for now</a>.</p>
| -1 | 2009-10-02T15:13:40Z | [
"python",
"ruby-on-rails",
"frameworks",
"python-3.x"
] |
Is there any framework like RoR on Python 3000? | 1,510,084 | <p>One of the feature I like in RoR is the db management, it can hide all the sql statement, also, it is very easy to change different db in RoR, is there any similar framework in Python 3000?</p>
| 1 | 2009-10-02T15:01:41Z | 1,510,214 | <p>This answer was awfully outdated. The current state of afairs is:</p>
<ul>
<li><a href="https://www.djangoproject.com/weblog/2012/mar/13/py3k/" rel="nofollow">Django is close to supporting Python 3</a></li>
<li><a href="http://www.cherrypy.org/" rel="nofollow">CherryPy</a> <a href="http://www.cherrypy.org/wiki/What... | 4 | 2009-10-02T15:20:56Z | [
"python",
"ruby-on-rails",
"frameworks",
"python-3.x"
] |
Is there any framework like RoR on Python 3000? | 1,510,084 | <p>One of the feature I like in RoR is the db management, it can hide all the sql statement, also, it is very easy to change different db in RoR, is there any similar framework in Python 3000?</p>
| 1 | 2009-10-02T15:01:41Z | 1,510,218 | <p>Python 3 is not ready for practical use, because there is not yet enough libraries that have been updated to support Python 3. So the answer is: No.</p>
<p>But there are LOADS of them on Python 2. Tens, at least.</p>
<p>Django, Turbogears, BFG and of course the old man of the game: Zope. To tell which is best for ... | 0 | 2009-10-02T15:21:04Z | [
"python",
"ruby-on-rails",
"frameworks",
"python-3.x"
] |
Is there any framework like RoR on Python 3000? | 1,510,084 | <p>One of the feature I like in RoR is the db management, it can hide all the sql statement, also, it is very easy to change different db in RoR, is there any similar framework in Python 3000?</p>
| 1 | 2009-10-02T15:01:41Z | 1,510,491 | <p>Python 3 isn't ready for web applications right now. The WSGI 1.0 specification isn't suitable for Py3k and the related standard libraries are 2to3 hacks that don't work consistently faced with bytes vs. unicode. It's a real mess.</p>
<p>WEB-SIG are bashing out proposals for a WSGI revision; hopefully it can move f... | 1 | 2009-10-02T16:08:15Z | [
"python",
"ruby-on-rails",
"frameworks",
"python-3.x"
] |
Is there any framework like RoR on Python 3000? | 1,510,084 | <p>One of the feature I like in RoR is the db management, it can hide all the sql statement, also, it is very easy to change different db in RoR, is there any similar framework in Python 3000?</p>
| 1 | 2009-10-02T15:01:41Z | 1,512,245 | <p>I believe CherryPy is on the verge of being released for Python 3.X.</p>
| 2 | 2009-10-02T23:11:49Z | [
"python",
"ruby-on-rails",
"frameworks",
"python-3.x"
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.