title
stringlengths
10
172
question_id
int64
469
40.1M
question_body
stringlengths
22
48.2k
question_score
int64
-44
5.52k
question_date
stringlengths
20
20
answer_id
int64
497
40.1M
answer_body
stringlengths
18
33.9k
answer_score
int64
-38
8.38k
answer_date
stringlengths
20
20
tags
list
Getting a list of all churches in a certain state using Python
1,903,966
<p>I am pretty good with Python, so pseudo-code will suffice when details are trivial. Please get me started on the task - how do go about crawling the net for the snail mail addresses of churches in my state. Once I have a one liner such as "123 Old West Road #3 Old Lyme City MD 01234", I can probably parse it into Ci...
-3
2009-12-14T22:29:44Z
1,904,300
<p>Python scripts might not be the best tool for this job, if you're just looking for addresses of churches in a geographic area.</p> <p>The US census provides a data set of churches for use with geographic information systems. If finding all the <code>x</code> in a spatial area is a recurring problem, invest in learn...
1
2009-12-14T23:34:17Z
[ "python", "automation", "web-crawler", "pseudocode", "street-address" ]
why list comprehension is called so in python?
1,903,980
<p>No flaming please, asking as a community wiki so nobody gets reputation here. I know python is not the first language to have list comprehension. I'm just interest in the history of the name.</p> <p>I'm particularly interested in why it's called <strong>comprehension</strong></p>
7
2009-12-14T22:32:11Z
1,903,994
<p>The history section of the wikipedia page discusses a little on where it came from. <a href="http://en.wikipedia.org/wiki/List%5Fcomprehension#History" rel="nofollow">List_comprehension#History</a></p>
1
2009-12-14T22:34:49Z
[ "python", "naming-conventions", "list-comprehension" ]
why list comprehension is called so in python?
1,903,980
<p>No flaming please, asking as a community wiki so nobody gets reputation here. I know python is not the first language to have list comprehension. I'm just interest in the history of the name.</p> <p>I'm particularly interested in why it's called <strong>comprehension</strong></p>
7
2009-12-14T22:32:11Z
1,904,054
<p>The name comes from the concept of a <a href="http://en.wikipedia.org/wiki/Set-builder%5Fnotation">set-comprehension</a></p> <p><em>Comprehension</em> is used here to mean <strong>complete inclusion</strong> or <strong>complete description</strong>. A set-comprehension is a (usually short) complete description of a...
7
2009-12-14T22:46:34Z
[ "python", "naming-conventions", "list-comprehension" ]
why list comprehension is called so in python?
1,903,980
<p>No flaming please, asking as a community wiki so nobody gets reputation here. I know python is not the first language to have list comprehension. I'm just interest in the history of the name.</p> <p>I'm particularly interested in why it's called <strong>comprehension</strong></p>
7
2009-12-14T22:32:11Z
2,005,502
<p>Because it's a very <strong>comprehensive</strong> way to describe a sequence (a set in math and other languages, and a list/sequence in Python).</p>
1
2010-01-05T10:55:29Z
[ "python", "naming-conventions", "list-comprehension" ]
why list comprehension is called so in python?
1,903,980
<p>No flaming please, asking as a community wiki so nobody gets reputation here. I know python is not the first language to have list comprehension. I'm just interest in the history of the name.</p> <p>I'm particularly interested in why it's called <strong>comprehension</strong></p>
7
2009-12-14T22:32:11Z
17,777,329
<p>"Comprehension" used to mean not only "understanding," but "inclusion" in logic. Oxford English Dictionary has the following: "I.4. <em>Logic</em> The sum of the attributes comprehended in a notion or concept; intension" as the fourth subdefinition under the first definition, "Inclusion, comprising." I wouldn't be...
0
2013-07-21T21:54:23Z
[ "python", "naming-conventions", "list-comprehension" ]
Django + MySQL on Mac OS 10.6.2 Snow Leopard
1,904,039
<p>There were some excellent answers to this question already, however, they are now outdated.</p> <p>I've been able to get the module installed, but "python manage.py runserver" fails with</p> <pre><code> iMac:myproject drhoden$ python manage.py runserver Validating models... Unhandled exception in thread started ...
9
2009-12-14T22:43:19Z
1,908,088
<p>This happens when you have mixed 32 and 64bit software. </p> <p>Basically, for Snow Leopard, you need to install MySQL 64bit package (which still is listed as 10.5, but that is no problem) , after that do an easy install of python-mysql again. All will work.</p>
1
2009-12-15T15:09:07Z
[ "python", "mysql", "django", "osx-snow-leopard" ]
Django + MySQL on Mac OS 10.6.2 Snow Leopard
1,904,039
<p>There were some excellent answers to this question already, however, they are now outdated.</p> <p>I've been able to get the module installed, but "python manage.py runserver" fails with</p> <pre><code> iMac:myproject drhoden$ python manage.py runserver Validating models... Unhandled exception in thread started ...
9
2009-12-14T22:43:19Z
1,908,157
<p>I wrote a blog post a few months ago following my successful installation of MySQL on Snow Leopard:</p> <p><a href="http://jboxer.com/2009/09/installing-mysql-on-snow-leopard/" rel="nofollow">http://jboxer.com/2009/09/installing-mysql-on-snow-leopard/</a></p> <p>If you follow those steps, it should (theoretically)...
4
2009-12-15T15:21:52Z
[ "python", "mysql", "django", "osx-snow-leopard" ]
Django + MySQL on Mac OS 10.6.2 Snow Leopard
1,904,039
<p>There were some excellent answers to this question already, however, they are now outdated.</p> <p>I've been able to get the module installed, but "python manage.py runserver" fails with</p> <pre><code> iMac:myproject drhoden$ python manage.py runserver Validating models... Unhandled exception in thread started ...
9
2009-12-14T22:43:19Z
1,914,329
<p>I have ultimately solved my own problem, with of course, the subconscious and conscious help from the many posts, blogs, and mail logs I've read. I would give links if I could remember.</p> <p>In a nutshell, I reinstalled EVERYTHING using MacPorts. </p> <p>After editing ~/.bash_profile and commenting out all the...
21
2009-12-16T12:18:31Z
[ "python", "mysql", "django", "osx-snow-leopard" ]
python libraries for programatic email access: mime, smtp, pop3
1,904,108
<p>Does python have built in libraries for accessing email including: smtp, pop3, mime parsers etc?</p>
0
2009-12-14T22:58:36Z
1,904,163
<p>Absolutely:</p> <ul> <li><a href="http://docs.python.org/library/smtplib.html" rel="nofollow">smtplib — SMTP protocol client</a></li> <li><a href="http://docs.python.org/library/poplib.html" rel="nofollow">poplib — POP3 protocol client</a></li> <li><a href="http://docs.python.org/library/imaplib.html" rel="nofo...
3
2009-12-14T23:07:27Z
[ "python", "email", "pop3" ]
Python: Checking Header Format
1,904,170
<p>I'm new to python and need help with a problem. Basically I need to open a file and read it which I can do no problem. The problem arises at line 0, where I need to check the header format.</p> <p>The header needs to be in the format: <code>p wncf nvar nclauses hard</code> where 'nvar' 'nclauses' and 'hard' are all...
2
2009-12-14T23:09:35Z
1,903,764
<p>something like that (lines is a list of all the lines in order):</p> <pre><code>import re if re.match(r'p wncf \d+ \d+ \d+', lines[0]) == None: print "Bad format" </code></pre>
4
2009-12-14T21:54:31Z
[ "python", "file", "input", "header", "format" ]
Python: Checking Header Format
1,904,170
<p>I'm new to python and need help with a problem. Basically I need to open a file and read it which I can do no problem. The problem arises at line 0, where I need to check the header format.</p> <p>The header needs to be in the format: <code>p wncf nvar nclauses hard</code> where 'nvar' 'nclauses' and 'hard' are all...
2
2009-12-14T23:09:35Z
1,903,809
<pre><code>p, wncf, nvar, nclauses, hard = line.split() nvar = int(nvar) nclauses = int(nclauses) hard = int(hard) </code></pre>
1
2009-12-14T22:02:09Z
[ "python", "file", "input", "header", "format" ]
Python: Checking Header Format
1,904,170
<p>I'm new to python and need help with a problem. Basically I need to open a file and read it which I can do no problem. The problem arises at line 0, where I need to check the header format.</p> <p>The header needs to be in the format: <code>p wncf nvar nclauses hard</code> where 'nvar' 'nclauses' and 'hard' are all...
2
2009-12-14T23:09:35Z
1,903,860
<p>Using regular expressions would be about the easiest way to check this header:-</p> <pre><code>import re p = re.compile('p wncf \d+ \d+ \d+$') if p.match(lineToBeChecked) == None: print "Header does not have correct format" </code></pre> <p>Note the use of the trailing $ in the regex to anchor the regex to the e...
0
2009-12-14T22:10:32Z
[ "python", "file", "input", "header", "format" ]
Python: Checking Header Format
1,904,170
<p>I'm new to python and need help with a problem. Basically I need to open a file and read it which I can do no problem. The problem arises at line 0, where I need to check the header format.</p> <p>The header needs to be in the format: <code>p wncf nvar nclauses hard</code> where 'nvar' 'nclauses' and 'hard' are all...
2
2009-12-14T23:09:35Z
1,904,225
<p>Alright, a few things.</p> <ol> <li><p>You only need to compile your regular expression once. In the example you gave above, you're recompiling it for every line in the file.</p></li> <li><p><code>line[0]</code> is just the first character in each line. Replace <code>line[0]</code> with <code>line</code> and your c...
6
2009-12-14T23:18:52Z
[ "python", "file", "input", "header", "format" ]
Python: Checking Header Format
1,904,170
<p>I'm new to python and need help with a problem. Basically I need to open a file and read it which I can do no problem. The problem arises at line 0, where I need to check the header format.</p> <p>The header needs to be in the format: <code>p wncf nvar nclauses hard</code> where 'nvar' 'nclauses' and 'hard' are all...
2
2009-12-14T23:09:35Z
1,904,235
<p>You might want to use <code>p.match(line)</code> instead. You're passing the first character of the line to the regex, not the whole line.</p>
2
2009-12-14T23:21:00Z
[ "python", "file", "input", "header", "format" ]
Python: Checking Header Format
1,904,170
<p>I'm new to python and need help with a problem. Basically I need to open a file and read it which I can do no problem. The problem arises at line 0, where I need to check the header format.</p> <p>The header needs to be in the format: <code>p wncf nvar nclauses hard</code> where 'nvar' 'nclauses' and 'hard' are all...
2
2009-12-14T23:09:35Z
1,904,599
<p>hi you don't need a regex to do this. here's one way you can check your header.</p> <pre><code>fh=open("file") header=fh.readline().rstrip() if not header.startswith("p wncf") : print "error" header=header.split() if len(header) != 5: print "error" if False in map(str.isdigit, header[2:]): print "Error"...
1
2009-12-15T00:56:13Z
[ "python", "file", "input", "header", "format" ]
Run a remote python script from ASP.Net
1,904,320
<p>I have a python script on a linux server that I can SSH into and I want to run the script on the linux server( and pass it parameters entered by the user) and get the output on an ASP.net webpage running on IIS. How would I be able to do that?</p> <p>Would it be easier if I was running a wamp server?</p> <p>Edit:...
1
2009-12-14T23:40:40Z
1,904,344
<p>Probably the best approach is the least coupled one. If you can determine a protocol that you're comfortable with the two (asp/python) talking in, it will go a long way to reducing headaches.</p> <p>Let's say you pick XML.</p> <p>Setup the python script to run as a WSGI application with either cherrypy or apache ...
0
2009-12-14T23:49:09Z
[ "asp.net", "python", "remote-execution" ]
Python Observer Pattern: Examples, Tips?
1,904,351
<p>Are there any exemplary examples of the GoF Observer implemented in Python? I have a bit code which currently has bits of debugging code laced through the key class (currently generating messages to stderr if a magic env is set). Additionally, the class has an interface for incrementally return results as well as s...
24
2009-12-14T23:51:31Z
1,904,379
<p>From <a href="http://en.wikipedia.org/wiki/Observer%5Fpattern#Python" rel="nofollow">wikipedia</a>:</p> <pre><code>from collections import defaultdict class Observable (defaultdict): def __init__ (self): defaultdict.__init__(self, object) def emit (self, *args): '''Pass parameters to all observer...
4
2009-12-14T23:57:24Z
[ "python", "design", "design-patterns", "listener", "observer-pattern" ]
Python Observer Pattern: Examples, Tips?
1,904,351
<p>Are there any exemplary examples of the GoF Observer implemented in Python? I have a bit code which currently has bits of debugging code laced through the key class (currently generating messages to stderr if a magic env is set). Additionally, the class has an interface for incrementally return results as well as s...
24
2009-12-14T23:51:31Z
1,904,428
<h3>Example: <a href="http://twistedmatrix.com/documents/current/core/howto/logging.html#auto4" rel="nofollow">twisted log observers</a></h3> <p>To register an observer <code>yourCallable()</code> (a callable that accepts a dictionary) to receive all log events (in addition to any other observers):</p> <pre><code>twi...
1
2009-12-15T00:09:43Z
[ "python", "design", "design-patterns", "listener", "observer-pattern" ]
Python Observer Pattern: Examples, Tips?
1,904,351
<p>Are there any exemplary examples of the GoF Observer implemented in Python? I have a bit code which currently has bits of debugging code laced through the key class (currently generating messages to stderr if a magic env is set). Additionally, the class has an interface for incrementally return results as well as s...
24
2009-12-14T23:51:31Z
1,925,836
<blockquote> <p>However it does lack flexibility.</p> </blockquote> <p>Well... actually, this looks like a good design to me if an asynchronous API is what you want. It usually is. Maybe all you need is to switch from stderr to Python's <a href="http://docs.python.org/library/logging.html"><code>logging</code></a> m...
30
2009-12-18T01:59:40Z
[ "python", "design", "design-patterns", "listener", "observer-pattern" ]
Python Observer Pattern: Examples, Tips?
1,904,351
<p>Are there any exemplary examples of the GoF Observer implemented in Python? I have a bit code which currently has bits of debugging code laced through the key class (currently generating messages to stderr if a magic env is set). Additionally, the class has an interface for incrementally return results as well as s...
24
2009-12-14T23:51:31Z
1,926,336
<p>A few more approaches...</p> <h3>Example: the logging module</h3> <p>Maybe all you need is to switch from stderr to Python's <a href="http://docs.python.org/library/logging.html#datagramhandler"><code>logging</code></a> module, which has a powerful publish/subscribe model.</p> <p>It's easy to get started producin...
8
2009-12-18T04:48:29Z
[ "python", "design", "design-patterns", "listener", "observer-pattern" ]
Python Observer Pattern: Examples, Tips?
1,904,351
<p>Are there any exemplary examples of the GoF Observer implemented in Python? I have a bit code which currently has bits of debugging code laced through the key class (currently generating messages to stderr if a magic env is set). Additionally, the class has an interface for incrementally return results as well as s...
24
2009-12-14T23:51:31Z
18,022,066
<p>Based on Jason's answer, I implemented the C#-like events example as a fully-fledged python module including documentation and tests. I love fancy pythonic stuff :)</p> <p>So, if you want some ready-to-use solution, you can just use the <a href="https://github.com/aepsil0n/event" rel="nofollow">code on github</a>.<...
2
2013-08-02T16:38:59Z
[ "python", "design", "design-patterns", "listener", "observer-pattern" ]
Python Observer Pattern: Examples, Tips?
1,904,351
<p>Are there any exemplary examples of the GoF Observer implemented in Python? I have a bit code which currently has bits of debugging code laced through the key class (currently generating messages to stderr if a magic env is set). Additionally, the class has an interface for incrementally return results as well as s...
24
2009-12-14T23:51:31Z
20,666,808
<p>A functional approach to observer design:</p> <pre><code>def add_listener(obj, method_name, listener): # Get any existing listeners listener_attr = method_name + '_listeners' listeners = getattr(obj, listener_attr, None) # If this is the first listener, then set up the method wrapper if not li...
0
2013-12-18T19:31:47Z
[ "python", "design", "design-patterns", "listener", "observer-pattern" ]
Python Observer Pattern: Examples, Tips?
1,904,351
<p>Are there any exemplary examples of the GoF Observer implemented in Python? I have a bit code which currently has bits of debugging code laced through the key class (currently generating messages to stderr if a magic env is set). Additionally, the class has an interface for incrementally return results as well as s...
24
2009-12-14T23:51:31Z
23,668,721
<p>How about an implementation where objects aren't kept alive just because they're observing something? Below please find an implementation of the observer pattern with the following features:</p> <ol> <li>Usage is pythonic. To add an observer to a bound method <code>.bar</code> of instance <code>foo</code>, just do ...
3
2014-05-15T03:24:56Z
[ "python", "design", "design-patterns", "listener", "observer-pattern" ]
Python Observer Pattern: Examples, Tips?
1,904,351
<p>Are there any exemplary examples of the GoF Observer implemented in Python? I have a bit code which currently has bits of debugging code laced through the key class (currently generating messages to stderr if a magic env is set). Additionally, the class has an interface for incrementally return results as well as s...
24
2009-12-14T23:51:31Z
27,315,715
<p>I think people in the other answers overdo it. You can easily achieve events in Python with less than 15 lines of code.</p> <p>You simple have two classes: <code>Event</code> and <code>Observer</code>. Any class that wants to listen for an event, needs to inherit Observer and set to listen (observe) for a specific ...
7
2014-12-05T12:17:00Z
[ "python", "design", "design-patterns", "listener", "observer-pattern" ]
Read the first line of a file using Python
1,904,394
<p>How would you get only the first line of a file as a string with Python?</p>
71
2009-12-15T00:00:48Z
1,904,407
<p>This should do it:</p> <pre><code>f = open('myfile.txt') first = f.readline() </code></pre>
5
2009-12-15T00:03:46Z
[ "python", "file" ]
Read the first line of a file using Python
1,904,394
<p>How would you get only the first line of a file as a string with Python?</p>
71
2009-12-15T00:00:48Z
1,904,409
<pre><code>infile = open('filename.txt', 'r') firstLine = infile.readline() </code></pre>
15
2009-12-15T00:04:01Z
[ "python", "file" ]
Read the first line of a file using Python
1,904,394
<p>How would you get only the first line of a file as a string with Python?</p>
71
2009-12-15T00:00:48Z
1,904,455
<p>Use the <code>.readline()</code> method (<a href="https://docs.python.org/2/library/stdtypes.html#file.readline">Python 2 docs</a>, <a href="https://docs.python.org/3/library/io.html#io.IOBase.readline">Python 3 docs</a>):</p> <pre><code>with open('myfile.txt', 'r') as f: first_line = f.readline() </code></pre>...
136
2009-12-15T00:17:17Z
[ "python", "file" ]
Read the first line of a file using Python
1,904,394
<p>How would you get only the first line of a file as a string with Python?</p>
71
2009-12-15T00:00:48Z
1,904,498
<p>I'm going to go ahead and spice this up a little bit:</p> <pre><code>with open('myfile.txt','r') as f: line = f.readline() </code></pre>
-2
2009-12-15T00:28:11Z
[ "python", "file" ]
Read the first line of a file using Python
1,904,394
<p>How would you get only the first line of a file as a string with Python?</p>
71
2009-12-15T00:00:48Z
1,904,563
<pre><code>fline=open("myfile").readline().rstrip() </code></pre>
10
2009-12-15T00:45:08Z
[ "python", "file" ]
Read the first line of a file using Python
1,904,394
<p>How would you get only the first line of a file as a string with Python?</p>
71
2009-12-15T00:00:48Z
1,904,743
<p>Lots of other answers here, but to answer <em>precisely</em> the question you asked (before @MarkAmery went and edited the original question and changed the meaning):</p> <pre><code>&gt;&gt;&gt; f = open('myfile.txt') &gt;&gt;&gt; data = f.read() &gt;&gt;&gt; # I'm assuming you had the above before asking the quest...
4
2009-12-15T01:43:26Z
[ "python", "file" ]
Read the first line of a file using Python
1,904,394
<p>How would you get only the first line of a file as a string with Python?</p>
71
2009-12-15T00:00:48Z
1,904,928
<p>To go back to the beginning of an open file, do this:</p> <pre><code>my_file.seek(0) </code></pre>
7
2009-12-15T02:55:17Z
[ "python", "file" ]
Read the first line of a file using Python
1,904,394
<p>How would you get only the first line of a file as a string with Python?</p>
71
2009-12-15T00:00:48Z
13,430,432
<pre><code>first_line = next(open(filename)) </code></pre>
6
2012-11-17T12:13:08Z
[ "python", "file" ]
Read the first line of a file using Python
1,904,394
<p>How would you get only the first line of a file as a string with Python?</p>
71
2009-12-15T00:00:48Z
30,826,878
<pre><code>f1 = open("input1.txt", "r") print(f1.readline()) </code></pre>
-4
2015-06-14T07:17:11Z
[ "python", "file" ]
Best dynamic languages for OpenGL/general graphics
1,904,454
<p>Which are the most mature and well supported solutions for writing graphical programs?</p> <p>I have been using C++ with OpenGL/GLUT, but would like to try a more flexible and expressive approach.</p> <p>Ruby and Processing? Python and OGRE? What things have worked well for you?</p>
6
2009-12-15T00:17:14Z
1,904,466
<p>Given you are familiar with C++, you might give <a href="http://www.lua.org/">Lua</a> a try. Lua is a dynamic language that can be embedded in any C/C++ program. It is very popular in the game industry.</p>
5
2009-12-15T00:20:37Z
[ "python", "ruby", "graphics", "scheme", "processing" ]
Best dynamic languages for OpenGL/general graphics
1,904,454
<p>Which are the most mature and well supported solutions for writing graphical programs?</p> <p>I have been using C++ with OpenGL/GLUT, but would like to try a more flexible and expressive approach.</p> <p>Ruby and Processing? Python and OGRE? What things have worked well for you?</p>
6
2009-12-15T00:17:14Z
1,904,621
<p>If you are just interested in experimenting, I'd suggest picking a 3D framework with bindings for a dynamic language you are already familiar with.</p> <p>I started doing experiments with Ruby/OpenGL a year or three ago and that was easy enough to play around with.</p> <p>If you seriously want to build a project (...
6
2009-12-15T01:06:00Z
[ "python", "ruby", "graphics", "scheme", "processing" ]
Best dynamic languages for OpenGL/general graphics
1,904,454
<p>Which are the most mature and well supported solutions for writing graphical programs?</p> <p>I have been using C++ with OpenGL/GLUT, but would like to try a more flexible and expressive approach.</p> <p>Ruby and Processing? Python and OGRE? What things have worked well for you?</p>
6
2009-12-15T00:17:14Z
1,905,523
<p>If you are looking for dynamic languages that support OpenGL out-of-the-box (no external bindings) try these:</p> <ul> <li><a href="http://www.plt-scheme.org/" rel="nofollow">PLT Scheme</a></li> <li><a href="http://spark-scheme.wikispot.org/" rel="nofollow">Spark-Scheme</a></li> <li><a href="http://factorcode.org/"...
2
2009-12-15T06:21:37Z
[ "python", "ruby", "graphics", "scheme", "processing" ]
Best dynamic languages for OpenGL/general graphics
1,904,454
<p>Which are the most mature and well supported solutions for writing graphical programs?</p> <p>I have been using C++ with OpenGL/GLUT, but would like to try a more flexible and expressive approach.</p> <p>Ruby and Processing? Python and OGRE? What things have worked well for you?</p>
6
2009-12-15T00:17:14Z
2,674,549
<p>I would like to mention Python with <a href="http://pyopengl.sourceforge.net/" rel="nofollow">PyOpenGL</a> as an option to consider.</p> <p>If you are already familiar with OpenGL, PyOpenGL is basically a API wrapper written in Python. I was surprised at first how similar the code looks in Python and in C++. Like t...
3
2010-04-20T11:15:07Z
[ "python", "ruby", "graphics", "scheme", "processing" ]
Best dynamic languages for OpenGL/general graphics
1,904,454
<p>Which are the most mature and well supported solutions for writing graphical programs?</p> <p>I have been using C++ with OpenGL/GLUT, but would like to try a more flexible and expressive approach.</p> <p>Ruby and Processing? Python and OGRE? What things have worked well for you?</p>
6
2009-12-15T00:17:14Z
3,779,827
<p>My personal suggestion if you are after maturity and support would be <a href="http://processing.org/" rel="nofollow">Processing</a> - very flexible, open source, well documented and a <a href="http://www.openprocessing.org/" rel="nofollow">great community</a>. Syntax is C-like so you should have no difficulty picki...
2
2010-09-23T15:16:52Z
[ "python", "ruby", "graphics", "scheme", "processing" ]
PyQt: Call a TrayMinimized application
1,904,557
<p>I have an application wich is minimized to the tray (showing an icon) when the user close it. What I need to know is how can I call it back with a combination of keys, like Ctrl+Alt+Something. Actually I call it back when I double-click it, but it will be nice to do the same on a keystroke. Here is a portion of the ...
0
2009-12-15T00:43:12Z
1,905,434
<p>For a keystroke to be handled by your application when it does not have keyboard focus, you need to install a global shortcut. Qt doesn't support this, but Qxt, a Qt extension library, does. See <a href="http://doc.libqxt.org/0.5.0/classQxtGlobalShortcut.html" rel="nofollow">http://doc.libqxt.org/0.5.0/classQxtGlob...
1
2009-12-15T05:57:45Z
[ "python", "qt", "pyqt" ]
What is the correct method of handling events in PyQt 4?
1,904,567
<p>I have seen examples like this:</p> <pre><code>self.connect(self.ui.add_button, QtCore.SIGNAL('clicked()'),self.printer) </code></pre> <p>And examples like this:</p> <pre><code>self.ui.add_button.clicked.connect(self.printer) </code></pre> <p>I'm just starting to learn Qt; which one should I focus on?</p>
2
2009-12-15T00:45:45Z
1,904,583
<p>I think that the second example is only supported by some Qt versions (the newer ones), while the first it supported by older ones. But, both are correct.</p>
3
2009-12-15T00:50:10Z
[ "python", "pyqt4" ]
What is the correct method of handling events in PyQt 4?
1,904,567
<p>I have seen examples like this:</p> <pre><code>self.connect(self.ui.add_button, QtCore.SIGNAL('clicked()'),self.printer) </code></pre> <p>And examples like this:</p> <pre><code>self.ui.add_button.clicked.connect(self.printer) </code></pre> <p>I'm just starting to learn Qt; which one should I focus on?</p>
2
2009-12-15T00:45:45Z
6,793,132
<p>AFAIK, the newer style doesn't work if there are overloaded signals, so </p> <pre><code>self.ui.add_button.clicked.connect(self.printer) </code></pre> <p>can't be used if there's also, say, a</p> <pre><code>clicked(float, float) </code></pre> <p>so you'd have to fall back to the older style. It's always good to ...
0
2011-07-22T16:32:24Z
[ "python", "pyqt4" ]
What is the correct method of handling events in PyQt 4?
1,904,567
<p>I have seen examples like this:</p> <pre><code>self.connect(self.ui.add_button, QtCore.SIGNAL('clicked()'),self.printer) </code></pre> <p>And examples like this:</p> <pre><code>self.ui.add_button.clicked.connect(self.printer) </code></pre> <p>I'm just starting to learn Qt; which one should I focus on?</p>
2
2009-12-15T00:45:45Z
9,743,190
<p>I know this post is pretty old, but I just stumbled across it, maybe you will too and now this saves your day ;) ok... by the way, it's my first post here on SO, yey!</p> <p>WARNING, i did not test this code, i just copied some snippets of code i wrote some time ago, so, there may be some error, but I hope it helps...
0
2012-03-16T19:12:44Z
[ "python", "pyqt4" ]
Py2exe: Embed static files in library.zip or exe file itself and transparently access them at runtime
1,904,647
<p>Is there a way to have py2exe embed static files (and/or subdirectories of static files) in a library.zip and/or the exe file itself (with zipfile=None) and then transparently access these embedded static files from code at runtime?</p> <p>Thank you, Malcolm</p>
5
2009-12-15T01:11:57Z
1,904,709
<p>This sounds like the recipe you need: <a href="http://crazedmonkey.com/blog/python/pkg%5Fresources-with-py2exe.html" rel="nofollow">Extend py2exe to copy files to the zipfile where pkg_resources can load them</a></p> <p>Using that effectively probably requires some knowledge of <a href="http://peak.telecommunity.co...
3
2009-12-15T01:30:43Z
[ "python", "py2exe" ]
Py2exe: Embed static files in library.zip or exe file itself and transparently access them at runtime
1,904,647
<p>Is there a way to have py2exe embed static files (and/or subdirectories of static files) in a library.zip and/or the exe file itself (with zipfile=None) and then transparently access these embedded static files from code at runtime?</p> <p>Thank you, Malcolm</p>
5
2009-12-15T01:11:57Z
3,686,374
<p>Just thought I'd share this here too for the benefit of those still looking for answers:</p> <p><a href="http://stackoverflow.com/questions/1939883/py2exe-embed-static-files-in-exe-file-itself-and-access-them/3686364#3686364">http://stackoverflow.com/questions/1939883/py2exe-embed-static-files-in-exe-file-itself-an...
1
2010-09-10T16:23:17Z
[ "python", "py2exe" ]
Is there any Python syntax highlighter for Visual Studio 2010?
1,904,681
<p>When I used Visual Studio 2008 I could install <a href="http://www.codeplex.com/wikipage?ProjectName=IronPython">IronPython</a> + <a href="http://ironpythonstudio.codeplex.com/">IronPython Integrated IDE</a> + <a href="http://www.microsoft.com/downloads/details.aspx?FamilyID=40646580-97FA-4698-B65F-620D4B4B1ED7&amp;...
13
2009-12-15T01:22:31Z
1,906,833
<p><strong><a href="http://pytools.codeplex.com/">Python Tools for Visual Studio 2010</a></strong></p> <p><a href="http://ironpython.net/">IronPython.Net</a></p> <p><strike> <strong>This Extension is no longer available. See Jeff Hardy's comment below.</strong></p> <p>Try IronPython Extensions for VisualStudio 2010:...
13
2009-12-15T11:29:46Z
[ "python", "visual-studio-2010", "ironpython", "syntax-highlighting" ]
Is there any Python syntax highlighter for Visual Studio 2010?
1,904,681
<p>When I used Visual Studio 2008 I could install <a href="http://www.codeplex.com/wikipage?ProjectName=IronPython">IronPython</a> + <a href="http://ironpythonstudio.codeplex.com/">IronPython Integrated IDE</a> + <a href="http://www.microsoft.com/downloads/details.aspx?FamilyID=40646580-97FA-4698-B65F-620D4B4B1ED7&amp;...
13
2009-12-15T01:22:31Z
6,562,629
<p>Here is the latest update (July 2011):</p> <p><a href="http://pytools.codeplex.com/" rel="nofollow">Python Tools for Visual Studio 2010</a></p>
10
2011-07-03T11:36:37Z
[ "python", "visual-studio-2010", "ironpython", "syntax-highlighting" ]
Is there any Python syntax highlighter for Visual Studio 2010?
1,904,681
<p>When I used Visual Studio 2008 I could install <a href="http://www.codeplex.com/wikipage?ProjectName=IronPython">IronPython</a> + <a href="http://ironpythonstudio.codeplex.com/">IronPython Integrated IDE</a> + <a href="http://www.microsoft.com/downloads/details.aspx?FamilyID=40646580-97FA-4698-B65F-620D4B4B1ED7&amp;...
13
2009-12-15T01:22:31Z
8,385,898
<p><a href="https://github.com/jesse99/Linguist" rel="nofollow">https://github.com/jesse99/Linguist</a> does the job, too. Horrible style settings, but it works great.</p>
0
2011-12-05T13:15:33Z
[ "python", "visual-studio-2010", "ironpython", "syntax-highlighting" ]
In python, is there a setdefault() equivalent for getting object attributes?
1,904,723
<p>Python's <a href="http://docs.python.org/library/stdtypes.html#dict.setdefault">setdefault</a> allows you to get a value from a dictionary, but if the key doesn't exist, then you assign the based on parameter <CODE>default</CODE>. You then fetch whatever is at the key in the dictionary.</p> <p>Without manipulating...
12
2009-12-15T01:37:09Z
1,904,747
<p>Python doesn't have one built in, but you can define your own:</p> <pre><code>def setdefaultattr(obj, name, value): if not hasattr(obj, name): setattr(obj, name, value) return getattr(obj, name) </code></pre>
5
2009-12-15T01:44:07Z
[ "python" ]
In python, is there a setdefault() equivalent for getting object attributes?
1,904,723
<p>Python's <a href="http://docs.python.org/library/stdtypes.html#dict.setdefault">setdefault</a> allows you to get a value from a dictionary, but if the key doesn't exist, then you assign the based on parameter <CODE>default</CODE>. You then fetch whatever is at the key in the dictionary.</p> <p>Without manipulating...
12
2009-12-15T01:37:09Z
1,904,759
<pre><code>vars(obj).setdefault(name, value) </code></pre>
2
2009-12-15T01:47:33Z
[ "python" ]
In python, is there a setdefault() equivalent for getting object attributes?
1,904,723
<p>Python's <a href="http://docs.python.org/library/stdtypes.html#dict.setdefault">setdefault</a> allows you to get a value from a dictionary, but if the key doesn't exist, then you assign the based on parameter <CODE>default</CODE>. You then fetch whatever is at the key in the dictionary.</p> <p>Without manipulating...
12
2009-12-15T01:37:09Z
1,905,593
<p>Note that the currently accepted answer will, if the attribute doesn't exist already, have called hasattr(), setattr() and getattr(). This would be necessary only if the OP had done something like overriding setattr and/or getattr -- in which case the OP is not the innocent enquirer we took him for. Otherwise callin...
16
2009-12-15T06:39:09Z
[ "python" ]
In python, is there a setdefault() equivalent for getting object attributes?
1,904,723
<p>Python's <a href="http://docs.python.org/library/stdtypes.html#dict.setdefault">setdefault</a> allows you to get a value from a dictionary, but if the key doesn't exist, then you assign the based on parameter <CODE>default</CODE>. You then fetch whatever is at the key in the dictionary.</p> <p>Without manipulating...
12
2009-12-15T01:37:09Z
1,906,981
<p>Don't Do This.</p> <p>Please.</p> <p>Use <code>__init__</code> to provide default values. Please. That's the Pythonic way.</p> <pre><code>class Foo( object ): def __init__( self ): self.bar = 'bah' </code></pre> <p>This is the normal, standard, typical approach. There's no compelling reason to do ...
0
2009-12-15T12:04:01Z
[ "python" ]
Py2exe: Are manifest files and w9xpopen.exe required when compiling a web server without GUI interface?
1,904,724
<p>I'm using Py2exe to compile a CherryPy (3.1) server using Python 2.6 (32-bit) on Windows 7 Pro (64-bit).</p> <p>This server will run without a GUI.</p> <p>Questions:</p> <ol> <li><p>Do I need to be concerned about adding a manifest file for this application if it runs without a GUI?</p></li> <li><p>Do I need to i...
10
2009-12-15T01:37:17Z
1,904,750
<p>w9xpopen.exe is for windows 95/98, So If you don't use those you will not need it.</p> <p>You can add <code>dll_excludes=['w9xpopen.exe']</code> in your setup file for py2exe to exclude that.</p> <p>and of course you will not need manifest file if you don't use GUI too.</p>
10
2009-12-15T01:44:31Z
[ "python", "windows", "py2exe", "cherrypy" ]
Py2exe: Are manifest files and w9xpopen.exe required when compiling a web server without GUI interface?
1,904,724
<p>I'm using Py2exe to compile a CherryPy (3.1) server using Python 2.6 (32-bit) on Windows 7 Pro (64-bit).</p> <p>This server will run without a GUI.</p> <p>Questions:</p> <ol> <li><p>Do I need to be concerned about adding a manifest file for this application if it runs without a GUI?</p></li> <li><p>Do I need to i...
10
2009-12-15T01:37:17Z
2,141,065
<p>A manifest file will not be required for console applications. <code>w9xpopen.exe</code> is not required for Win XP and later.</p>
0
2010-01-26T17:06:33Z
[ "python", "windows", "py2exe", "cherrypy" ]
Py2exe: Are manifest files and w9xpopen.exe required when compiling a web server without GUI interface?
1,904,724
<p>I'm using Py2exe to compile a CherryPy (3.1) server using Python 2.6 (32-bit) on Windows 7 Pro (64-bit).</p> <p>This server will run without a GUI.</p> <p>Questions:</p> <ol> <li><p>Do I need to be concerned about adding a manifest file for this application if it runs without a GUI?</p></li> <li><p>Do I need to i...
10
2009-12-15T01:37:17Z
35,107,114
<ul> <li><p>A manifest should not be required.</p></li> <li><p>And you can exclude w9xpopen.exe (for Win XP and above)</p></li> </ul> <p>For what it's worth, using py2exe v 0.6.9 to automatically exclude w9xpopen I had to set <code>dll_excludes</code> as a py2exe option within my setup.py file. Here's an example for "...
0
2016-01-30T21:07:23Z
[ "python", "windows", "py2exe", "cherrypy" ]
Install libxml2 and associated python bindings - Windows
1,904,752
<p>I am attempting to install libxml2 so that I can setup the python bindings and eventually use lxml.</p> <p>However I am unable to work out here on earth I am supposed to be unzipping the files. I haven't been able to google successfully.</p> <p>Do I need Cygwin/MinGW for the installation to be successful?</p> <p>...
25
2009-12-15T01:44:59Z
1,904,784
<p>If you don't have special reasons to compile from source, you can use <a href="https://pypi.python.org/pypi/lxml">prebuilt binaries</a> for lxml</p>
26
2009-12-15T01:57:42Z
[ "python", "windows", "libxml2" ]
Install libxml2 and associated python bindings - Windows
1,904,752
<p>I am attempting to install libxml2 so that I can setup the python bindings and eventually use lxml.</p> <p>However I am unable to work out here on earth I am supposed to be unzipping the files. I haven't been able to google successfully.</p> <p>Do I need Cygwin/MinGW for the installation to be successful?</p> <p>...
25
2009-12-15T01:44:59Z
1,904,789
<p>It appears that the program "xslt-config" is not located in a directory in your PATH environment. Here's an article on setting PATH on Windows:</p> <p><a href="http://www.cs.usask.ca/~wew036/latex/env.html" rel="nofollow">http://www.cs.usask.ca/~wew036/latex/env.html</a></p>
0
2009-12-15T01:59:39Z
[ "python", "windows", "libxml2" ]
Install libxml2 and associated python bindings - Windows
1,904,752
<p>I am attempting to install libxml2 so that I can setup the python bindings and eventually use lxml.</p> <p>However I am unable to work out here on earth I am supposed to be unzipping the files. I haven't been able to google successfully.</p> <p>Do I need Cygwin/MinGW for the installation to be successful?</p> <p>...
25
2009-12-15T01:44:59Z
4,041,336
<p>If you are using python 2.5.x, just use "<strong>easy_install lxml==2.2.2</strong>" to install</p>
3
2010-10-28T09:08:23Z
[ "python", "windows", "libxml2" ]
Install libxml2 and associated python bindings - Windows
1,904,752
<p>I am attempting to install libxml2 so that I can setup the python bindings and eventually use lxml.</p> <p>However I am unable to work out here on earth I am supposed to be unzipping the files. I haven't been able to google successfully.</p> <p>Do I need Cygwin/MinGW for the installation to be successful?</p> <p>...
25
2009-12-15T01:44:59Z
9,056,298
<p>The Windows binaries of the latest version of lxml (as well as a wide range of other Python packages) are available on <a href="http://www.lfd.uci.edu/~gohlke/pythonlibs/">http://www.lfd.uci.edu/~gohlke/pythonlibs/</a></p>
28
2012-01-29T20:04:47Z
[ "python", "windows", "libxml2" ]
Install libxml2 and associated python bindings - Windows
1,904,752
<p>I am attempting to install libxml2 so that I can setup the python bindings and eventually use lxml.</p> <p>However I am unable to work out here on earth I am supposed to be unzipping the files. I haven't been able to google successfully.</p> <p>Do I need Cygwin/MinGW for the installation to be successful?</p> <p>...
25
2009-12-15T01:44:59Z
33,213,398
<p>Realize this is an old topic but have had issues installing this on windows.</p> <p>I have Python version 3.4.4.</p> <p>When attempting to install whl files make sure you are using the correct version for your version of python.</p> <p>so in this case i needed to use</p> <pre><code>lxml‑3.4.4‑cp34‑none‑w...
2
2015-10-19T11:37:38Z
[ "python", "windows", "libxml2" ]
How can I sort by the id of a ManyToManyField in Django?
1,904,978
<p>I've got a ManyToManyField in a user object and it's used to map the users that user is following. I'm trying to show a subset list of who they have most recently followed. Is there a trick in .order_by() that will allow me to sort by the id of the ManyToManyField? The data is there, right?</p> <pre><code># (people...
2
2009-12-15T03:25:11Z
1,911,230
<p>I am not sure whether you can achieve this with a regular <code>ManytoManyField</code>. You could try defining the intermediate model explicitly.</p> <p><strong>nb: Untested code!</strong></p> <pre><code>class Person(models.Model) name = models.CharField(max_length=30) class FollowerRelationship(models.Model)...
0
2009-12-15T23:28:03Z
[ "python", "django", "django-models", "sql-order-by", "manytomanyfield" ]
How can I sort by the id of a ManyToManyField in Django?
1,904,978
<p>I've got a ManyToManyField in a user object and it's used to map the users that user is following. I'm trying to show a subset list of who they have most recently followed. Is there a trick in .order_by() that will allow me to sort by the id of the ManyToManyField? The data is there, right?</p> <pre><code># (people...
2
2009-12-15T03:25:11Z
25,315,033
<p>I just found a way to do this without having to create a class for the relationship. It relies on the <code>extra</code> feature that lets you add additional columns to output. In your example it would look like:</p> <pre><code>theuser.following.filter(user__is_active=True)\ .extra(select={'creation_seq': 'ap...
1
2014-08-14T18:23:32Z
[ "python", "django", "django-models", "sql-order-by", "manytomanyfield" ]
Is IronPython usable as a replacement for CPython?
1,905,023
<p>Has IronPython gotten to a point where you can just drop it in as a replacement for CPython?</p> <p>To clarify: I mean can IronPython run applications originally written for CPython (no .NET involved, of course)</p>
4
2009-12-15T03:41:48Z
1,905,168
<p>Yes, pretty much, at least on Windows with "real" (Microsoft) .NET underneath. If you're depending on C-coded extensions, chances are that <a href="http://code.google.com/p/ironclad/" rel="nofollow">ironclad</a> can bail you out; you get 2.6 support, just about every CPython standard library or third-party extensio...
8
2009-12-15T04:27:03Z
[ "python", "ironpython", "dynamic-language-runtime", "cpython" ]
Is IronPython usable as a replacement for CPython?
1,905,023
<p>Has IronPython gotten to a point where you can just drop it in as a replacement for CPython?</p> <p>To clarify: I mean can IronPython run applications originally written for CPython (no .NET involved, of course)</p>
4
2009-12-15T03:41:48Z
1,905,306
<p>It has been tested to work well with mono on Linux and I use it regularly to open up opportunities to use - as Alex Martelli so eloquently put it - "every .NET module on the planet".</p> <p>I have faced some troubles in accessing third party extension modules, but that has pretty much always been a path issue, whi...
3
2009-12-15T05:14:41Z
[ "python", "ironpython", "dynamic-language-runtime", "cpython" ]
Is IronPython usable as a replacement for CPython?
1,905,023
<p>Has IronPython gotten to a point where you can just drop it in as a replacement for CPython?</p> <p>To clarify: I mean can IronPython run applications originally written for CPython (no .NET involved, of course)</p>
4
2009-12-15T03:41:48Z
3,157,192
<p>Ironpython have some prolbems to replace the cpython,like Base on cpy, you can use some libs directly, but, in ipy, you must use ironclad, and the effiencency is insufferable. And, if you want use py files, there will be many errors, even if you use same gramma. So, there are two different things, only same gramma...
-1
2010-07-01T11:11:16Z
[ "python", "ironpython", "dynamic-language-runtime", "cpython" ]
Keyword Matching in Pyparsing: non-greedy slurping of tokens
1,905,278
<p>Pythonistas:</p> <p>Suppose you want to parse the following string using Pyparsing:</p> <pre><code>'ABC_123_SPEED_X 123' </code></pre> <p>were <code>ABC_123</code> is an identifier; <code>SPEED_X</code> is a parameter, and <code>123</code> is a value. I thought of the following BNF using Pyparsing:</p> <pre><cod...
5
2009-12-15T05:05:23Z
1,905,567
<p>This answers a question that you probably have also asked yourself: "What's a real-world application for <code>reduce</code>?):</p> <pre><code>&gt;&gt;&gt; keys = ['CAT', 'DOG', 'HORSE', 'DEER', 'RHINOCEROS'] &gt;&gt;&gt; p = reduce(lambda x, y: x | y, [Keyword(x) for x in keys]) &gt;&gt;&gt; p {{{{"CAT" | "DOG"} ...
-1
2009-12-15T06:31:42Z
[ "python", "parsing", "grammar", "pyparsing" ]
Keyword Matching in Pyparsing: non-greedy slurping of tokens
1,905,278
<p>Pythonistas:</p> <p>Suppose you want to parse the following string using Pyparsing:</p> <pre><code>'ABC_123_SPEED_X 123' </code></pre> <p>were <code>ABC_123</code> is an identifier; <code>SPEED_X</code> is a parameter, and <code>123</code> is a value. I thought of the following BNF using Pyparsing:</p> <pre><cod...
5
2009-12-15T05:05:23Z
1,905,809
<p>I based my answer off of <a href="http://pyparsing.wikispaces.com/message/view/HowToUsePyparsing/178079" rel="nofollow">this one</a>, since what you're trying to do is get a non-greedy match. It seems like this is difficult to make happen in pyparsing, but not impossible with some cleverness and compromise. The foll...
7
2009-12-15T07:46:51Z
[ "python", "parsing", "grammar", "pyparsing" ]
Keyword Matching in Pyparsing: non-greedy slurping of tokens
1,905,278
<p>Pythonistas:</p> <p>Suppose you want to parse the following string using Pyparsing:</p> <pre><code>'ABC_123_SPEED_X 123' </code></pre> <p>were <code>ABC_123</code> is an identifier; <code>SPEED_X</code> is a parameter, and <code>123</code> is a value. I thought of the following BNF using Pyparsing:</p> <pre><cod...
5
2009-12-15T05:05:23Z
1,906,323
<p>If you are sure that the identifier never ends with an underscore, you can enforce it in the definition:</p> <pre><code>from pyparsing import * my_string = 'ABC_123_SPEED_X 123' Identifier = Combine(Word(alphanums) + Literal('_') + Word(alphanums)) Parameter = Literal('SPEED_X') | Literal('SPEED_Y') | Literal('SP...
1
2009-12-15T09:55:02Z
[ "python", "parsing", "grammar", "pyparsing" ]
Keyword Matching in Pyparsing: non-greedy slurping of tokens
1,905,278
<p>Pythonistas:</p> <p>Suppose you want to parse the following string using Pyparsing:</p> <pre><code>'ABC_123_SPEED_X 123' </code></pre> <p>were <code>ABC_123</code> is an identifier; <code>SPEED_X</code> is a parameter, and <code>123</code> is a value. I thought of the following BNF using Pyparsing:</p> <pre><cod...
5
2009-12-15T05:05:23Z
1,906,508
<p>You can also parse the identifier and parameter as one token, and split them in a parse action:</p> <pre><code>from pyparsing import * import re def split_ident_and_param(tokens): mo = re.match(r"^(.*?_.*?)_(.*?_.*?)$", tokens[0]) return [mo.group(1), mo.group(2)] ident_and_param = Word(alphanums + "_").s...
1
2009-12-15T10:31:12Z
[ "python", "parsing", "grammar", "pyparsing" ]
Starting Python script without explicitly having X11 open
1,905,382
<p>I had Python v2.3 on my system. When I wanted to run a Tkinter script I could just use</p> <pre><code>python myscript.py </code></pre> <p>I recently upgraded to Python 2.5 and now I need to have X11 running and the "DISPLAY" environment variable set before I can run any of my scripts. This is bad for me, because I...
1
2009-12-14T18:44:31Z
1,905,383
<p>I have installed Python 2.6.4 and I haven't any problem at all running it without a $DISPLAY variable ...</p> <p>I'm on linux ...</p>
0
2009-12-14T23:52:19Z
[ "python", "osx", "x11", "tkinter" ]
Starting Python script without explicitly having X11 open
1,905,382
<p>I had Python v2.3 on my system. When I wanted to run a Tkinter script I could just use</p> <pre><code>python myscript.py </code></pre> <p>I recently upgraded to Python 2.5 and now I need to have X11 running and the "DISPLAY" environment variable set before I can run any of my scripts. This is bad for me, because I...
1
2009-12-14T18:44:31Z
1,906,083
<p>Install <a href="http://www.python.org/download/releases/2.5.4/" rel="nofollow">python2.5</a> or <a href="http://www.python.org/download/releases/2.6.4/" rel="nofollow">python2.6</a> for OS X from python.org. They use the native Aqua Tk and thus do not require X11 for IDLE or python scripts that use Tkinter.</p>
1
2009-12-15T08:55:27Z
[ "python", "osx", "x11", "tkinter" ]
Starting Python script without explicitly having X11 open
1,905,382
<p>I had Python v2.3 on my system. When I wanted to run a Tkinter script I could just use</p> <pre><code>python myscript.py </code></pre> <p>I recently upgraded to Python 2.5 and now I need to have X11 running and the "DISPLAY" environment variable set before I can run any of my scripts. This is bad for me, because I...
1
2009-12-14T18:44:31Z
1,909,264
<p>If I had to guess (and I do...), it sounds like you installed an X11 based version of python and tkinter rather than one that uses the native windowing system on OSX. I think you can safely write your scripts without telling people they have to have X11 running. You merely have to say they have to have a proper envi...
0
2009-12-15T18:05:47Z
[ "python", "osx", "x11", "tkinter" ]
Literals in django template language?
1,905,396
<p>If I want some text to appear literally in a Django template, e.g.</p> <pre><code>{{Image.jpg|title}} </code></pre> <p>and I want that text to be output (not interpretated) in the HTML, how do I do so?</p>
0
2009-12-15T05:43:36Z
1,905,427
<p>You could start it with an HTML entity. e.g.:</p> <pre><code>&amp;#123;{Image.jpg|title}} </code></pre> <p>However, I can only imagine this means you are writing content in your templates, which is normally not advisable.</p>
1
2009-12-15T05:55:26Z
[ "python", "django", "templates", "django-templates", "literals" ]
Literals in django template language?
1,905,396
<p>If I want some text to appear literally in a Django template, e.g.</p> <pre><code>{{Image.jpg|title}} </code></pre> <p>and I want that text to be output (not interpretated) in the HTML, how do I do so?</p>
0
2009-12-15T05:43:36Z
1,905,482
<p>Try the <code>{% templatetag %}</code> template tag</p> <pre><code>{% templatetag openvariable %}Image.jpg|title{% templatetag closevariable %} </code></pre> <p><a href="http://docs.djangoproject.com/en/dev/ref/templates/builtins/#templatetag" rel="nofollow">http://docs.djangoproject.com/en/dev/ref/templates/built...
5
2009-12-15T06:12:36Z
[ "python", "django", "templates", "django-templates", "literals" ]
Python QPushButton setIcon: put icon on button
1,905,402
<p>I want to put an in ICON into a push button.. the code should work like that:</p> <pre><code> self.printButton = QtGui.QPushButton(self.tab_name) self.printButton.setIcon(QtGui.QPixmap('printer.tif')) self.printButton.setGeometry(QtCore.QRect(1030, 500, 161, 61)) </code></pre> <p>But instead, it gives t...
1
2009-12-15T05:46:08Z
1,905,587
<p>This is strange, I quickly tested the code on my C++ application and it seems to be working...</p> <p>Maybe by using this you could correct your problem :</p> <pre><code>rMyIcon = QtGui.QPixmap("printer.tif"); self.printButton.setIcon(QtGui.QIcon(rMyIcon)) </code></pre> <p>Hope this helps a bit...</p>
6
2009-12-15T06:37:46Z
[ "python", "user-interface", "qt", "button", "icons" ]
Python QPushButton setIcon: put icon on button
1,905,402
<p>I want to put an in ICON into a push button.. the code should work like that:</p> <pre><code> self.printButton = QtGui.QPushButton(self.tab_name) self.printButton.setIcon(QtGui.QPixmap('printer.tif')) self.printButton.setGeometry(QtCore.QRect(1030, 500, 161, 61)) </code></pre> <p>But instead, it gives t...
1
2009-12-15T05:46:08Z
1,905,655
<p>Create a QIcon rather than a QPixmap for passing to setIcon(). Try changing the second line to</p> <pre><code>self.printButton.setIcon(QtGui.QIcon('printer.tif')) </code></pre>
5
2009-12-15T07:01:35Z
[ "python", "user-interface", "qt", "button", "icons" ]
Python QPushButton setIcon: put icon on button
1,905,402
<p>I want to put an in ICON into a push button.. the code should work like that:</p> <pre><code> self.printButton = QtGui.QPushButton(self.tab_name) self.printButton.setIcon(QtGui.QPixmap('printer.tif')) self.printButton.setGeometry(QtCore.QRect(1030, 500, 161, 61)) </code></pre> <p>But instead, it gives t...
1
2009-12-15T05:46:08Z
1,906,028
<p>Hi Baysmith and Andy... thanks for the input. I tested your suggestions, it worked. I also have to add setIconSize, otherwise the icon is displayed very small. Here is code:</p> <pre><code>def printerButton(self,tab_name): self.printButton = QtGui.QPushButton(tab_name) self.printButton.setIcon(QtGui.QIcon('...
1
2009-12-15T08:47:10Z
[ "python", "user-interface", "qt", "button", "icons" ]
python time(milli seconds) calculation
1,905,403
<p>How to calculate milliseconds,from the code below.</p> <pre><code>a = datetime.datetime.now() b = datetime.datetime.now() c = b - a &gt;&gt;&gt; c &gt;&gt;&gt; c.days 0 &gt;&gt;&gt; c.seconds 4 &gt;&gt;&gt; c.microseconds </code></pre>
6
2009-12-15T05:46:32Z
1,905,423
<pre><code>milliseconds = (c.days * 24 * 60 * 60 + c.seconds) * 1000 + c.microseconds / 1000.0 </code></pre>
11
2009-12-15T05:52:30Z
[ "python", "time" ]
python time(milli seconds) calculation
1,905,403
<p>How to calculate milliseconds,from the code below.</p> <pre><code>a = datetime.datetime.now() b = datetime.datetime.now() c = b - a &gt;&gt;&gt; c &gt;&gt;&gt; c.days 0 &gt;&gt;&gt; c.seconds 4 &gt;&gt;&gt; c.microseconds </code></pre>
6
2009-12-15T05:46:32Z
27,929,936
<p>Or, new since 2.7:</p> <pre><code>c.total_seconds()*1000 </code></pre> <p>(<a href="https://docs.python.org/2/library/datetime.html">https://docs.python.org/2/library/datetime.html</a>)</p>
6
2015-01-13T19:24:07Z
[ "python", "time" ]
Crop a PNG image to its minimum size
1,905,421
<p>How to cut off the blank border area of a PNG image and shrink it to its minimum size using Python?</p>
5
2009-12-15T05:52:01Z
1,905,455
<p>You can use <a href="http://www.pythonware.com/products/pil/" rel="nofollow">PIL</a> to find rows and cols of your image that are made up purely of your border color.</p> <p>Using this information, you can easily determine the extents of the inlaid image.</p> <p>PIL again will then allow you to crop the image to r...
1
2009-12-15T06:05:42Z
[ "python", "image", "png" ]
Crop a PNG image to its minimum size
1,905,421
<p>How to cut off the blank border area of a PNG image and shrink it to its minimum size using Python?</p>
5
2009-12-15T05:52:01Z
1,905,468
<p><a href="http://www.pythonware.com/products/pil/">PIL</a>'s <a href="http://www.pythonware.com/library/pil/handbook/image.htm">getbbox</a> is working for me</p> <blockquote> <p>im.getbbox() => 4-tuple or None</p> <p>Calculates the bounding box of the non-zero regions in the image. The bounding box is ret...
10
2009-12-15T06:09:32Z
[ "python", "image", "png" ]
Crop a PNG image to its minimum size
1,905,421
<p>How to cut off the blank border area of a PNG image and shrink it to its minimum size using Python?</p>
5
2009-12-15T05:52:01Z
11,555,094
<p><a href="https://gist.github.com/3141140" rel="nofollow">https://gist.github.com/3141140</a></p> <pre><code>import Image import sys import glob # Trim all png images with alpha in a folder # Usage "python PNGAlphaTrim.py ../someFolder" try: folderName = sys.argv[1] except : print "Usage: python PNGPNGAlph...
2
2012-07-19T06:29:42Z
[ "python", "image", "png" ]
Crop a PNG image to its minimum size
1,905,421
<p>How to cut off the blank border area of a PNG image and shrink it to its minimum size using Python?</p>
5
2009-12-15T05:52:01Z
35,707,447
<p>I think it's necessary to supplement @Frank Krueger's answer. He makes a good point, but it doesn't include how to properly crop extra border color out of an image. I found that <a href="http://stackoverflow.com/questions/10615901/trim-whitespace-using-pil/10616717#10616717">here</a>. Specifically, I found this us...
0
2016-02-29T19:02:14Z
[ "python", "image", "png" ]
Django date filter to output "am" or "A.M."
1,905,721
<p>The Django date template filter takes the format character "a" for "a.m." and "A" for "AM". How do you get lower case without periods or upper case with the periods?</p> <p>You can use lower and upper filters, but they will mess with month and day of the week formatting.</p>
3
2009-12-15T07:22:36Z
1,906,710
<p>Best way would be to write a custom template filter.</p> <p>Documentation <a href="http://docs.djangoproject.com/en/dev/howto/custom-template-tags/#writing-custom-template-filters" rel="nofollow">here</a></p>
0
2009-12-15T11:07:59Z
[ "python", "django" ]
Django date filter to output "am" or "A.M."
1,905,721
<p>The Django date template filter takes the format character "a" for "a.m." and "A" for "AM". How do you get lower case without periods or upper case with the periods?</p> <p>You can use lower and upper filters, but they will mess with month and day of the week formatting.</p>
3
2009-12-15T07:22:36Z
1,906,732
<p>you can create your own filter so your templates will look like this:</p> <pre><code>{{ value|date:"D d M Y" }} {{ value|meridiem:"u" }} </code></pre> <p>where meridiem could be:</p> <pre><code>def meridiem(value, arg="ld"): if not value: return u'' if 'u' in arg: if 'd' in arg: ...
1
2009-12-15T11:13:15Z
[ "python", "django" ]
Django date filter to output "am" or "A.M."
1,905,721
<p>The Django date template filter takes the format character "a" for "a.m." and "A" for "AM". How do you get lower case without periods or upper case with the periods?</p> <p>You can use lower and upper filters, but they will mess with month and day of the week formatting.</p>
3
2009-12-15T07:22:36Z
1,909,373
<p>Alternately you could inherit the base functionality and simply add the output you're looking for. (again with a custom filter).</p> <p>Here's a custom template fitler which adds a new argument 'c' that will change (get it, c... change) the functional of a/A. It basically serves as a switch to toggle the functiona...
4
2009-12-15T18:20:11Z
[ "python", "django" ]
turbogears request/user object in templates and request context
1,905,885
<p>I am currently making the switch from Django to Turbogears 2.1 and am running into some problems that I could not find the answers to in the Turbogears docs. If tg developers read this, let me tell you that one of the best features Django has over TG is its documentation!</p> <p>1) How do I access the request (user...
1
2009-12-15T08:08:46Z
1,908,249
<p>I've moved from Turbogears 1.0 to Django. Might not be able to answer all of these, but I believe in general TG2 tries to keep things fairly similar to TG1. Hopefully pointing out how it works in TG 1, might help...</p> <p>1) In Turbogears 1.0 you would use tg.identity.anonymous to see if the user was logged in o...
1
2009-12-15T15:37:40Z
[ "python", "django", "turbogears", "mako", "requestcontext" ]
split svnversion output in bash
1,905,980
<p>I have this function, works fine, but I would like to rewrite it in bash. the problem is, I have too little knowledge of what's available in bash.</p> <pre><code>#!/usr/bin/python def parse_svnversion(value): """split the output of svnversion into its three components given a string that looks like the o...
0
2009-12-15T08:34:20Z
1,906,247
<p>you can use this subroutine</p> <pre><code>parsesvn(){ toparse="$1" num=${toparse%%[A-Z]*} alpha=${toparse##*[0-9]} IFS=":" set -- $num for i in $@ do printf "%s " $i done if [ ! -z "$alpha" ];then printf "%s" "$alpha" fi } # main # var=$(parsesvn "1024:2000") set -- $var if [ "$1" -lt "$2" ];the...
1
2009-12-15T09:36:14Z
[ "python", "bash", "parsing" ]
split svnversion output in bash
1,905,980
<p>I have this function, works fine, but I would like to rewrite it in bash. the problem is, I have too little knowledge of what's available in bash.</p> <pre><code>#!/usr/bin/python def parse_svnversion(value): """split the output of svnversion into its three components given a string that looks like the o...
0
2009-12-15T08:34:20Z
1,906,542
<p>The following solution stores the values into the array arr[ ] to match your original tuple as closely as possible. After the <code>if-else-fi</code> block you can do whatever you want with arr[0],arr[1], and arr[2]. I tried to match your post (and comment) as closely as possible. Also, I took the liberty to send t...
0
2009-12-15T10:38:24Z
[ "python", "bash", "parsing" ]
split svnversion output in bash
1,905,980
<p>I have this function, works fine, but I would like to rewrite it in bash. the problem is, I have too little knowledge of what's available in bash.</p> <pre><code>#!/usr/bin/python def parse_svnversion(value): """split the output of svnversion into its three components given a string that looks like the o...
0
2009-12-15T08:34:20Z
1,906,716
<p>This creates an array called "tuple" with three elements:</p> <pre><code>[[ $(svnversion .) =~ ([0-9]+):*([0-9]*)([A-Z]*) ]] tuple[0]=${BASH_REMATCH[1]} tuple[1]=${BASH_REMATCH[2]:-${tuple[0]}} tuple[2]=${BASH_REMATCH[3]:-''} </code></pre> <p>Requires Bash 3.2 or greater. It may work in Bash >= 3 and &lt; 3.2. Not...
4
2009-12-15T11:08:58Z
[ "python", "bash", "parsing" ]
dict keys with spaces in Django templates
1,906,129
<p>I am trying to present a dictionary from my view.py at the HTML template such as:</p> <pre><code>test = { 'works': True, 'this fails':False } </code></pre> <p>and in the template:</p> <p>This works without a problem:</p> <pre><code>{{ test.works }} </code></pre> <p>But a dictionary key that is having an empty s...
12
2009-12-15T09:06:30Z
1,906,164
<p>That doesn't look right to me. Can you do the following?</p> <pre><code>{{ test['works'] }} {{ test['this fails'] }} </code></pre> <p>This is how dictionary access in python typically works.</p>
-4
2009-12-15T09:12:37Z
[ "python", "django", "django-templates", "whitespace" ]
dict keys with spaces in Django templates
1,906,129
<p>I am trying to present a dictionary from my view.py at the HTML template such as:</p> <pre><code>test = { 'works': True, 'this fails':False } </code></pre> <p>and in the template:</p> <p>This works without a problem:</p> <pre><code>{{ test.works }} </code></pre> <p>But a dictionary key that is having an empty s...
12
2009-12-15T09:06:30Z
1,906,216
<p>I don't know any standard solution in Django. I think it is possible with a template filter. </p> <p>You may be interested by this article <a href="http://push.cx/2007/django-template-tag-for-dictionary-access" rel="nofollow">http://push.cx/2007/django-template-tag-for-dictionary-access</a> (the author is using tem...
2
2009-12-15T09:27:41Z
[ "python", "django", "django-templates", "whitespace" ]
dict keys with spaces in Django templates
1,906,129
<p>I am trying to present a dictionary from my view.py at the HTML template such as:</p> <pre><code>test = { 'works': True, 'this fails':False } </code></pre> <p>and in the template:</p> <p>This works without a problem:</p> <pre><code>{{ test.works }} </code></pre> <p>But a dictionary key that is having an empty s...
12
2009-12-15T09:06:30Z
1,906,279
<p>The filter you want is something like </p> <pre><code>@register.filter(name='getkey') def getkey(value, arg): return value[arg] </code></pre> <p>And used with </p> <pre><code>{{test|getkey:'this works'}} </code></pre> <p>source: <a href="http://www.bhphp.com/blog4.php/2009/08/17/django-templates-and-dictiona...
16
2009-12-15T09:43:27Z
[ "python", "django", "django-templates", "whitespace" ]
multiple requests in a single connection?
1,906,151
<p>Is it possible to put multiple requests without breaking the connection using python httplib?. Like, can I upload a big file to the server in parts but in a single socket connection.</p> <p>I looked for answers. But nothing seemed so clear and definite.</p> <p>Any examples/related links will be helpfull. Thanks. ...
3
2009-12-15T09:09:37Z
1,906,201
<p>Yes, the connection stays open until you close it using the <code>close()</code> method.</p> <p>The following example, taken from the <a href="http://docs.python.org/dev/library/httplib.html">httplib documentation</a>, shows how to perform multiple requests using a single connection:</p> <pre><code>&gt;&gt;&gt; im...
10
2009-12-15T09:23:37Z
[ "python", "connection", "httplib" ]
multiple requests in a single connection?
1,906,151
<p>Is it possible to put multiple requests without breaking the connection using python httplib?. Like, can I upload a big file to the server in parts but in a single socket connection.</p> <p>I looked for answers. But nothing seemed so clear and definite.</p> <p>Any examples/related links will be helpfull. Thanks. ...
3
2009-12-15T09:09:37Z
10,034,081
<p>You need to be sure to call the .read() function on your response. Otherwise you'll get an error like:</p> <pre><code>Traceback (most recent call last): File "&lt;pyshell#13&gt;", line 1, in &lt;module&gt; conn.request("GET", "/2.html") File "C:\Python27\lib\httplib.py", line 955, in request self._send_...
2
2012-04-05T18:38:29Z
[ "python", "connection", "httplib" ]
How to connect an application with Facebook?
1,906,184
<p>The topic may be a bit ambiguous. I am writing a Python application. I want to upload it on Facebook as a Facebook application (NOT <a href="http://en.wikipedia.org/wiki/Facebook%5FPlatform#Facebook%5FConnect" rel="nofollow">Facebook Connect</a>). But I am having the hardest time figuring out how to implement the f...
0
2009-12-15T09:17:52Z
1,906,248
<p>There is a good Facebook library that supports Django, <a href="http://github.com/sciyoshi/pyfacebook/" rel="nofollow">pyfacebook</a>. There are some examples in that package of how to use it.</p> <p>And there's no substitute for the actual <a href="http://wiki.developers.facebook.com/index.php/Main%5FPage" rel="no...
2
2009-12-15T09:36:20Z
[ "python", "django", "facebook", "facebook-fql" ]
How to connect an application with Facebook?
1,906,184
<p>The topic may be a bit ambiguous. I am writing a Python application. I want to upload it on Facebook as a Facebook application (NOT <a href="http://en.wikipedia.org/wiki/Facebook%5FPlatform#Facebook%5FConnect" rel="nofollow">Facebook Connect</a>). But I am having the hardest time figuring out how to implement the f...
0
2009-12-15T09:17:52Z
1,907,005
<p>Amit, in addition to the links above also have a look at the following links. Also note: You mention you would like to 'upload your app into facebook' you can add your app to facebook, however they DO NOT host it. You will have to host the application on your own server.</p> <ol> <li><a href="http://uswaretech.com/...
0
2009-12-15T12:09:36Z
[ "python", "django", "facebook", "facebook-fql" ]
Django general template controled by which variables?
1,906,350
<p>I have been developing some Django app and there's some duplicated code for different Models. I'd like to create a generic table template and pass the Model class, a list of model instances, and Form classes to it so it can render the page and generate the forms to add/delete elements. Then create some generic add/d...
0
2009-12-15T10:01:44Z
1,906,635
<p>I'm not exaclty sure about your question and your code, but here is a short story about <code>_meta</code> ...</p> <p>To access the column name of a class, you can inspect the <code>_meta</code> attribute of the class.</p> <p>Example. A sample model, which defines three fields and a helper methods <code>whats_insi...
0
2009-12-15T10:53:02Z
[ "python", "django", "django-templates", "django-forms" ]
Django general template controled by which variables?
1,906,350
<p>I have been developing some Django app and there's some duplicated code for different Models. I'd like to create a generic table template and pass the Model class, a list of model instances, and Form classes to it so it can render the page and generate the forms to add/delete elements. Then create some generic add/d...
0
2009-12-15T10:01:44Z
1,906,972
<p>As MYYN says, your question is not very clear. However i assume you would like to do the following:</p> <ol> <li>Create a generic template</li> <li>Dynamically load this template based on the model and other params passed</li> <li>The table in the template is populated with the necessary forms etc </li> <li>Create ...
0
2009-12-15T12:02:20Z
[ "python", "django", "django-templates", "django-forms" ]
splitting integer in python?
1,906,717
<p>my integer input is suppose 12345 , i want to split and put it into an array as 1,2,3,4,5 . How will i be able to do it?</p>
11
2009-12-15T11:09:00Z
1,906,723
<p>return array as string</p> <pre><code>&gt;&gt;&gt; list(str(12345)) ['1', '2', '3', '4', '5'] </code></pre> <p>return array as integer</p> <pre><code>&gt;&gt;&gt; map(int,str(12345)) [1, 2, 3, 4, 5] </code></pre>
31
2009-12-15T11:10:17Z
[ "python" ]
splitting integer in python?
1,906,717
<p>my integer input is suppose 12345 , i want to split and put it into an array as 1,2,3,4,5 . How will i be able to do it?</p>
11
2009-12-15T11:09:00Z
1,906,724
<p>Strings are just as iterable as arrays, so just convert it to string:</p> <pre><code>str(12345) </code></pre>
1
2009-12-15T11:10:17Z
[ "python" ]