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
Cross platform hidden file detection
284,115
<p>What is the best way to do cross-platform handling of hidden files? (preferably in Python, but other solutions still appreciated)</p> <p>Simply checking for a leading '.' works for *nix/Mac, and file attributes work on Windows. However, this seems a little simplistic, and also doesn't account for alternative method...
13
2008-11-12T14:35:29Z
31,111,306
<p>Incorporating my previous answer as well as that from @abarnert, I've released <a href="https://pypi.python.org/pypi/jaraco.path/1.1" rel="nofollow">jaraco.path 1.1</a> with cross-platform support for hidden file detection. With that package installed, to detect the hidden state of any file, simply invoke <code>is_h...
0
2015-06-29T08:43:15Z
[ "python", "cross-platform", "filesystems" ]
Notebook widget in Tkinter
284,234
<p>Having played around a little with both Tkinter and wxPython, I like Tkinter much better in terms of how clean my source code looks. However, it doesn't seem to have as many features; in particular it doesn't have tabs (as in, the tabs at the top of a Firefox window).</p> <p>A little Googling on the subject offers...
10
2008-11-12T15:10:26Z
284,396
<p>"Or is it simply the case that anyone who needs more powerful windowing components has to use wxPython?"<br /> Short answer: yes.</p> <p>Long answer: It may take some practice for your wxPython code to feel "clean," but it is nicer and much more powerful than Tkinter. You will also get better support, since more p...
0
2008-11-12T15:58:20Z
[ "python", "wxpython", "tabs", "tkinter" ]
Notebook widget in Tkinter
284,234
<p>Having played around a little with both Tkinter and wxPython, I like Tkinter much better in terms of how clean my source code looks. However, it doesn't seem to have as many features; in particular it doesn't have tabs (as in, the tabs at the top of a Firefox window).</p> <p>A little Googling on the subject offers...
10
2008-11-12T15:10:26Z
284,695
<p>On recent Python (> 2.7) versions, you can use the <a href="https://docs.python.org/2/library/ttk.html" rel="nofollow"><code>ttk</code></a> module, which provides access to the <em>Tk themed widget</em> set, which has been introduced in <code>Tk 8.5</code>.</p> <p>Here's how you import <code>ttk</code> in Python 2:...
9
2008-11-12T17:32:26Z
[ "python", "wxpython", "tabs", "tkinter" ]
Notebook widget in Tkinter
284,234
<p>Having played around a little with both Tkinter and wxPython, I like Tkinter much better in terms of how clean my source code looks. However, it doesn't seem to have as many features; in particular it doesn't have tabs (as in, the tabs at the top of a Firefox window).</p> <p>A little Googling on the subject offers...
10
2008-11-12T15:10:26Z
285,642
<p>What problems did you have with pmw? It's old, yes, but it's pure python so it should work.</p> <p>Note that Tix doesn't work with py2exe, if that is an issue for you.</p>
0
2008-11-12T22:34:39Z
[ "python", "wxpython", "tabs", "tkinter" ]
Notebook widget in Tkinter
284,234
<p>Having played around a little with both Tkinter and wxPython, I like Tkinter much better in terms of how clean my source code looks. However, it doesn't seem to have as many features; in particular it doesn't have tabs (as in, the tabs at the top of a Firefox window).</p> <p>A little Googling on the subject offers...
10
2008-11-12T15:10:26Z
288,151
<p>While it may not help you at the moment, tk 8.5 comes with an extended set of widgets. This extended set is available with tk 8.4 by way of an extension known as "tile". Included in the extended set of widgets is a notebook widget. Unfortunately, at this time Tkinter by default uses a fairly old version of Tk that d...
3
2008-11-13T20:20:33Z
[ "python", "wxpython", "tabs", "tkinter" ]
Notebook widget in Tkinter
284,234
<p>Having played around a little with both Tkinter and wxPython, I like Tkinter much better in terms of how clean my source code looks. However, it doesn't seem to have as many features; in particular it doesn't have tabs (as in, the tabs at the top of a Firefox window).</p> <p>A little Googling on the subject offers...
10
2008-11-12T15:10:26Z
18,922,125
<p>If anyone still looking, I have got this working as Tab in tkinter. Play around with the code to make it function the way you want (for example, you can add button to add a new tab):</p> <pre><code>from tkinter import * class Tabs(Frame): """Tabs for testgen output""" def __init__(self, parent): ...
5
2013-09-20T17:02:01Z
[ "python", "wxpython", "tabs", "tkinter" ]
Processing chunked encoded HTTP POST requests in python (or generic CGI under apache)
284,741
<p>I have a j2me client that would post some chunked encoded data to a webserver. I'd like to process the data in python. The script is being run as a CGI one, but apparently apache will refuse a chunked encoded post request to a CGI script. As far as I could see mod_python, WSGI and FastCGI are no go too.</p> <p>I'd ...
5
2008-11-12T17:50:29Z
284,752
<p>I'd say use the twisted framework for building your http listener. Twisted supports chunked encoding.</p> <p><a href="http://python.net/crew/mwh/apidocs/twisted.web.http._ChunkedTransferEncoding.html" rel="nofollow">http://python.net/crew/mwh/apidocs/twisted.web.http._ChunkedTransferEncoding.html</a></p> <p>Hope t...
2
2008-11-12T17:56:15Z
[ "python", "http", "post", "java-me", "midlet" ]
Processing chunked encoded HTTP POST requests in python (or generic CGI under apache)
284,741
<p>I have a j2me client that would post some chunked encoded data to a webserver. I'd like to process the data in python. The script is being run as a CGI one, but apparently apache will refuse a chunked encoded post request to a CGI script. As far as I could see mod_python, WSGI and FastCGI are no go too.</p> <p>I'd ...
5
2008-11-12T17:50:29Z
284,857
<p>Maybe it is a configuration issue? Django can be fronted with Apache by mod_python, WSGI and FastCGI and it can accept file uploads. </p>
1
2008-11-12T18:29:05Z
[ "python", "http", "post", "java-me", "midlet" ]
Processing chunked encoded HTTP POST requests in python (or generic CGI under apache)
284,741
<p>I have a j2me client that would post some chunked encoded data to a webserver. I'd like to process the data in python. The script is being run as a CGI one, but apparently apache will refuse a chunked encoded post request to a CGI script. As far as I could see mod_python, WSGI and FastCGI are no go too.</p> <p>I'd ...
5
2008-11-12T17:50:29Z
284,869
<p>Apache 2.2 mod_cgi works fine for me, Apache transparently unchunks the request as it is passed to the CGI application.</p> <p>WSGI currently disallows chunked requests, and mod_wsgi does indeed block them with a 411 response. It's on the drawing board for WSGI 2.0. But congratulations on finding something that doe...
2
2008-11-12T18:32:21Z
[ "python", "http", "post", "java-me", "midlet" ]
Processing chunked encoded HTTP POST requests in python (or generic CGI under apache)
284,741
<p>I have a j2me client that would post some chunked encoded data to a webserver. I'd like to process the data in python. The script is being run as a CGI one, but apparently apache will refuse a chunked encoded post request to a CGI script. As far as I could see mod_python, WSGI and FastCGI are no go too.</p> <p>I'd ...
5
2008-11-12T17:50:29Z
1,187,738
<p>I had the exact same problem a year ago with a J2ME client talking to a Python/Ruby backend. The only solution I found which <em>doesn't</em> require application or infrastructure level changes was to use a relatively unknown feature of mod_proxy.</p> <p>Mod_proxy has the ability to buffer incoming (chunked) reques...
6
2009-07-27T11:51:03Z
[ "python", "http", "post", "java-me", "midlet" ]
Processing chunked encoded HTTP POST requests in python (or generic CGI under apache)
284,741
<p>I have a j2me client that would post some chunked encoded data to a webserver. I'd like to process the data in python. The script is being run as a CGI one, but apparently apache will refuse a chunked encoded post request to a CGI script. As far as I could see mod_python, WSGI and FastCGI are no go too.</p> <p>I'd ...
5
2008-11-12T17:50:29Z
1,197,441
<p>You can't do what you want with mod_python. You can do it with mod_wsgi if you are using version 3.0. You do however have to step outside of the WSGI 1.0 specification as WSGI effectively prohibits chunked request content.</p> <p>Search for WSGIChunkedRequest in <a href="http://code.google.com/p/modwsgi/wiki/Change...
2
2009-07-29T00:13:45Z
[ "python", "http", "post", "java-me", "midlet" ]
How do you programmatically set an attribute in Python?
285,061
<p>Suppose I have a python object <code>x</code> and a string <code>s</code>, how do I set the attribute <code>s</code> on <code>x</code>? So:</p> <pre><code>&gt;&gt;&gt; x = SomeObject() &gt;&gt;&gt; attr = 'myAttr' &gt;&gt;&gt; # magic goes here &gt;&gt;&gt; x.myAttr 'magic' </code></pre> <p>What's the magic? The g...
105
2008-11-12T19:33:07Z
285,076
<pre><code>setattr(x, attr, 'magic') </code></pre> <p>For help on it:</p> <pre><code>&gt;&gt;&gt; help(setattr) Help on built-in function setattr in module __builtin__: setattr(...) setattr(object, name, value) Set a named attribute on an object; setattr(x, 'y', v) is equivalent to ``x.y = v''. </code><...
156
2008-11-12T19:38:30Z
[ "python", "attributes", "object" ]
How do you programmatically set an attribute in Python?
285,061
<p>Suppose I have a python object <code>x</code> and a string <code>s</code>, how do I set the attribute <code>s</code> on <code>x</code>? So:</p> <pre><code>&gt;&gt;&gt; x = SomeObject() &gt;&gt;&gt; attr = 'myAttr' &gt;&gt;&gt; # magic goes here &gt;&gt;&gt; x.myAttr 'magic' </code></pre> <p>What's the magic? The g...
105
2008-11-12T19:33:07Z
285,086
<p>Usually, we define classes for this.</p> <pre><code>class XClass( object ): def __init__( self ): self.myAttr= None x= XClass() x.myAttr= 'magic' x.myAttr </code></pre> <p>However, you can, to an extent, do this with the <code>setattr</code> and <code>getattr</code> built-in functions. However, they do...
27
2008-11-12T19:41:19Z
[ "python", "attributes", "object" ]
How do you programmatically set an attribute in Python?
285,061
<p>Suppose I have a python object <code>x</code> and a string <code>s</code>, how do I set the attribute <code>s</code> on <code>x</code>? So:</p> <pre><code>&gt;&gt;&gt; x = SomeObject() &gt;&gt;&gt; attr = 'myAttr' &gt;&gt;&gt; # magic goes here &gt;&gt;&gt; x.myAttr 'magic' </code></pre> <p>What's the magic? The g...
105
2008-11-12T19:33:07Z
19,637,635
<p>let x be an object then you can do it two ways</p> <pre><code>x.attr_name = s setattr(x, 'attr_name', s) </code></pre>
4
2013-10-28T14:37:59Z
[ "python", "attributes", "object" ]
With what kind of IDE (if any) you build python GUI projects?
285,132
<p>Is there any IDE (like VS) with drag and drop support for building python GUI, connecting to dbs etc? Eventhough I am an emacs guy, I find it much easier to create GUI with VS.</p>
3
2008-11-12T19:57:25Z
285,150
<p><a href="http://www.eclipse.org/" rel="nofollow">Eclipse</a> has python support.</p> <p>There's also <a href="http://www.python.org/idle/doc/idle2.html" rel="nofollow">IDLE</a> or <a href="http://www.wingware.com/" rel="nofollow">Wingware</a>, though I'm not sure of their GUI support.</p> <p>I'm sure a good <a hre...
1
2008-11-12T20:04:11Z
[ "python", "user-interface", "ide" ]
With what kind of IDE (if any) you build python GUI projects?
285,132
<p>Is there any IDE (like VS) with drag and drop support for building python GUI, connecting to dbs etc? Eventhough I am an emacs guy, I find it much easier to create GUI with VS.</p>
3
2008-11-12T19:57:25Z
285,174
<p>The short answer is "no". There is not a swiss-army-knife like IDE that is both a full-featured Python code-editor and a full-featured WYSIWYG GUI editor. However, there are several stand-alone tools that make creating a GUI easier and there are a myriad of code editors, so if you can handle having two windows ope...
4
2008-11-12T20:09:06Z
[ "python", "user-interface", "ide" ]
With what kind of IDE (if any) you build python GUI projects?
285,132
<p>Is there any IDE (like VS) with drag and drop support for building python GUI, connecting to dbs etc? Eventhough I am an emacs guy, I find it much easier to create GUI with VS.</p>
3
2008-11-12T19:57:25Z
285,175
<p>You can try <a href="http://boa-constructor.sourceforge.net/" rel="nofollow">Boa Constructor</a> or <a href="http://www.dabodev.com/" rel="nofollow">Dabo</a></p>
1
2008-11-12T20:09:16Z
[ "python", "user-interface", "ide" ]
With what kind of IDE (if any) you build python GUI projects?
285,132
<p>Is there any IDE (like VS) with drag and drop support for building python GUI, connecting to dbs etc? Eventhough I am an emacs guy, I find it much easier to create GUI with VS.</p>
3
2008-11-12T19:57:25Z
285,186
<p>For GUI only, I find VisualWx (<a href="http://visualwx.altervista.org/" rel="nofollow">http://visualwx.altervista.org/</a>) to be very good for designing wxPython apps under Windows.</p> <p>For GUI + database, dabo (<a href="http://dabodev.com/" rel="nofollow">http://dabodev.com/</a>) is probably a good answer.</p...
4
2008-11-12T20:12:28Z
[ "python", "user-interface", "ide" ]
With what kind of IDE (if any) you build python GUI projects?
285,132
<p>Is there any IDE (like VS) with drag and drop support for building python GUI, connecting to dbs etc? Eventhough I am an emacs guy, I find it much easier to create GUI with VS.</p>
3
2008-11-12T19:57:25Z
285,209
<p>For <a href="http://wxpython.org/" rel="nofollow">wxPython</a> I use <a href="http://xrced.sourceforge.net/" rel="nofollow">xrced</a> to make GUI definitions contained in xml files, I find this way to be elegant and scalable.</p> <p><a href="http://wxformbuilder.org/" rel="nofollow">wxformbuilder</a> is also good.<...
0
2008-11-12T20:22:39Z
[ "python", "user-interface", "ide" ]
With what kind of IDE (if any) you build python GUI projects?
285,132
<p>Is there any IDE (like VS) with drag and drop support for building python GUI, connecting to dbs etc? Eventhough I am an emacs guy, I find it much easier to create GUI with VS.</p>
3
2008-11-12T19:57:25Z
285,449
<p>I'm a GNOME guy, so I prefer PyGTK. The standard GUI builder for that is the <a href="http://glade.gnome.org/" rel="nofollow">Glade Interface Designer</a> (until it transitions to GtkBuilder).</p>
1
2008-11-12T21:30:59Z
[ "python", "user-interface", "ide" ]
With what kind of IDE (if any) you build python GUI projects?
285,132
<p>Is there any IDE (like VS) with drag and drop support for building python GUI, connecting to dbs etc? Eventhough I am an emacs guy, I find it much easier to create GUI with VS.</p>
3
2008-11-12T19:57:25Z
285,494
<p>Also for PyGTK, there is <a href="http://gazpacho.sicem.biz/" rel="nofollow">Gazpacho</a>, it's pure python which makes adding your own custom widgets easier, and already has gtkbuilder support.</p> <p>I took over maintenance of the project a few months ago, and we plan to release it under the umbrella of the <a hr...
4
2008-11-12T21:45:11Z
[ "python", "user-interface", "ide" ]
With what kind of IDE (if any) you build python GUI projects?
285,132
<p>Is there any IDE (like VS) with drag and drop support for building python GUI, connecting to dbs etc? Eventhough I am an emacs guy, I find it much easier to create GUI with VS.</p>
3
2008-11-12T19:57:25Z
285,516
<p>I'm not really a Pythonista, but I <em>am</em> a Mac user and I appreciate a good, native interface in the apps I write and use. So, if I were to use Python for a GUI app on the Mac, I'd use PyObjC with Interface Builder and Xcode, rather than a cross-platform solution.</p>
2
2008-11-12T21:53:29Z
[ "python", "user-interface", "ide" ]
With what kind of IDE (if any) you build python GUI projects?
285,132
<p>Is there any IDE (like VS) with drag and drop support for building python GUI, connecting to dbs etc? Eventhough I am an emacs guy, I find it much easier to create GUI with VS.</p>
3
2008-11-12T19:57:25Z
285,912
<p>If your into QT <a href="http://die-offenbachs.de/eric/index.html" rel="nofollow">EricIDE</a> is a good choice</p>
3
2008-11-13T00:20:38Z
[ "python", "user-interface", "ide" ]
What Python tools can I use to interface with a website's API?
285,226
<p>Let's say I wanted to make a python script interface with a site like Twitter.</p> <p>What would I use to do that? I'm used to using curl/wget from bash, but Python seems to be much nicer to use. What's the equivalent?</p> <p>(This isn't Python run from a webserver, but run locally via the command line)</p>
6
2008-11-12T20:28:55Z
285,252
<p>Python has a very nice httplib module as well as a url module which together will probably accomplish most of what you need (at least with regards to wget functionality).</p>
2
2008-11-12T20:35:12Z
[ "python", "web-services", "twitter" ]
What Python tools can I use to interface with a website's API?
285,226
<p>Let's say I wanted to make a python script interface with a site like Twitter.</p> <p>What would I use to do that? I'm used to using curl/wget from bash, but Python seems to be much nicer to use. What's the equivalent?</p> <p>(This isn't Python run from a webserver, but run locally via the command line)</p>
6
2008-11-12T20:28:55Z
285,260
<p>I wholeheartedly recommend <a href="http://wwwsearch.sourceforge.net/mechanize/" rel="nofollow">mechanize</a> for python. It's exactly a programmable web browser that you can use from python, which handles forms and cookies as well! It makes any kind of site crawling a breeze.</p> <p>Take a look at the examples on ...
4
2008-11-12T20:36:57Z
[ "python", "web-services", "twitter" ]
What Python tools can I use to interface with a website's API?
285,226
<p>Let's say I wanted to make a python script interface with a site like Twitter.</p> <p>What would I use to do that? I'm used to using curl/wget from bash, but Python seems to be much nicer to use. What's the equivalent?</p> <p>(This isn't Python run from a webserver, but run locally via the command line)</p>
6
2008-11-12T20:28:55Z
285,280
<p>Python has urllib2, which is extensible library for opening URLs</p> <p>Full-featured easy to use library.</p> <p><a href="https://docs.python.org/library/urllib2.html" rel="nofollow">https://docs.python.org/library/urllib2.html</a></p>
5
2008-11-12T20:42:01Z
[ "python", "web-services", "twitter" ]
What Python tools can I use to interface with a website's API?
285,226
<p>Let's say I wanted to make a python script interface with a site like Twitter.</p> <p>What would I use to do that? I'm used to using curl/wget from bash, but Python seems to be much nicer to use. What's the equivalent?</p> <p>(This isn't Python run from a webserver, but run locally via the command line)</p>
6
2008-11-12T20:28:55Z
285,437
<p>For something like Twitter, you'll save yourself a ton of time by not reinventing the wheel. Try a library like <a href="http://code.google.com/p/python-twitter/" rel="nofollow">python-twitter</a>. This way, you can write your script, or even a full fledged application, that interfaces with Twitter, and you don't ha...
8
2008-11-12T21:27:20Z
[ "python", "web-services", "twitter" ]
What Python tools can I use to interface with a website's API?
285,226
<p>Let's say I wanted to make a python script interface with a site like Twitter.</p> <p>What would I use to do that? I'm used to using curl/wget from bash, but Python seems to be much nicer to use. What's the equivalent?</p> <p>(This isn't Python run from a webserver, but run locally via the command line)</p>
6
2008-11-12T20:28:55Z
288,173
<p>If you're used to dealing with cURL, consider <a href="http://pycurl.sourceforge.net/" rel="nofollow">PycURL</a>.</p>
0
2008-11-13T20:27:38Z
[ "python", "web-services", "twitter" ]
Exit codes in Python
285,289
<p>I got a message saying <code>script xyz.py returned exit code 0</code>. What does this mean?</p> <p>What do the exit codes in Python mean? How many are there? Which ones are important?</p>
76
2008-11-12T20:43:08Z
285,304
<p>Exit codes of 0 usually mean, "nothing wrong here." However if the programmer of the script didn't follow convention you may have to consult the source to see what it means. Usually a non-zero value is returned as an error code.</p>
9
2008-11-12T20:46:28Z
[ "python", "exit-code" ]
Exit codes in Python
285,289
<p>I got a message saying <code>script xyz.py returned exit code 0</code>. What does this mean?</p> <p>What do the exit codes in Python mean? How many are there? Which ones are important?</p>
76
2008-11-12T20:43:08Z
285,306
<p>The exit codes only have meaning as assigned by the script author. The Unix tradition is that exit code 0 means 'success', anything else is failure. The only way to be sure what the exit codes for a given script mean is to examine the script itself.</p>
2
2008-11-12T20:46:50Z
[ "python", "exit-code" ]
Exit codes in Python
285,289
<p>I got a message saying <code>script xyz.py returned exit code 0</code>. What does this mean?</p> <p>What do the exit codes in Python mean? How many are there? Which ones are important?</p>
76
2008-11-12T20:43:08Z
285,310
<p>Exit codes in many programming languages are up to programmers. So you have to look at your program source code (or manual). Zero usually means "everything went fine".</p>
1
2008-11-12T20:48:04Z
[ "python", "exit-code" ]
Exit codes in Python
285,289
<p>I got a message saying <code>script xyz.py returned exit code 0</code>. What does this mean?</p> <p>What do the exit codes in Python mean? How many are there? Which ones are important?</p>
76
2008-11-12T20:43:08Z
285,326
<p>What you're looking for in the script is calls to <a href="https://docs.python.org/2/library/sys.html#sys.exit"><code>sys.exit()</code></a>. The argument to that method is returned to the environment as the exit code.</p> <p>It's fairly likely that the script is never calling the exit method, and that 0 is the def...
91
2008-11-12T20:50:48Z
[ "python", "exit-code" ]
Exit codes in Python
285,289
<p>I got a message saying <code>script xyz.py returned exit code 0</code>. What does this mean?</p> <p>What do the exit codes in Python mean? How many are there? Which ones are important?</p>
76
2008-11-12T20:43:08Z
285,451
<p>From <a href="https://docs.python.org/2/library/sys.html#sys.exit">the documentation for <code>sys.exit</code></a>:</p> <blockquote> <p>The optional argument arg can be an integer giving the exit status (defaulting to zero), or another type of object. If it is an integer, zero is considered “successful ...
43
2008-11-12T21:31:23Z
[ "python", "exit-code" ]
Exit codes in Python
285,289
<p>I got a message saying <code>script xyz.py returned exit code 0</code>. What does this mean?</p> <p>What do the exit codes in Python mean? How many are there? Which ones are important?</p>
76
2008-11-12T20:43:08Z
285,752
<p>Operating system commands have exit codes. Look for <a href="http://steve-parker.org/sh/exitcodes.shtml" rel="nofollow">linux exit codes</a> to see some material on this. The shell uses the exit codes to decide if the program worked, had problems, or failed. There are some efforts to create standard (or at least ...
4
2008-11-12T23:12:15Z
[ "python", "exit-code" ]
Exit codes in Python
285,289
<p>I got a message saying <code>script xyz.py returned exit code 0</code>. What does this mean?</p> <p>What do the exit codes in Python mean? How many are there? Which ones are important?</p>
76
2008-11-12T20:43:08Z
286,444
<p>There is an <a href="http://docs.python.org/library/errno.html"><code>errno</code></a> module that defines standard exit codes:</p> <p>For example, <strong>Permission denied</strong> is error code <strong>13</strong>:</p> <pre><code>import errno, sys if can_access_resource(): do_something() else: sys.exit...
16
2008-11-13T07:32:08Z
[ "python", "exit-code" ]
Exit codes in Python
285,289
<p>I got a message saying <code>script xyz.py returned exit code 0</code>. What does this mean?</p> <p>What do the exit codes in Python mean? How many are there? Which ones are important?</p>
76
2008-11-12T20:43:08Z
30,776,037
<p>For the record, you can use POSIX standard exit codes defined <a href="https://docs.python.org/2/library/os.html#process-management">here</a>.</p> <p>Example:</p> <pre><code>import sys, os try: config() except: sys.exit(os.EX_CONFIG) try: do_stuff() except: sys.exit(os.EX_SOFTWARE) sys.exit(os.EX...
8
2015-06-11T08:53:44Z
[ "python", "exit-code" ]
Exit codes in Python
285,289
<p>I got a message saying <code>script xyz.py returned exit code 0</code>. What does this mean?</p> <p>What do the exit codes in Python mean? How many are there? Which ones are important?</p>
76
2008-11-12T20:43:08Z
37,757,298
<p>If you would like to portably use the <a href="https://www.gnu.org/software/libc/manual/html_node/Exit-Status.html" rel="nofollow">standard POSIX exit codes</a>, see the <a href="https://pypi.python.org/pypi/exitstatus/" rel="nofollow">exitstatus</a> package on PyPI.</p> <p>Install the package:</p> <pre><code>pip ...
0
2016-06-10T21:17:29Z
[ "python", "exit-code" ]
Python module to extract probable dates from strings?
285,408
<p>I'm looking for a Python module that would take an arbitrary block of text, search it for something that looks like a date string, and build a DateTime object out of it. Something like <a href="http://search.cpan.org/~sartak/Date-Extract-0.03/lib/Date/Extract.pm">Date::Extract</a> in Perl</p> <p>Thank you in advan...
13
2008-11-12T21:11:25Z
285,677
<p>The nearest equivalent is probably the <a href="http://labix.org/python-dateutil">dateutil</a> module. Usage is:</p> <pre><code>&gt;&gt;&gt; from dateutil.parser import parse &gt;&gt;&gt; parse("Wed, Nov 12") datetime.datetime(2008, 11, 12, 0, 0) </code></pre> <p>Using the fuzzy parameter should ignore extraneous...
12
2008-11-12T22:46:58Z
[ "python" ]
Python module to extract probable dates from strings?
285,408
<p>I'm looking for a Python module that would take an arbitrary block of text, search it for something that looks like a date string, and build a DateTime object out of it. Something like <a href="http://search.cpan.org/~sartak/Date-Extract-0.03/lib/Date/Extract.pm">Date::Extract</a> in Perl</p> <p>Thank you in advan...
13
2008-11-12T21:11:25Z
285,726
<p>Why no give <a href="http://code.google.com/p/parsedatetime/" rel="nofollow">parsedatetime</a> a try?</p>
5
2008-11-12T23:02:35Z
[ "python" ]
How to access a Python global variable from C?
285,455
<p>I have some global variables in a Python script. Some functions in that script call into C - is it possible to set one of those variables while in C and if so, how?</p> <p>I appreciate that this isn't a very nice design in the first place, but I need to make a small change to existing code, I don't want to embark o...
5
2008-11-12T21:32:08Z
285,498
<p>I'm not a python guru, but I found this question interesting so I googled around. <a href="http://mail.python.org/pipermail/python-list/2007-September/508180.html">This</a> was the first hit on "python embedding API" - does it help?</p> <blockquote> <p>If the attributes belong to the global scope of a module, t...
9
2008-11-12T21:46:13Z
[ "python", "c" ]
How to access a Python global variable from C?
285,455
<p>I have some global variables in a Python script. Some functions in that script call into C - is it possible to set one of those variables while in C and if so, how?</p> <p>I appreciate that this isn't a very nice design in the first place, but I need to make a small change to existing code, I don't want to embark o...
5
2008-11-12T21:32:08Z
285,606
<p>I recommend using <a href="http://www.cosc.canterbury.ac.nz/greg.ewing/python/Pyrex/" rel="nofollow"><code>pyrex</code></a> to make an extension module you can store the values in in python, and cdef a bunch of functions which can be called from C to return the values there.</p> <p>Otherwise, much depends on the ty...
0
2008-11-12T22:23:27Z
[ "python", "c" ]
How to access a Python global variable from C?
285,455
<p>I have some global variables in a Python script. Some functions in that script call into C - is it possible to set one of those variables while in C and if so, how?</p> <p>I appreciate that this isn't a very nice design in the first place, but I need to make a small change to existing code, I don't want to embark o...
5
2008-11-12T21:32:08Z
287,695
<p>Are you willing to modify the API a <em>little bit</em>?</p> <ul> <li><p>You can make the C function return the new value for the global, and then call it like this:</p> <p><code>my_global = my_c_func(...)</code></p></li> <li><p>If you're using <a href="http://robin.python-hosting.com/" rel="nofollow">Robin</a> or...
0
2008-11-13T17:55:12Z
[ "python", "c" ]
How to access a Python global variable from C?
285,455
<p>I have some global variables in a Python script. Some functions in that script call into C - is it possible to set one of those variables while in C and if so, how?</p> <p>I appreciate that this isn't a very nice design in the first place, but I need to make a small change to existing code, I don't want to embark o...
5
2008-11-12T21:32:08Z
25,907,027
<p>For anyone coming here from Google, here's the direct method:</p> <pre><code>PyObject* PyEval_GetGlobals() </code></pre> <p><a href="https://docs.python.org/2/c-api/reflection.html" rel="nofollow">https://docs.python.org/2/c-api/reflection.html</a></p> <p><a href="https://docs.python.org/3/c-api/reflection.html" ...
2
2014-09-18T07:47:54Z
[ "python", "c" ]
WX Python and Raw Input on Windows (WM_INPUT)
285,869
<p>Does anyone know how to use the <a href="http://msdn.microsoft.com/en-us/library/ms645543(VS.85).aspx" rel="nofollow">Raw Input</a> facility on Windows from a WX Python application?</p> <p>What I need to do is be able to differentiate the input from multiple keyboards. So if there is another way to achieving that, ...
4
2008-11-12T23:56:24Z
307,018
<p>Have you tried using ctypes?</p> <pre><code>&gt;&gt;&gt; import ctypes &gt;&gt;&gt; ctypes.windll.user32.RegisterRawInputDevices &lt;_FuncPtr object at 0x01FCFDC8&gt; </code></pre> <p>It would be a little work setting up the Python version of the necessary structures, but you may be able to query the Win32 API dir...
4
2008-11-20T22:03:01Z
[ "python", "windows", "wxpython", "raw-input" ]
WX Python and Raw Input on Windows (WM_INPUT)
285,869
<p>Does anyone know how to use the <a href="http://msdn.microsoft.com/en-us/library/ms645543(VS.85).aspx" rel="nofollow">Raw Input</a> facility on Windows from a WX Python application?</p> <p>What I need to do is be able to differentiate the input from multiple keyboards. So if there is another way to achieving that, ...
4
2008-11-12T23:56:24Z
467,729
<p>Theres a nice looking library here <a href="http://code.google.com/p/pymultimouse/" rel="nofollow">http://code.google.com/p/pymultimouse/</a></p> <p>It's not wx-python specific - but it does use raw input in python with ctypes (and worked in my test with 2 mice)</p>
1
2009-01-22T01:05:21Z
[ "python", "windows", "wxpython", "raw-input" ]
Using Regex Plus Function in Python to Encode and Substitute
285,931
<p>I'm trying to substitute something in a string in python and am having some trouble. Here's what I'd like to do.</p> <p>For a given comment in my posting:</p> <pre><code>"here are some great sites that i will do cool things with! http://stackoverflow.com/it's a pig &amp; http://google.com" </code></pre> <p>I'd li...
0
2008-11-13T00:34:43Z
285,943
<p>I think you want <code>url_pattern.sub(getExpandedURL, text)</code>.</p> <blockquote> <p>re.sub(pattern, repl, string, count=0)</p> <p>Return the string obtained by replacing the leftmost non-overlapping occurrences of the pattern in string by the replacement repl. repl can be either a string or a callable;...
3
2008-11-13T00:41:36Z
[ "python", "regex" ]
Decomposing HTML to link text and target
285,938
<p>Given an HTML link like</p> <pre><code>&lt;a href="urltxt" class="someclass" close="true"&gt;texttxt&lt;/a&gt; </code></pre> <p>how can I isolate the url and the text? </p> <p><strong>Updates</strong></p> <p>I'm using Beautiful Soup, and am unable to figure out how to do that. </p> <p>I did </p> <pre><code>sou...
5
2008-11-13T00:38:56Z
285,941
<p>Use <a href="http://crummy.com/software/BeautifulSoup">Beautiful Soup</a>. Doing it yourself is harder than it looks, you'll be better off using a tried and tested module.</p> <p><strong>EDIT:</strong></p> <p>I think you want:</p> <pre><code>soup = BeautifulSoup.BeautifulSoup(urllib.urlopen(url).read()) </code><...
8
2008-11-13T00:40:29Z
[ "python", "html", "regex", "beautifulsoup" ]
Decomposing HTML to link text and target
285,938
<p>Given an HTML link like</p> <pre><code>&lt;a href="urltxt" class="someclass" close="true"&gt;texttxt&lt;/a&gt; </code></pre> <p>how can I isolate the url and the text? </p> <p><strong>Updates</strong></p> <p>I'm using Beautiful Soup, and am unable to figure out how to do that. </p> <p>I did </p> <pre><code>sou...
5
2008-11-13T00:38:56Z
285,959
<p>Here's a code example, showing getting the attributes and contents of the links:</p> <pre><code>soup = BeautifulSoup.BeautifulSoup(urllib.urlopen(url)) for link in soup.findAll('a'): print link.attrs, link.contents </code></pre>
6
2008-11-13T00:48:43Z
[ "python", "html", "regex", "beautifulsoup" ]
Decomposing HTML to link text and target
285,938
<p>Given an HTML link like</p> <pre><code>&lt;a href="urltxt" class="someclass" close="true"&gt;texttxt&lt;/a&gt; </code></pre> <p>how can I isolate the url and the text? </p> <p><strong>Updates</strong></p> <p>I'm using Beautiful Soup, and am unable to figure out how to do that. </p> <p>I did </p> <pre><code>sou...
5
2008-11-13T00:38:56Z
285,963
<p>Though I suppose the others <em>might</em> be correct in pointing you to using Beautiful Soup, they <em>might</em> not, and using an external library might be massively over-the-top for your purposes. Here's a regex which will do what you ask.</p> <pre><code>/&lt;a\s+[^&gt;]*?href="([^"]*)".*?&gt;(.*?)&lt;\/a&gt;/ ...
3
2008-11-13T00:51:54Z
[ "python", "html", "regex", "beautifulsoup" ]
Decomposing HTML to link text and target
285,938
<p>Given an HTML link like</p> <pre><code>&lt;a href="urltxt" class="someclass" close="true"&gt;texttxt&lt;/a&gt; </code></pre> <p>how can I isolate the url and the text? </p> <p><strong>Updates</strong></p> <p>I'm using Beautiful Soup, and am unable to figure out how to do that. </p> <p>I did </p> <pre><code>sou...
5
2008-11-13T00:38:56Z
286,019
<p>Looks like you have two issues there:</p> <ol> <li>link.content**s**, not link.content</li> <li>attrs is a dictionary, not a string. It holds key value pairs for each attribute in an HTML element. link.attrs['href'] will get you what you appear to be looking for, but you'd want to wrap that in a check in case you c...
4
2008-11-13T01:23:56Z
[ "python", "html", "regex", "beautifulsoup" ]
Parse HTML via XPath
285,990
<p>In .Net, I found this great library, <a href="http://www.codeplex.com/htmlagilitypack">HtmlAgilityPack</a> that allows you to easily parse non-well-formed HTML using XPath. I've used this for a couple years in my .Net sites, but I've had to settle for more painful libraries for my Python, Ruby and other projects. ...
22
2008-11-13T01:05:59Z
286,094
<p><a href="http://www.crummy.com/software/BeautifulSoup/" rel="nofollow">BeautifulSoup</a> is a good Python library for dealing with messy HTML in clean ways.</p>
6
2008-11-13T02:32:56Z
[ "python", "html", "ruby", "xpath", "parsing" ]
Parse HTML via XPath
285,990
<p>In .Net, I found this great library, <a href="http://www.codeplex.com/htmlagilitypack">HtmlAgilityPack</a> that allows you to easily parse non-well-formed HTML using XPath. I've used this for a couple years in my .Net sites, but I've had to settle for more painful libraries for my Python, Ruby and other projects. ...
22
2008-11-13T01:05:59Z
286,222
<p>It seems the question could be more precisely stated as "<em>How to convert HTML to XML so that XPath expressions can be evaluated against it</em>".</p> <p>Here are two good tools:</p> <ol> <li><p><a href="http://home.ccil.org/~cowan/XML/tagsoup/" rel="nofollow"><strong>TagSoup</strong></a>, an open-source program...
3
2008-11-13T03:57:23Z
[ "python", "html", "ruby", "xpath", "parsing" ]
Parse HTML via XPath
285,990
<p>In .Net, I found this great library, <a href="http://www.codeplex.com/htmlagilitypack">HtmlAgilityPack</a> that allows you to easily parse non-well-formed HTML using XPath. I've used this for a couple years in my .Net sites, but I've had to settle for more painful libraries for my Python, Ruby and other projects. ...
22
2008-11-13T01:05:59Z
288,965
<p>An outstanding achievement is <a href="http://www.dcarlisle.demon.co.uk/htmlparse.xsl" rel="nofollow"><strong>the pure XSLT 2.0 Parser of HTML</strong></a> written by <a href="http://dpcarlisle.blogspot.com/" rel="nofollow"><strong>David Carlisle</strong></a>.</p> <p>Reading its code would be a great learning exerc...
1
2008-11-14T01:23:20Z
[ "python", "html", "ruby", "xpath", "parsing" ]
Parse HTML via XPath
285,990
<p>In .Net, I found this great library, <a href="http://www.codeplex.com/htmlagilitypack">HtmlAgilityPack</a> that allows you to easily parse non-well-formed HTML using XPath. I've used this for a couple years in my .Net sites, but I've had to settle for more painful libraries for my Python, Ruby and other projects. ...
22
2008-11-13T01:05:59Z
288,976
<p>For Ruby, I highly recommend Hpricot that Jb Evain pointed out. If you're looking for a faster libxml-based competitor, Nokogiri (see <a href="http://tenderlovemaking.com/2008/10/30/nokogiri-is-released/" rel="nofollow">http://tenderlovemaking.com/2008/10/30/nokogiri-is-released/</a>) is pretty good too (it supports...
2
2008-11-14T01:31:31Z
[ "python", "html", "ruby", "xpath", "parsing" ]
Parse HTML via XPath
285,990
<p>In .Net, I found this great library, <a href="http://www.codeplex.com/htmlagilitypack">HtmlAgilityPack</a> that allows you to easily parse non-well-formed HTML using XPath. I've used this for a couple years in my .Net sites, but I've had to settle for more painful libraries for my Python, Ruby and other projects. ...
22
2008-11-13T01:05:59Z
288,994
<p>There is a free C implementation for XML called libxml2 which has some api bits for XPath which I have used with great success which you can specify HTML as the document being loaded. This had worked for me for some less than perfect HTML documents.. </p> <p>For the most part, XPath is most useful when the inboun...
1
2008-11-14T01:42:04Z
[ "python", "html", "ruby", "xpath", "parsing" ]
Parse HTML via XPath
285,990
<p>In .Net, I found this great library, <a href="http://www.codeplex.com/htmlagilitypack">HtmlAgilityPack</a> that allows you to easily parse non-well-formed HTML using XPath. I've used this for a couple years in my .Net sites, but I've had to settle for more painful libraries for my Python, Ruby and other projects. ...
22
2008-11-13T01:05:59Z
289,167
<p>In python, <a href="http://pypi.python.org/pypi/elementtidy/1.0-20050212">ElementTidy</a> parses tag soup and produces an element tree, which allows querying using XPath:</p> <pre><code>&gt;&gt;&gt; from elementtidy.TidyHTMLTreeBuilder import TidyHTMLTreeBuilder as TB &gt;&gt;&gt; tb = TB() &gt;&gt;&gt; tb.feed("&l...
7
2008-11-14T03:37:03Z
[ "python", "html", "ruby", "xpath", "parsing" ]
Parse HTML via XPath
285,990
<p>In .Net, I found this great library, <a href="http://www.codeplex.com/htmlagilitypack">HtmlAgilityPack</a> that allows you to easily parse non-well-formed HTML using XPath. I've used this for a couple years in my .Net sites, but I've had to settle for more painful libraries for my Python, Ruby and other projects. ...
22
2008-11-13T01:05:59Z
4,747,067
<p>I'm surprised there isn't a single mention of lxml. It's blazingly fast and will work in any environment that allows CPython libraries.</p> <p>Here's how <a href="http://codespeak.net/lxml/xpathxslt.html">you can parse HTML via XPATH using lxml</a>.</p> <pre><code>&gt;&gt;&gt; from lxml import etree &gt;&gt;&gt; d...
29
2011-01-20T12:24:30Z
[ "python", "html", "ruby", "xpath", "parsing" ]
Parse HTML via XPath
285,990
<p>In .Net, I found this great library, <a href="http://www.codeplex.com/htmlagilitypack">HtmlAgilityPack</a> that allows you to easily parse non-well-formed HTML using XPath. I've used this for a couple years in my .Net sites, but I've had to settle for more painful libraries for my Python, Ruby and other projects. ...
22
2008-11-13T01:05:59Z
9,441,191
<p>The most stable results I've had have been using lxml.html's soupparser. You'll need to install python-lxml and python-beautifulsoup, then you can do the following:</p> <pre><code>from lxml.html.soupparser import fromstring tree = fromstring('&lt;mal form="ed"&gt;&lt;html/&gt;here!') matches = tree.xpath("./mal[@fo...
4
2012-02-25T04:17:56Z
[ "python", "html", "ruby", "xpath", "parsing" ]
Decimal place issues with floats and decimal.Decimal
286,061
<p>I seem to be losing a lot of precision with floats.</p> <p>For example I need to solve a matrix:</p> <pre><code>4.0x -2.0y 1.0z =11.0 1.0x +5.0y -3.0z =-6.0 2.0x +2.0y +5.0z =7.0 </code></pre> <p>This is the code I use to import the matrix from a text file:</p> <pre><code>f = open('gauss.dat') lines = f.readlin...
2
2008-11-13T02:06:30Z
286,064
<p>I'm not familiar enough with the Decimal class to help you out, but your problem is due to the fact that decimal fractions can often not be accurate represented in binary, so what you're seeing is the closest possible approximation; there's no way to avoid this problem without using a special class (like Decimal, pr...
11
2008-11-13T02:09:08Z
[ "python", "floating-point", "decimal", "floating-accuracy" ]
Decimal place issues with floats and decimal.Decimal
286,061
<p>I seem to be losing a lot of precision with floats.</p> <p>For example I need to solve a matrix:</p> <pre><code>4.0x -2.0y 1.0z =11.0 1.0x +5.0y -3.0z =-6.0 2.0x +2.0y +5.0z =7.0 </code></pre> <p>This is the code I use to import the matrix from a text file:</p> <pre><code>f = open('gauss.dat') lines = f.readlin...
2
2008-11-13T02:06:30Z
286,068
<p>IEEE floating point is binary, not decimal. There is no fixed length binary fraction that is exactly 0.1, or any multiple thereof. It is a repeating fraction, like 1/3 in decimal.</p> <p>Please read <a href="http://docs.sun.com/source/806-3568/ncg_goldberg.html" rel="nofollow">What Every Computer Scientist Should K...
14
2008-11-13T02:11:58Z
[ "python", "floating-point", "decimal", "floating-accuracy" ]
Decimal place issues with floats and decimal.Decimal
286,061
<p>I seem to be losing a lot of precision with floats.</p> <p>For example I need to solve a matrix:</p> <pre><code>4.0x -2.0y 1.0z =11.0 1.0x +5.0y -3.0z =-6.0 2.0x +2.0y +5.0z =7.0 </code></pre> <p>This is the code I use to import the matrix from a text file:</p> <pre><code>f = open('gauss.dat') lines = f.readlin...
2
2008-11-13T02:06:30Z
286,119
<p>First, your input can be simplified a lot. You don't need to read and parse a file. You can just declare your objects in Python notation. Eval the file.</p> <pre><code>b = [ [4.0, -2.0, 1.0], [1.0, +5.0, -3.0], [2.0, +2.0, +5.0], ] y = [ 11.0, -6.0, 7.0 ] </code></pre> <p>Second, y=-1.2-0.200000000...
4
2008-11-13T02:49:01Z
[ "python", "floating-point", "decimal", "floating-accuracy" ]
Decimal place issues with floats and decimal.Decimal
286,061
<p>I seem to be losing a lot of precision with floats.</p> <p>For example I need to solve a matrix:</p> <pre><code>4.0x -2.0y 1.0z =11.0 1.0x +5.0y -3.0z =-6.0 2.0x +2.0y +5.0z =7.0 </code></pre> <p>This is the code I use to import the matrix from a text file:</p> <pre><code>f = open('gauss.dat') lines = f.readlin...
2
2008-11-13T02:06:30Z
286,122
<p>Also see <a href="http://stackoverflow.com/questions/249467/what-is-a-simple-example-of-floating-pointrounding-error">What is a simple example of floating point error</a>, here on SO, which has some answers. The one I give actually uses python as the example language...</p>
0
2008-11-13T02:49:57Z
[ "python", "floating-point", "decimal", "floating-accuracy" ]
Decimal place issues with floats and decimal.Decimal
286,061
<p>I seem to be losing a lot of precision with floats.</p> <p>For example I need to solve a matrix:</p> <pre><code>4.0x -2.0y 1.0z =11.0 1.0x +5.0y -3.0z =-6.0 2.0x +2.0y +5.0z =7.0 </code></pre> <p>This is the code I use to import the matrix from a text file:</p> <pre><code>f = open('gauss.dat') lines = f.readlin...
2
2008-11-13T02:06:30Z
287,079
<p>I'd caution against the decimal module for tasks like this. Its purpose is really more dealing with real-world decimal numbers (eg. matching human bookkeeping practices), with finite precision, not performing exact precision math. There are numbers not exactly representable in decimal just as there are in binary, ...
4
2008-11-13T14:30:33Z
[ "python", "floating-point", "decimal", "floating-accuracy" ]
Decimal place issues with floats and decimal.Decimal
286,061
<p>I seem to be losing a lot of precision with floats.</p> <p>For example I need to solve a matrix:</p> <pre><code>4.0x -2.0y 1.0z =11.0 1.0x +5.0y -3.0z =-6.0 2.0x +2.0y +5.0z =7.0 </code></pre> <p>This is the code I use to import the matrix from a text file:</p> <pre><code>f = open('gauss.dat') lines = f.readlin...
2
2008-11-13T02:06:30Z
317,171
<p>It is not an answer to your question, but related:</p> <pre><code>#!/usr/bin/env python from numpy import abs, dot, loadtxt, max from numpy.linalg import solve data = loadtxt('gauss.dat', delimiter=',') a, b = data[:,:-1], data[:,-1:] x = solve(a, b) # here you may use any method you like instead of `solve` print(...
2
2008-11-25T12:28:41Z
[ "python", "floating-point", "decimal", "floating-accuracy" ]
Decimal place issues with floats and decimal.Decimal
286,061
<p>I seem to be losing a lot of precision with floats.</p> <p>For example I need to solve a matrix:</p> <pre><code>4.0x -2.0y 1.0z =11.0 1.0x +5.0y -3.0z =-6.0 2.0x +2.0y +5.0z =7.0 </code></pre> <p>This is the code I use to import the matrix from a text file:</p> <pre><code>f = open('gauss.dat') lines = f.readlin...
2
2008-11-13T02:06:30Z
407,419
<p>Just a suggestion (I don't know what constraints you're working under): </p> <p>Why not use straightforward Gaussian elimination, rather than Gauss-Seidel iteration? If you choose the coefficient with the largest value as the pivot for each elimination step, you'll minimise the FP rounding errors. </p> <p>This may...
0
2009-01-02T17:04:55Z
[ "python", "floating-point", "decimal", "floating-accuracy" ]
Decimal place issues with floats and decimal.Decimal
286,061
<p>I seem to be losing a lot of precision with floats.</p> <p>For example I need to solve a matrix:</p> <pre><code>4.0x -2.0y 1.0z =11.0 1.0x +5.0y -3.0z =-6.0 2.0x +2.0y +5.0z =7.0 </code></pre> <p>This is the code I use to import the matrix from a text file:</p> <pre><code>f = open('gauss.dat') lines = f.readlin...
2
2008-11-13T02:06:30Z
407,735
<p>instead of decimal, you might want to look at <a href="http://code.google.com/p/mpmath/" rel="nofollow">mpmath</a>.</p>
0
2009-01-02T19:06:25Z
[ "python", "floating-point", "decimal", "floating-accuracy" ]
Accounting for a changing path
286,486
<p>In relation to <a href="http://stackoverflow.com/questions/283431/why-would-an-command-not-recognized-error-occur-only-when-a-window-is-populated">another question</a>, how do you account for paths that may change? For example, if a program is calling a file in the same directory as the program, you can simply use t...
1
2008-11-13T08:10:28Z
286,499
<p>If your file is always in the same directory as your program then:</p> <pre><code>def _isInProductionMode(): """ returns True when running the exe, False when running from a script, ie development mode. """ return (hasattr(sys, "frozen") or # new py2exe hasattr(sys, "importers") # ol...
0
2008-11-13T08:15:58Z
[ "python", "file", "path" ]
Accounting for a changing path
286,486
<p>In relation to <a href="http://stackoverflow.com/questions/283431/why-would-an-command-not-recognized-error-occur-only-when-a-window-is-populated">another question</a>, how do you account for paths that may change? For example, if a program is calling a file in the same directory as the program, you can simply use t...
1
2008-11-13T08:10:28Z
286,801
<p>What -- specifically -- do you mean by "calling a file...foo.py"?</p> <ol> <li><p>Import? If so, the path is totally outside of your program. Set the <code>PYTHONPATH</code> environment variable with <code>.</code> or <code>c:\</code> or whatever at the shell level. You can, for example, write 2-line shell scrip...
0
2008-11-13T10:54:11Z
[ "python", "file", "path" ]
Accounting for a changing path
286,486
<p>In relation to <a href="http://stackoverflow.com/questions/283431/why-would-an-command-not-recognized-error-occur-only-when-a-window-is-populated">another question</a>, how do you account for paths that may change? For example, if a program is calling a file in the same directory as the program, you can simply use t...
1
2008-11-13T08:10:28Z
286,802
<p>Simple answer: You work out the absolute path based on the environment.</p> <p>What you really need is a few pointers. There are various bits of runtime and environment information that you can glean from various places in the standard library (and they certainly help me when I want to deploy an application on wind...
4
2008-11-13T10:54:40Z
[ "python", "file", "path" ]
Accounting for a changing path
286,486
<p>In relation to <a href="http://stackoverflow.com/questions/283431/why-would-an-command-not-recognized-error-occur-only-when-a-window-is-populated">another question</a>, how do you account for paths that may change? For example, if a program is calling a file in the same directory as the program, you can simply use t...
1
2008-11-13T08:10:28Z
286,914
<p>I figured out by using <strong>os.getcwd()</strong>. I also learned about using <strong>os.path.join</strong> to automatically determine the correct path format based on the OS. Here's the code:</p> <pre><code>def openNewRecord(self, event): # wxGlade: CharSheet.&lt;event_handler&gt; """Create a new, blank reco...
-1
2008-11-13T13:37:10Z
[ "python", "file", "path" ]
Django multiselect checkboxes
286,558
<p>I have a list of objects, each with it's own checkbox, where the user can select multiple of these. The list is a result of a query.</p> <p>How can I mark in the view which checkboxes are already selected? There doesn't seem to be an in operator in the template language.</p> <p>I want something along the lines of:...
0
2008-11-13T08:48:03Z
295,377
<p>You could use a templatetag like the one in this snippet comments:</p> <p><a href="http://www.djangosnippets.org/snippets/177/" rel="nofollow">http://www.djangosnippets.org/snippets/177/</a></p> <pre><code>@register.filter def in_list(value,arg): return value in arg </code></pre> <p>To be used in templates:</...
0
2008-11-17T11:39:22Z
[ "python", "django", "checkbox", "django-templates" ]
What's the best way to transfer data from python to another application in windows?
286,614
<p>I'm developing an application with a team in .Net (C++) and provide a COM interface to interact with python and other languages.</p> <p>What we've found is that pushing data through COM turns out to be pretty slow.</p> <p>I've considered several alternatives:</p> <ul> <li>dumping data to a file and sending the fi...
8
2008-11-13T09:25:21Z
286,680
<p>XML/JSON and a either a Web Service or directly through a socket. It is also language and platform independent so if you decide you want to host the python portion on UNIX you can, or if you want to suddenly use Java or PHP or pretty much any other language you can.</p> <p>As a general rule proprietary protocols/a...
2
2008-11-13T09:50:30Z
[ "python", "winapi", "com", "data-transfer" ]
What's the best way to transfer data from python to another application in windows?
286,614
<p>I'm developing an application with a team in .Net (C++) and provide a COM interface to interact with python and other languages.</p> <p>What we've found is that pushing data through COM turns out to be pretty slow.</p> <p>I've considered several alternatives:</p> <ul> <li>dumping data to a file and sending the fi...
8
2008-11-13T09:25:21Z
286,682
<p>It shouldn't be too complicated to set up a test for each of your alternatives and do a benchmark. Noting beats context sensitive empirical data... :)</p> <p>Oh, and if you do this I'm sure a lot of people would be interested in the results.</p>
0
2008-11-13T09:50:39Z
[ "python", "winapi", "com", "data-transfer" ]
What's the best way to transfer data from python to another application in windows?
286,614
<p>I'm developing an application with a team in .Net (C++) and provide a COM interface to interact with python and other languages.</p> <p>What we've found is that pushing data through COM turns out to be pretty slow.</p> <p>I've considered several alternatives:</p> <ul> <li>dumping data to a file and sending the fi...
8
2008-11-13T09:25:21Z
286,738
<p>Staying within the Windows interprocess communication mechanisms, we had positive experience using <em>windows named pipes</em>. Using Windows overlapped IO and the <code>win32pipe</code> module from <a href="http://pywin32.sourceforge.net/">pywin32</a>.</p> <p>You can learn much about win32 and python in the <a h...
9
2008-11-13T10:20:33Z
[ "python", "winapi", "com", "data-transfer" ]
What's the best way to transfer data from python to another application in windows?
286,614
<p>I'm developing an application with a team in .Net (C++) and provide a COM interface to interact with python and other languages.</p> <p>What we've found is that pushing data through COM turns out to be pretty slow.</p> <p>I've considered several alternatives:</p> <ul> <li>dumping data to a file and sending the fi...
8
2008-11-13T09:25:21Z
287,751
<p>+1 on the named pipes but I would also like to add that from your comments it seems that your application is very chatty. Every time you make a remote call no matter how fast the underlying transport is you have a fixed cost of marshaling the data and making a connection. You can save a huge amount of overhead if ...
2
2008-11-13T18:18:12Z
[ "python", "winapi", "com", "data-transfer" ]
Any AOP support library for Python?
286,958
<p>I am trying to use some AOP in my Python programming, but I do not have any experience of the various libs that exists. So my question is :</p> <p>What AOP support exists for Python, and what are the advantages of the differents libraries between them ?</p> <p>Edit : I've found some, but I don't know how they comp...
23
2008-11-13T13:51:27Z
286,998
<p>I'd start with the <a href="http://wiki.python.org/moin/PythonDecoratorLibrary" rel="nofollow">Python Decorator Library</a>. Much of that is AOP kind of stuff. </p>
2
2008-11-13T14:05:33Z
[ "python", "aop" ]
Any AOP support library for Python?
286,958
<p>I am trying to use some AOP in my Python programming, but I do not have any experience of the various libs that exists. So my question is :</p> <p>What AOP support exists for Python, and what are the advantages of the differents libraries between them ?</p> <p>Edit : I've found some, but I don't know how they comp...
23
2008-11-13T13:51:27Z
287,009
<p>In Python, aspect-oriented programming typically consists of dynamically modifying classes and instances at runtime, which is commonly referred to as monkeypatching. In an answer to another AOP question, I summarized some of these <a href="http://stackoverflow.com/questions/20663/do-you-use-aop-aspect-oriented-prog...
5
2008-11-13T14:11:06Z
[ "python", "aop" ]
Any AOP support library for Python?
286,958
<p>I am trying to use some AOP in my Python programming, but I do not have any experience of the various libs that exists. So my question is :</p> <p>What AOP support exists for Python, and what are the advantages of the differents libraries between them ?</p> <p>Edit : I've found some, but I don't know how they comp...
23
2008-11-13T13:51:27Z
287,640
<p>See S.Lott's link about Python decorators for some great examples, and see the <a href="http://www.python.org/dev/peps/pep-0318/">defining PEP for decorators</a>.</p> <p>Python had AOP since the beginning, it just didn't have an impressive name. In Python 2.4 the decorator syntax was added, which makes applying dec...
22
2008-11-13T17:39:10Z
[ "python", "aop" ]
Any AOP support library for Python?
286,958
<p>I am trying to use some AOP in my Python programming, but I do not have any experience of the various libs that exists. So my question is :</p> <p>What AOP support exists for Python, and what are the advantages of the differents libraries between them ?</p> <p>Edit : I've found some, but I don't know how they comp...
23
2008-11-13T13:51:27Z
2,884,843
<p>Using annotations is not really AOP, because the weaving process is somewhat hard-coded.</p> <p>There are several AOP frameworks in Python (I counted and compared 8 of them, of which Aspyct was the clear winner). I'm going to publish a paper with my findings on one of the next conferences, including a real-life ind...
6
2010-05-21T19:08:59Z
[ "python", "aop" ]
Any AOP support library for Python?
286,958
<p>I am trying to use some AOP in my Python programming, but I do not have any experience of the various libs that exists. So my question is :</p> <p>What AOP support exists for Python, and what are the advantages of the differents libraries between them ?</p> <p>Edit : I've found some, but I don't know how they comp...
23
2008-11-13T13:51:27Z
5,220,447
<p>Another AOP library for python would be pytilities. It is currently the most powerful (, for as far as I know).</p> <p>pytilities homepage: <a href="http://pytilities.sourceforge.net/">http://pytilities.sourceforge.net/</a></p> <p>Its features are:</p> <ul> <li>make reusable Aspect classes</li> <li>apply multiple...
7
2011-03-07T13:48:30Z
[ "python", "aop" ]
Any AOP support library for Python?
286,958
<p>I am trying to use some AOP in my Python programming, but I do not have any experience of the various libs that exists. So my question is :</p> <p>What AOP support exists for Python, and what are the advantages of the differents libraries between them ?</p> <p>Edit : I've found some, but I don't know how they comp...
23
2008-11-13T13:51:27Z
34,287,453
<p>What about the BSD-licensed <a href="https://github.com/ionelmc/python-aspectlib/" rel="nofollow">python-aspectlib</a>?</p> <blockquote> <h2>Implementation status</h2> <p>Weaving functions, methods, instances and classes is completed.</p> </blockquote>
0
2015-12-15T10:59:24Z
[ "python", "aop" ]
Python program start
287,204
<p>Should I start a Python program with:</p> <pre><code>if__name__ == '__main__': some code... </code></pre> <p>And if so, why? I saw it many times but don't have a clue about it.</p>
11
2008-11-13T15:16:35Z
287,215
<p>If your program is usable as a library but you also have a main program (e.g. to test the library), that construct lets others import the file as a library and not run your main program. If your program is named foo.py and you do "import foo" from another python file, <code>__name__</code> evaluates to <code>'foo'</...
19
2008-11-13T15:20:28Z
[ "python" ]
Python program start
287,204
<p>Should I start a Python program with:</p> <pre><code>if__name__ == '__main__': some code... </code></pre> <p>And if so, why? I saw it many times but don't have a clue about it.</p>
11
2008-11-13T15:16:35Z
287,234
<p>This is good practice. First, it clearly marks your module entry point (assuming you don't have any other executable code at toplevel - yuck). Second, it makes your module importable by other modules without executing, which some tools like code checkers, packagers etc. need to do.</p>
3
2008-11-13T15:25:37Z
[ "python" ]
Python program start
287,204
<p>Should I start a Python program with:</p> <pre><code>if__name__ == '__main__': some code... </code></pre> <p>And if so, why? I saw it many times but don't have a clue about it.</p>
11
2008-11-13T15:16:35Z
287,237
<p>A better pattern is this:</p> <pre><code>def main(): ... if __name__ == '__main__': main() </code></pre> <p>This allows your code to be invoked by someone who imported it, while also making programs such as <A HREF="http://pychecker.sourceforge.net/">pychecker</A> and <A HREF="http://www.logilab.org/project...
17
2008-11-13T15:26:28Z
[ "python" ]
Python program start
287,204
<p>Should I start a Python program with:</p> <pre><code>if__name__ == '__main__': some code... </code></pre> <p>And if so, why? I saw it many times but don't have a clue about it.</p>
11
2008-11-13T15:16:35Z
287,548
<p>Guido Van Rossum <a href="http://www.artima.com/weblogs/viewpost.jsp?thread=4829">suggests</a>:</p> <pre><code>def main(argv=None): if argv is None: argv = sys.argv ... if __name__ == "__main__": sys.exit(main()) </code></pre> <p>This way you can run <code>main()</code> from somewhere else (supplying ...
14
2008-11-13T17:09:51Z
[ "python" ]
Tix documentation for Python
287,312
<p>I've recently starting playing around with <a href="http://tix.sourceforge.net/">Tix</a> in Python, and I'm distressed at the lack of Python documentation for it online. Both the <a href="http://tix.sourceforge.net/tixtutorial/index.htm">tutorial</a> and <a href="http://tix.sourceforge.net/docs/html/TixBook/TixBook...
10
2008-11-13T15:52:03Z
287,351
<p>I haven't used Tix, but perhaps:</p> <pre><code>import Tix help(Tix) </code></pre> <p>?</p>
-1
2008-11-13T16:09:14Z
[ "python", "documentation", "tkinter", "tix" ]
Tix documentation for Python
287,312
<p>I've recently starting playing around with <a href="http://tix.sourceforge.net/">Tix</a> in Python, and I'm distressed at the lack of Python documentation for it online. Both the <a href="http://tix.sourceforge.net/tixtutorial/index.htm">tutorial</a> and <a href="http://tix.sourceforge.net/docs/html/TixBook/TixBook...
10
2008-11-13T15:52:03Z
287,515
<p>I have noticed too the lack of Python documentation. The docs I've found are only these that come up first as Google searches (with the <a href="http://tix.sourceforge.net/docs/html/TixUser/TixUser.html" rel="nofollow">Python Tix User Guide</a> being the most prominent.</p> <p>So far, I've done exactly what you des...
3
2008-11-13T17:00:03Z
[ "python", "documentation", "tkinter", "tix" ]
Tix documentation for Python
287,312
<p>I've recently starting playing around with <a href="http://tix.sourceforge.net/">Tix</a> in Python, and I'm distressed at the lack of Python documentation for it online. Both the <a href="http://tix.sourceforge.net/tixtutorial/index.htm">tutorial</a> and <a href="http://tix.sourceforge.net/docs/html/TixBook/TixBook...
10
2008-11-13T15:52:03Z
16,267,054
<p>I have only just started to look at this myself.</p> <p>If you create this:</p> <pre><code>#!/usr/bin/python import Tix help(Tix) </code></pre> <p>save it as tix.py</p> <p>Make it executable then run it : ./tix.py>tix.txt</p> <p>you will have all the help in a file which you can view or print later.</p> <p>Thi...
1
2013-04-28T19:45:54Z
[ "python", "documentation", "tkinter", "tix" ]
Parsing C++ preprocessor #if statements
287,379
<p>I have a C/C++ source file with conditional compilation. Before I ship it to customers I want to remove most of the #if statements, so that my customers do not need to worry about passing the right -D options to the compiler.</p> <p>I have this implemented and working in Python, but it only handles #ifdef and #ifn...
4
2008-11-13T16:18:37Z
287,392
<p>Have you looked at <a href="http://www.boost.org/libs/wave" rel="nofollow">Boost.Wave</a>?</p>
4
2008-11-13T16:21:59Z
[ "python", "c++", "c", "parsing", "c-preprocessor" ]
Parsing C++ preprocessor #if statements
287,379
<p>I have a C/C++ source file with conditional compilation. Before I ship it to customers I want to remove most of the #if statements, so that my customers do not need to worry about passing the right -D options to the compiler.</p> <p>I have this implemented and working in Python, but it only handles #ifdef and #ifn...
4
2008-11-13T16:18:37Z
287,393
<p>The GCC preprocessor is typicallly a stand-alone program, typically called <code>cpp</code>. That will probably also strip off your comments, of course.</p>
0
2008-11-13T16:22:24Z
[ "python", "c++", "c", "parsing", "c-preprocessor" ]
Parsing C++ preprocessor #if statements
287,379
<p>I have a C/C++ source file with conditional compilation. Before I ship it to customers I want to remove most of the #if statements, so that my customers do not need to worry about passing the right -D options to the compiler.</p> <p>I have this implemented and working in Python, but it only handles #ifdef and #ifn...
4
2008-11-13T16:18:37Z
287,395
<p>Instead of reinventing the wheel, download "unifdef". If you're on some flavour of Linux, you can probably find a package for it, otherwise it's on <a href="http://freshmeat.net/projects/unifdef/" rel="nofollow">FreshMeat</a></p>
7
2008-11-13T16:23:07Z
[ "python", "c++", "c", "parsing", "c-preprocessor" ]
Parsing C++ preprocessor #if statements
287,379
<p>I have a C/C++ source file with conditional compilation. Before I ship it to customers I want to remove most of the #if statements, so that my customers do not need to worry about passing the right -D options to the compiler.</p> <p>I have this implemented and working in Python, but it only handles #ifdef and #ifn...
4
2008-11-13T16:18:37Z
287,405
<p>How about just passing through the C preprocessor, and letting that do the job. It will get rid of all of them, so you might need to have a pre-preprocessor step and a post pre-processor step to protect things you don't want to be expanded.</p> <ol> <li>Change all #include to @include</li> <li>Pass file through pr...
12
2008-11-13T16:25:25Z
[ "python", "c++", "c", "parsing", "c-preprocessor" ]
Parsing C++ preprocessor #if statements
287,379
<p>I have a C/C++ source file with conditional compilation. Before I ship it to customers I want to remove most of the #if statements, so that my customers do not need to worry about passing the right -D options to the compiler.</p> <p>I have this implemented and working in Python, but it only handles #ifdef and #ifn...
4
2008-11-13T16:18:37Z
287,521
<p>As <a href="http://stackoverflow.com/questions/287379/parsing-c-preprocessor-if-statements#287405">KeithB said</a>, you could just let the preprocessor do this for you. </p> <p>But if you're not trying to hide things (ie., there may be stuff in the conditionally compiled code that you don't want or aren't permitted...
14
2008-11-13T17:02:13Z
[ "python", "c++", "c", "parsing", "c-preprocessor" ]
Python's ConfigParser unique keys per section
287,757
<p>I read the part of <a href="http://docs.python.org/library/configparser.html">the docs</a> and saw that the <code>ConfigParser</code> returns a list of key/value pairs for the options within a section. I figured that keys did not need to be unique within a section, otherwise the parser would just return a mapping. I...
8
2008-11-13T18:20:11Z
287,942
<p>ConfigParser isn't designed to handle such conditions. Furthermore, your config file doesn't make sense to me.</p> <p>ConfigParser gives you a dict-like structure for each section, so when you call parser.items(section), I'm expecting similar output to dict.items(), which is just a list of key/value tuples. I would...
11
2008-11-13T19:24:23Z
[ "python", "design", "configuration-files" ]
Python's ConfigParser unique keys per section
287,757
<p>I read the part of <a href="http://docs.python.org/library/configparser.html">the docs</a> and saw that the <code>ConfigParser</code> returns a list of key/value pairs for the options within a section. I figured that keys did not need to be unique within a section, otherwise the parser would just return a mapping. I...
8
2008-11-13T18:20:11Z
13,340,655
<p>This deficiency of ConfigParser is the reason why pyglet used <a href="http://code.google.com/p/pyglet/source/diff?spec=svnffc4fe58bc2179a75d3338aa821eb04649609871&amp;old=95d2cfa3167ddd5ca7eb0cd25c277902370fd7f1&amp;r=ffc4fe58bc2179a75d3338aa821eb04649609871&amp;format=unidiff&amp;path=%2Ftools%2Fepydoc%2Fepydoc%2F...
0
2012-11-12T08:51:04Z
[ "python", "design", "configuration-files" ]
Dictonaries and Lambda inside a class?
287,823
<p>How can i do something like this:</p> <pre><code>class Foo(): do_stuff = { "A" : lambda x: self.do_A(x), "B" : lambda x: self.do_B(x) } def __init__(self): print "hi" def run(self): muh = ['A', 'B', 'A'] for each in muh: self.do_stuff[each](each) def do_A(self, moo): print "A" def do_B(self, boo)...
3
2008-11-13T18:44:08Z
287,867
<p>do_stuff is not an instance variable in your example. It's more like a static variable. You need to define do_stuff within a method (e.g., the <strong>init</strong> method) where you have a reference to self in order to make it an instance variable. I hope this example clarifies things for you:</p> <pre><code>class...
7
2008-11-13T18:56:32Z
[ "python", "lambda" ]
In Python, how can I efficiently manage references between script files?
287,845
<p>I have a fair number of Python scripts that contain reusable code that are used and referenced by other Python scripts. However, these scripts tend to be scattered across different directories and I find it to be somewhat tedious to have to include (most often multiple) calls to sys.path.append on my top-level scrip...
6
2008-11-13T18:49:03Z
287,884
<p>If your reusable files are packaged (that is, they include an <code>__init__.py</code> file) and the path to that package is part of your PYTHONPATH or sys.path then you should be able to do just</p> <pre><code>import Foo </code></pre> <p><a href="http://stackoverflow.com/questions/279237/python-import-a-module-fr...
3
2008-11-13T19:02:27Z
[ "python", "scripting", "metadata" ]
In Python, how can I efficiently manage references between script files?
287,845
<p>I have a fair number of Python scripts that contain reusable code that are used and referenced by other Python scripts. However, these scripts tend to be scattered across different directories and I find it to be somewhat tedious to have to include (most often multiple) calls to sys.path.append on my top-level scrip...
6
2008-11-13T18:49:03Z
287,886
<p>The simple answer is to put your reusable code in your site-packages directory, which is in your sys.path.</p> <p>You can also extend the search path by adding .pth files somewhere in your path. See <a href="https://docs.python.org/2/install/#modifying-python-s-search-path" rel="nofollow">https://docs.python.org/2/...
4
2008-11-13T19:02:41Z
[ "python", "scripting", "metadata" ]
In Python, how can I efficiently manage references between script files?
287,845
<p>I have a fair number of Python scripts that contain reusable code that are used and referenced by other Python scripts. However, these scripts tend to be scattered across different directories and I find it to be somewhat tedious to have to include (most often multiple) calls to sys.path.append on my top-level scrip...
6
2008-11-13T18:49:03Z
288,123
<p>You can put the reusable stuff in <code>site-packages</code>. That's completely transparent, since it's in <code>sys.path</code> by default.</p> <p>You can put <code>someName.pth</code> files in <code>site-packages</code>. These files have the directory in which your actual reusable stuff lives. This is also com...
1
2008-11-13T20:15:37Z
[ "python", "scripting", "metadata" ]
In Python, how can I efficiently manage references between script files?
287,845
<p>I have a fair number of Python scripts that contain reusable code that are used and referenced by other Python scripts. However, these scripts tend to be scattered across different directories and I find it to be somewhat tedious to have to include (most often multiple) calls to sys.path.append on my top-level scrip...
6
2008-11-13T18:49:03Z
288,174
<p>In one project, I wanted to make sure that the user could put python scripts (that could basically be used as plugins) anywhere. My solution was to put the following in the config file for that project:</p> <pre><code>[server] PYPATH_APPEND: /home/jason:/usr/share/some_directory </code></pre> <p>That way, this wo...
1
2008-11-13T20:27:56Z
[ "python", "scripting", "metadata" ]