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
Any gotchas using unicode_literals in Python 2.6?
809,796
<p>We've already gotten our code base running under Python 2.6. In order to prepare for Python 3.0, we've started adding:</p> <pre> from __future__ import unicode_literals </pre> <p>into our <code>.py</code> files (as we modify them). I'm wondering if anyone else has been doing this and has run into any non-obvious...
91
2009-05-01T00:56:37Z
3,987,102
<p>Also take into account that <code>unicode_literal</code> will affect <code>eval()</code> but not <code>repr()</code> (an asymmetric behavior which imho is a bug), i.e. <code>eval(repr(b'\xa4'))</code> won't be equal to <code>b'\xa4'</code> (as it would with Python 3).</p> <p>Ideally, the following code would be an ...
8
2010-10-21T11:51:19Z
[ "python", "unicode", "python-2.6", "unicode-literals" ]
Any gotchas using unicode_literals in Python 2.6?
809,796
<p>We've already gotten our code base running under Python 2.6. In order to prepare for Python 3.0, we've started adding:</p> <pre> from __future__ import unicode_literals </pre> <p>into our <code>.py</code> files (as we modify them). I'm wondering if anyone else has been doing this and has run into any non-obvious...
91
2009-05-01T00:56:37Z
18,872,703
<p>There are more.</p> <p>There are libraries and builtins that expect strings that don't tolerate unicode.</p> <p>Two examples:</p> <p>builtin:</p> <pre><code>myenum = type('Enum', (), enum) </code></pre> <p>(slightly esotic) doesn't work with unicode_literals: type() expects a string.</p> <p>library:</p> <pre>...
5
2013-09-18T12:48:43Z
[ "python", "unicode", "python-2.6", "unicode-literals" ]
How to work with threads in pygtk
809,818
<p>I have a problem with threads in pygtk. My application consist of a program that downloads pictures off the internet and then displays it with pygtk. The problem is that in order to do this and keep the GUI responsive, I need to use threads. </p> <p>So I got into a callback after the user clicked on the button "Dow...
5
2009-05-01T01:05:26Z
810,854
<p>Your question is a bit vague, and without a reference to your actual code it's hard to speculate what you're doing wrong.</p> <p>So I'll give you some pointers to read, then speculate wildly based on experience.</p> <p>First of all, you seem to think that you can only keep the GUI responsive by using threads. Thi...
12
2009-05-01T10:03:37Z
[ "python", "multithreading", "pygtk" ]
How to work with threads in pygtk
809,818
<p>I have a problem with threads in pygtk. My application consist of a program that downloads pictures off the internet and then displays it with pygtk. The problem is that in order to do this and keep the GUI responsive, I need to use threads. </p> <p>So I got into a callback after the user clicked on the button "Dow...
5
2009-05-01T01:05:26Z
900,787
<p>You can use gtk.gdk.threads_init() in order to allow any thread modify the UI with the respecting gtk.gdk.threads_enter() and gtk.gdk.theads_leave() lock, but, the problem with this is that doesn't work well on windows. I have tested it on Linux and performs quite well, but I had no luck making this to work over win...
1
2009-05-23T03:32:33Z
[ "python", "multithreading", "pygtk" ]
Python regex for finding contents of MediaWiki markup links
809,837
<p>If I have some xml containing things like the following mediawiki markup:</p> <blockquote> <p>" ...collected in the 12th century, of which [[Alexander the Great]] was the hero, and in which he was represented, somewhat like the British [[King Arthur|Arthur]]"</p> </blockquote> <p>what would be the appro...
3
2009-05-01T01:11:52Z
809,858
<p>Here is an example</p> <pre><code>import re pattern = re.compile(r"\[\[([\w \|]+)\]\]") text = "blah blah [[Alexander of Paris|poet named Alexander]] bldfkas" results = pattern.findall(text) output = [] for link in results: output.append(link.split("|")[0]) # outputs ['Alexander of Paris'] </code></pre> <p>...
5
2009-05-01T01:20:08Z
[ "python", "regex", "mediawiki" ]
Python regex for finding contents of MediaWiki markup links
809,837
<p>If I have some xml containing things like the following mediawiki markup:</p> <blockquote> <p>" ...collected in the 12th century, of which [[Alexander the Great]] was the hero, and in which he was represented, somewhat like the British [[King Arthur|Arthur]]"</p> </blockquote> <p>what would be the appro...
3
2009-05-01T01:11:52Z
809,900
<p><strong>RegExp:</strong> \w+( \w+)+(?=]])</p> <p><strong>input</strong></p> <p>[[Alexander of Paris|poet named Alexander]]</p> <p><strong>output</strong></p> <p>poet named Alexander</p> <p><strong>input</strong></p> <p>[[Alexander of Paris]]</p> <p><strong>output</strong></p> <p>Alexander of Paris</p>
1
2009-05-01T01:52:23Z
[ "python", "regex", "mediawiki" ]
Python regex for finding contents of MediaWiki markup links
809,837
<p>If I have some xml containing things like the following mediawiki markup:</p> <blockquote> <p>" ...collected in the 12th century, of which [[Alexander the Great]] was the hero, and in which he was represented, somewhat like the British [[King Arthur|Arthur]]"</p> </blockquote> <p>what would be the appro...
3
2009-05-01T01:11:52Z
809,908
<pre><code>import re pattern = re.compile(r"\[\[([\w ]+)(?:\||\]\])") text = "of which [[Alexander the Great]] was somewhat like [[King Arthur|Arthur]]" results = pattern.findall(text) print results </code></pre> <p>Would give the output</p> <pre><code>["Alexander the Great", "King Arthur"] </code></pre>
1
2009-05-01T01:57:28Z
[ "python", "regex", "mediawiki" ]
Python regex for finding contents of MediaWiki markup links
809,837
<p>If I have some xml containing things like the following mediawiki markup:</p> <blockquote> <p>" ...collected in the 12th century, of which [[Alexander the Great]] was the hero, and in which he was represented, somewhat like the British [[King Arthur|Arthur]]"</p> </blockquote> <p>what would be the appro...
3
2009-05-01T01:11:52Z
810,186
<p>If you are trying to get all the links from a page, of course it is much easier to use the MediaWiki API if at all possible, e.g. <a href="http://en.wikipedia.org/w/api.php?action=query&amp;prop=links&amp;titles=Stack%5FOverflow%5F%28website%29" rel="nofollow">http://en.wikipedia.org/w/api.php?action=query&amp;prop=...
1
2009-05-01T04:23:25Z
[ "python", "regex", "mediawiki" ]
Biggest python projects
810,055
<p>What is the biggest software development team that uses Python? I am wondering how well the dynamic type system scales to large development teams.</p> <p>It's pretty clear that at Google they have C++ and Java codebases with thousands of developers; their use of Python is much smaller.</p> <p>Are there some huge c...
13
2009-05-01T03:24:53Z
810,063
<p><a href="http://www.youtube.com">Youtube</a> is probably the biggest user after Google (and subsequently bought by them).</p> <p><a href="http://www.reddit.com">Reddit</a>, a digg-like website, is written in Python.</p> <p><a href="http://www.eveonline.com/faq/faq%5F07.asp">Eve</a>, an MMO with a good chunk writte...
30
2009-05-01T03:28:24Z
[ "python" ]
Biggest python projects
810,055
<p>What is the biggest software development team that uses Python? I am wondering how well the dynamic type system scales to large development teams.</p> <p>It's pretty clear that at Google they have C++ and Java codebases with thousands of developers; their use of Python is much smaller.</p> <p>Are there some huge c...
13
2009-05-01T03:24:53Z
810,240
<p>Among many other Python-centered companies, beyond the ones already mentioned by Unknown, I'd mention big pharma firms such as Astra-Zeneca, film studios such as Lucasfilm, and research places such as NASA, Caltech, Lawrence Livermore NRL.</p> <p>Among the sponsors of Pycon Italia Tre (next week in Firenze, IT -- s...
10
2009-05-01T04:55:05Z
[ "python" ]
Biggest python projects
810,055
<p>What is the biggest software development team that uses Python? I am wondering how well the dynamic type system scales to large development teams.</p> <p>It's pretty clear that at Google they have C++ and Java codebases with thousands of developers; their use of Python is much smaller.</p> <p>Are there some huge c...
13
2009-05-01T03:24:53Z
810,992
<p>Our project is over 30,000 lines of Python. That's probably small by some standards. But it's plenty big enough to fill my little brain. The application is mentioned in our annual report, so it's "strategic" in that sense. We're not a "huge" company, so we don't really qualify.</p> <p>A "huge company" (Fortune ...
6
2009-05-01T11:06:16Z
[ "python" ]
python- is beautifulsoup misreporting my html?
810,173
<p>I have two machines each, to the best of my knowledge, running python 2.5 and BeautifulSoup 3.1.0.1. </p> <p>I'm trying to scrape <a href="http://utahcritseries.com/RawResults.aspx" rel="nofollow">http://utahcritseries.com/RawResults.aspx</a>, using:</p> <pre><code>from BeautifulSoup import BeautifulSoup import u...
2
2009-05-01T04:19:02Z
810,272
<p>There are <a href="http://www.crummy.com/software/BeautifulSoup/3.1-problems.html" rel="nofollow">documented problems</a> with version 3.1 of BeautifulSoup.</p> <p>You might want to double check that is the version you in fact are using, and if so downgrade.</p>
2
2009-05-01T05:13:48Z
[ "python", "osx", "configuration", "screen-scraping", "beautifulsoup" ]
python- is beautifulsoup misreporting my html?
810,173
<p>I have two machines each, to the best of my knowledge, running python 2.5 and BeautifulSoup 3.1.0.1. </p> <p>I'm trying to scrape <a href="http://utahcritseries.com/RawResults.aspx" rel="nofollow">http://utahcritseries.com/RawResults.aspx</a>, using:</p> <pre><code>from BeautifulSoup import BeautifulSoup import u...
2
2009-05-01T04:19:02Z
812,712
<p>I suspect the problem is in the urlib2 request, not BeautifulSoup:</p> <p>It might help if you show us the same section of the raw data as returned by this command on both machines:</p> <pre><code>urllib2.urlopen(base_url) </code></pre> <p>This page looks like it might help: <a href="http://bytes.com/groups/pytho...
1
2009-05-01T18:51:24Z
[ "python", "osx", "configuration", "screen-scraping", "beautifulsoup" ]
Django form field using SelectDateWidget
810,308
<p>I've installed the latest SVN branch from Django which includes the new forms. I'm trying to use the SelectDateWidget from django.forms.extras.widgets but the field is showing up as a normal DateInput widget.</p> <p>Here is the forms.py from my application:</p> <pre><code>from django import forms from jacob_forms....
6
2009-05-01T05:36:12Z
810,315
<p>From the ticket re: the lack of documentation for SelectDateWidget here: <a href="http://code.djangoproject.com/attachment/ticket/7437/SelectDateWidget-doc.diff" rel="nofollow">Ticket #7437</a></p> <p>It looks like you need to use it like this:</p> <pre><code>widget=forms.extras.widgets.SelectDateWidget() </code><...
3
2009-05-01T05:45:29Z
[ "python", "django", "forms", "widget", "admin" ]
Django form field using SelectDateWidget
810,308
<p>I've installed the latest SVN branch from Django which includes the new forms. I'm trying to use the SelectDateWidget from django.forms.extras.widgets but the field is showing up as a normal DateInput widget.</p> <p>Here is the forms.py from my application:</p> <pre><code>from django import forms from jacob_forms....
6
2009-05-01T05:36:12Z
811,181
<p>Your code works fine for me as written. In a case like this, check for mismatches between the name of the field in the model and form (<code>DOB</code> versus <code>dob</code> is an easy typo to make), and that you've instantiated the right form in your view, and passed it to the template.</p>
0
2009-05-01T12:40:00Z
[ "python", "django", "forms", "widget", "admin" ]
Django form field using SelectDateWidget
810,308
<p>I've installed the latest SVN branch from Django which includes the new forms. I'm trying to use the SelectDateWidget from django.forms.extras.widgets but the field is showing up as a normal DateInput widget.</p> <p>Here is the forms.py from my application:</p> <pre><code>from django import forms from jacob_forms....
6
2009-05-01T05:36:12Z
812,513
<p>The real problem was that SelectDateWidget can't be referenced this way. Changing the code to reference it differently solved my problem:</p> <pre><code>from django.forms import extras ... DOB = forms.DateField(widget=extras.SelectDateWidget) </code></pre> <p>This seems to be a limitation that you can't refere...
9
2009-05-01T18:12:11Z
[ "python", "django", "forms", "widget", "admin" ]
Django form field using SelectDateWidget
810,308
<p>I've installed the latest SVN branch from Django which includes the new forms. I'm trying to use the SelectDateWidget from django.forms.extras.widgets but the field is showing up as a normal DateInput widget.</p> <p>Here is the forms.py from my application:</p> <pre><code>from django import forms from jacob_forms....
6
2009-05-01T05:36:12Z
28,325,368
<p>Here is the form.py</p> <pre><code>from django import forms from django.forms import extras DOY = ('1980', '1981', '1982', '1983', '1984', '1985', '1986', '1987', '1988', '1989', '1990', '1991', '1992', '1993', '1994', '1995', '1996', '1997', '1998', '1999', '2000', '2001', '2002', '2003', '20...
1
2015-02-04T15:39:56Z
[ "python", "django", "forms", "widget", "admin" ]
string encodings in python
810,794
<p>In python, strings may be unicode ( both utf-16 and utf-8 ) and single-byte with different encodings ( cp1251, cp1252 etc ). Is it possible to check what encoding string is? For example,</p> <pre><code>time.strftime( "%b" ) </code></pre> <p>will return a string with text name of a month. Under MacOS returned strin...
0
2009-05-01T09:36:24Z
810,812
<p>charset encoding detection is very complex.</p> <p>however, what's your real purpose for this? if you just want to value to be in unicode, simply write</p> <pre><code>unicode(time.strftime("%b")) </code></pre> <p>and it should work for all the cases you've mentioned above:</p> <ul> <li>mac os: unicode(unicode) -...
1
2009-05-01T09:43:31Z
[ "python", "unicode", "codepages" ]
string encodings in python
810,794
<p>In python, strings may be unicode ( both utf-16 and utf-8 ) and single-byte with different encodings ( cp1251, cp1252 etc ). Is it possible to check what encoding string is? For example,</p> <pre><code>time.strftime( "%b" ) </code></pre> <p>will return a string with text name of a month. Under MacOS returned strin...
0
2009-05-01T09:36:24Z
810,893
<p>Strings don't store any encoding information, you just have to specify one when you convert to/from unicode or print to an output device :</p> <pre><code>import locale lang, encoding = locale.getdefaultlocale() mystring = u"blabla" print mystring.encode(encoding) </code></pre> <p>UTF-8 is <em>not</em> unicode, it'...
5
2009-05-01T10:19:15Z
[ "python", "unicode", "codepages" ]
string encodings in python
810,794
<p>In python, strings may be unicode ( both utf-16 and utf-8 ) and single-byte with different encodings ( cp1251, cp1252 etc ). Is it possible to check what encoding string is? For example,</p> <pre><code>time.strftime( "%b" ) </code></pre> <p>will return a string with text name of a month. Under MacOS returned strin...
0
2009-05-01T09:36:24Z
811,866
<p>If you have a reasonably long string in an unknown encoding, you can try to guess the encoding, e.g. with the Universal Encoding Detector at <a href="https://github.com/dcramer/chardet" rel="nofollow">https://github.com/dcramer/chardet</a> -- not foolproof of course, but sometimes it guesses right;-). But that won'...
1
2009-05-01T15:26:23Z
[ "python", "unicode", "codepages" ]
how to manually assign imagefield in Django
811,167
<p>I have a model that has an ImageField. How can I manually assign an imagefile to it? I want it to treat it like any other uploaded file...</p>
12
2009-05-01T12:32:16Z
811,288
<p>See the django docs for <a href="http://docs.djangoproject.com/en/dev/ref/files/file/#django.core.files.File.save">django.core.files.File</a></p> <p>Where fd is an open file object:</p> <pre><code>model_instance.image_field.save('filename.jpeg', fd.read(), True) </code></pre>
14
2009-05-01T13:13:40Z
[ "python", "django", "django-models" ]
Is it possible to write a great PHP app which uses Unicode?
811,306
<p>My next web application project will make extensive use of Unicode. I usually use PHP and CodeIgniter however Unicode is not one of PHP's strong points.</p> <p>Is there a PHP tool out there that can help me get Unicode working well in PHP?</p> <p>Or should I take the opportunity to look into alternatives such as P...
1
2009-05-01T13:18:37Z
811,321
<p>PHP can handle unicode fine once you make sure to encode and decode on entry and exit. If you are storing in a database, ensure that the language encodings and charset mappings match up between the html pages, web server, your editor, and the database.</p> <p>If the whole application uses UTF-8 everywhere, decoding...
4
2009-05-01T13:23:20Z
[ "php", "python", "web-applications", "unicode" ]
Is it possible to write a great PHP app which uses Unicode?
811,306
<p>My next web application project will make extensive use of Unicode. I usually use PHP and CodeIgniter however Unicode is not one of PHP's strong points.</p> <p>Is there a PHP tool out there that can help me get Unicode working well in PHP?</p> <p>Or should I take the opportunity to look into alternatives such as P...
1
2009-05-01T13:18:37Z
811,578
<p>One of the Major feature of <em>PHP 6 will be tightly integrated with UNICODE support.</em></p> <p><strong>Implementing UTF-8 in PHP 5.</strong> Since PHP strings are byte-oriented, the only practical encoding scheme for Unicode text is UTF-8. Tricks are [Got it from PHp Architect Magazine]:</p> <ul> <li>Present H...
1
2009-05-01T14:23:51Z
[ "php", "python", "web-applications", "unicode" ]
Is it possible to write a great PHP app which uses Unicode?
811,306
<p>My next web application project will make extensive use of Unicode. I usually use PHP and CodeIgniter however Unicode is not one of PHP's strong points.</p> <p>Is there a PHP tool out there that can help me get Unicode working well in PHP?</p> <p>Or should I take the opportunity to look into alternatives such as P...
1
2009-05-01T13:18:37Z
811,857
<p>PHP is mostly unaware of chrasets and treats strings as bytestreams. That's not much of a problem really, but you'll have to do a bit of work your self.</p> <p>The general rule of thumb is that you should use the same charset everywhere. If you use UTF-8 everywhere, then you're 99% there. Just make sure that you do...
0
2009-05-01T15:24:05Z
[ "php", "python", "web-applications", "unicode" ]
reading a stream made by urllib2 never recovers when connection got interrupted
811,446
<p>While trying to make one of my python applications a bit more robust in case of connection interruptions I discovered that calling the read function of an http-stream made by urllib2 may block the script forever. </p> <p>I thought that the read function will timeout and eventually raise an exception but this does n...
8
2009-05-01T13:51:52Z
811,602
<p>Good question, I would be really interested in finding an answer. The only workaround I could think of is using the signal trick explained in <a href="http://docs.python.org/library/signal.html#example" rel="nofollow">python docs</a>. In your case it will be more like:</p> <pre><code>import signal import urllib2 d...
2
2009-05-01T14:32:14Z
[ "python", "urllib2" ]
reading a stream made by urllib2 never recovers when connection got interrupted
811,446
<p>While trying to make one of my python applications a bit more robust in case of connection interruptions I discovered that calling the read function of an http-stream made by urllib2 may block the script forever. </p> <p>I thought that the read function will timeout and eventually raise an exception but this does n...
8
2009-05-01T13:51:52Z
811,748
<p>Try something like:</p> <pre><code>import socket socket.setdefaulttimeout(5.0) ... try: ... except socket.timeout: (it timed out, retry) </code></pre>
6
2009-05-01T14:57:26Z
[ "python", "urllib2" ]
How to scroll automaticaly within a Tkinter message window
811,532
<p>I wrote the following class for producing "monitoring" output within an extra window.</p> <ol> <li>Unfortunately it doesn't scroll automatically down to the most recent line. What is wrong?</li> <li>As I also have problems with Tkinter and ipython: how would an equivalent implementation with qt4 look like?</li> </o...
5
2009-05-01T14:16:00Z
811,708
<p>Add a statement <code>cls.text.see(Tkinter.END)</code> right after the one calling insert.</p>
18
2009-05-01T14:50:48Z
[ "python", "qt", "qt4", "tkinter", "ipython" ]
How to scroll automaticaly within a Tkinter message window
811,532
<p>I wrote the following class for producing "monitoring" output within an extra window.</p> <ol> <li>Unfortunately it doesn't scroll automatically down to the most recent line. What is wrong?</li> <li>As I also have problems with Tkinter and ipython: how would an equivalent implementation with qt4 look like?</li> </o...
5
2009-05-01T14:16:00Z
17,749,213
<p>To those who might want to try binding:</p> <pre><code>def callback(): text.see(END) text.edit_modified(0) text.bind('&lt;&lt;Modified&gt;&gt;', callback) </code></pre> <p>Just be careful. As @BryanOakley pointed out, the Modified virtual event is only called once until it is reset. Consider below:</p> <p...
2
2013-07-19T14:53:24Z
[ "python", "qt", "qt4", "tkinter", "ipython" ]
Sqlite and Python -- return a dictionary using fetchone()?
811,548
<p>I'm using sqlite3 in python 2.5. I've created a table that looks like this:</p> <pre><code> create table votes ( bill text, senator_id text, vote text) </code></pre> <p>I'm accessing it with something like this:</p> <pre><code>v_cur.execute("select * from votes") row = v_cur.fetchone() bill =...
22
2009-05-01T14:19:06Z
811,623
<p>Sure, make yourself a DictConnection and DictCursor as explained and shown at <a href="http://trac.edgewall.org/pysqlite.org-mirror/wiki/PysqliteFactories" rel="nofollow">http://trac.edgewall.org/pysqlite.org-mirror/wiki/PysqliteFactories</a> for example.</p>
5
2009-05-01T14:35:38Z
[ "python", "database", "sqlite" ]
Sqlite and Python -- return a dictionary using fetchone()?
811,548
<p>I'm using sqlite3 in python 2.5. I've created a table that looks like this:</p> <pre><code> create table votes ( bill text, senator_id text, vote text) </code></pre> <p>I'm accessing it with something like this:</p> <pre><code>v_cur.execute("select * from votes") row = v_cur.fetchone() bill =...
22
2009-05-01T14:19:06Z
811,637
<p>The way I've done this in the past:</p> <pre><code>def dict_factory(cursor, row): d = {} for idx,col in enumerate(cursor.description): d[col[0]] = row[idx] return d </code></pre> <p>Then you set it up in your connection:</p> <pre><code>from pysqlite2 import dbapi2 as sqlite conn = sqlite.conne...
17
2009-05-01T14:37:46Z
[ "python", "database", "sqlite" ]
Sqlite and Python -- return a dictionary using fetchone()?
811,548
<p>I'm using sqlite3 in python 2.5. I've created a table that looks like this:</p> <pre><code> create table votes ( bill text, senator_id text, vote text) </code></pre> <p>I'm accessing it with something like this:</p> <pre><code>v_cur.execute("select * from votes") row = v_cur.fetchone() bill =...
22
2009-05-01T14:19:06Z
819,454
<p>I know you're not asking this, but why not just use sqlalchemy to build an orm for the database? then you can do things like,</p> <pre><code> entry = model.Session.query(model.Votes).first() print entry.bill, entry.senator_id, entry.vote </code></pre> <p>as an added bonus your code will be easily portable to an ...
2
2009-05-04T09:33:33Z
[ "python", "database", "sqlite" ]
Sqlite and Python -- return a dictionary using fetchone()?
811,548
<p>I'm using sqlite3 in python 2.5. I've created a table that looks like this:</p> <pre><code> create table votes ( bill text, senator_id text, vote text) </code></pre> <p>I'm accessing it with something like this:</p> <pre><code>v_cur.execute("select * from votes") row = v_cur.fetchone() bill =...
22
2009-05-01T14:19:06Z
2,526,294
<p>There is actually an option for this in sqlite3. Change the <code>row_factory</code> member of the connection object to <code>sqlite3.Row</code>:</p> <pre><code>conn = sqlite3.connect('db', row_factory=sqlite3.Row) </code></pre> <p>or</p> <pre><code>conn.row_factory = sqlite3.Row </code></pre> <p>This will allo...
66
2010-03-26T19:51:49Z
[ "python", "database", "sqlite" ]
Sqlite and Python -- return a dictionary using fetchone()?
811,548
<p>I'm using sqlite3 in python 2.5. I've created a table that looks like this:</p> <pre><code> create table votes ( bill text, senator_id text, vote text) </code></pre> <p>I'm accessing it with something like this:</p> <pre><code>v_cur.execute("select * from votes") row = v_cur.fetchone() bill =...
22
2009-05-01T14:19:06Z
14,574,700
<p>I was recently trying to do something similar while using sqlite3.Row(). While sqlite3.Row() is great for providing a dictionary-like interface or a tuple like interface, it didn't work when I piped in the row using **kwargs. So, needed a quick way of converting it to a dictionary. I realised that the Row() object c...
5
2013-01-29T02:29:29Z
[ "python", "database", "sqlite" ]
Sqlite and Python -- return a dictionary using fetchone()?
811,548
<p>I'm using sqlite3 in python 2.5. I've created a table that looks like this:</p> <pre><code> create table votes ( bill text, senator_id text, vote text) </code></pre> <p>I'm accessing it with something like this:</p> <pre><code>v_cur.execute("select * from votes") row = v_cur.fetchone() bill =...
22
2009-05-01T14:19:06Z
18,948,238
<p>I've used this:</p> <pre><code>def get_dict(sql): return dict(c.execute(sql,()).fetchall()) </code></pre> <p>Then you can do this:</p> <pre><code>c = conn.cursor() d = get_dict("select user,city from vals where user like 'a%'"); </code></pre> <p>Now <code>d</code> is a dictionary where the keys are <code>use...
1
2013-09-22T20:06:19Z
[ "python", "database", "sqlite" ]
How can I create a locked-down python environment?
811,670
<p>I'm responsible for developing a large Python/Windows/Excel application used by a financial institution which has offices all round the world. Recently the regulations in one country have changed, and as a result we have been told that we need to create a "locked-down" version of our distribution.</p> <p>After some...
4
2009-05-01T14:41:58Z
811,711
<p>"reasonably safe" defined arbitrarily as "safer than Excel and VBA".</p> <p>You can't win that fight. Because the fight is over the wrong thing. Anyone can use any EXE or DLL.</p> <p>You need to define "locked down" differently -- in a way that you can succeed.</p> <p>You need to define "locked down" as "cannot...
9
2009-05-01T14:51:10Z
[ "python", "windows", "security", "excel" ]
How can I create a locked-down python environment?
811,670
<p>I'm responsible for developing a large Python/Windows/Excel application used by a financial institution which has offices all round the world. Recently the regulations in one country have changed, and as a result we have been told that we need to create a "locked-down" version of our distribution.</p> <p>After some...
4
2009-05-01T14:41:58Z
811,736
<p>Sadly, Python is not very safe in this way, and this is quite well known. Its dynamic nature combined with the very thin layer over standard OS functionality makes it hard to lock things down. Usually the best option is to ensure the user running the app has limited rights, but I expect that is not practical. Anothe...
3
2009-05-01T14:55:23Z
[ "python", "windows", "security", "excel" ]
How can I create a locked-down python environment?
811,670
<p>I'm responsible for developing a large Python/Windows/Excel application used by a financial institution which has offices all round the world. Recently the regulations in one country have changed, and as a result we have been told that we need to create a "locked-down" version of our distribution.</p> <p>After some...
4
2009-05-01T14:41:58Z
811,785
<p>One idea is to run IronPython inside an AppDomain on .NET. See David W.'s comment <a href="http://tav.espians.com/a-challenge-to-break-python-security.html" rel="nofollow">here</a>.</p> <p>Also, there is a module you can import to restrict the interpreter from writing files. It's called <a href="http://tav.espians....
3
2009-05-01T15:04:23Z
[ "python", "windows", "security", "excel" ]
How can I create a locked-down python environment?
811,670
<p>I'm responsible for developing a large Python/Windows/Excel application used by a financial institution which has offices all round the world. Recently the regulations in one country have changed, and as a result we have been told that we need to create a "locked-down" version of our distribution.</p> <p>After some...
4
2009-05-01T14:41:58Z
814,427
<p>I agree that you should examine the regulations to see what they actually require. If you really do need a "locked down" Python DLL, here's a way that might do it. It will probably take a while and won't be easy to get right. BTW, since this is theoretical, I'm waving my hands over work that varies from massive to...
0
2009-05-02T08:30:46Z
[ "python", "windows", "security", "excel" ]
How can I create a locked-down python environment?
811,670
<p>I'm responsible for developing a large Python/Windows/Excel application used by a financial institution which has offices all round the world. Recently the regulations in one country have changed, and as a result we have been told that we need to create a "locked-down" version of our distribution.</p> <p>After some...
4
2009-05-01T14:41:58Z
814,437
<p>Follow the <a href="http://www.xs4all.nl/~weegen/eelis/geordi/#faq" rel="nofollow">geordi</a> way. </p> <p>Each suspect program is run in its own jailed account. Monitor system calls from the process (I know how to do this in Windows, but it is beyond the scope of this question) and kill the process if needed. </p>...
1
2009-05-02T08:39:10Z
[ "python", "windows", "security", "excel" ]
Python Timeout
811,692
<p>I've been looking all over the place for a good timeout script that can kill a thread if it's been active for more than X seconds, but all the examples I've seen have flaws that don't always stop the thread. Using thread.join(x) ends up defeating the purpose of it being a thread.</p> <p>The only decent example I've...
8
2009-05-01T14:46:54Z
811,780
<p>I know this might not be what you want, but have you considered the signal approach? <a href="http://stackoverflow.com/questions/492519/timeout-on-a-python-function-call/494273#494273">http://stackoverflow.com/questions/492519/timeout-on-a-python-function-call/494273#494273</a> <a href="http://docs.python.org/librar...
0
2009-05-01T15:03:09Z
[ "python", "multithreading", "timeout" ]
Python Timeout
811,692
<p>I've been looking all over the place for a good timeout script that can kill a thread if it's been active for more than X seconds, but all the examples I've seen have flaws that don't always stop the thread. Using thread.join(x) ends up defeating the purpose of it being a thread.</p> <p>The only decent example I've...
8
2009-05-01T14:46:54Z
812,061
<p>See my answer to <a href="http://stackoverflow.com/questions/605013/python-how-to-send-packets-in-multi-thread-and-then-the-thread-kill-itself/605865#605865">python: how to send packets in multi thread and then the thread kill itself</a> - there is a fragment with InterruptableThread class and example that kill anot...
1
2009-05-01T16:17:48Z
[ "python", "multithreading", "timeout" ]
What causes this Genshi's Template Syntax Error?
811,737
<p>A Genshi template raises the following error:</p> <blockquote> <p>TemplateSyntaxError: invalid syntax in expression <code>"${item.error}"</code> of <code>"choose"</code> directive</p> </blockquote> <p>The part of the template code that the error specifies is the following (<em>'feed' is a list of dictionary whic...
0
2009-05-01T14:55:32Z
812,704
<p>I've never used Genshi, but based on the documentation I found, it looks like you're trying to use the inline Python expression syntax inside a templates directives argument, which seems to be unneccesary. Try this instead:</p> <pre><code>&lt;item py:for="item in feed"&gt; &lt;py:choose error="item.error"&gt; &...
0
2009-05-01T18:49:34Z
[ "python", "syntax-error", "genshi" ]
What causes this Genshi's Template Syntax Error?
811,737
<p>A Genshi template raises the following error:</p> <blockquote> <p>TemplateSyntaxError: invalid syntax in expression <code>"${item.error}"</code> of <code>"choose"</code> directive</p> </blockquote> <p>The part of the template code that the error specifies is the following (<em>'feed' is a list of dictionary whic...
0
2009-05-01T14:55:32Z
1,024,392
<p>The <a href="http://genshi.edgewall.org/wiki/Documentation/0.5.x/xml-templates.html#id2" rel="nofollow">docs</a> perhaps don't make this clear, but the attribute needs to be called <code>test</code> (as it is in their examples) instead of <code>error</code>.</p> <pre><code>&lt;item py:for="item in feed"&gt; &lt;py:...
4
2009-06-21T17:44:08Z
[ "python", "syntax-error", "genshi" ]
What version of Python (2.4, 2.5, 2.6, 3.0) do you standardize on for production development efforts (and why)?
812,085
<p>In our group we primarily do search engine architecture and content integration work and most of that code base is in Python. All our build tools and Python module dependencies are in source control so they can be checked out and the environment loaded for use regardless of os/platform, kinda similar to the approach...
5
2009-05-01T16:25:21Z
812,161
<p>I wouldn't abandon 2.6 just because of deprecation warnings; those will disappear over time. (You can use the <code>-W ignore</code> option to the Python interpreter to prevent them from being printed out, at least) But if modules you need to use actually don't work with Python 2.6, that would be a legitimate reason...
5
2009-05-01T16:41:50Z
[ "python", "standards", "production", "supervisord" ]
What version of Python (2.4, 2.5, 2.6, 3.0) do you standardize on for production development efforts (and why)?
812,085
<p>In our group we primarily do search engine architecture and content integration work and most of that code base is in Python. All our build tools and Python module dependencies are in source control so they can be checked out and the environment loaded for use regardless of os/platform, kinda similar to the approach...
5
2009-05-01T16:25:21Z
812,177
<p>To me the most important to stick with python 2.5+ is because it officially supports <code>ctypes</code>, which changed many plugin systems.</p> <p>Although you can find ctypes to work with 2.3/2.4, they are not officially bundled.</p> <p>So my suggestion would be 2.5.</p>
2
2009-05-01T16:43:31Z
[ "python", "standards", "production", "supervisord" ]
What version of Python (2.4, 2.5, 2.6, 3.0) do you standardize on for production development efforts (and why)?
812,085
<p>In our group we primarily do search engine architecture and content integration work and most of that code base is in Python. All our build tools and Python module dependencies are in source control so they can be checked out and the environment loaded for use regardless of os/platform, kinda similar to the approach...
5
2009-05-01T16:25:21Z
812,181
<p>My company is standardized in 2.5. Like you we can't make the switch to 3.0 for a million reasons, but I very much wish we could move up to 2.6. </p> <p>Doing coding day to day I'll be looking through the documentation and I'll find exactly the module or function that I want, but then it'll have the little annota...
4
2009-05-01T16:44:25Z
[ "python", "standards", "production", "supervisord" ]
What version of Python (2.4, 2.5, 2.6, 3.0) do you standardize on for production development efforts (and why)?
812,085
<p>In our group we primarily do search engine architecture and content integration work and most of that code base is in Python. All our build tools and Python module dependencies are in source control so they can be checked out and the environment loaded for use regardless of os/platform, kinda similar to the approach...
5
2009-05-01T16:25:21Z
812,188
<p>We're sticking with 2.5.2 for now. Our tech stack centers on Django (but we have a dozen other bits and bobs.) So we stay close to what they do.</p> <p>We had to go back to docutils to 0.4 so it would work with epydoc 3.0.1. So far, this hasn't been a big issue, but it may -- at some point -- cause us to rethin...
2
2009-05-01T16:46:51Z
[ "python", "standards", "production", "supervisord" ]
What version of Python (2.4, 2.5, 2.6, 3.0) do you standardize on for production development efforts (and why)?
812,085
<p>In our group we primarily do search engine architecture and content integration work and most of that code base is in Python. All our build tools and Python module dependencies are in source control so they can be checked out and the environment loaded for use regardless of os/platform, kinda similar to the approach...
5
2009-05-01T16:25:21Z
812,352
<p>I think the best solution is to give up the hope on total uniformity, although having a common environment is something to strive for. You will always will be confronted with version problems, for example when upgrading to the next best interpreter version.</p> <p>So instead of dealing with it on a per issue base y...
1
2009-05-01T17:27:00Z
[ "python", "standards", "production", "supervisord" ]
How can I get my setup.py to use a relative path to my files?
812,242
<p>I'm trying to build a Python distribution with <code>distutils</code>. Unfortunately, my directory structure looks like this:</p> <pre> /code /mypackage __init__.py file1.py file2.py /subpackage __init__.py /build setup.py </pre> <p>Here's my <code>setup...
8
2009-05-01T17:00:33Z
812,306
<p>A sorta lame workaround but I'd probably just use a Makefile that rsynced ./mypackage to ./build/mypackage and then use the usual distutils syntax from inside ./build. Fact is, distutils expects to unpack setup.py into the root of the sdist and have code under there, so you're going to have a devil of time convincin...
0
2009-05-01T17:15:34Z
[ "python", "distutils" ]
How can I get my setup.py to use a relative path to my files?
812,242
<p>I'm trying to build a Python distribution with <code>distutils</code>. Unfortunately, my directory structure looks like this:</p> <pre> /code /mypackage __init__.py file1.py file2.py /subpackage __init__.py /build setup.py </pre> <p>Here's my <code>setup...
8
2009-05-01T17:00:33Z
814,118
<p>What directory structure do you want inside of the distribution archive file? The same as your existing structure?</p> <p>You could package everything one directory higher (<code>code</code> in your example) with this modified setup.py:</p> <pre><code>from distutils.core import setup setup( name = 'MyPackage'...
2
2009-05-02T04:08:59Z
[ "python", "distutils" ]
How can I get my setup.py to use a relative path to my files?
812,242
<p>I'm trying to build a Python distribution with <code>distutils</code>. Unfortunately, my directory structure looks like this:</p> <pre> /code /mypackage __init__.py file1.py file2.py /subpackage __init__.py /build setup.py </pre> <p>Here's my <code>setup...
8
2009-05-01T17:00:33Z
816,283
<p>Have it change to the parent directory first, perhaps?</p> <pre><code>import os os.chdir(os.pardir) from distutils.core import setup </code></pre> <p>etc.</p> <p>Or if you might be running it from anywhere (this is overkill, but...):</p> <pre><code>import os.path my_path = os.path.abspath(__file__) os.chdir(os....
-1
2009-05-03T03:46:00Z
[ "python", "distutils" ]
How can I get my setup.py to use a relative path to my files?
812,242
<p>I'm trying to build a Python distribution with <code>distutils</code>. Unfortunately, my directory structure looks like this:</p> <pre> /code /mypackage __init__.py file1.py file2.py /subpackage __init__.py /build setup.py </pre> <p>Here's my <code>setup...
8
2009-05-01T17:00:33Z
3,042,465
<p><strong>Run setup.py from the root folder of the project</strong></p> <p>In your case, place setup.py in code/</p> <p>code/ should also include:</p> <ul> <li>LICENSE.txt</li> <li>README.txt</li> <li>INSTALL.txt</li> <li>TODO.txt</li> <li>CHANGELOG.txt</li> </ul> <p>The when you run "setup.py sdist' it should aut...
1
2010-06-15T04:14:33Z
[ "python", "distutils" ]
How can I get my setup.py to use a relative path to my files?
812,242
<p>I'm trying to build a Python distribution with <code>distutils</code>. Unfortunately, my directory structure looks like this:</p> <pre> /code /mypackage __init__.py file1.py file2.py /subpackage __init__.py /build setup.py </pre> <p>Here's my <code>setup...
8
2009-05-01T17:00:33Z
28,692,213
<p>Also a lame workaround, but a junction/link of the package directory inside of the build project should work.</p>
0
2015-02-24T09:33:38Z
[ "python", "distutils" ]
Why does python logging package not support printing variable length args?
812,422
<p>When I first learned Python, I got used to doing this:</p> <pre><code> print "text", lineNumber, "some dictionary", my_dict </code></pre> <p>When I wrote my own logging facility, I naturally wanted to be able to hand it an arbitrarily-sized list of items, so I did this:</p> <pre><code>def error(*args): print ...
2
2009-05-01T17:44:04Z
812,452
<p>Well, printing and logging are two very different things. It stands to reason that as such their usages could potentially be quite different as well.</p>
0
2009-05-01T17:50:47Z
[ "python", "logging" ]
Why does python logging package not support printing variable length args?
812,422
<p>When I first learned Python, I got used to doing this:</p> <pre><code> print "text", lineNumber, "some dictionary", my_dict </code></pre> <p>When I wrote my own logging facility, I naturally wanted to be able to hand it an arbitrarily-sized list of items, so I did this:</p> <pre><code>def error(*args): print ...
2
2009-05-01T17:44:04Z
812,537
<p>It's relatively easy to <a href="http://www.daniel-lemire.com/blog/archives/2005/12/21/metaclass-programming-in-python/" rel="nofollow">add a method to a class</a> dynamically. Why not just add your method to Logging.</p>
0
2009-05-01T18:17:26Z
[ "python", "logging" ]
Why does python logging package not support printing variable length args?
812,422
<p>When I first learned Python, I got used to doing this:</p> <pre><code> print "text", lineNumber, "some dictionary", my_dict </code></pre> <p>When I wrote my own logging facility, I naturally wanted to be able to hand it an arbitrarily-sized list of items, so I did this:</p> <pre><code>def error(*args): print ...
2
2009-05-01T17:44:04Z
812,617
<p>I would suggest that it would be better to update the existing logging messages to the style that the logging module expects as it will be easier for other people looking at your code as the logging module will not longer function as they expect. </p> <p>That out of the way, the following code will make the loggin...
6
2009-05-01T18:33:43Z
[ "python", "logging" ]
Why does python logging package not support printing variable length args?
812,422
<p>When I first learned Python, I got used to doing this:</p> <pre><code> print "text", lineNumber, "some dictionary", my_dict </code></pre> <p>When I wrote my own logging facility, I naturally wanted to be able to hand it an arbitrarily-sized list of items, so I did this:</p> <pre><code>def error(*args): print ...
2
2009-05-01T17:44:04Z
812,678
<p>Your claim about logging is not completely true.</p> <pre><code>log= logging.getLogger( "some.logger" ) log.info( "%s %d", "test", value ) log.error("text %d some dictionary %s", lineNumber, my_dict) </code></pre> <p>You don't need to explicitly use the string formatting operator, <code>%</code></p> <p><hr /></p>...
1
2009-05-01T18:45:38Z
[ "python", "logging" ]
Why does python logging package not support printing variable length args?
812,422
<p>When I first learned Python, I got used to doing this:</p> <pre><code> print "text", lineNumber, "some dictionary", my_dict </code></pre> <p>When I wrote my own logging facility, I naturally wanted to be able to hand it an arbitrarily-sized list of items, so I did this:</p> <pre><code>def error(*args): print ...
2
2009-05-01T17:44:04Z
813,754
<p>Patching the logging package (as one answer recommended) is actually a bad idea, because it means that <em>other</em> code (that you didn't write, e.g. stuff in the standard library) that calls logging.error() would no longer work correctly.</p> <p>Instead, you can change your existing error() function to call logg...
2
2009-05-01T23:59:57Z
[ "python", "logging" ]
How many times was logging.error() called?
812,477
<p>Maybe it's just doesn't exist, as I cannot find it in pydoc. But using python's logging package, is there a way to query a Logger to find out how many times a particular function was called? For example, how many errors/warnings were reported?</p>
7
2009-05-01T18:00:09Z
812,706
<p>There'a a <a href="http://www.python.org/doc/2.5.2/lib/module-warnings.html" rel="nofollow">warnings</a> module that -- to an extent -- does some of that.</p> <p>You might want to add this counting feature to a customized <a href="http://www.python.org/doc/2.5.2/lib/node409.html" rel="nofollow">Handler</a>. The pr...
0
2009-05-01T18:50:01Z
[ "python", "logging" ]
How many times was logging.error() called?
812,477
<p>Maybe it's just doesn't exist, as I cannot find it in pydoc. But using python's logging package, is there a way to query a Logger to find out how many times a particular function was called? For example, how many errors/warnings were reported?</p>
7
2009-05-01T18:00:09Z
812,714
<p>The logging module doesn't appear to support this. In the long run you'd probably be better off creating a new module, and adding this feature via sub-classing the items in the existing logging module to add the features you need, but you could also achieve this behavior pretty easily with a decorator:</p> <pre><c...
9
2009-05-01T18:51:37Z
[ "python", "logging" ]
How many times was logging.error() called?
812,477
<p>Maybe it's just doesn't exist, as I cannot find it in pydoc. But using python's logging package, is there a way to query a Logger to find out how many times a particular function was called? For example, how many errors/warnings were reported?</p>
7
2009-05-01T18:00:09Z
31,142,078
<p>You can also add a new Handler to the logger which counts all calls:</p> <pre><code>class MsgCounterHandler(logging.Handler): level2count = None def __init__(self, *args, **kwargs): super(MsgCounterHandler, self).__init__(*args, **kwargs) self.level2count = {} def emit(self, record): ...
2
2015-06-30T15:11:41Z
[ "python", "logging" ]
Resources (resx) with Python
812,644
<p>Do you know of any Python module for resources (resx files) manipulation?</p> <p>P.S.: I know I could write a custom wrapper on top of base XML processor available, I'm just checking out before going to hack my own code...</p>
1
2009-05-01T18:38:24Z
1,615,872
<p>This question <a href="http://stackoverflow.com/questions/806305/resources-resx-maintenance-in-big-projects">http://stackoverflow.com/questions/806305/resources-resx-maintenance-in-big-projects</a> has an answer pointing to some .NET source code for a tool to manage RESX resources. Since <a href="http://www.codeplex...
0
2009-10-23T21:00:52Z
[ "python", "resources", "module", "resx" ]
Python's bz2 module not compiled by default
812,781
<p>It seems that Python 2.6.1 doesn't compile bz2 library by default from source.</p> <p>I don't have lib-dynload/bz2.so</p> <p>What's the quickest way to add it (without installing Python from scratch)?</p> <p>OS is Linux 2.4.32-grsec+f6b+gr217+nfs+a32+fuse23+tg+++opt+c8+gr2b-v6.194 #1 SMP Tue Jun 6 15:52:09 PDT 20...
22
2009-05-01T19:03:50Z
813,112
<p>You need libbz2.so (the general purpose libbz2 library) properly installed first, for Python to be able to build its own interface to it. That would typically be from a package in your Linux distro likely to have "libbz2" and "dev" in the package name.</p>
28
2009-05-01T20:24:55Z
[ "python", "c", "compiler-construction" ]
Python's bz2 module not compiled by default
812,781
<p>It seems that Python 2.6.1 doesn't compile bz2 library by default from source.</p> <p>I don't have lib-dynload/bz2.so</p> <p>What's the quickest way to add it (without installing Python from scratch)?</p> <p>OS is Linux 2.4.32-grsec+f6b+gr217+nfs+a32+fuse23+tg+++opt+c8+gr2b-v6.194 #1 SMP Tue Jun 6 15:52:09 PDT 20...
22
2009-05-01T19:03:50Z
813,744
<p>Use your vendor's package management to add the package that contains the development files for bz2. It's usually a package called "libbz2-dev". E.g. on Ubuntu</p> <p><code>sudo apt-get install libbz2-dev</code></p>
20
2009-05-01T23:52:30Z
[ "python", "c", "compiler-construction" ]
Python's bz2 module not compiled by default
812,781
<p>It seems that Python 2.6.1 doesn't compile bz2 library by default from source.</p> <p>I don't have lib-dynload/bz2.so</p> <p>What's the quickest way to add it (without installing Python from scratch)?</p> <p>OS is Linux 2.4.32-grsec+f6b+gr217+nfs+a32+fuse23+tg+++opt+c8+gr2b-v6.194 #1 SMP Tue Jun 6 15:52:09 PDT 20...
22
2009-05-01T19:03:50Z
6,848,047
<p>If you happen to be trying to compile Python on RHEL5 the package is called <strong>bzip2-devel</strong>, and if you have RHN set up it can be installed with this command:</p> <blockquote> <p>yum install bzip2-devel</p> </blockquote> <p>Once that is done, you don't need either of the --enable-bz2 or --with-bz2 o...
8
2011-07-27T16:38:23Z
[ "python", "c", "compiler-construction" ]
Python's bz2 module not compiled by default
812,781
<p>It seems that Python 2.6.1 doesn't compile bz2 library by default from source.</p> <p>I don't have lib-dynload/bz2.so</p> <p>What's the quickest way to add it (without installing Python from scratch)?</p> <p>OS is Linux 2.4.32-grsec+f6b+gr217+nfs+a32+fuse23+tg+++opt+c8+gr2b-v6.194 #1 SMP Tue Jun 6 15:52:09 PDT 20...
22
2009-05-01T19:03:50Z
10,972,897
<p>There are 2 solutions for this trouble:</p> <h2>option 1. install bzip2-devel</h2> <p>On Debian and derivatives, you can install easily like this:</p> <pre><code>sudo apt-get install bzip2-devel </code></pre> <h2>option 2. build and install bzip2</h2> <p>In the README file of <a href="http://bzip.org">bzip2 pac...
13
2012-06-10T22:37:21Z
[ "python", "c", "compiler-construction" ]
Thread Finished Event in Python
812,870
<p>I have a PyQt program, in this program I start a new thread for drawing a complicated image. I want to know when the thread has finished so I can print the image on the form.</p> <p>The only obstacle I'm facing is that I need to invoke the method of drawing from inside the GUI thread, so I want a way to tell the GU...
2
2009-05-01T19:27:20Z
813,045
<p>In the samples with <a href="http://www.riverbankcomputing.co.uk/software/pyqt/download" rel="nofollow">PyQt-Py2.6-gpl-4.4.4-2.exe</a>, there's the Mandelbrot app. In my install, the source is in C:\Python26\Lib\site-packages\PyQt4\examples\threads\mandelbrot.pyw. It uses a thread to render the pixmap and a signal...
2
2009-05-01T20:10:39Z
[ "python", "delegates", "multithreading" ]
Thread Finished Event in Python
812,870
<p>I have a PyQt program, in this program I start a new thread for drawing a complicated image. I want to know when the thread has finished so I can print the image on the form.</p> <p>The only obstacle I'm facing is that I need to invoke the method of drawing from inside the GUI thread, so I want a way to tell the GU...
2
2009-05-01T19:27:20Z
813,078
<p>I believe that your drawing thread can send an event to the main thread using QApplication.postEvent. You just need to pick some object as the receiver of the event. <a href="http://www.riverbankcomputing.com/static/Docs/PyQt4/html/qcoreapplication.html#postEvent" rel="nofollow">More info</a></p>
0
2009-05-01T20:16:54Z
[ "python", "delegates", "multithreading" ]
Thread Finished Event in Python
812,870
<p>I have a PyQt program, in this program I start a new thread for drawing a complicated image. I want to know when the thread has finished so I can print the image on the form.</p> <p>The only obstacle I'm facing is that I need to invoke the method of drawing from inside the GUI thread, so I want a way to tell the GU...
2
2009-05-01T19:27:20Z
813,111
<p>Expanding on Jeff's answer: the <a href="http://doc.trolltech.com/4.5/threads.html#signals-and-slots-across-threads" rel="nofollow">Qt documentation on thread support</a> states that it's possible to make event handlers (slots in Qt parlance) execute in the thread that "owns" an object.</p> <p>So in your case, you'...
0
2009-05-01T20:24:32Z
[ "python", "delegates", "multithreading" ]
Thread Finished Event in Python
812,870
<p>I have a PyQt program, in this program I start a new thread for drawing a complicated image. I want to know when the thread has finished so I can print the image on the form.</p> <p>The only obstacle I'm facing is that I need to invoke the method of drawing from inside the GUI thread, so I want a way to tell the GU...
2
2009-05-01T19:27:20Z
813,155
<p>I had a similar issue with one of my projects, and used signals to tell my main GUI thread when to display results from the worker and update a progress bar.</p> <p>Note that there are several examples to connect objects and signals in the <a href="http://www.riverbankcomputing.co.uk/static/Docs/PyQt4/pyqt4ref.html...
1
2009-05-01T20:37:04Z
[ "python", "delegates", "multithreading" ]
How to debug wxpython applications?
812,911
<p>I'm trying wxpython for the first time. I've wrote a GUI for a python program and when I run it, it produces some error in the GUI, but the GUI disappears very quickly, quickly enough for me to be unable to read the error info.</p> <p>Is there any log that I can check for the error message? (I'm running Mac OS X) o...
18
2009-05-01T19:40:11Z
812,928
<p>Start the application from the command line (I believe its called 'Terminal' in OS X) as noted below instead of double clicking on the python file. This way when the application crashes you'll see the stack trace. </p> <blockquote> <p>python NameOfScript.py</p> </blockquote> <p>Alternatively, you can redirect ...
1
2009-05-01T19:45:16Z
[ "python", "user-interface", "wxpython" ]
How to debug wxpython applications?
812,911
<p>I'm trying wxpython for the first time. I've wrote a GUI for a python program and when I run it, it produces some error in the GUI, but the GUI disappears very quickly, quickly enough for me to be unable to read the error info.</p> <p>Is there any log that I can check for the error message? (I'm running Mac OS X) o...
18
2009-05-01T19:40:11Z
813,011
<p>Add print statements to your program, so you can tell how it's starting up and where it ends up dying (by running from the terminal as you already said you do).</p>
0
2009-05-01T20:03:31Z
[ "python", "user-interface", "wxpython" ]
How to debug wxpython applications?
812,911
<p>I'm trying wxpython for the first time. I've wrote a GUI for a python program and when I run it, it produces some error in the GUI, but the GUI disappears very quickly, quickly enough for me to be unable to read the error info.</p> <p>Is there any log that I can check for the error message? (I'm running Mac OS X) o...
18
2009-05-01T19:40:11Z
813,041
<p>You could also run your project from a Python IDE, such as <a href="http://eric-ide.python-projects.org/" rel="nofollow">Eric IDE</a>. You get the added bonus of being able to trace, watch variables and tons of other cool stuff! :-)</p>
0
2009-05-01T20:09:56Z
[ "python", "user-interface", "wxpython" ]
How to debug wxpython applications?
812,911
<p>I'm trying wxpython for the first time. I've wrote a GUI for a python program and when I run it, it produces some error in the GUI, but the GUI disappears very quickly, quickly enough for me to be unable to read the error info.</p> <p>Is there any log that I can check for the error message? (I'm running Mac OS X) o...
18
2009-05-01T19:40:11Z
813,102
<p>Here's a way to have the error be reported in the GUI instead of the console, via a MessageDialog. You can use the show_error() method anywhere an exception is caught, here I just have it being caught at the top-most level. You can change it so that the app continues running after the error occurs, if the error ca...
8
2009-05-01T20:23:01Z
[ "python", "user-interface", "wxpython" ]
How to debug wxpython applications?
812,911
<p>I'm trying wxpython for the first time. I've wrote a GUI for a python program and when I run it, it produces some error in the GUI, but the GUI disappears very quickly, quickly enough for me to be unable to read the error info.</p> <p>Is there any log that I can check for the error message? (I'm running Mac OS X) o...
18
2009-05-01T19:40:11Z
813,156
<p>Launch from a Python IDE with a debugger.</p> <p>Running in <a href="http://www.wingware.com/products" rel="nofollow">WingIDE</a> immediatelly pinpoints the two problems:</p> <ul> <li><code>ID_ABOUT</code> should be <code>wx.ID_ABOUT</code> (line #4 of <code>__init__</code>).</li> <li><code>OnAboutBox</code> (the ...
2
2009-05-01T20:37:24Z
[ "python", "user-interface", "wxpython" ]
How to debug wxpython applications?
812,911
<p>I'm trying wxpython for the first time. I've wrote a GUI for a python program and when I run it, it produces some error in the GUI, but the GUI disappears very quickly, quickly enough for me to be unable to read the error info.</p> <p>Is there any log that I can check for the error message? (I'm running Mac OS X) o...
18
2009-05-01T19:40:11Z
814,418
<p>not sure about the mac version, but wxPython has a built in way to redirect errors to a window (which will unfortunately close when your application crashes, but it's useful for catching errors that silently fail) or to a log file (only updated after your application closes):</p> <pre><code>app = wx.App(redirect=Tr...
14
2009-05-02T08:24:49Z
[ "python", "user-interface", "wxpython" ]
How to debug wxpython applications?
812,911
<p>I'm trying wxpython for the first time. I've wrote a GUI for a python program and when I run it, it produces some error in the GUI, but the GUI disappears very quickly, quickly enough for me to be unable to read the error info.</p> <p>Is there any log that I can check for the error message? (I'm running Mac OS X) o...
18
2009-05-01T19:40:11Z
14,693,654
<p>If you are using Spyder, hit F6, check "interact with the python interpreter after execution". The window will not close, and you can see the error message.</p>
0
2013-02-04T19:04:06Z
[ "python", "user-interface", "wxpython" ]
I want to make a temporary answerphone which records MP3s
813,114
<p>An artistic project will encourage users to ring a number and leave a voice-mail on an automated service. These voice-mails will be collected and edited into a half-hour radio show. </p> <p>I want to make a <strong>temporary</strong> system (with as little as possible programming) which will:</p> <ul> <li>Allow me...
2
2009-05-01T20:25:56Z
813,128
<p>You may want to check out <a href="http://www.asterisk.org/" rel="nofollow">asterisk</a>. I don't think it will become any easier than using an existing system.</p> <p>Maybe you can find someone in the asterisk community to help set up such a system.</p>
1
2009-05-01T20:29:20Z
[ "python", "voip" ]
I want to make a temporary answerphone which records MP3s
813,114
<p>An artistic project will encourage users to ring a number and leave a voice-mail on an automated service. These voice-mails will be collected and edited into a half-hour radio show. </p> <p>I want to make a <strong>temporary</strong> system (with as little as possible programming) which will:</p> <ul> <li>Allow me...
2
2009-05-01T20:25:56Z
813,139
<p>I use twilio, very easy, very fun.</p>
5
2009-05-01T20:33:23Z
[ "python", "voip" ]
I want to make a temporary answerphone which records MP3s
813,114
<p>An artistic project will encourage users to ring a number and leave a voice-mail on an automated service. These voice-mails will be collected and edited into a half-hour radio show. </p> <p>I want to make a <strong>temporary</strong> system (with as little as possible programming) which will:</p> <ul> <li>Allow me...
2
2009-05-01T20:25:56Z
813,152
<p>Skype has a <a href="http://skype.com/allfeatures/voicemail/" rel="nofollow">voicemail</a> feature which sounds perfect for this and I suppose you would need a <a href="http://skype.com/allfeatures/onlinenumber/" rel="nofollow">SkypeIn number</a> as well</p>
2
2009-05-01T20:36:25Z
[ "python", "voip" ]
I want to make a temporary answerphone which records MP3s
813,114
<p>An artistic project will encourage users to ring a number and leave a voice-mail on an automated service. These voice-mails will be collected and edited into a half-hour radio show. </p> <p>I want to make a <strong>temporary</strong> system (with as little as possible programming) which will:</p> <ul> <li>Allow me...
2
2009-05-01T20:25:56Z
813,773
<p>Take a look at Sipgate.co.uk, they provide a free UK dial in number and free incoming calls. Not so relavant for you but they also have a python api.</p> <p>They are a SIP provider and there are many libraries (e.g. <a href="http://trac.pjsip.org/repos/wiki/Python_SIP_Tutorial" rel="nofollow">http://trac.pjsip.org...
1
2009-05-02T00:09:32Z
[ "python", "voip" ]
Does Python have properties?
813,135
<p>So something like:</p> <pre><code>vector3.Length </code></pre> <p>that's in fact a function call that calculates the length of the vector, not a variable.</p>
3
2009-05-01T20:32:08Z
813,140
<p>If your variable <em>vector3</em> is a 3-dimensional directed distance of a point from an origin, and you need its length, use something like:</p> <pre><code>import math vector3 = [5, 6, -7] print math.sqrt(vector3[0]**2 + vector3[1]**2 + vector3[2]**2) </code></pre> <p>If you need a solution which works for any n...
5
2009-05-01T20:33:38Z
[ "python" ]
Does Python have properties?
813,135
<p>So something like:</p> <pre><code>vector3.Length </code></pre> <p>that's in fact a function call that calculates the length of the vector, not a variable.</p>
3
2009-05-01T20:32:08Z
813,142
<p>Yes: <a href="http://docs.python.org/library/functions.html#property" rel="nofollow">http://docs.python.org/library/functions.html#property</a></p>
6
2009-05-01T20:34:09Z
[ "python" ]
Does Python have properties?
813,135
<p>So something like:</p> <pre><code>vector3.Length </code></pre> <p>that's in fact a function call that calculates the length of the vector, not a variable.</p>
3
2009-05-01T20:32:08Z
813,143
<p>With new-style classes you can use <code>property()</code>: <a href="http://www.python.org/download/releases/2.2.3/descrintro/#property" rel="nofollow">http://www.python.org/download/releases/2.2.3/descrintro/#property</a>.</p>
14
2009-05-01T20:34:36Z
[ "python" ]
Does Python have properties?
813,135
<p>So something like:</p> <pre><code>vector3.Length </code></pre> <p>that's in fact a function call that calculates the length of the vector, not a variable.</p>
3
2009-05-01T20:32:08Z
813,177
<p>Before the property() decorator came in, the idiom was using a no-parameter method for computed properties. This idiom is still often used in preference to the decorator, though that might be for consistency within a library that started before new-style classes.</p>
3
2009-05-01T20:43:33Z
[ "python" ]
Does Python have properties?
813,135
<p>So something like:</p> <pre><code>vector3.Length </code></pre> <p>that's in fact a function call that calculates the length of the vector, not a variable.</p>
3
2009-05-01T20:32:08Z
816,843
<p>you can override some special methods to change how attributes are accesss, see the python documentation <a href="http://docs.python.org/reference/datamodel.html#customizing-attribute-access" rel="nofollow">here</a> or <a href="http://docs.python.org/reference/datamodel.html#more-attribute-access-for-new-style-clas...
0
2009-05-03T11:40:58Z
[ "python" ]
Ruby String Translation
813,147
<p>I want to find the successor of each element in my encoded string. For example K->M A->C etc. </p> <pre><code>string.each_char do |ch| dummy_string&lt;&lt; ch.succ.succ end </code></pre> <p>However this method translates y->aa. </p> <p>Is there a method in Ruby that is like maketrans() in Python?</p>
2
2009-05-01T20:35:38Z
813,179
<p>You seem to be looking for <a href="http://ruby-doc.org/core/classes/String.html#M000845">String#tr</a>. Use like this: <code>some_string.tr('a-zA-Z', 'c-zabC-ZAB')</code></p>
8
2009-05-01T20:43:54Z
[ "python", "ruby", "string" ]
Ruby String Translation
813,147
<p>I want to find the successor of each element in my encoded string. For example K->M A->C etc. </p> <pre><code>string.each_char do |ch| dummy_string&lt;&lt; ch.succ.succ end </code></pre> <p>However this method translates y->aa. </p> <p>Is there a method in Ruby that is like maketrans() in Python?</p>
2
2009-05-01T20:35:38Z
813,184
<p>I don't know of one offhand, but I think the Ruby way would probably involve passing a block to a regexp function. Here's a dumb one that only works for upper-case letters:</p> <pre><code>"ABCYZ".gsub(/\w/) { |a| a=="Z" ? "A" : a.succ } =&gt; "BCDZA" </code></pre> <p>Edit: meh, never mind, listen to Pesto, he sou...
0
2009-05-01T20:44:28Z
[ "python", "ruby", "string" ]
Ruby String Translation
813,147
<p>I want to find the successor of each element in my encoded string. For example K->M A->C etc. </p> <pre><code>string.each_char do |ch| dummy_string&lt;&lt; ch.succ.succ end </code></pre> <p>However this method translates y->aa. </p> <p>Is there a method in Ruby that is like maketrans() in Python?</p>
2
2009-05-01T20:35:38Z
813,189
<pre><code>def successor(s) s.tr('a-zA-Z','c-zabC-ZAB') end successor("Chris Doggett") #"Ejtku Fqiigvv" </code></pre>
1
2009-05-01T20:45:37Z
[ "python", "ruby", "string" ]
Embedding a Python shell inside a Python program
813,571
<p>I am making a sort of a science lab in Python, in which the user can create, modify and analyze all sorts of objects. I would like to put a Python shell inside the program, so the user could manipulate the objects through the shell. (Note: He could also manipulate the objects through the usual GUI.)</p> <p>A mockup...
11
2009-05-01T22:31:41Z
813,588
<p>The Python <code>eval()</code> function only handles expressions. You may want to consider the <a href="http://docs.python.org/reference/simple%5Fstmts.html#grammar-token-exec%5Fstmt" rel="nofollow"><code>exec</code></a> statement instead, which can run any arbitrary Python code.</p>
3
2009-05-01T22:37:13Z
[ "python", "shell" ]
Embedding a Python shell inside a Python program
813,571
<p>I am making a sort of a science lab in Python, in which the user can create, modify and analyze all sorts of objects. I would like to put a Python shell inside the program, so the user could manipulate the objects through the shell. (Note: He could also manipulate the objects through the usual GUI.)</p> <p>A mockup...
11
2009-05-01T22:31:41Z
813,593
<p>You are looking for <a href="http://docs.python.org/library/code.html" rel="nofollow">code - Interpreter base classes</a>, particularly code.interact().</p> <p>Some <a href="http://effbot.org/librarybook/code.htm" rel="nofollow">examples from effbot</a>.</p>
14
2009-05-01T22:38:19Z
[ "python", "shell" ]
Embedding a Python shell inside a Python program
813,571
<p>I am making a sort of a science lab in Python, in which the user can create, modify and analyze all sorts of objects. I would like to put a Python shell inside the program, so the user could manipulate the objects through the shell. (Note: He could also manipulate the objects through the usual GUI.)</p> <p>A mockup...
11
2009-05-01T22:31:41Z
813,736
<p>FWIW, I believe Enthought has written something like this for use with their Python-based (and NumPy-based) visualization suite. I saw a demo two years ago where they indeed let you manipulate objects directly via the GUI or via the Python interpreter.</p> <p>Also, to add to the first answer, you might have to sub...
2
2009-05-01T23:47:40Z
[ "python", "shell" ]
Embedding a Python shell inside a Python program
813,571
<p>I am making a sort of a science lab in Python, in which the user can create, modify and analyze all sorts of objects. I would like to put a Python shell inside the program, so the user could manipulate the objects through the shell. (Note: He could also manipulate the objects through the usual GUI.)</p> <p>A mockup...
11
2009-05-01T22:31:41Z
814,817
<p>Depending on your GUI framework, it may already has been done:</p> <ul> <li>For wxpython, look up "PyCrust" - it's very easy to embed into your app</li> <li>For PyQt, <a href="http://code.google.com/p/pyqtshell/">pyqtshell</a> (<strong>Update 29.04.2011:</strong> these days called <code>spyder</code>)</li> </ul> ...
10
2009-05-02T12:48:42Z
[ "python", "shell" ]
Embedding a Python shell inside a Python program
813,571
<p>I am making a sort of a science lab in Python, in which the user can create, modify and analyze all sorts of objects. I would like to put a Python shell inside the program, so the user could manipulate the objects through the shell. (Note: He could also manipulate the objects through the usual GUI.)</p> <p>A mockup...
11
2009-05-01T22:31:41Z
15,499,439
<p>I use pdb.set_trace() as a shell. It also has some debugging capabilities :)</p>
0
2013-03-19T12:24:07Z
[ "python", "shell" ]
Is there a way to check whether function output is assigned to a variable in Python?
813,882
<p>In Python, I'd like to write a function that would pretty-print its results to the console if called by itself (mostly for use interactively or for debugging). For the purpose of this question, let's say it checks the status of something. If I call just</p> <pre><code>check_status() </code></pre> <p>I would like t...
2
2009-05-02T01:08:18Z
813,899
<p>There is no way for a function to know how its return value is being used.</p> <p>Well, as you mention, egregious bytecode hacks might be able to do it, but it would be really complicated and probably fragile. Go the simpler explicit route.</p>
1
2009-05-02T01:15:11Z
[ "python", "functional-programming", "bytecode" ]
Is there a way to check whether function output is assigned to a variable in Python?
813,882
<p>In Python, I'd like to write a function that would pretty-print its results to the console if called by itself (mostly for use interactively or for debugging). For the purpose of this question, let's say it checks the status of something. If I call just</p> <pre><code>check_status() </code></pre> <p>I would like t...
2
2009-05-02T01:08:18Z
813,901
<p>There is no way to do this, at least not with the normal syntax procedures, because the function call and the assignment are completely independent operations, which have no awareness of each other.</p> <p>The simplest workaround I can see for this is to pass a flag as an arg to your <code>check_status</code> funct...
0
2009-05-02T01:16:21Z
[ "python", "functional-programming", "bytecode" ]
Is there a way to check whether function output is assigned to a variable in Python?
813,882
<p>In Python, I'd like to write a function that would pretty-print its results to the console if called by itself (mostly for use interactively or for debugging). For the purpose of this question, let's say it checks the status of something. If I call just</p> <pre><code>check_status() </code></pre> <p>I would like t...
2
2009-05-02T01:08:18Z
813,908
<p>The only way to do what you want is indeed "to play with the bytecode" -- there is no other way to recover that info. A much better way, of course, is to provide two separate functions: one to get the status as a dict, the other to call the first one and format it. </p> <p>Alternatively (but not an excellent arch...
0
2009-05-02T01:18:41Z
[ "python", "functional-programming", "bytecode" ]
Is there a way to check whether function output is assigned to a variable in Python?
813,882
<p>In Python, I'd like to write a function that would pretty-print its results to the console if called by itself (mostly for use interactively or for debugging). For the purpose of this question, let's say it checks the status of something. If I call just</p> <pre><code>check_status() </code></pre> <p>I would like t...
2
2009-05-02T01:08:18Z
813,930
<blockquote> <p>However, I would also like it to pass the output as a list</p> </blockquote> <p>You mean "return the output as a dictionary" - be careful ;-)</p> <p>One thing you could do is use the ability of the Python interpreter to automatically convert to a string the result of any expression. To do this, crea...
4
2009-05-02T01:32:18Z
[ "python", "functional-programming", "bytecode" ]
Is there a way to check whether function output is assigned to a variable in Python?
813,882
<p>In Python, I'd like to write a function that would pretty-print its results to the console if called by itself (mostly for use interactively or for debugging). For the purpose of this question, let's say it checks the status of something. If I call just</p> <pre><code>check_status() </code></pre> <p>I would like t...
2
2009-05-02T01:08:18Z
813,938
<p><strong>New Solution</strong></p> <p>This is a new that solution detects when the result of the function is used for assignment by examining its own bytecode. There is no bytecode writing done, and it should even be compatible with future versions of Python because it uses the opcode module for definitions.</p> <p...
6
2009-05-02T01:35:18Z
[ "python", "functional-programming", "bytecode" ]
Is there a way to check whether function output is assigned to a variable in Python?
813,882
<p>In Python, I'd like to write a function that would pretty-print its results to the console if called by itself (mostly for use interactively or for debugging). For the purpose of this question, let's say it checks the status of something. If I call just</p> <pre><code>check_status() </code></pre> <p>I would like t...
2
2009-05-02T01:08:18Z
813,953
<p>There's no use case for this. Python assigns all interactive results to a special variable named <code>_</code>. </p> <p>You can do the following interactively. Works great. No funny business.</p> <pre><code>&gt;&gt;&gt; check_status() {'cond_op': 1, 't_canoncharge': 1342, 'stage_booster': 5, 'range_est_sigma'...
2
2009-05-02T01:42:49Z
[ "python", "functional-programming", "bytecode" ]