title
stringlengths
10
172
question_id
int64
469
40.1M
question_body
stringlengths
22
48.2k
question_score
int64
-44
5.52k
question_date
stringlengths
20
20
answer_id
int64
497
40.1M
answer_body
stringlengths
18
33.9k
answer_score
int64
-38
8.38k
answer_date
stringlengths
20
20
tags
listlengths
1
5
Finding the command for a specific PID in Linux from Python
1,440,941
<p>I'd like to know if it's possible to find out the "command" that a PID is set to. When I say command, I mean what you see in the last column when you run the command "top" in a linux shell. I'd like to get this information from Python somehow when I have a specific PID.</p> <p>Any help would be great. Thanks.</p>
5
2009-09-17T19:44:09Z
11,960,592
<p>An interesting Python package is <a href="http://code.google.com/p/psutil" rel="nofollow">psutil</a>.</p> <p>For example, to get the command for a specific PID:</p> <pre><code>import psutil pid = 1234 # The pid whose info you're looking for p = psutil.Process(pid) print p.cmdline </code></pre> <p>The last line wi...
3
2012-08-14T20:55:30Z
[ "python", "linux", "process" ]
Finding the command for a specific PID in Linux from Python
1,440,941
<p>I'd like to know if it's possible to find out the "command" that a PID is set to. When I say command, I mean what you see in the last column when you run the command "top" in a linux shell. I'd like to get this information from Python somehow when I have a specific PID.</p> <p>Any help would be great. Thanks.</p>
5
2009-09-17T19:44:09Z
31,840,230
<p>This worked for me:</p> <pre><code>def filter_non_printable(str): ret="" for c in str: if ord(c) &gt; 31 or ord(c) == 9: ret += c else: ret += " " return ret # # Get /proc/&lt;cpu&gt;/cmdline information # def pid_name(pid): try: with open(os.path.jo...
0
2015-08-05T18:34:16Z
[ "python", "linux", "process" ]
Python Inspect - Lookup the data type for a property in a GAE db.model Class
1,440,958
<pre><code>class Employee(db.Model): firstname = db.StringProperty() lastname = db.StringProperty() address1 = db.StringProperty() timezone = db.FloatProperty() #might be -3.5 (can contain fractions) class TestClassAttributes(webapp.RequestHandler)...
1
2009-09-17T19:48:21Z
1,441,354
<p>Iterate using "for name, property in Employee.properties().items()". The property argument is the Property instance, which you can compare using instanceof.</p>
2
2009-09-17T21:05:35Z
[ "python", "google-app-engine", "reflection", "inspection" ]
Python Inspect - Lookup the data type for a property in a GAE db.model Class
1,440,958
<pre><code>class Employee(db.Model): firstname = db.StringProperty() lastname = db.StringProperty() address1 = db.StringProperty() timezone = db.FloatProperty() #might be -3.5 (can contain fractions) class TestClassAttributes(webapp.RequestHandler)...
1
2009-09-17T19:48:21Z
1,441,598
<p>For problems like these, the interactive Python shell is really handy. If you had used it to poke around at your Employee object, you might have discovered the answer to your question through trial and error.</p> <p>Something like:</p> <pre><code>&gt;&gt;&gt; from groups.models import Group &gt;&gt;&gt; Group.pro...
1
2009-09-17T22:14:48Z
[ "python", "google-app-engine", "reflection", "inspection" ]
Python Inspect - Lookup the data type for a property in a GAE db.model Class
1,440,958
<pre><code>class Employee(db.Model): firstname = db.StringProperty() lastname = db.StringProperty() address1 = db.StringProperty() timezone = db.FloatProperty() #might be -3.5 (can contain fractions) class TestClassAttributes(webapp.RequestHandler)...
1
2009-09-17T19:48:21Z
4,241,950
<p>I add the same problem, and the first 2 answers did not help me 100%. I was not able to get the type information, from the meta data of the class or the instance property, which is bizarre. So I had to use a dictionary.</p> <p>The method GetType() will return the type of the property as a string.</p> <p>Here is my...
0
2010-11-22T03:10:54Z
[ "python", "google-app-engine", "reflection", "inspection" ]
Why do I get error, KeyError: 'wsgi.input'?
1,441,038
<p>I'm using WSGI and trying to access the get/post data, using this code:</p> <pre><code>import os import cgi from traceback import format_exception from sys import exc_info def application(environ, start_response): try: f = cgi.FieldStorage(fp=os.environ['wsgi.input'], environ=os.environ) outpu...
1
2009-09-17T20:02:45Z
1,441,080
<p>You're misusing the <a href="http://www.python.org/dev/peps/pep-0333/#specification-details">WSGI API</a>. </p> <p>Please create a minimal ("hello world") function that shows this error so we can comment on your code. [Don't post your entire application, it may be too big and unwieldy for us to comment on.]</p> ...
6
2009-09-17T20:11:33Z
[ "python", "mod-wsgi" ]
Hiding Vertical Scrollbar in wx.TextCtrl
1,441,502
<p>I have a wx.TextCtrl that I am using to represent a display with a fixed number of character rows and columns. I would like to hide the vertical scrollbar that is displayed to the right of the text pane since it is entirely unnecessary in my application. Is there a way to achieve this?</p> <p>Also...I would like to...
4
2009-09-17T21:47:20Z
1,442,312
<p>How about setting the style <code>wx.TE_NO_VSCROLL</code> for the wx.TxtCtrl?</p>
4
2009-09-18T02:25:54Z
[ "python", "wxpython", "wxtextctrl" ]
Plotting color map with zip codes in R or Python
1,441,717
<p>I have some US demographic and firmographic data.<br /> I would like to plot zipcode areas in a state or a smaller region (e.g. city). Each area would be annotated by color and/or text specific to that area. The output would be similar to <a href="http://maps.huge.info/">http://maps.huge.info/</a> but a) with annota...
25
2009-09-17T22:50:42Z
1,441,788
<p>Depending on your application, a long way around might be to use something like this:</p> <p><a href="http://googlemapsmania.blogspot.com/2006/07/new-google-maps-us-zip-code-mashups.html" rel="nofollow">http://googlemapsmania.blogspot.com/2006/07/new-google-maps-us-zip-code-mashups.html</a></p> <p>To map your data...
0
2009-09-17T23:11:05Z
[ "python", "graphics", "zipcode" ]
Plotting color map with zip codes in R or Python
1,441,717
<p>I have some US demographic and firmographic data.<br /> I would like to plot zipcode areas in a state or a smaller region (e.g. city). Each area would be annotated by color and/or text specific to that area. The output would be similar to <a href="http://maps.huge.info/">http://maps.huge.info/</a> but a) with annota...
25
2009-09-17T22:50:42Z
1,441,822
<p>Check out this excellent online visualization tool by IBM <a href="http://manyeyes.alphaworks.ibm.com/manyeyes/" rel="nofollow">http://manyeyes.alphaworks.ibm.com/manyeyes/</a></p> <p><strong>EDIT</strong> FYI, ManyEyes uses the <a href="http://prefuse.org/gallery/" rel="nofollow">Prefuse visualization toolkit</a> ...
0
2009-09-17T23:19:55Z
[ "python", "graphics", "zipcode" ]
Plotting color map with zip codes in R or Python
1,441,717
<p>I have some US demographic and firmographic data.<br /> I would like to plot zipcode areas in a state or a smaller region (e.g. city). Each area would be annotated by color and/or text specific to that area. The output would be similar to <a href="http://maps.huge.info/">http://maps.huge.info/</a> but a) with annota...
25
2009-09-17T22:50:42Z
1,441,833
<p>Someone may have something more direct for you, but I found O'Reilly's 'Data Mashups in R' very interesting... in part, it's a spatial mapping of home foreclosure auctions.</p> <p><a href="http://oreilly.com/catalog/9780596804770/" rel="nofollow">http://oreilly.com/catalog/9780596804770/</a></p>
3
2009-09-17T23:21:25Z
[ "python", "graphics", "zipcode" ]
Plotting color map with zip codes in R or Python
1,441,717
<p>I have some US demographic and firmographic data.<br /> I would like to plot zipcode areas in a state or a smaller region (e.g. city). Each area would be annotated by color and/or text specific to that area. The output would be similar to <a href="http://maps.huge.info/">http://maps.huge.info/</a> but a) with annota...
25
2009-09-17T22:50:42Z
1,442,241
<p>There is a rich and sophisticated series of packages in R to plot, do analysis, and other functions related to GIS. One place to get started is the CRAN task view on <a href="http://cran.r-project.org/web/views/Spatial.html" rel="nofollow">Spatial Data</a>: This is a complex and sometimes arcane world, and takes so...
1
2009-09-18T01:48:30Z
[ "python", "graphics", "zipcode" ]
Plotting color map with zip codes in R or Python
1,441,717
<p>I have some US demographic and firmographic data.<br /> I would like to plot zipcode areas in a state or a smaller region (e.g. city). Each area would be annotated by color and/or text specific to that area. The output would be similar to <a href="http://maps.huge.info/">http://maps.huge.info/</a> but a) with annota...
25
2009-09-17T22:50:42Z
1,442,252
<p><a href="http://trends.techcrunch.com/" rel="nofollow">Daniel Levine at TechCrunch Trends</a> has done nice things with the <code>maps</code> package in R. He has code available on his site, too.</p> <p>Paul's suggestion of looking into Processing - which Ben Fry used to make zipdecode - is also a good one, if you...
1
2009-09-18T01:50:41Z
[ "python", "graphics", "zipcode" ]
Plotting color map with zip codes in R or Python
1,441,717
<p>I have some US demographic and firmographic data.<br /> I would like to plot zipcode areas in a state or a smaller region (e.g. city). Each area would be annotated by color and/or text specific to that area. The output would be similar to <a href="http://maps.huge.info/">http://maps.huge.info/</a> but a) with annota...
25
2009-09-17T22:50:42Z
1,442,254
<p>There are many ways to do this in R (see the <a href="http://cran.r-project.org/web/views/Spatial.html">spatial view</a>); many of these <a href="http://cran.r-project.org/web/packages/maps/index.html">depend on the "maps" package</a>.</p> <ul> <li><p>Check out this <a href="http://www.ai.rug.nl/~hedderik/R/US2004/...
9
2009-09-18T01:51:40Z
[ "python", "graphics", "zipcode" ]
Plotting color map with zip codes in R or Python
1,441,717
<p>I have some US demographic and firmographic data.<br /> I would like to plot zipcode areas in a state or a smaller region (e.g. city). Each area would be annotated by color and/or text specific to that area. The output would be similar to <a href="http://maps.huge.info/">http://maps.huge.info/</a> but a) with annota...
25
2009-09-17T22:50:42Z
1,446,144
<p>I am assuming you want static maps. </p> <p><img src="http://files.eduardoleoni.com/mapUS.png" alt="alt text" /></p> <p>1) Get the shapefiles of the <a href="http://www.census.gov/geo/www/cob/zt%5Fmetadata.html">zip</a> boundaries and <a href="http://www.census.gov/geo/www/cob/st2000.html">state</a> boundaries at ...
33
2009-09-18T18:21:07Z
[ "python", "graphics", "zipcode" ]
Plotting color map with zip codes in R or Python
1,441,717
<p>I have some US demographic and firmographic data.<br /> I would like to plot zipcode areas in a state or a smaller region (e.g. city). Each area would be annotated by color and/or text specific to that area. The output would be similar to <a href="http://maps.huge.info/">http://maps.huge.info/</a> but a) with annota...
25
2009-09-17T22:50:42Z
1,871,605
<p>In Python, you can use shapefiles from the US census along with the <code>basemap</code> package. Here is an example of <a href="http://matplotlib.svn.sourceforge.net/viewvc/matplotlib/trunk/toolkits/basemap/examples/fillstates.py?view=markup" rel="nofollow">filling in states</a> according to population.</p>
1
2009-12-09T04:38:07Z
[ "python", "graphics", "zipcode" ]
How can I omit words in the middle of a regular expression in Python?
1,441,866
<p>I have a multi-line string like this:</p> <pre><code>"...Togo...Togo...Togo...ACTIVE..." </code></pre> <p>I want to get everything between the third 'Togo' and 'ACTIVE' and the remainder of the string. I am unable to create a regular expression that can do this. If I try something like </p> <pre><code>reg = "(Tog...
0
2009-09-17T23:32:35Z
1,441,879
<pre><code>reg = "Togo.*Togo.*Togo(.*)ACTIVE" </code></pre> <p>Alternatively, if you want to match the string between the last occurrence of Togo and the following occurence of ACTIVE, and the number of Togo occurences is not necessarily three, try this:</p> <pre><code>reg = "Togo(([^T]|T[^o]|To[^g]|Tog[^o])*T?.?.?)A...
1
2009-09-17T23:36:18Z
[ "python", "string" ]
How can I omit words in the middle of a regular expression in Python?
1,441,866
<p>I have a multi-line string like this:</p> <pre><code>"...Togo...Togo...Togo...ACTIVE..." </code></pre> <p>I want to get everything between the third 'Togo' and 'ACTIVE' and the remainder of the string. I am unable to create a regular expression that can do this. If I try something like </p> <pre><code>reg = "(Tog...
0
2009-09-17T23:32:35Z
1,441,929
<p>This matches just the desired parts:</p> <pre><code>.*(Togo.*?)(ACTIVE.*) </code></pre> <p>The leading <code>.*</code> is greedy, so the following <code>Togo</code> matches at the last possible place. The captured part starts at the last <code>Togo</code>.</p> <p>In your expression <code>^[Togo]*?</code> doesn't ...
1
2009-09-17T23:50:37Z
[ "python", "string" ]
How can I omit words in the middle of a regular expression in Python?
1,441,866
<p>I have a multi-line string like this:</p> <pre><code>"...Togo...Togo...Togo...ACTIVE..." </code></pre> <p>I want to get everything between the third 'Togo' and 'ACTIVE' and the remainder of the string. I am unable to create a regular expression that can do this. If I try something like </p> <pre><code>reg = "(Tog...
0
2009-09-17T23:32:35Z
1,449,813
<pre><code>"(Togo(?:(?!Togo).)*)(ACTIVE.*)" </code></pre> <p>The square brackets in your regex form a character class that matches one of the characters 'T', 'o', or 'g'. The caret ('^') matches the beginning of the input if it's not in a character class, and it can be used inside the square brackets to invert the ch...
1
2009-09-19T23:43:08Z
[ "python", "string" ]
Is it possible to have a python app authentication with a remote linux server?
1,441,875
<p>The idea here is to have a python app, that when started, asks for a user/password combination. This user/password combination should be the same as the user/password of the remote linux server or in such case, and authentication system.</p> <p>Is this possible? How? Which APIs can I use?</p> <p>Thanks a lot.</p>
0
2009-09-17T23:34:58Z
1,441,889
<p>I would recommend looking into <a href="http://en.wikipedia.org/wiki/Lightweight%5FDirectory%5FAccess%5FProtocol" rel="nofollow">LDAP</a> and <a href="http://www.linuxjournal.com/article/6988" rel="nofollow">python-ldap</a></p>
0
2009-09-17T23:39:39Z
[ "python", "authentication", "login" ]
Python imaging alternatives
1,441,967
<p>I have python code that needs to do just a couple simple things to photographs: crop, resize, and overlay a watermark. I've used PIL, and the resample/resize results are TERRIBLE. I've used imagemagick, and the interface and commands were designed by packaging a cat in a box, and then repeatedly throwing it down a s...
10
2009-09-18T00:05:57Z
1,442,011
<p>PIL can do good resizing. Make sure your source image is in RGB mode, not palette colors, and try the different algorithm choices.</p>
1
2009-09-18T00:17:46Z
[ "python", "command-line", "libraries", "imaging" ]
Python imaging alternatives
1,441,967
<p>I have python code that needs to do just a couple simple things to photographs: crop, resize, and overlay a watermark. I've used PIL, and the resample/resize results are TERRIBLE. I've used imagemagick, and the interface and commands were designed by packaging a cat in a box, and then repeatedly throwing it down a s...
10
2009-09-18T00:05:57Z
1,442,034
<p>While imagemagick seems to be the de facto open-source imaging library, possibly <a href="http://openil.sourceforge.net/features.php" rel="nofollow">DevIL</a> (cross platform, seems to do simple image operations) or <a href="http://freeimage.sourceforge.net/features.html" rel="nofollow">FreeImage</a>.</p>
1
2009-09-18T00:25:12Z
[ "python", "command-line", "libraries", "imaging" ]
Python imaging alternatives
1,441,967
<p>I have python code that needs to do just a couple simple things to photographs: crop, resize, and overlay a watermark. I've used PIL, and the resample/resize results are TERRIBLE. I've used imagemagick, and the interface and commands were designed by packaging a cat in a box, and then repeatedly throwing it down a s...
10
2009-09-18T00:05:57Z
1,442,062
<blockquote> <p>I've used PIL, and the resample/resize results are TERRIBLE.</p> </blockquote> <p>They shouldn't be, as long as you:</p> <ol> <li>use only Image.ANTIALIAS filtering for downscaling operations</li> <li>use only Image.BICUBIC filtering for upscaling operations.</li> <li>remember to convert to 'RGB' co...
16
2009-09-18T00:37:44Z
[ "python", "command-line", "libraries", "imaging" ]
Python imaging alternatives
1,441,967
<p>I have python code that needs to do just a couple simple things to photographs: crop, resize, and overlay a watermark. I've used PIL, and the resample/resize results are TERRIBLE. I've used imagemagick, and the interface and commands were designed by packaging a cat in a box, and then repeatedly throwing it down a s...
10
2009-09-18T00:05:57Z
1,442,110
<p>Have you checked <a href="http://pypi.python.org/pypi/" rel="nofollow">pypi</a>? A cursory search shows some image related tools there, I also discovered python-gd, no clue how useful it might be though.</p> <p>I've never had any issues with PIL myself, but some kind of variety might be interesting.</p>
1
2009-09-18T00:53:31Z
[ "python", "command-line", "libraries", "imaging" ]
Python imaging alternatives
1,441,967
<p>I have python code that needs to do just a couple simple things to photographs: crop, resize, and overlay a watermark. I've used PIL, and the resample/resize results are TERRIBLE. I've used imagemagick, and the interface and commands were designed by packaging a cat in a box, and then repeatedly throwing it down a s...
10
2009-09-18T00:05:57Z
1,442,286
<p>GIMP has a reasonable command-line interface, I think.</p>
1
2009-09-18T02:10:00Z
[ "python", "command-line", "libraries", "imaging" ]
Python imaging alternatives
1,441,967
<p>I have python code that needs to do just a couple simple things to photographs: crop, resize, and overlay a watermark. I've used PIL, and the resample/resize results are TERRIBLE. I've used imagemagick, and the interface and commands were designed by packaging a cat in a box, and then repeatedly throwing it down a s...
10
2009-09-18T00:05:57Z
1,545,544
<p>Take a look at some of these imaging libraries:</p> <p>hxxp://pypi.python.org/pypi/collective.croppingimagefield/0.1beta</p> <p>hxxp://pypi.python.org/pypi/cropresize/0.1.1</p> <p>hxxp://pypi.python.org/pypi/image_resize/1.0</p>
1
2009-10-09T19:03:58Z
[ "python", "command-line", "libraries", "imaging" ]
Python imaging alternatives
1,441,967
<p>I have python code that needs to do just a couple simple things to photographs: crop, resize, and overlay a watermark. I've used PIL, and the resample/resize results are TERRIBLE. I've used imagemagick, and the interface and commands were designed by packaging a cat in a box, and then repeatedly throwing it down a s...
10
2009-09-18T00:05:57Z
2,986,465
<p>Last time I compared, this downscaler's output is almost identical to that of GIMP's "cubic" option:</p> <pre><code> import Image def stretch(im, size, filter=Image.NEAREST): im.load() im = im._new(im.im.stretch(size, filter)) return im </code></pre> <p>IIRC, the differences are visually indisting...
0
2010-06-07T00:13:36Z
[ "python", "command-line", "libraries", "imaging" ]
Python imaging alternatives
1,441,967
<p>I have python code that needs to do just a couple simple things to photographs: crop, resize, and overlay a watermark. I've used PIL, and the resample/resize results are TERRIBLE. I've used imagemagick, and the interface and commands were designed by packaging a cat in a box, and then repeatedly throwing it down a s...
10
2009-09-18T00:05:57Z
5,598,396
<p>I'm unsure as to why Image.thumbnail is getting such flak. In the present release that I'm running off of it does little more than figure out the desired size and resize the image in place. As long as you're using the proper resample filter and convert to RGB first (as bobince says) thumbnail shouldn't be any diff...
2
2011-04-08T17:01:52Z
[ "python", "command-line", "libraries", "imaging" ]
Python imaging alternatives
1,441,967
<p>I have python code that needs to do just a couple simple things to photographs: crop, resize, and overlay a watermark. I've used PIL, and the resample/resize results are TERRIBLE. I've used imagemagick, and the interface and commands were designed by packaging a cat in a box, and then repeatedly throwing it down a s...
10
2009-09-18T00:05:57Z
39,942,859
<blockquote> <p>I've used PIL, and the resample/resize results are TERRIBLE.</p> </blockquote> <p>Resizing in PIL was broken in many ways and PIL is not maintained for a long time. Starting from <a href="https://pillow.readthedocs.io/en/3.4.x/releasenotes/2.7.0.html" rel="nofollow">Pillow 2.7</a> most of the problem...
0
2016-10-09T11:03:48Z
[ "python", "command-line", "libraries", "imaging" ]
Whats the error in this python code?
1,441,979
<p>What do i do to solve it? Terminal output is: </p> <p><code><pre> abhi@abhi-desktop:~/Desktop/sslstrip-0.1$ python sslstrip.py --listen=3130 Traceback (most recent call last): File "sslstrip.py", line 254, in main(sys.argv[1:]) File "sslstrip.py", line 246, in main server = ThreadingHTTPServer(('', lis...
0
2009-09-18T00:08:57Z
1,442,002
<p>Does it fail when you don't specify a port?</p> <p>My guess is that listenPort is coming out of the option parsing as a string and needs to be cast to an in sslstrip.py on line 77.</p>
2
2009-09-18T00:15:19Z
[ "python", "session-hijacking" ]
Whats the error in this python code?
1,441,979
<p>What do i do to solve it? Terminal output is: </p> <p><code><pre> abhi@abhi-desktop:~/Desktop/sslstrip-0.1$ python sslstrip.py --listen=3130 Traceback (most recent call last): File "sslstrip.py", line 254, in main(sys.argv[1:]) File "sslstrip.py", line 246, in main server = ThreadingHTTPServer(('', lis...
0
2009-09-18T00:08:57Z
1,442,144
<p>The provided link is to sslstrip-0.5. You are using sslstrip-0.1. These are <em>very</em> different (sslstrip-0.5 uses twisted). This bug was fixed in sslstrip-0.2. If you don't have twisted or don't want to install twisted, I suggest that you get <a href="http://www.thoughtcrime.org/software/sslstrip/sslstrip-0.4.t...
2
2009-09-18T01:06:45Z
[ "python", "session-hijacking" ]
Subdomains and Logins
1,442,017
<p>If you multiple subdomains e.g.:</p> <blockquote> <p>sub1.domain_name.com</p> <p>sub2.domain_name.com</p> </blockquote> <p>Is there a way to have a user be able to log into both of these without issues and double login issue?</p> <p>The platform is Python, Django.</p>
4
2009-09-18T00:19:48Z
1,442,029
<p>Without information regarding what platform you are using, it is difficult to say. If you use cookies to store authentication information, and you are using subdomains as you describe, then you can force the cookie to be issued for the highest level domain, e.g. domain_name.com.</p> <p>This will be accessable by bo...
10
2009-09-18T00:23:13Z
[ "python", "django", "login", "subdomain", "login-control" ]
Subdomains and Logins
1,442,017
<p>If you multiple subdomains e.g.:</p> <blockquote> <p>sub1.domain_name.com</p> <p>sub2.domain_name.com</p> </blockquote> <p>Is there a way to have a user be able to log into both of these without issues and double login issue?</p> <p>The platform is Python, Django.</p>
4
2009-09-18T00:19:48Z
1,442,058
<p>Yes. Just set the cookie on the domain ".domain_name.com" and the cookie will be available to sub1.domain_name.com, and sub2.domain_name.com.</p> <p>As long as you maintain your session information on both domains, you should be fine.</p> <p>This is a very common practice, and is why you can log into your Google A...
6
2009-09-18T00:35:26Z
[ "python", "django", "login", "subdomain", "login-control" ]
Python execute program change path
1,442,024
<p>I'm trying to make a python script run another program from its own path. I've got the execution of the other program working using os.system, but the program will crash because it cannot find its reasources (wrong path, I assume). I tried adding the folder harboring the executable to the path, but that didn't help....
1
2009-09-18T00:22:14Z
1,442,077
<p>You can change the current directory of your script with <code>os.chdir</code>(). You can also set environment variables with <code>os.environ</code></p>
3
2009-09-18T00:41:55Z
[ "python", "path", "executable" ]
Python execute program change path
1,442,024
<p>I'm trying to make a python script run another program from its own path. I've got the execution of the other program working using os.system, but the program will crash because it cannot find its reasources (wrong path, I assume). I tried adding the folder harboring the executable to the path, but that didn't help....
1
2009-09-18T00:22:14Z
1,442,309
<p>Use the <a href="http://docs.python.org/library/subprocess.html" rel="nofollow">subprocess module</a>, and use the <code>cwd</code> argument to set the child's working directory.</p>
1
2009-09-18T02:24:35Z
[ "python", "path", "executable" ]
transforming Jython's source / ast
1,442,084
<p>I've got a problem to solve in Jython. The function I've got looks like this:</p> <pre><code>ok = whatever1(x, ...) self.assertTrue("whatever1 failed: "+x...(), ok) ok = whatever2(x, ...) self.assertTrue("whatever2 failed: "+x...(), ok) [ many many lines ] ... </code></pre> <p>There are many tests that look like...
1
2009-09-18T00:44:53Z
1,442,141
<p>Are you sure you need an AST? If the only lines of interest are the ones starting with "ok = ", then maybe simple string work on the source files would be enough?</p>
2
2009-09-18T01:04:26Z
[ "python", "jython", "abstract-syntax-tree" ]
Python Web-Scrape Loop via CSV list of URLs?
1,442,097
<p>HI, I've got a list of 10 websites in CSV. All of the sites have the same general format, including a large table. I only want the the data in the 7th columns. I am able to extract the html and filter the 7th column data (via RegEx) on an individual basis but I can't figure out how to loop through the CSV. I think I...
1
2009-09-18T00:48:00Z
1,442,151
<p>When I copied your routine, I did get a white space / tab error error. Check your tabs. You were indexing into the URL string incorrectly using your loop counter. This would have also messed you up.</p> <p>Also, you don't really need to control the loop with a counter. This will loop for each line entry in your CSV...
2
2009-09-18T01:09:04Z
[ "python", "list", "csv", "loops" ]
Multiple Windows in PyQt4
1,442,128
<p>I have a PyQt program used to visualize some python objects. I would like to do display multiple objects, each in its own window. </p> <p>What is the best way to achieve multi-window applications in PyQt4?</p> <p>Currently I have the following:</p> <pre><code>from PyQt4 import QtGui class MainWindow(QtGui.QMainW...
2
2009-09-18T00:57:14Z
1,442,522
<p>In order to reference the subclass that is inheriting the super-class from inside the super-class, I am using <code>self.__class__()</code>, so the MultiWindows class now reads:</p> <pre><code>class MultiWindows(QtGui.QMainWindow): windowList = [] def __init__(self, param): raise NotImplementedError() def add...
0
2009-09-18T03:57:36Z
[ "python", "inheritance", "pyqt4" ]
Multiple Windows in PyQt4
1,442,128
<p>I have a PyQt program used to visualize some python objects. I would like to do display multiple objects, each in its own window. </p> <p>What is the best way to achieve multi-window applications in PyQt4?</p> <p>Currently I have the following:</p> <pre><code>from PyQt4 import QtGui class MainWindow(QtGui.QMainW...
2
2009-09-18T00:57:14Z
1,443,181
<p>Why not using dialogs? In Qt you do not need to use the main window unless you want to use docks etc.. Using dialogs will have the same effect. </p> <p>I can also see a problem in your logic regarding the fact that you want your super class to be calling the constructor of its children, which of course can be any t...
5
2009-09-18T08:15:15Z
[ "python", "inheritance", "pyqt4" ]
Accessing a Python variable in a list
1,442,250
<p>I think this is probably something really simple, but I'd appreciate a hint:</p> <p>I am using a python list to hold some some database insert statements:</p> <pre><code>list = [ "table_to_insert_to" ],["column1","column2"],[getValue.value1],["value2"]] </code></pre> <p>The problem is one of the values isn't eval...
0
2009-09-18T01:50:35Z
1,442,333
<p>Just wrap it in a function and call the function when you have the data to initialize it.</p> <pre><code># module.py def setstatement(value1): global sql sql = ['select', 'column1', 'column2', value1] # some other file import module module.setstatement(1) # now you can use it. &gt;&gt;&gt; module.sql ['s...
2
2009-09-18T02:38:08Z
[ "python", "list", "variables" ]
Accessing a Python variable in a list
1,442,250
<p>I think this is probably something really simple, but I'd appreciate a hint:</p> <p>I am using a python list to hold some some database insert statements:</p> <pre><code>list = [ "table_to_insert_to" ],["column1","column2"],[getValue.value1],["value2"]] </code></pre> <p>The problem is one of the values isn't eval...
0
2009-09-18T01:50:35Z
1,442,524
<p>You've just pointed out one (out of a zillion) problems with global variables: not using global variables is the best solution to this problem and many others. If you still mistakenly believe you must use a global variable, put a placeholder (e.g. <code>None</code>) in the place where the value you don't yet know wi...
3
2009-09-18T03:58:19Z
[ "python", "list", "variables" ]
Accessing a Python variable in a list
1,442,250
<p>I think this is probably something really simple, but I'd appreciate a hint:</p> <p>I am using a python list to hold some some database insert statements:</p> <pre><code>list = [ "table_to_insert_to" ],["column1","column2"],[getValue.value1],["value2"]] </code></pre> <p>The problem is one of the values isn't eval...
0
2009-09-18T01:50:35Z
1,442,553
<p>May be put functions instead of value, these functions should be called at run time and will give correct results e.g.</p> <pre><code>def getValue1Func(): return getValue.value1 my_list = [ "table_to_insert_to" ],["column1","column2"],[getValue1Func],["value2"]] </code></pre> <p>now I do not know how you use ...
1
2009-09-18T04:09:57Z
[ "python", "list", "variables" ]
Full-featured date and time library
1,442,264
<p>I'm wondering if anyone knows of a good date and time library that has correctly-implemented features like the following:</p> <ul> <li><strong>Microsecond resolution</strong></li> <li><strong>Daylight savings</strong> <ul> <li><em>Example:</em> it knows that 2:30am did not exist in the US on 8 March 2009 for timez...
7
2009-09-18T02:00:01Z
1,442,299
<p>Take a look at the <a href="http://labix.org/python-dateutil">dateutil</a> and possibly <a href="http://www.egenix.com/products/python/mxBase/mxDateTime/">mx.DateTime</a> packages.</p>
6
2009-09-18T02:19:34Z
[ "python", "c", "datetime" ]
Full-featured date and time library
1,442,264
<p>I'm wondering if anyone knows of a good date and time library that has correctly-implemented features like the following:</p> <ul> <li><strong>Microsecond resolution</strong></li> <li><strong>Daylight savings</strong> <ul> <li><em>Example:</em> it knows that 2:30am did not exist in the US on 8 March 2009 for timez...
7
2009-09-18T02:00:01Z
1,442,519
<p>Python's standard library's <code>datetime</code> module is deliberately limited to non-controversial aspects that aren't changing all the time by legislative fiat -- that's why it deliberately excludes direct support for timezones, DST, fuzzy parsing and ill-defined arithmetic (such as "one month later"...) and the...
11
2009-09-18T03:55:47Z
[ "python", "c", "datetime" ]
Full-featured date and time library
1,442,264
<p>I'm wondering if anyone knows of a good date and time library that has correctly-implemented features like the following:</p> <ul> <li><strong>Microsecond resolution</strong></li> <li><strong>Daylight savings</strong> <ul> <li><em>Example:</em> it knows that 2:30am did not exist in the US on 8 March 2009 for timez...
7
2009-09-18T02:00:01Z
1,442,541
<blockquote> <p>I should be able to specify a timezone like "US/Eastern" and it should be smart enough to know whether a given timestamp should correspond to EST or EDT.</p> </blockquote> <p>This part isn't always possible - in the same way that 2:30am doesn't exist for one day of the year (in timezones with...
4
2009-09-18T04:04:44Z
[ "python", "c", "datetime" ]
Full-featured date and time library
1,442,264
<p>I'm wondering if anyone knows of a good date and time library that has correctly-implemented features like the following:</p> <ul> <li><strong>Microsecond resolution</strong></li> <li><strong>Daylight savings</strong> <ul> <li><em>Example:</em> it knows that 2:30am did not exist in the US on 8 March 2009 for timez...
7
2009-09-18T02:00:01Z
1,443,308
<p>Although the book is over ten years old, I would strongly recommend reading <a href="http://rads.stackoverflow.com/amzn/click/0879304960" rel="nofollow"><strong>Standard C Date/Time Library: Programming the World's Calendars and Clocks</strong></a> by Lance Latham. This is one of those books that you will pick back ...
2
2009-09-18T08:50:36Z
[ "python", "c", "datetime" ]
Full-featured date and time library
1,442,264
<p>I'm wondering if anyone knows of a good date and time library that has correctly-implemented features like the following:</p> <ul> <li><strong>Microsecond resolution</strong></li> <li><strong>Daylight savings</strong> <ul> <li><em>Example:</em> it knows that 2:30am did not exist in the US on 8 March 2009 for timez...
7
2009-09-18T02:00:01Z
16,908,406
<p>Saw this the other day, I havn't used it myself... looks promising. <a href="http://crsmithdev.com/arrow/">http://crsmithdev.com/arrow/</a> </p>
6
2013-06-04T01:25:41Z
[ "python", "c", "datetime" ]
Full-featured date and time library
1,442,264
<p>I'm wondering if anyone knows of a good date and time library that has correctly-implemented features like the following:</p> <ul> <li><strong>Microsecond resolution</strong></li> <li><strong>Daylight savings</strong> <ul> <li><em>Example:</em> it knows that 2:30am did not exist in the US on 8 March 2009 for timez...
7
2009-09-18T02:00:01Z
21,643,548
<p>I just released a Python library called Fleming (<a href="https://github.com/ambitioninc/fleming" rel="nofollow">https://github.com/ambitioninc/fleming</a>), and it appears to solve two of your problems with sophistication in regards to Daylight Savings Time.</p> <p>Problem 1, Arithmetic - Fleming has an add_timede...
1
2014-02-08T07:59:16Z
[ "python", "c", "datetime" ]
Python program to split a list into two lists with alternating elements
1,442,782
<p>Can you make it more simple/elegant?</p> <pre><code>def zigzag(seq): """Return two sequences with alternating elements from `seq`""" x, y = [], [] p, q = x, y for e in seq: p.append(e) p, q = q, p return x, y </code></pre>
11
2009-09-18T05:53:08Z
1,442,788
<pre><code>def zigzag(seq): return seq[::2], seq[1::2] </code></pre>
7
2009-09-18T05:55:46Z
[ "python", "algorithm", "list" ]
Python program to split a list into two lists with alternating elements
1,442,782
<p>Can you make it more simple/elegant?</p> <pre><code>def zigzag(seq): """Return two sequences with alternating elements from `seq`""" x, y = [], [] p, q = x, y for e in seq: p.append(e) p, q = q, p return x, y </code></pre>
11
2009-09-18T05:53:08Z
1,442,794
<p>If <code>seq</code>, as you say, is a list, then:</p> <pre><code>def zigzag(seq): return seq[::2], seq[1::2] </code></pre> <p>If <code>seq</code> is a totally generic iterable, such as possibly a generator:</p> <pre><code>def zigzag(seq): results = [], [] for i, e in enumerate(seq): results[i%2].append(...
34
2009-09-18T05:57:45Z
[ "python", "algorithm", "list" ]
Python program to split a list into two lists with alternating elements
1,442,782
<p>Can you make it more simple/elegant?</p> <pre><code>def zigzag(seq): """Return two sequences with alternating elements from `seq`""" x, y = [], [] p, q = x, y for e in seq: p.append(e) p, q = q, p return x, y </code></pre>
11
2009-09-18T05:53:08Z
1,443,595
<p>This takes an iterator and returns two iterators:</p> <pre><code> import itertools def zigzag(seq): t1,t2 = itertools.tee(seq) even = itertools.islice(t1,0,None,2) odd = itertools.islice(t2,1,None,2) return even,odd </code></pre> <p>If you prefer lists then you can <code>return list(even),list...
9
2009-09-18T10:04:10Z
[ "python", "algorithm", "list" ]
Lauch default editor (like 'webbrowser' module)
1,442,841
<p>Is there a simple way to lauch the systems default editor from a Python command-line tool, like the <a href="http://docs.python.org/library/webbrowser.html">webbrowser</a> module?</p>
7
2009-09-18T06:18:43Z
1,442,894
<p>If you need to open a file for editing, you could be interested in <a href="http://stackoverflow.com/questions/434597/open-document-with-default-application-in-python">this question</a>.</p>
2
2009-09-18T06:41:45Z
[ "python", "command-line", "editor" ]
Lauch default editor (like 'webbrowser' module)
1,442,841
<p>Is there a simple way to lauch the systems default editor from a Python command-line tool, like the <a href="http://docs.python.org/library/webbrowser.html">webbrowser</a> module?</p>
7
2009-09-18T06:18:43Z
1,443,128
<p>Under windows you can simply "execute" the file and the default action will be taken: </p> <p><code>os.system('c:/tmp/sample.txt')</code></p> <p>For this example a default editor will spawn. Under UNIX there is an environment variable called <code>EDITOR</code>, so you need to use something like: </p> <p><code>os...
10
2009-09-18T08:01:24Z
[ "python", "command-line", "editor" ]
Lauch default editor (like 'webbrowser' module)
1,442,841
<p>Is there a simple way to lauch the systems default editor from a Python command-line tool, like the <a href="http://docs.python.org/library/webbrowser.html">webbrowser</a> module?</p>
7
2009-09-18T06:18:43Z
1,443,498
<p>The modern Linux way to open a file is using <code>xdg-open</code>; however it does not guarantee that a text editor will open the file. Using <code>$EDITOR</code> is appropriate if your program is command-line oriented (and your users).</p>
3
2009-09-18T09:38:48Z
[ "python", "command-line", "editor" ]
Lauch default editor (like 'webbrowser' module)
1,442,841
<p>Is there a simple way to lauch the systems default editor from a Python command-line tool, like the <a href="http://docs.python.org/library/webbrowser.html">webbrowser</a> module?</p>
7
2009-09-18T06:18:43Z
25,984,833
<p>You can actually use the webbrowser module to do this. All the answers given so far for both this and the linked question are just the same things the webbrowser module does behind the hood. </p> <p>The ONLY difference is if they have <code>$EDITOR</code> set. (which is rare). So perhaps a better flow would be:</p>...
1
2014-09-22T23:57:21Z
[ "python", "command-line", "editor" ]
Radix 64 and encryption
1,442,896
<p>Need to share my problem that is : A PGP public key server gives me the key in Radix64 format . And i searching for any method which can encrypt my message using this Radix64 format public key .</p> <p>any alternate suggestions or documents are welcome .........</p>
0
2009-09-18T06:42:20Z
1,442,907
<p><a href="http://www.freenet.org.nz/ezPyCrypto/" rel="nofollow">exPyCrypto</a> looks good.</p> <p>This <a href="http://stackoverflow.com/questions/1387867/how-to-convert-base64-radix64-public-key-to-a-pem-format-in-python">previous SO question</a> addresses Radix64 format specifically for public keys.</p> <p>To con...
0
2009-09-18T06:47:05Z
[ "python" ]
Radix 64 and encryption
1,442,896
<p>Need to share my problem that is : A PGP public key server gives me the key in Radix64 format . And i searching for any method which can encrypt my message using this Radix64 format public key .</p> <p>any alternate suggestions or documents are welcome .........</p>
0
2009-09-18T06:42:20Z
1,442,911
<p>You can decode the key by using the <a href="http://docs.python.org/library/base64.html" rel="nofollow">base64</a> module and then encrypt the message.</p>
0
2009-09-18T06:48:18Z
[ "python" ]
Completely wrap an object in Python
1,443,129
<p>I am wanting to completely wrap an object so that all attribute and method requests get forwarded to the object it's wrapping, but also overriding any methods or variables that I want, as well as providing some of my own methods. This wrapper class should appear 100% as the existing class (<code>isinstance</code> mu...
15
2009-09-18T08:01:42Z
1,443,165
<p><code>__getattr__</code> is only called for things that Python can't find in <code>__dict__</code>, so you don't have to worry about <code>overriddenMethod</code>, etc.</p> <p>For more details, see section 5 "Proxy" in <a href="http://www.python.org/workshops/1997-10/proceedings/savikko.html" rel="nofollow">this ar...
1
2009-09-18T08:09:55Z
[ "python", "reflection" ]
Completely wrap an object in Python
1,443,129
<p>I am wanting to completely wrap an object so that all attribute and method requests get forwarded to the object it's wrapping, but also overriding any methods or variables that I want, as well as providing some of my own methods. This wrapper class should appear 100% as the existing class (<code>isinstance</code> mu...
15
2009-09-18T08:01:42Z
1,443,170
<p><code>__getattr__</code> has the advantage that it's only called when the attribute does not exist, so you should not need an explicit list -- anything you don't define will automatically get proxied.</p> <p><code>__setattr__</code> is trickier because it's always called. Make sure you use a superclass call or <cod...
3
2009-09-18T08:12:01Z
[ "python", "reflection" ]
Completely wrap an object in Python
1,443,129
<p>I am wanting to completely wrap an object so that all attribute and method requests get forwarded to the object it's wrapping, but also overriding any methods or variables that I want, as well as providing some of my own methods. This wrapper class should appear 100% as the existing class (<code>isinstance</code> mu...
15
2009-09-18T08:01:42Z
1,443,179
<p>By 'existing object' you mean an instance of another class? Sounds to me as though you just need to inherit from the base class. When you create your new object, pass in the details of the base object, or add a method in your new class which copies the data of the base class instance into itself.</p>
0
2009-09-18T08:14:31Z
[ "python", "reflection" ]
Completely wrap an object in Python
1,443,129
<p>I am wanting to completely wrap an object so that all attribute and method requests get forwarded to the object it's wrapping, but also overriding any methods or variables that I want, as well as providing some of my own methods. This wrapper class should appear 100% as the existing class (<code>isinstance</code> mu...
15
2009-09-18T08:01:42Z
1,443,389
<p>Start with this and mess with stuff in the loop to suit your needs:</p> <pre><code>import inspect class Delegate(object): def __init__(self, implementation): self.__class__ = implementation.__class__ for n, m in inspect.getmembers(implementation, callable): if not n.startswith('_'): ...
1
2009-09-18T09:14:12Z
[ "python", "reflection" ]
Completely wrap an object in Python
1,443,129
<p>I am wanting to completely wrap an object so that all attribute and method requests get forwarded to the object it's wrapping, but also overriding any methods or variables that I want, as well as providing some of my own methods. This wrapper class should appear 100% as the existing class (<code>isinstance</code> mu...
15
2009-09-18T08:01:42Z
1,445,289
<p>The simplest way in most cases is probably:</p> <pre><code>class ObjectWrapper(BaseClass): def __init__(self, baseObject): self.__class__ = type(baseObject.__class__.__name__, (self.__class__, baseObject.__class__), {}) self.__dict__ = ...
27
2009-09-18T15:30:42Z
[ "python", "reflection" ]
Completely wrap an object in Python
1,443,129
<p>I am wanting to completely wrap an object so that all attribute and method requests get forwarded to the object it's wrapping, but also overriding any methods or variables that I want, as well as providing some of my own methods. This wrapper class should appear 100% as the existing class (<code>isinstance</code> mu...
15
2009-09-18T08:01:42Z
31,437,314
<p>The following approach is similar to <a href="http://stackoverflow.com/a/1445289/17523">the one by Alex Martelli</a>, but is more readable to me:</p> <p>Instead of creating a new class, I create a class-like function that instantiates the underlying object and overwrites needed functions, as follows:</p> <pre><cod...
1
2015-07-15T17:38:13Z
[ "python", "reflection" ]
Completely wrap an object in Python
1,443,129
<p>I am wanting to completely wrap an object so that all attribute and method requests get forwarded to the object it's wrapping, but also overriding any methods or variables that I want, as well as providing some of my own methods. This wrapper class should appear 100% as the existing class (<code>isinstance</code> mu...
15
2009-09-18T08:01:42Z
32,188,347
<p>Please look at <a href="http://code.activestate.com/recipes/577555-object-wrapper-class/" rel="nofollow">http://code.activestate.com/recipes/577555-object-wrapper-class/</a> for the complete code, including important comments. It boils down to:</p> <pre><code>class Wrapper(object): def __init__(self, obj): ...
1
2015-08-24T17:38:45Z
[ "python", "reflection" ]
How do I protect my Python codebase so that guests can't see certain modules but so it still works?
1,443,146
<p>We're starting a new project in Python with a few proprietary algorithms and sensitive bits of logic that we'd like to keep private. We also will have a few outsiders (select members of the public) working on the code. We cannot grant the outsiders access to the small, private bits of code, but we'd like a public ve...
3
2009-09-18T08:05:22Z
1,443,266
<p><a href="http://docs.python.org/tutorial/modules.html#packages-in-multiple-directories" rel="nofollow">In the <code>__init__</code> method of the <code>foo</code> package you can change <code>__path__</code> to make it look for its modules in other directories.</a></p> <p>So create a directory called <code>secret</...
3
2009-09-18T08:36:49Z
[ "python", "svn", "project-management", "repository", "modularity" ]
How do I protect my Python codebase so that guests can't see certain modules but so it still works?
1,443,146
<p>We're starting a new project in Python with a few proprietary algorithms and sensitive bits of logic that we'd like to keep private. We also will have a few outsiders (select members of the public) working on the code. We cannot grant the outsiders access to the small, private bits of code, but we'd like a public ve...
3
2009-09-18T08:05:22Z
1,443,289
<p>Use some sort of plugin system, and keep your plugins to your self, but also have publically available plugins that gets shipped with the open code.</p> <p>Plugin systems abound. You can easily make dead simple ones yourself. If you want something more advanced I prefer the Zope Component Architecture, but there ar...
2
2009-09-18T08:44:21Z
[ "python", "svn", "project-management", "repository", "modularity" ]
How do I protect my Python codebase so that guests can't see certain modules but so it still works?
1,443,146
<p>We're starting a new project in Python with a few proprietary algorithms and sensitive bits of logic that we'd like to keep private. We also will have a few outsiders (select members of the public) working on the code. We cannot grant the outsiders access to the small, private bits of code, but we'd like a public ve...
3
2009-09-18T08:05:22Z
3,192,648
<p>Here's an alternate solution I noticed when reading the docs for <a href="http://flask.pocoo.org/docs/" rel="nofollow">Flask</a>:</p> <blockquote> <p><strong><code>flaskext/__init__.py</code></strong></p> <p>The only purpose of this file is to mark the package as namespace package. This is required so that m...
0
2010-07-07T07:19:03Z
[ "python", "svn", "project-management", "repository", "modularity" ]
Is it possible to divert a module in python? (ResourceX diverted to ResourceXSimulated)
1,443,173
<p>I want to simulate MyApp that imports a module (ResourceX) which requires a resource that is not available at the time and will not work. </p> <p>A solution for this is to make and import a mock module of ResourceX (named ResourceXSimulated) and divert it to MyApp as ResourceX. I want to do this in order to avoid b...
1
2009-09-18T08:12:47Z
1,443,195
<p>Yes, Python can do that, and so long as the methods exposed in the ResourceXSimulated module "look and smell" like these of the original module, the application should not see much any difference (other than, I'm assuming, bogus data fillers, different response times and such).</p>
0
2009-09-18T08:20:33Z
[ "python", "testing", "mocking", "module", "monkeypatching" ]
Is it possible to divert a module in python? (ResourceX diverted to ResourceXSimulated)
1,443,173
<p>I want to simulate MyApp that imports a module (ResourceX) which requires a resource that is not available at the time and will not work. </p> <p>A solution for this is to make and import a mock module of ResourceX (named ResourceXSimulated) and divert it to MyApp as ResourceX. I want to do this in order to avoid b...
1
2009-09-18T08:12:47Z
1,443,257
<p>This is called monkey-patching, and it's a fairly widely-used technique in dynamic languages like Python.</p> <p>So presumably you have a class:</p> <pre><code>class MyOriginal(object): def method_x(self): do_something_expensive_you_dont_want_in_testing() obj = MyOriginal() obj.method_x() </code></p...
1
2009-09-18T08:35:32Z
[ "python", "testing", "mocking", "module", "monkeypatching" ]
Is it possible to divert a module in python? (ResourceX diverted to ResourceXSimulated)
1,443,173
<p>I want to simulate MyApp that imports a module (ResourceX) which requires a resource that is not available at the time and will not work. </p> <p>A solution for this is to make and import a mock module of ResourceX (named ResourceXSimulated) and divert it to MyApp as ResourceX. I want to do this in order to avoid b...
1
2009-09-18T08:12:47Z
1,443,281
<p>Yes, it's possible. Some starters:</p> <p>You can "divert" modules by manipulating sys.modules. It keeps a list of imported modules, and there you can make your module appear under the same name as the original one. You must do this manipulating before any module that imports the module you want to fake though.</p>...
1
2009-09-18T08:41:06Z
[ "python", "testing", "mocking", "module", "monkeypatching" ]
Is it possible to divert a module in python? (ResourceX diverted to ResourceXSimulated)
1,443,173
<p>I want to simulate MyApp that imports a module (ResourceX) which requires a resource that is not available at the time and will not work. </p> <p>A solution for this is to make and import a mock module of ResourceX (named ResourceXSimulated) and divert it to MyApp as ResourceX. I want to do this in order to avoid b...
1
2009-09-18T08:12:47Z
1,443,288
<p>Just change all lines <code>import ResourceX</code> in <code>MyApp</code> to <code>import ResourceXSimulated as ResourceX</code>, and lines like <code>from ResourceX import Y</code> to <code>from ResourceXSimulated import Y</code>.</p> <p>However if don't have access to <code>MyApp</code> source or there are other ...
4
2009-09-18T08:42:26Z
[ "python", "testing", "mocking", "module", "monkeypatching" ]
Is it possible to divert a module in python? (ResourceX diverted to ResourceXSimulated)
1,443,173
<p>I want to simulate MyApp that imports a module (ResourceX) which requires a resource that is not available at the time and will not work. </p> <p>A solution for this is to make and import a mock module of ResourceX (named ResourceXSimulated) and divert it to MyApp as ResourceX. I want to do this in order to avoid b...
1
2009-09-18T08:12:47Z
1,443,324
<p>It's possible with the <code>sys.modules</code> hack, as already said.</p> <p>Note that if you have control over module <code>ResourceX</code> it's certainly better that it takes care of it itself. This is actually a common pattern when writing modules that work better when some resource is present, e.g.: </p> <pr...
1
2009-09-18T08:55:00Z
[ "python", "testing", "mocking", "module", "monkeypatching" ]
Django : Iterate over a query set without cache
1,443,279
<p>I have a dumb simple loop</p> <pre><code>for alias in models.Alias.objects.all() : alias.update_points() </code></pre> <p>but looking into the django QuerySet it seems to keep around a <code>_result_cache</code> of all the previous results. This is eating Gigs and Gigs of my machine and eventually everything b...
5
2009-09-18T08:40:47Z
1,443,304
<p>Use the queryset's <a href="http://docs.djangoproject.com/en/dev/ref/models/querysets/#iterator"><code>iterator()</code></a> method to return the models in chunks, without populating the result cache:</p> <pre><code>for alias in models.Alias.objects.iterator() : alias.update_points() </code></pre>
11
2009-09-18T08:49:48Z
[ "python", "django", "caching" ]
Django : Iterate over a query set without cache
1,443,279
<p>I have a dumb simple loop</p> <pre><code>for alias in models.Alias.objects.all() : alias.update_points() </code></pre> <p>but looking into the django QuerySet it seems to keep around a <code>_result_cache</code> of all the previous results. This is eating Gigs and Gigs of my machine and eventually everything b...
5
2009-09-18T08:40:47Z
1,443,682
<p>You should consider saving your changes back to the database.</p> <pre><code>for alias in models.Alias.objects.all() : alias.update_points() alias.save() </code></pre>
0
2009-09-18T10:22:48Z
[ "python", "django", "caching" ]
regular expression to parse network interface config
1,443,433
<p>I am wondering if problem down here can be solved with one regular expression or I should make standard loop and evaluate line by line,</p> <p>when I run included code I get <code>['Ethernet0/22', 'Ethernet0/24']</code>, only result should be <code>['Ethernet0/23', 'Ethernet0/25']</code>.</p> <p>any advice on this...
2
2009-09-18T09:24:21Z
1,443,517
<p>Your problem is that the regex is continuing to find the BTO in the next group. As a quick workaround, you could just prohibit the "#" character in the interface id (assuming this isn't valid within records, and only seperates them).</p> <pre><code>re1 = '''^interface ([^#]*?$)[^#]*?BTO.*?^#$''' </code></pre>
4
2009-09-18T09:41:11Z
[ "python", "regex" ]
regular expression to parse network interface config
1,443,433
<p>I am wondering if problem down here can be solved with one regular expression or I should make standard loop and evaluate line by line,</p> <p>when I run included code I get <code>['Ethernet0/22', 'Ethernet0/24']</code>, only result should be <code>['Ethernet0/23', 'Ethernet0/25']</code>.</p> <p>any advice on this...
2
2009-09-18T09:24:21Z
1,443,518
<p>Rather than trying to make a pattern between the ^ and $ anchors, and relying on the # you could use the newlines break down the 'sublines' inside the single block match</p> <p>e.g. identify the clauses in terms of a sequence of literal not-newlines leading up to a newline.</p> <p>something like</p> <pre><code> ...
1
2009-09-18T09:42:33Z
[ "python", "regex" ]
regular expression to parse network interface config
1,443,433
<p>I am wondering if problem down here can be solved with one regular expression or I should make standard loop and evaluate line by line,</p> <p>when I run included code I get <code>['Ethernet0/22', 'Ethernet0/24']</code>, only result should be <code>['Ethernet0/23', 'Ethernet0/25']</code>.</p> <p>any advice on this...
2
2009-09-18T09:24:21Z
1,443,540
<h2>An example without regular expressions:</h2> <pre><code>print [ stanza.split()[0] for stanza in txt.split("interface ") if stanza.lower().startswith( "ethernet" ) and stanza.lower().find("bto") &gt; -1 ] </code></pre> <h2>Explanation:</h2> <p>I find compositions are best read "inside-out"...
2
2009-09-18T09:49:05Z
[ "python", "regex" ]
regular expression to parse network interface config
1,443,433
<p>I am wondering if problem down here can be solved with one regular expression or I should make standard loop and evaluate line by line,</p> <p>when I run included code I get <code>['Ethernet0/22', 'Ethernet0/24']</code>, only result should be <code>['Ethernet0/23', 'Ethernet0/25']</code>.</p> <p>any advice on this...
2
2009-09-18T09:24:21Z
1,444,113
<p>Here is a little pyparsing parser for your file. Not only does this show a solution to your immediate problem, but the parser gives you a nice set of objects that you can use to easily access the data in each interface.</p> <p>Here is the parser:</p> <pre><code>from pyparsing import * # set up the parser comment...
5
2009-09-18T11:58:40Z
[ "python", "regex" ]
How to read a structure containing an array using Python's ctypes and readinto?
1,444,159
<p>We have some binary files created by a C program.</p> <p>One type of file is created by calling fwrite to write the following C structure to file:</p> <pre><code>typedef struct { unsigned long int foo; unsigned short int bar; unsigned short int bow; } easyStruc; </code></pre> <p>In Python, I read the...
4
2009-09-18T12:05:54Z
1,444,339
<p>According to this <a href="http://docs.activestate.com/activepython/3.1/python/library/ctypes.html" rel="nofollow">documentation page</a> (section: 15.15.1.13. Arrays), it should be something like:</p> <pre><code>class strucWithArrays(Structure): _fields_ = [ ("foo", c_ulong), ("barFloat", c_float * 4), ("b...
8
2009-09-18T12:43:48Z
[ "python", "ctypes" ]
How to read a structure containing an array using Python's ctypes and readinto?
1,444,159
<p>We have some binary files created by a C program.</p> <p>One type of file is created by calling fwrite to write the following C structure to file:</p> <pre><code>typedef struct { unsigned long int foo; unsigned short int bar; unsigned short int bow; } easyStruc; </code></pre> <p>In Python, I read the...
4
2009-09-18T12:05:54Z
1,444,349
<p>There's a section about <a href="http://docs.python.org/library/ctypes.html#arrays" rel="nofollow">arrays in ctypes</a> in the documentation. Basically this means:</p> <pre><code>class structWithArray(Structure): _fields_ = [ ("foo", c_ulong), ("barFloat", c_float * 4), ("bowFloat", c_float * ...
2
2009-09-18T12:46:08Z
[ "python", "ctypes" ]
Django Models internal methods
1,444,222
<p>I'm new to Django so I just made up an project to get to know it but I'm having a little problem with this code, I want to be able to as the car obj if it is available so I do a:</p> <pre><code>&gt;&gt;&gt;cars = Car.objects.all() &gt;&gt;&gt;print cars[0].category &gt;&gt;&gt;'A' &gt;&gt;&gt;cars[0].available(fr, ...
0
2009-09-18T12:20:58Z
1,444,390
<p>Although I can't see how the error you are getting relates to it, the filter you are using doesn't look correct.</p> <p>You define category as a string in the Car model:</p> <pre><code>category = models.CharField("Category",max_length=1,primary_key=True) </code></pre> <p>And define car as a foreignkey in the Rent...
0
2009-09-18T12:55:02Z
[ "python", "django", "django-models" ]
Example code for a python server wrapper
1,444,358
<p>I have a command line server for which I want to create a wrapper in python. The idea is that the wrapper receives commands like:</p> <pre><code>my_wrapper start my_wrapper stop my_wrapper restart my_wrapper status </code></pre> <p>And handles the server in background, unlinked to the terminal that launched it fro...
1
2009-09-18T12:48:18Z
1,444,373
<p>You could use an implementation of <a href="http://www.python.org/dev/peps/pep-3143/" rel="nofollow">PEP 3143 - Standard daemon process library</a>. One existing is <a href="http://pypi.python.org/pypi/python-daemon/" rel="nofollow">python-daemon</a>.</p>
1
2009-09-18T12:52:42Z
[ "python", "wrapper" ]
Differences between Framework and non-Framework builds of Python on Mac OS X
1,444,543
<h3>Question</h3> <p>What are the differences between a Framework build and a non-Framework build (i.e., standard UNIX build) of Python on Mac OS X? Also, what are the advantages and disadvantages of each?</p> <h3>Preliminary Research</h3> <p>Here is the information that I found prior to posting this question:</p> ...
44
2009-09-18T13:27:54Z
1,445,711
<p>You've already listed all important advantages of making a framework (congratulations for excellent research and reporting thereof!); the only flip side is that it's harder to arrange to build one properly, but if you take your clues from the examples in the installer you quote, it should be doable.</p> <p>BTW, wha...
11
2009-09-18T16:53:24Z
[ "python", "osx", "frameworks" ]
Differences between Framework and non-Framework builds of Python on Mac OS X
1,444,543
<h3>Question</h3> <p>What are the differences between a Framework build and a non-Framework build (i.e., standard UNIX build) of Python on Mac OS X? Also, what are the advantages and disadvantages of each?</p> <h3>Preliminary Research</h3> <p>Here is the information that I found prior to posting this question:</p> ...
44
2009-09-18T13:27:54Z
1,493,606
<p>I use <a href="http://www.macports.org/install.php" rel="nofollow" title="Macports">Macports</a> on 10.6, which makes it very simple to install multiple versions of python and switch between them and Apple's version:</p> <pre><code>sudo port install python26 sudo port install python_select sudo python_select -l </c...
0
2009-09-29T16:24:02Z
[ "python", "osx", "frameworks" ]
Differences between Framework and non-Framework builds of Python on Mac OS X
1,444,543
<h3>Question</h3> <p>What are the differences between a Framework build and a non-Framework build (i.e., standard UNIX build) of Python on Mac OS X? Also, what are the advantages and disadvantages of each?</p> <h3>Preliminary Research</h3> <p>Here is the information that I found prior to posting this question:</p> ...
44
2009-09-18T13:27:54Z
1,493,981
<p>If you are going to ship your code (have it running on another machine), you'd better use the system version of python otherwise your program behavior will be undefined on the other machines.</p>
1
2009-09-29T17:38:22Z
[ "python", "osx", "frameworks" ]
Differences between Framework and non-Framework builds of Python on Mac OS X
1,444,543
<h3>Question</h3> <p>What are the differences between a Framework build and a non-Framework build (i.e., standard UNIX build) of Python on Mac OS X? Also, what are the advantages and disadvantages of each?</p> <h3>Preliminary Research</h3> <p>Here is the information that I found prior to posting this question:</p> ...
44
2009-09-18T13:27:54Z
1,494,311
<p>Framework builds are owned by the 'root' account when installed. A source build will be owned by the account installing it. The advantage (and disadvantage) of having ownership of the Python installation is that you don't need to change accounts to modify it.</p> <p>A small difference is that Framework builds are b...
-1
2009-09-29T18:56:04Z
[ "python", "osx", "frameworks" ]
Differences between Framework and non-Framework builds of Python on Mac OS X
1,444,543
<h3>Question</h3> <p>What are the differences between a Framework build and a non-Framework build (i.e., standard UNIX build) of Python on Mac OS X? Also, what are the advantages and disadvantages of each?</p> <h3>Preliminary Research</h3> <p>Here is the information that I found prior to posting this question:</p> ...
44
2009-09-18T13:27:54Z
13,324,455
<p>There is another difference: typically the Framework installation provided by the installer from python.org has several architectures. </p> <blockquote> <p><code>$ file libpython2.7.dylib</code> </p> <p><code>libpython2.7.dylib: Mach-O universal binary with 2 architectures</code> <code>libpython2.7.dylib (...
3
2012-11-10T17:42:04Z
[ "python", "osx", "frameworks" ]
Django admin choice field dynamically populated by generic foreign key's model fields
1,444,587
<p>Say I have the following simple models for some tagging application (this is simplified from the actual code):</p> <pre><code># Model of tag templates class TagTemplate(models.Model): name = models.CharField() content_type = models.ForeignKey(ContentType) class Tag(models.Model): template = models.Fore...
3
2009-09-18T13:35:04Z
5,981,489
<p>You can subclass the form for that model</p> <pre><code>class TagTemplateForm(forms.ModelForm): def __init__(self, *args, **kwargs): super(TagTemplateForm, self).__init__(*args, **kwargs) if self.instance.content_type == SomeContentType: **dynamically create your fields here** ...
1
2011-05-12T16:45:23Z
[ "python", "django", "django-models", "django-admin" ]
Pydev code browsing?
1,444,651
<p>I've been -trying- to use pydev to do some python (can't say I'm having good times so far). I finally got code completion working for the libraries I'm using, but I'm still wondering about a couple of things... </p> <p>So the library I'm using is called orange. Say I call the function orange.MakeRandomIndices2, but...
2
2009-09-18T13:47:57Z
1,445,869
<p>When you hover your cursor over a function or class, Pydev should show you the docstring. Click on the function/class, then press F3, and it will take you to the definition of that function/class. If that is not happening, you probably have not configured Pydev correctly. Look over the documentation again, making su...
2
2009-09-18T17:28:17Z
[ "python", "eclipse", "pydev" ]
Werkzeug and SQLAlchemy 0.5x session
1,444,735
<p>Updated:</p> <p>Going through the Werkzeug <a href="http://werkzeug.pocoo.org/documentation/0.5.1" rel="nofollow">link text</a> tutorial, got stack with creating SQLAlchemy session using sessionmaker() instead of create_session() as recommended.</p> <p>Note: it is not about SA, it is about Werkzeug.</p> <p>Werkze...
0
2009-09-18T14:02:38Z
1,444,931
<p><code>sessionmaker()</code> returns a session factory, not a session itself. <code>scoped_session()</code> takes a session factory as argument. So just omit the <code>lambda:</code> and pass the result of <code>sessionmaker()</code> directly to <code>scoped_session()</code>.</p>
4
2009-09-18T14:30:57Z
[ "python", "sqlalchemy", "werkzeug" ]
Python: module for creating PID-based lockfile?
1,444,790
<p>I'm writing a Python script that may or may not (depending on a bunch of things) run for a long time, and I'd like to make sure that multiple instances (started via cron) don't step on each others toes. The logical way to do this seems to be a PID-based lockfile… But I don't want to re-invent the wheel if there is...
16
2009-09-18T14:10:52Z
1,444,850
<p>This might be of help to you: <a href="http://pypi.python.org/pypi/zc.lockfile">lockfile</a></p>
9
2009-09-18T14:18:47Z
[ "python", "pid", "lockfile" ]
Python: module for creating PID-based lockfile?
1,444,790
<p>I'm writing a Python script that may or may not (depending on a bunch of things) run for a long time, and I'd like to make sure that multiple instances (started via cron) don't step on each others toes. The logical way to do this seems to be a PID-based lockfile… But I don't want to re-invent the wheel if there is...
16
2009-09-18T14:10:52Z
1,444,860
<p>If you can use GPLv2, Mercurial has a module for that:</p> <p><a href="http://bitbucket.org/mirror/mercurial/src/tip/mercurial/lock.py">http://bitbucket.org/mirror/mercurial/src/tip/mercurial/lock.py</a></p> <p>Example usage:</p> <pre><code>from mercurial import error, lock try: l = lock.lock("/path/to/lock"...
8
2009-09-18T14:19:54Z
[ "python", "pid", "lockfile" ]
Python: module for creating PID-based lockfile?
1,444,790
<p>I'm writing a Python script that may or may not (depending on a bunch of things) run for a long time, and I'd like to make sure that multiple instances (started via cron) don't step on each others toes. The logical way to do this seems to be a PID-based lockfile… But I don't want to re-invent the wheel if there is...
16
2009-09-18T14:10:52Z
1,444,862
<p>I believe you will find the necessary information <a href="http://pypi.python.org/pypi/python-daemon/" rel="nofollow">here</a>. The page in question refers to a package for building daemons in python: this process involves creating a PID lockfile.</p>
3
2009-09-18T14:20:16Z
[ "python", "pid", "lockfile" ]
Python: module for creating PID-based lockfile?
1,444,790
<p>I'm writing a Python script that may or may not (depending on a bunch of things) run for a long time, and I'd like to make sure that multiple instances (started via cron) don't step on each others toes. The logical way to do this seems to be a PID-based lockfile… But I don't want to re-invent the wheel if there is...
16
2009-09-18T14:10:52Z
1,444,890
<p>There is a <a href="http://code.activestate.com/recipes/498171/" rel="nofollow">recipe on ActiveState on creating lockfiles</a>.</p> <p>To generate the filename you can use <a href="http://docs.python.org/library/os.html#os.getpid" rel="nofollow">os.getpid()</a> to get the PID.</p>
2
2009-09-18T14:23:15Z
[ "python", "pid", "lockfile" ]
Python: module for creating PID-based lockfile?
1,444,790
<p>I'm writing a Python script that may or may not (depending on a bunch of things) run for a long time, and I'd like to make sure that multiple instances (started via cron) don't step on each others toes. The logical way to do this seems to be a PID-based lockfile… But I don't want to re-invent the wheel if there is...
16
2009-09-18T14:10:52Z
23,837,022
<p>i've been pretty unhappy with all of those, so i wrote this:</p> <pre><code>class Pidfile(): def __init__(self, path, log=sys.stdout.write, warn=sys.stderr.write): self.pidfile = path self.log = log self.warn = warn def __enter__(self): try: self.pidfd = os.open(...
1
2014-05-23T19:23:50Z
[ "python", "pid", "lockfile" ]
In Django Admin, I want to change how foreign keys are displayed in a Many-Many Relationship admin widget
1,444,912
<p>I have a ManyToMany relationship:</p> <pre> class Book: title = models.CharField(...) isbn = models.CharField(...) def unicode(self): return self.title def ISBN(self): return self.isbn class Author: name = models.CharField(...) books = models.ManyToManyField(Book...) </pre> <p>In the admin i...
2
2009-09-18T14:27:13Z
1,445,536
<p>For 2), use this in your AuthorAdmin class:</p> <pre><code>raw_id_fields = ['books'] </code></pre> <p>Check here: <a href="http://docs.djangoproject.com/en/dev/ref/contrib/admin/#ref-contrib-admin" rel="nofollow">http://docs.djangoproject.com/en/dev/ref/contrib/admin/#ref-contrib-admin</a> for instructions on crea...
1
2009-09-18T16:12:50Z
[ "python", "django", "django-admin", "django-widget" ]
In Django Admin, I want to change how foreign keys are displayed in a Many-Many Relationship admin widget
1,444,912
<p>I have a ManyToMany relationship:</p> <pre> class Book: title = models.CharField(...) isbn = models.CharField(...) def unicode(self): return self.title def ISBN(self): return self.isbn class Author: name = models.CharField(...) books = models.ManyToManyField(Book...) </pre> <p>In the admin i...
2
2009-09-18T14:27:13Z
1,447,266
<p>To display the ISBN you could make a custom field like this:</p> <pre><code> class BooksField(forms.ModelMultipleChoiceField): def label_from_instance(self, obj): return obj.isbn </code></pre> <p>There's a <a href="http://docs.djangoproject.com/en/dev/ref/forms/widgets/#django.forms.CheckboxSelectMulti...
1
2009-09-18T23:58:21Z
[ "python", "django", "django-admin", "django-widget" ]
What is the best-maintained generic functions implementation for Python?
1,445,065
<p>A <a href="http://en.wikipedia.org/wiki/Generic%5Ffunctions">generic function</a> is dispatched based on the type of all its arguments. The programmer defines several implementations of a function. The correct one is chosen at call time based on the types of its arguments. This is useful for object adaptation among ...
7
2009-09-18T14:54:28Z
1,445,119
<p>I'd recommend the <a href="http://pypi.python.org/pypi/PEAK-Rules">PEAK-Rules</a> library by P. Eby. By the same author (deprecated though) is the <a href="http://peak.telecommunity.com/">RuleDispatch</a> package (the predecessor of PEAK-Rules). The latter being no longer maintained IIRC. </p> <p>PEAK-Rules has a l...
7
2009-09-18T15:02:01Z
[ "python", "generics" ]
What is the best-maintained generic functions implementation for Python?
1,445,065
<p>A <a href="http://en.wikipedia.org/wiki/Generic%5Ffunctions">generic function</a> is dispatched based on the type of all its arguments. The programmer defines several implementations of a function. The correct one is chosen at call time based on the types of its arguments. This is useful for object adaptation among ...
7
2009-09-18T14:54:28Z
1,445,132
<p>You can use a construction like this:</p> <pre><code>def my_func(*args, **kwargs): pass </code></pre> <p>In this case args will be a list of any unnamed arguments, and kwargs will be a dictionary of the named ones. From here you can detect their types and act as appropriate.</p>
0
2009-09-18T15:04:21Z
[ "python", "generics" ]
What is the best-maintained generic functions implementation for Python?
1,445,065
<p>A <a href="http://en.wikipedia.org/wiki/Generic%5Ffunctions">generic function</a> is dispatched based on the type of all its arguments. The programmer defines several implementations of a function. The correct one is chosen at call time based on the types of its arguments. This is useful for object adaptation among ...
7
2009-09-18T14:54:28Z
1,445,246
<p>I'm unable to see the point in these "generic" functions. It sounds like simple polymorphism.</p> <p>Your "generic" features can be implemented like this without resorting to any run-time type identification. </p> <pre><code>class intWithDumbExample( int ): def dumbexample( self ): return self*2 cla...
0
2009-09-18T15:23:24Z
[ "python", "generics" ]
Why can't a Python class definition assign a closure variable to itself?
1,445,207
<p>Why doesn't the following work in Python?</p> <pre><code>def make_class(a): class A(object): a=a return A </code></pre>
2
2009-09-18T15:17:37Z
1,445,230
<p>Both appear to work fine (in Python 2.5, at least):</p> <pre><code>&gt;&gt;&gt; def make_class(a): ... class A(object): ... _a = a ... return A ... &gt;&gt;&gt; make_class(10)._a 10 &gt;&gt;&gt; def make_class(b): ... class B(object): ... def get_b(self): ... ...
2
2009-09-18T15:21:22Z
[ "python", "closures" ]