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
Downloading a Large Number of Files from S3
1,051,275
<p>What's the Fastest way to get a large number of files (relatively small 10-50kB) from Amazon S3 from Python? (In the order of 200,000 - million files). </p> <p>At the moment I am using boto to generate Signed URLs, and using PyCURL to get the files one by one. </p> <p>Would some type of concurrency help? PyCurl.Cu...
2
2009-06-26T21:02:04Z
1,051,408
<p>I've been using txaws with twisted for S3 work, though what you'd probably want is just to get the authenticated URL and use twisted.web.client.DownloadPage (by default will happily go from stream to file without much interaction).</p> <p>Twisted makes it easy to run at whatever concurrency you want. For something...
0
2009-06-26T21:47:56Z
[ "python", "curl", "amazon-s3", "amazon-web-services", "boto" ]
Downloading a Large Number of Files from S3
1,051,275
<p>What's the Fastest way to get a large number of files (relatively small 10-50kB) from Amazon S3 from Python? (In the order of 200,000 - million files). </p> <p>At the moment I am using boto to generate Signed URLs, and using PyCURL to get the files one by one. </p> <p>Would some type of concurrency help? PyCurl.Cu...
2
2009-06-26T21:02:04Z
1,051,414
<p>In the case of python, as this is IO bound, multiple threads will use of the CPU, but it will probably use up only one core. If you have multiple cores, you might want to consider the new <a href="http://docs.python.org/dev/library/multiprocessing.html" rel="nofollow">multiprocessor</a> module. Even then you may wa...
1
2009-06-26T21:50:34Z
[ "python", "curl", "amazon-s3", "amazon-web-services", "boto" ]
Downloading a Large Number of Files from S3
1,051,275
<p>What's the Fastest way to get a large number of files (relatively small 10-50kB) from Amazon S3 from Python? (In the order of 200,000 - million files). </p> <p>At the moment I am using boto to generate Signed URLs, and using PyCURL to get the files one by one. </p> <p>Would some type of concurrency help? PyCurl.Cu...
2
2009-06-26T21:02:04Z
1,051,596
<p>what about thread + queue, I love this article: <a href="http://www.ibm.com/developerworks/aix/library/au-threadingpython/" rel="nofollow">Practical threaded programming with Python</a></p>
0
2009-06-26T22:42:24Z
[ "python", "curl", "amazon-s3", "amazon-web-services", "boto" ]
Downloading a Large Number of Files from S3
1,051,275
<p>What's the Fastest way to get a large number of files (relatively small 10-50kB) from Amazon S3 from Python? (In the order of 200,000 - million files). </p> <p>At the moment I am using boto to generate Signed URLs, and using PyCURL to get the files one by one. </p> <p>Would some type of concurrency help? PyCurl.Cu...
2
2009-06-26T21:02:04Z
1,052,748
<p>You might consider using <a href="http://code.google.com/p/s3fs/wiki/FuseOverAmazon" rel="nofollow">s3fs</a>, and just running concurrent file system commands from Python.</p>
1
2009-06-27T12:18:30Z
[ "python", "curl", "amazon-s3", "amazon-web-services", "boto" ]
Downloading a Large Number of Files from S3
1,051,275
<p>What's the Fastest way to get a large number of files (relatively small 10-50kB) from Amazon S3 from Python? (In the order of 200,000 - million files). </p> <p>At the moment I am using boto to generate Signed URLs, and using PyCURL to get the files one by one. </p> <p>Would some type of concurrency help? PyCurl.Cu...
2
2009-06-26T21:02:04Z
1,085,055
<p>Each job can be done with appropriate tools :)</p> <p>You want use python for stress testing S3 :), so I suggest find a large volume downloader program and pass link to it.</p> <p>On Windows I have experience for installing ReGet program (shareware, from <a href="http://reget.com" rel="nofollow">http://reget.com</...
0
2009-07-05T23:25:12Z
[ "python", "curl", "amazon-s3", "amazon-web-services", "boto" ]
Mutex in Python Twisted
1,051,652
<p>I'm using the Twisted framework, and am getting RPCs asynchronously. I have another function which does a task every 2 seconds, and sleeps in between. This is called through reactor.callInThread. These depend on a shared resources, so I need some thread-safe way of accessing them. How does one go about using critica...
2
2009-06-26T23:02:43Z
1,051,678
<p>Though you can use threads in twisted, the usual idiom with twisted is to do RPC asyncronously using a single thread. Thats one of its advantages. The twisted framework will run the reactor and call your handler events when RPC results are ready for you. Then your code runs, and when your handler exits, control goes...
2
2009-06-26T23:18:48Z
[ "python", "multithreading", "locking", "twisted", "mutex" ]
Mutex in Python Twisted
1,051,652
<p>I'm using the Twisted framework, and am getting RPCs asynchronously. I have another function which does a task every 2 seconds, and sleeps in between. This is called through reactor.callInThread. These depend on a shared resources, so I need some thread-safe way of accessing them. How does one go about using critica...
2
2009-06-26T23:02:43Z
1,302,967
<p>Twisted lets you write event-driven code in a single thread. Multiple events can write to standard Python non-thread-safe data structures in a safe matter, and non-thread-safe data structures can be used as mutexes. If you <strong>do</strong> start using threads, then you have to worry about these things. But you...
0
2009-08-19T22:29:13Z
[ "python", "multithreading", "locking", "twisted", "mutex" ]
Reading a single character (getch style) in Python is not working in Unix
1,052,107
<p>Any time I use the recipe at <a href="http://code.activestate.com/recipes/134892/" rel="nofollow">http://code.activestate.com/recipes/134892/</a> I can't seem to get it working. It always throws the following error:</p> <pre><code>Traceback (most recent call last): ... old_settings = termios.tcgetattr(fd) t...
4
2009-06-27T04:19:23Z
1,052,115
<p>This is working on Ubuntu 8.04.1 , Python 2.5.2, i get no such error. May be you should try it from command line, eclipse may be using its own stdin, i get exact same error if I run it from Wing IDE, but from command line it works great. Reason is that IDE e.g Wing is using there own class netserver.CDbgInputStream ...
9
2009-06-27T04:34:18Z
[ "python", "getch" ]
Reading a single character (getch style) in Python is not working in Unix
1,052,107
<p>Any time I use the recipe at <a href="http://code.activestate.com/recipes/134892/" rel="nofollow">http://code.activestate.com/recipes/134892/</a> I can't seem to get it working. It always throws the following error:</p> <pre><code>Traceback (most recent call last): ... old_settings = termios.tcgetattr(fd) t...
4
2009-06-27T04:19:23Z
17,939,632
<p>Putting terminal into raw mode isn't always a good idea. Actually it's enough to clear ICANON bit. Here is another version of getch() with timeout support:</p> <pre><code>import tty, sys, termios import select def setup_term(fd, when=termios.TCSAFLUSH): mode = termios.tcgetattr(fd) mode[tty.LFLAG] = mode[t...
2
2013-07-30T06:21:12Z
[ "python", "getch" ]
Some help understanding async USB operations with libusb-1.0 and ctypes
1,052,135
<p>Alright. I figured it out. transfer.flags needed to be a byte instead of an int. Silly me. Now I'm getting an error code from ioctl, errno 16, which I think means the device is busy. What a workaholic. I've asked on the libusb mailing list.</p> <p>Below is what I have so far. This isn't really that much code. Most ...
2
2009-06-27T04:51:18Z
1,052,223
<p>where is the initial declaration of transfer? I am not familiar with python, but is this ok to assign values to fields in your struct without defining what data type it should be?</p>
-1
2009-06-27T06:15:16Z
[ "python", "usb", "ctypes", "libusb" ]
Some help understanding async USB operations with libusb-1.0 and ctypes
1,052,135
<p>Alright. I figured it out. transfer.flags needed to be a byte instead of an int. Silly me. Now I'm getting an error code from ioctl, errno 16, which I think means the device is busy. What a workaholic. I've asked on the libusb mailing list.</p> <p>Below is what I have so far. This isn't really that much code. Most ...
2
2009-06-27T04:51:18Z
1,052,319
<ul> <li>Have you checked to make sure the return values of <code>libusb_alloc_transfer</code> and <code>libusb_open_device_with_vid_pid</code> are valid?</li> <li>Have you tried annotating the library functions with the appropriate <a href="http://python.net/crew/theller/ctypes/reference.html#foreign-functions" rel="n...
2
2009-06-27T07:39:17Z
[ "python", "usb", "ctypes", "libusb" ]
Some help understanding async USB operations with libusb-1.0 and ctypes
1,052,135
<p>Alright. I figured it out. transfer.flags needed to be a byte instead of an int. Silly me. Now I'm getting an error code from ioctl, errno 16, which I think means the device is busy. What a workaholic. I've asked on the libusb mailing list.</p> <p>Below is what I have so far. This isn't really that much code. Most ...
2
2009-06-27T04:51:18Z
1,071,460
<p>Running it as root once fixed the busy flag.</p>
0
2009-07-01T21:22:40Z
[ "python", "usb", "ctypes", "libusb" ]
Convert python filenames to unicode
1,052,225
<p>I am on python 2.6 for Windows.</p> <p>I use os.walk to read a file tree. Files may have non-7-bit characters (German "ae" for example) in their filenames. These are encoded in Pythons internal string representation.</p> <p>I am processing these filenames with Python library functions and that fails due to wrong e...
15
2009-06-27T06:17:20Z
1,052,238
<p>If you pass a Unicode string to <code>os.walk()</code>, you'll get Unicode results:</p> <pre><code>&gt;&gt;&gt; list(os.walk(r'C:\example')) # Passing an ASCII string [('C:\\example', [], ['file.txt'])] &gt;&gt;&gt; &gt;&gt;&gt; list(os.walk(ur'C:\example')) # Passing a Unicode string [(u'C:\\examp...
42
2009-06-27T06:34:37Z
[ "python", "unicode" ]
Convert python filenames to unicode
1,052,225
<p>I am on python 2.6 for Windows.</p> <p>I use os.walk to read a file tree. Files may have non-7-bit characters (German "ae" for example) in their filenames. These are encoded in Pythons internal string representation.</p> <p>I am processing these filenames with Python library functions and that fails due to wrong e...
15
2009-06-27T06:17:20Z
1,052,241
<p><a href="http://docs.python.org/library/os.html#os.walk" rel="nofollow"><code>os.walk</code></a> isn't specified to always use <code>os.listdir</code>, but neither is it listed how Unicode is handled. However, <a href="http://docs.python.org/library/os.html#os.listdir" rel="nofollow"><code>os.listdir</code></a> does...
1
2009-06-27T06:36:27Z
[ "python", "unicode" ]
Convert python filenames to unicode
1,052,225
<p>I am on python 2.6 for Windows.</p> <p>I use os.walk to read a file tree. Files may have non-7-bit characters (German "ae" for example) in their filenames. These are encoded in Pythons internal string representation.</p> <p>I am processing these filenames with Python library functions and that fails due to wrong e...
15
2009-06-27T06:17:20Z
1,052,293
<p>No, they are not encoded in Pythons internal string representation, there is no such thing. They are encoded in the encoding of the operating system/file system. Passing in unicode works for os.walk though. </p> <p>I don't know how os.walk behaves when filenames can't be decoded, but I assume that you'll get a stri...
1
2009-06-27T07:18:26Z
[ "python", "unicode" ]
Convert python filenames to unicode
1,052,225
<p>I am on python 2.6 for Windows.</p> <p>I use os.walk to read a file tree. Files may have non-7-bit characters (German "ae" for example) in their filenames. These are encoded in Pythons internal string representation.</p> <p>I am processing these filenames with Python library functions and that fails due to wrong e...
15
2009-06-27T06:17:20Z
2,392,967
<p>a more direct way might be to try the following -- find your file system's encoding, and then convert that to unicode. for example,</p> <pre><code>unicode_name = unicode(filename, "utf-8", errors="ignore") </code></pre> <p>to go the other way,</p> <pre><code>unicode_name.encode("utf-8") </code></pre>
1
2010-03-06T15:27:15Z
[ "python", "unicode" ]
Convert python filenames to unicode
1,052,225
<p>I am on python 2.6 for Windows.</p> <p>I use os.walk to read a file tree. Files may have non-7-bit characters (German "ae" for example) in their filenames. These are encoded in Pythons internal string representation.</p> <p>I am processing these filenames with Python library functions and that fails due to wrong e...
15
2009-06-27T06:17:20Z
6,007,172
<p>I was looking for a solution for Python 3.0+. Will put it up here incase someone else needs it.</p> <pre><code>rootdir = r'D:\COUNTRY\ROADS\' fs_enc = sys.getfilesystemencoding() for (root, dirname, filename) in os.walk(rootdir.encode(fs_enc)): # do your stuff here, but remember that now # root, dirname, fi...
6
2011-05-15T07:48:05Z
[ "python", "unicode" ]
Convert python filenames to unicode
1,052,225
<p>I am on python 2.6 for Windows.</p> <p>I use os.walk to read a file tree. Files may have non-7-bit characters (German "ae" for example) in their filenames. These are encoded in Pythons internal string representation.</p> <p>I am processing these filenames with Python library functions and that fails due to wrong e...
15
2009-06-27T06:17:20Z
30,253,676
<pre><code>os.walk(unicode(root_dir, 'utf-8')) </code></pre>
1
2015-05-15T07:14:48Z
[ "python", "unicode" ]
How to create a message box with tkinter?
1,052,420
<p>I've been trying to build a fairly simple message box in tkinter that has "YES" and "NO" buttons. When I push the "YES" button internally it must go and write YES to a file. Similarly, when "NO" is pushed, NO must be written to a file. How can I do this?</p>
5
2009-06-27T08:48:36Z
1,052,428
<p>You can use the module <a href="http://infohost.nmt.edu/tcc/help/pubs/tkinter/dialogs.html#tkMessageBox" rel="nofollow">tkMessageBox</a> for Python 2.7 or the corresponding version for Python 3 called <code>tkinter.messagebox</code>.</p> <p>It looks like <code>askquestion()</code> is exactly the function that you w...
14
2009-06-27T08:54:42Z
[ "python", "tkinter", "messagebox" ]
How to create a message box with tkinter?
1,052,420
<p>I've been trying to build a fairly simple message box in tkinter that has "YES" and "NO" buttons. When I push the "YES" button internally it must go and write YES to a file. Similarly, when "NO" is pushed, NO must be written to a file. How can I do this?</p>
5
2009-06-27T08:48:36Z
11,497,024
<p>Here's how you can ask a question using a message box in Python 2.7. You need specifically the module <code>tkMessageBox</code>.</p> <pre><code>from Tkinter import * import tkMessageBox root = Tk().withdraw() # hiding the main window var = tkMessageBox.askyesno("Title", "Your question goes here?") filename = "l...
5
2012-07-16T01:06:29Z
[ "python", "tkinter", "messagebox" ]
How to create a message box with tkinter?
1,052,420
<p>I've been trying to build a fairly simple message box in tkinter that has "YES" and "NO" buttons. When I push the "YES" button internally it must go and write YES to a file. Similarly, when "NO" is pushed, NO must be written to a file. How can I do this?</p>
5
2009-06-27T08:48:36Z
13,797,893
<p>You can assign the return value of the <code>askquestion</code> function to a variable, and then you simply write the variable to a file:</p> <pre><code>from tkinter import messagebox variable = messagebox.askquestion('title','question') with open('myfile.extension', 'w') as file: # option 'a' to append file....
6
2012-12-10T09:10:44Z
[ "python", "tkinter", "messagebox" ]
Run a function every X minutes - Python
1,052,574
<p>I'm using Python and PyGTK. I'm interested in running a certain function, which gets data from a serial port and saves it, every several minutes.</p> <p>Currently, I'm using the sleep() function in the time library. In order to be able to do processing, I have my system set up like this:</p> <pre><code>import time...
11
2009-06-27T10:28:42Z
1,052,581
<p>Do not use such loop with sleep, it will block gtk from processing any UI events, instead use gtk timer e.g.</p> <pre><code>def my_timer(*args): return True# do ur work here, but not for long gtk.timeout_add(60*1000, my_timer) # call every min </code></pre>
22
2009-06-27T10:34:54Z
[ "python", "gtk", "timer", "pygtk" ]
Run a function every X minutes - Python
1,052,574
<p>I'm using Python and PyGTK. I'm interested in running a certain function, which gets data from a serial port and saves it, every several minutes.</p> <p>Currently, I'm using the sleep() function in the time library. In order to be able to do processing, I have my system set up like this:</p> <pre><code>import time...
11
2009-06-27T10:28:42Z
1,309,480
<p>This is exactly like <a href="http://stackoverflow.com/questions/1309006/running-function-5-seconds-after-pygtk-widget-is-shown/1309404#1309404">my answer here</a></p> <p>If the time is not critical to be exact to the tenth of a second, use</p> <pre><code>glib.timeout_add_seconds(60, ..) </code></pre> <p>else as ...
8
2009-08-21T00:01:57Z
[ "python", "gtk", "timer", "pygtk" ]
Run a function every X minutes - Python
1,052,574
<p>I'm using Python and PyGTK. I'm interested in running a certain function, which gets data from a serial port and saves it, every several minutes.</p> <p>Currently, I'm using the sleep() function in the time library. In order to be able to do processing, I have my system set up like this:</p> <pre><code>import time...
11
2009-06-27T10:28:42Z
4,651,015
<p>gtk.timeout_add appears to be deprecated, so you should use </p> <pre><code>def my_timer(*args): # Do your work here return True gobject.timeout_add( 60*1000, my_timer ) </code></pre>
4
2011-01-10T20:11:00Z
[ "python", "gtk", "timer", "pygtk" ]
Run a function every X minutes - Python
1,052,574
<p>I'm using Python and PyGTK. I'm interested in running a certain function, which gets data from a serial port and saves it, every several minutes.</p> <p>Currently, I'm using the sleep() function in the time library. In order to be able to do processing, I have my system set up like this:</p> <pre><code>import time...
11
2009-06-27T10:28:42Z
14,468,874
<p>try:</p> <pre><code>import wx wx.CallLater(1000, my_timer) </code></pre>
1
2013-01-22T22:02:39Z
[ "python", "gtk", "timer", "pygtk" ]
How can I parse the output of /proc/net/dev into key:value pairs per interface using Python?
1,052,589
<p>The output of <a href="http://www.redhat.com/docs/manuals/enterprise/RHEL-4-Manual/en-US/Reference%5FGuide/s2-proc-dir-net.html" rel="nofollow">/proc/net/dev</a> on Linux looks like this:</p> <pre><code>Inter-| Receive | Transmit face |bytes packets errs drop fi...
2
2009-06-27T10:40:34Z
1,052,623
<p>Does this help?</p> <pre><code>dev = open("/proc/net/dev", "r").readlines() header_line = dev[1] header_names = header_line[header_line.index("|")+1:].replace("|", " ").split() values={} for line in dev[2:]: intf = line[:line.index(":")].strip() values[intf] = [int(value) for value in line[line.index(":")+...
1
2009-06-27T10:56:59Z
[ "python", "linux", "parsing" ]
How can I parse the output of /proc/net/dev into key:value pairs per interface using Python?
1,052,589
<p>The output of <a href="http://www.redhat.com/docs/manuals/enterprise/RHEL-4-Manual/en-US/Reference%5FGuide/s2-proc-dir-net.html" rel="nofollow">/proc/net/dev</a> on Linux looks like this:</p> <pre><code>Inter-| Receive | Transmit face |bytes packets errs drop fi...
2
2009-06-27T10:40:34Z
1,052,628
<p>this is pretty formatted input and you can easily get columns and data list by splitting each line, and then create a dict of of it.</p> <p>here is a simple script without regex</p> <pre><code>lines = open("/proc/net/dev", "r").readlines() columnLine = lines[1] _, receiveCols , transmitCols = columnLine.split("|"...
9
2009-06-27T11:00:13Z
[ "python", "linux", "parsing" ]
How can I parse the output of /proc/net/dev into key:value pairs per interface using Python?
1,052,589
<p>The output of <a href="http://www.redhat.com/docs/manuals/enterprise/RHEL-4-Manual/en-US/Reference%5FGuide/s2-proc-dir-net.html" rel="nofollow">/proc/net/dev</a> on Linux looks like this:</p> <pre><code>Inter-| Receive | Transmit face |bytes packets errs drop fi...
2
2009-06-27T10:40:34Z
1,052,652
<pre><code>#!/usr/bin/env python from __future__ import with_statement import re import pprint ifaces = {} with open('/proc/net/dev') as fd: lines = map(lambda x: x.strip(), fd.readlines()) lines = lines[1:] lines[0] = lines[0].replace('|', ':', 1) lines[0] = lines[0].replace('|', ' ', 1) lines[0] = lines[0...
1
2009-06-27T11:13:57Z
[ "python", "linux", "parsing" ]
Issue with Facebook showAddSectionButton
1,052,613
<p>I am going absolutely batty trying to figure out how to get showAddSectionButton to work.</p> <p>The problem: I'm trying to get the 'add section button' to show up. There is nothing showing up right now.</p> <p>My code:</p> <pre><code>&lt;html xmlns="http://www.w3.org/1999/xhtml" xmlns:fb="http://www.facebook....
-1
2009-06-27T10:52:29Z
1,097,219
<p>I did finally figure out the problem.</p> <p>Facebook doesn't allow anything but FBML on the profile page (for some reason I thought I could use an iframe), which means you have to call setFBML with the profile_main property filled first.</p> <p>Once I did that, the button popped right up.</p>
0
2009-07-08T10:13:40Z
[ "python", "facebook", "google-app-engine" ]
Is registered atexit handler inherited by spawned child processes?
1,052,716
<p>I am writing a daemon program using python 2.5. In the main process an exit handler is registered with <code>atexit</code> module, it <strong>seems</strong> that the handler gets called when each child process ends, which is not I expected.</p> <p>I noticed this behavior isn't mentioned in python <code>atexit</co...
2
2009-06-27T11:54:07Z
1,052,742
<p><code>atexit.register()</code> basically registers your function in <code>atexit._exithandlers</code>, which is a module private list of functions called by <code>sys.exitfunc()</code>. You can set <code>exitfunc()</code> to your custom made exit handler function, which then checks for child status or simply unregis...
1
2009-06-27T12:13:21Z
[ "python", "multiprocessing", "atexit" ]
Is registered atexit handler inherited by spawned child processes?
1,052,716
<p>I am writing a daemon program using python 2.5. In the main process an exit handler is registered with <code>atexit</code> module, it <strong>seems</strong> that the handler gets called when each child process ends, which is not I expected.</p> <p>I noticed this behavior isn't mentioned in python <code>atexit</co...
2
2009-06-27T11:54:07Z
1,053,223
<p>When you <code>fork</code> to make a child process, that child is an exact copy of the parent -- including of course registered exit functions as well as all other code and data structures. I believe that's the issue you're observing -- of course it's not mentioned in each and every module, because it necessarily ap...
2
2009-06-27T17:14:18Z
[ "python", "multiprocessing", "atexit" ]
Is registered atexit handler inherited by spawned child processes?
1,052,716
<p>I am writing a daemon program using python 2.5. In the main process an exit handler is registered with <code>atexit</code> module, it <strong>seems</strong> that the handler gets called when each child process ends, which is not I expected.</p> <p>I noticed this behavior isn't mentioned in python <code>atexit</co...
2
2009-06-27T11:54:07Z
1,062,691
<p>There isn't an API to do it in Python 2.5, but you can just:</p> <pre><code>import atexit atexit._exithandlers = [] </code></pre> <p>in your child processes - if you know you only have one exit handler installed, and that no other handlers are installed. However, be aware that some parts of the stdlib (e.g. <code>...
3
2009-06-30T09:28:56Z
[ "python", "multiprocessing", "atexit" ]
matplotlib "DLL load failed" when import pylab
1,052,831
<p>I'm new to matplotlib. My environment is WinXP, PythonWin 2.6.2, NumPy 1.3.0, matplotlib 0.98.5.3.</p> <pre><code>&gt;&gt;&gt; import matplotlib.pylab as pylab Traceback (most recent call last): File "&lt;interactive input&gt;", line 1, in &lt;module&gt; File "D:\Python26\lib\site-packages\matplotlib\pylab.py",...
1
2009-06-27T13:32:09Z
1,052,910
<p>try this, before using any other module</p> <pre><code>import matplotlib matplotlib.use('Agg') import matplotlib.pylab as pylab </code></pre> <p>see <a href="http://www.mail-archive.com/matplotlib-users@lists.sourceforge.net/msg05372.html">http://www.mail-archive.com/matplotlib-users@lists.sourceforge.net/msg0537...
8
2009-06-27T14:26:56Z
[ "python", "matplotlib" ]
matplotlib "DLL load failed" when import pylab
1,052,831
<p>I'm new to matplotlib. My environment is WinXP, PythonWin 2.6.2, NumPy 1.3.0, matplotlib 0.98.5.3.</p> <pre><code>&gt;&gt;&gt; import matplotlib.pylab as pylab Traceback (most recent call last): File "&lt;interactive input&gt;", line 1, in &lt;module&gt; File "D:\Python26\lib\site-packages\matplotlib\pylab.py",...
1
2009-06-27T13:32:09Z
1,302,790
<p>I had the same problem installing activestat python 2.6 and pylab. After installing the sourceforge python 2.6.2 however it worked fine</p>
1
2009-08-19T21:43:33Z
[ "python", "matplotlib" ]
matplotlib "DLL load failed" when import pylab
1,052,831
<p>I'm new to matplotlib. My environment is WinXP, PythonWin 2.6.2, NumPy 1.3.0, matplotlib 0.98.5.3.</p> <pre><code>&gt;&gt;&gt; import matplotlib.pylab as pylab Traceback (most recent call last): File "&lt;interactive input&gt;", line 1, in &lt;module&gt; File "D:\Python26\lib\site-packages\matplotlib\pylab.py",...
1
2009-06-27T13:32:09Z
20,202,509
<p>I actually found the answer and the graphs are running great on my computer. If you are getting a DLL error like this, try downloading msvcp71.dll and msvcr71.dll in your computer and then copy paste these two in your System32 folder:</p> <blockquote> <p>C:\Windows\System32 </p> </blockquote> <p>and also copy-pa...
0
2013-11-25T20:21:39Z
[ "python", "matplotlib" ]
matplotlib "DLL load failed" when import pylab
1,052,831
<p>I'm new to matplotlib. My environment is WinXP, PythonWin 2.6.2, NumPy 1.3.0, matplotlib 0.98.5.3.</p> <pre><code>&gt;&gt;&gt; import matplotlib.pylab as pylab Traceback (most recent call last): File "&lt;interactive input&gt;", line 1, in &lt;module&gt; File "D:\Python26\lib\site-packages\matplotlib\pylab.py",...
1
2009-06-27T13:32:09Z
33,422,418
<p>I had this issue using iPython notebooks using Python 2.7. Apparently the latest Seaborn update does not play well with my local configuration settings, so I did "conda/pip install seaborn=0.5.1". It downgraded the necessary packages automatically, and my problem went away.</p>
0
2015-10-29T18:52:53Z
[ "python", "matplotlib" ]
How can I convert a Perl regex with named groups to Python?
1,052,930
<p>I am trying to convert the following Perl regex I found in the <a href="http://search.cpan.org/dist/Video-Filename" rel="nofollow">Video::Filename</a> Perl module to a Python 2.5.4 regex to parse a filename</p> <pre><code># Perl &gt; v5.10 re =&gt; '^(?:(?&lt;name&gt;.*?)[\/\s._-]*)?(?&lt;openb&gt;\[)?(?&lt;season&...
3
2009-06-27T14:40:28Z
1,052,954
<p>Those regexps are the product of a sick an twisted mind... :-)</p> <p>Anyway, (?()) are conditions in both Python and Perl, and the perl syntax above looks like it should be the same as the Python syntax, i.e., it evaluates as true of the group named exists.</p> <p>Where to start looking? The documentation for th...
0
2009-06-27T14:50:42Z
[ "python", "regex", "perl" ]
How can I convert a Perl regex with named groups to Python?
1,052,930
<p>I am trying to convert the following Perl regex I found in the <a href="http://search.cpan.org/dist/Video-Filename" rel="nofollow">Video::Filename</a> Perl module to a Python 2.5.4 regex to parse a filename</p> <pre><code># Perl &gt; v5.10 re =&gt; '^(?:(?&lt;name&gt;.*?)[\/\s._-]*)?(?&lt;openb&gt;\[)?(?&lt;season&...
3
2009-06-27T14:40:28Z
1,052,985
<p>I found the offending part but can't figure out what exactly is wrong without wrapping my mind around the whole thing.</p> <pre><code>r = re.compile(r'^(?:(?P&lt;name&gt;.*?)[\/\s._-]*)?(?P&lt;openb&gt;\[)?(?P&lt;season&gt;\d{1,2})[x\/](?P&lt;episode&gt;\d{1,2})(?:-(?:\kP&lt;season&gt;x)?(?P&lt;endep&gt;\d{1,2}))? ...
2
2009-06-27T15:03:53Z
[ "python", "regex", "perl" ]
How can I convert a Perl regex with named groups to Python?
1,052,930
<p>I am trying to convert the following Perl regex I found in the <a href="http://search.cpan.org/dist/Video-Filename" rel="nofollow">Video::Filename</a> Perl module to a Python 2.5.4 regex to parse a filename</p> <pre><code># Perl &gt; v5.10 re =&gt; '^(?:(?&lt;name&gt;.*?)[\/\s._-]*)?(?&lt;openb&gt;\[)?(?&lt;season&...
3
2009-06-27T14:40:28Z
1,052,993
<p>There are 2 problems with your translation. First of all, the second mention of <code>openb</code> has extra parenthesis around it making it a <a href="http://perldoc.perl.org/perlre.html#%27%28?%28condition%29yes-pattern|no-pattern%29%27" rel="nofollow" title="Perl RE conditional expression documentation">condition...
6
2009-06-27T15:07:59Z
[ "python", "regex", "perl" ]
How can I convert a Perl regex with named groups to Python?
1,052,930
<p>I am trying to convert the following Perl regex I found in the <a href="http://search.cpan.org/dist/Video-Filename" rel="nofollow">Video::Filename</a> Perl module to a Python 2.5.4 regex to parse a filename</p> <pre><code># Perl &gt; v5.10 re =&gt; '^(?:(?&lt;name&gt;.*?)[\/\s._-]*)?(?&lt;openb&gt;\[)?(?&lt;season&...
3
2009-06-27T14:40:28Z
1,053,031
<p>I may be wrong but you tried to get the backreference using :</p> <pre><code>(?:\k&lt;season&gt;x) </code></pre> <p>Isn't the syntax <code>\g&lt;name&gt;</code> in Python ?</p>
0
2009-06-27T15:29:28Z
[ "python", "regex", "perl" ]
Testing for ImportErrors in Python
1,052,931
<p>We're having a real problem with people checking in code that doesn't work because something's been refactored. Admittedly, this is partly because our developers don't really have any good tools for finding these kinds of mistakes easily.</p> <p>Are there any tools to help find ImportErrors in Python? Of course, ...
1
2009-06-27T14:41:37Z
1,053,028
<p>Something like this?</p> <pre><code>import os for x in os.listdir("some/path"): execfile( x ) </code></pre> <p>Is that enough, or would you need more?</p> <p>Note that any module that lacks <code>if __name__ == "__main__":</code> will -- obviously -- take off and start doing stuff.</p>
1
2009-06-27T15:26:22Z
[ "python", "unit-testing", "refactoring", "continuous-integration", "importerror" ]
Testing for ImportErrors in Python
1,052,931
<p>We're having a real problem with people checking in code that doesn't work because something's been refactored. Admittedly, this is partly because our developers don't really have any good tools for finding these kinds of mistakes easily.</p> <p>Are there any tools to help find ImportErrors in Python? Of course, ...
1
2009-06-27T14:41:37Z
1,053,195
<p>Pychecker is for you. It imports the modules and will find these errors.</p> <p><a href="http://pychecker.sourceforge.net/" rel="nofollow">http://pychecker.sourceforge.net/</a></p> <p>Oh, and "pylint &lt;modulename&gt;" will import the module, but I guess you would have to call it once for every module you want, w...
3
2009-06-27T16:57:43Z
[ "python", "unit-testing", "refactoring", "continuous-integration", "importerror" ]
psycopg2 on OSX: do I have to install PostgreSQL too?
1,052,957
<p>I want to access a postgreSQL database that's running on a remote machine, from Python in OS/X. Do I have to install postgres on the mac as well? Or will psycopg2 work on its own. </p> <p>Any hints for a good installation guide for psycopg2 for os/x? </p>
1
2009-06-27T14:52:33Z
1,052,990
<p>macports tells me that the psycopg2 package has a dependency on the postgres client and libraries (but not the db server). If you successfully installed psycopg, then you should be good to go.</p> <p>If you haven't installed yet, consider using macports or fink to deal with dependency resolution for you. In most ca...
3
2009-06-27T15:07:33Z
[ "python", "osx", "postgresql" ]
psycopg2 on OSX: do I have to install PostgreSQL too?
1,052,957
<p>I want to access a postgreSQL database that's running on a remote machine, from Python in OS/X. Do I have to install postgres on the mac as well? Or will psycopg2 work on its own. </p> <p>Any hints for a good installation guide for psycopg2 for os/x? </p>
1
2009-06-27T14:52:33Z
1,054,337
<p>psycopg2 requires the PostgreSQL libpq libraries and the pg_config utility, which means you need a decent chunk of PostgreSQL to be installed. You could install Postgres and psycopg2 via MacPorts, but the version situation is somewhat messy--you may need to install a newer Python as well, particularly if you want t...
1
2009-06-28T05:41:29Z
[ "python", "osx", "postgresql" ]
psycopg2 on OSX: do I have to install PostgreSQL too?
1,052,957
<p>I want to access a postgreSQL database that's running on a remote machine, from Python in OS/X. Do I have to install postgres on the mac as well? Or will psycopg2 work on its own. </p> <p>Any hints for a good installation guide for psycopg2 for os/x? </p>
1
2009-06-27T14:52:33Z
1,139,001
<p>You can install from an <a href="http://www.postgresql.org/download/macosx" rel="nofollow">OS X PostgreSQL package</a>. Allow it to change your memory settings and reboot (it's reversible by removing '/etc/sysctl.conf') - the README file (which tells you to do this yourself) is out of date. Then use (or get, if you ...
1
2009-07-16T17:16:08Z
[ "python", "osx", "postgresql" ]
Is there any way to create a "project file" in Emacs?
1,052,969
<p>I say "project file" in the loosest sense. I have a few python projects that I work on with ropemacs using emacs W32 for Windows. What would be ideal is if I could have an icon I could click on on my desktop to open up emacs, open up the rope project, and set the speed bar in the top-level directory of that projec...
7
2009-06-27T14:56:04Z
1,052,995
<p>You can roll your own in bash/cmd.exe. The windows emacs distribution comes with a .bat file called runemacs.bat which accepts files to open as arguments. Write a small script and it should be able to open everything up from one icon.</p>
1
2009-06-27T15:08:10Z
[ "python", "windows", "emacs", "elisp", "ropemacs" ]
Is there any way to create a "project file" in Emacs?
1,052,969
<p>I say "project file" in the loosest sense. I have a few python projects that I work on with ropemacs using emacs W32 for Windows. What would be ideal is if I could have an icon I could click on on my desktop to open up emacs, open up the rope project, and set the speed bar in the top-level directory of that projec...
7
2009-06-27T14:56:04Z
1,053,004
<p>I use the following "solution" for myself: A project root is defined by a directory that contains a <code>Makefile</code>. I've bound F12 to the mode specific elisp function that "compiles" the project by makeing the first target of the corresponding Makefile. This is found by recursively going upwards from the dire...
2
2009-06-27T15:11:36Z
[ "python", "windows", "emacs", "elisp", "ropemacs" ]
Is there any way to create a "project file" in Emacs?
1,052,969
<p>I say "project file" in the loosest sense. I have a few python projects that I work on with ropemacs using emacs W32 for Windows. What would be ideal is if I could have an icon I could click on on my desktop to open up emacs, open up the rope project, and set the speed bar in the top-level directory of that projec...
7
2009-06-27T14:56:04Z
1,053,681
<p>You could get everything set up the way you want for a project, then use the answer I posted about using desktop.el and named sessions:</p> <p><a href="http://stackoverflow.com/questions/847962/what-alternate-session-managers-are-available-for-emacs/849180#849180">http://stackoverflow.com/questions/847962/what-alte...
6
2009-06-27T21:37:17Z
[ "python", "windows", "emacs", "elisp", "ropemacs" ]
Is there any way to create a "project file" in Emacs?
1,052,969
<p>I say "project file" in the loosest sense. I have a few python projects that I work on with ropemacs using emacs W32 for Windows. What would be ideal is if I could have an icon I could click on on my desktop to open up emacs, open up the rope project, and set the speed bar in the top-level directory of that projec...
7
2009-06-27T14:56:04Z
1,055,091
<p>There's <a href="http://wiki.github.com/jrockway/eproject" rel="nofollow">eproject</a>, but it seems to be very sparsely documented.</p>
2
2009-06-28T15:15:02Z
[ "python", "windows", "emacs", "elisp", "ropemacs" ]
Is there any way to create a "project file" in Emacs?
1,052,969
<p>I say "project file" in the loosest sense. I have a few python projects that I work on with ropemacs using emacs W32 for Windows. What would be ideal is if I could have an icon I could click on on my desktop to open up emacs, open up the rope project, and set the speed bar in the top-level directory of that projec...
7
2009-06-27T14:56:04Z
1,055,878
<p>I'm actually working on a solution to this very problem. I always had a group of files I wanted to open/close at the same time, plus do things like open a magit-status window, a dired buffer, etc. I've started on my own project mode called metaproject. It's in the very early stages, but is functional enough that ...
4
2009-06-28T21:58:15Z
[ "python", "windows", "emacs", "elisp", "ropemacs" ]
Is there any way to create a "project file" in Emacs?
1,052,969
<p>I say "project file" in the loosest sense. I have a few python projects that I work on with ropemacs using emacs W32 for Windows. What would be ideal is if I could have an icon I could click on on my desktop to open up emacs, open up the rope project, and set the speed bar in the top-level directory of that projec...
7
2009-06-27T14:56:04Z
2,105,780
<p>See <a href="http://www.emacswiki.org/emacs/CategoryProgrammerUtils#ProjectSupport" rel="nofollow">http://www.emacswiki.org/emacs/CategoryProgrammerUtils#ProjectSupport</a>. There are several packages which manage "projects". I favor mk-project, but then again, I wrote it. ;-)</p>
1
2010-01-20T23:13:46Z
[ "python", "windows", "emacs", "elisp", "ropemacs" ]
Is there any way to create a "project file" in Emacs?
1,052,969
<p>I say "project file" in the loosest sense. I have a few python projects that I work on with ropemacs using emacs W32 for Windows. What would be ideal is if I could have an icon I could click on on my desktop to open up emacs, open up the rope project, and set the speed bar in the top-level directory of that projec...
7
2009-06-27T14:56:04Z
7,303,057
<p>You can use Desktop bookmarks, Dired bookmarks, or Bookmark-List bookmarks to do what you want -- see <a href="http://www.emacswiki.org/emacs/BookmarkPlus" rel="nofollow"><strong><em>Bookmark+</em></strong></a>. You can even encapsulate code and multiple bookmarks in a single bookmark to get just the state and setu...
0
2011-09-05T00:44:09Z
[ "python", "windows", "emacs", "elisp", "ropemacs" ]
Can you access a subbed-classed model from within the super-class model in the Django ORM?
1,053,053
<p>Lets say I have model inheritance set up in the way defined below.</p> <pre><code>class ArticleBase(models.Model): title = models.CharField() author = models.CharField() class Review(ArticleBase): rating = models.IntegerField() class News(ArticleBase): source = models.CharField() </code></pre> <p...
3
2009-06-27T15:40:40Z
1,053,213
<p>You don't ever need to know the subclass of an ArticleBase. The two subclasses -- if you design this properly -- have the same methods and can be used interchangeably.</p> <p>Currently, your two subclasses aren't trivially polymorphic. They each have unique attributes. </p> <p>For the 80% case, they have nothin...
1
2009-06-27T17:09:32Z
[ "python", "django", "django-models" ]
Can you access a subbed-classed model from within the super-class model in the Django ORM?
1,053,053
<p>Lets say I have model inheritance set up in the way defined below.</p> <pre><code>class ArticleBase(models.Model): title = models.CharField() author = models.CharField() class Review(ArticleBase): rating = models.IntegerField() class News(ArticleBase): source = models.CharField() </code></pre> <p...
3
2009-06-27T15:40:40Z
1,053,907
<p>A less sophisticated yet practical approach might be to have a single model with an article_type field. It's a lot easier to work with all articles and you're just a simple filter clause away from your news and review query sets.</p> <p>I'd be interested to hear the arguments against this or the scenarios in which ...
0
2009-06-28T00:13:27Z
[ "python", "django", "django-models" ]
Can you access a subbed-classed model from within the super-class model in the Django ORM?
1,053,053
<p>Lets say I have model inheritance set up in the way defined below.</p> <pre><code>class ArticleBase(models.Model): title = models.CharField() author = models.CharField() class Review(ArticleBase): rating = models.IntegerField() class News(ArticleBase): source = models.CharField() </code></pre> <p...
3
2009-06-27T15:40:40Z
1,075,981
<p>I am assuming that all ArticleBase instances are instances of ArticleBase subclasses.</p> <p>One solution is to store the subclass name in ArticleBase and some methods that return the subclass or subclass object based on that information. As multi-table inheritance defines a property on the parent instance to acce...
1
2009-07-02T18:33:41Z
[ "python", "django", "django-models" ]
Can you access a subbed-classed model from within the super-class model in the Django ORM?
1,053,053
<p>Lets say I have model inheritance set up in the way defined below.</p> <pre><code>class ArticleBase(models.Model): title = models.CharField() author = models.CharField() class Review(ArticleBase): rating = models.IntegerField() class News(ArticleBase): source = models.CharField() </code></pre> <p...
3
2009-06-27T15:40:40Z
9,519,172
<p><a href="https://docs.djangoproject.com/en/dev/topics/db/models/#multi-table-inheritance" rel="nofollow">https://docs.djangoproject.com/en/dev/topics/db/models/#multi-table-inheritance</a></p> <p>You don't have to <em>explicitly</em> query the database, you can do</p> <pre><code>article_base_instance.review </code...
0
2012-03-01T15:42:50Z
[ "python", "django", "django-models" ]
How do I convert a Python float to a hexadecimal string in python 2.5? Nonworking solution attached
1,053,121
<p>What I really need to do is to export a floating point number to C with no precision loss.</p> <p>I did this in python:</p> <pre><code>import math import struct x = math.sqrt(2) print struct.unpack('ii', struct.pack('d', x)) # prints (1719614413, 1073127582) </code></pre> <p>And in C I try this:</p> <pre><code>#...
2
2009-06-27T16:21:37Z
1,053,135
<p>The Python code appears to work. The problem is in the C code: you have the <code>long long</code> filled out right, but then you convert the integer value directly into floating point, rather than <strong>reinterpreting the bytes</strong> as a <code>double</code>. If you throw some pointers/addressing at it it work...
6
2009-06-27T16:27:57Z
[ "python", "double" ]
How do I convert a Python float to a hexadecimal string in python 2.5? Nonworking solution attached
1,053,121
<p>What I really need to do is to export a floating point number to C with no precision loss.</p> <p>I did this in python:</p> <pre><code>import math import struct x = math.sqrt(2) print struct.unpack('ii', struct.pack('d', x)) # prints (1719614413, 1073127582) </code></pre> <p>And in C I try this:</p> <pre><code>#...
2
2009-06-27T16:21:37Z
1,053,141
<p>If you're targeting a little-endian architecture,</p> <pre><code>&gt;&gt;&gt; s = struct.pack('&lt;d', x) &gt;&gt;&gt; ''.join('%.2x' % ord(c) for c in s) 'cd3b7f669ea0f63f' </code></pre> <p>if big-endian, use <code>'&gt;d'</code> instead of <code>&lt;d</code>. In either case, this gives you a hex string as you're...
3
2009-06-27T16:30:20Z
[ "python", "double" ]
How do I convert a Python float to a hexadecimal string in python 2.5? Nonworking solution attached
1,053,121
<p>What I really need to do is to export a floating point number to C with no precision loss.</p> <p>I did this in python:</p> <pre><code>import math import struct x = math.sqrt(2) print struct.unpack('ii', struct.pack('d', x)) # prints (1719614413, 1073127582) </code></pre> <p>And in C I try this:</p> <pre><code>#...
2
2009-06-27T16:21:37Z
1,053,839
<p>repr() is your friend.</p> <pre><code>C:\junk\es2&gt;type es2.c #include &lt;stdio.h&gt; #include &lt;math.h&gt; #include &lt;assert.h&gt; int main(int argc, char** argv) { double expected, actual; int nconv; expected = sqrt(2.0); printf("expected: %20.17g\n", expected); actual = -666.666; ...
1
2009-06-27T23:13:36Z
[ "python", "double" ]
Modeling a complex relationship in Django
1,053,344
<p>I'm working on a Web service in Django, and I need to model a very specific, complex relationship which I just can't be able to solve.</p> <p>Imagine three general models, let's call them Site, Category and Item. Each Site contains one or several Categories, but it can relate to them in one of two possible ways: on...
2
2009-06-27T18:05:54Z
1,053,361
<p>Why not just have both types of category in one model, so you just have 3 models?</p> <pre><code>Site Category Sites = models.ManyToManyField(Site) IsCommon = models.BooleanField() Item Category = models.ForeignKey(Category) </code></pre> <p>You say "Internally, those two type of Categories are completel...
4
2009-06-27T18:17:36Z
[ "python", "django", "django-models", "entity-relationship" ]
Modeling a complex relationship in Django
1,053,344
<p>I'm working on a Web service in Django, and I need to model a very specific, complex relationship which I just can't be able to solve.</p> <p>Imagine three general models, let's call them Site, Category and Item. Each Site contains one or several Categories, but it can relate to them in one of two possible ways: on...
2
2009-06-27T18:05:54Z
1,053,526
<p>Caveat: I know Object-Relation mapping, Rails, and Python, but not Django specifically.</p> <p>I see two additinal options:</p> <ol> <li>Thinking from a database point of view, I could make the table needed for the many-many relation hold an additional field which indicates a "common" vs. "site" relationship and ...
0
2009-06-27T20:08:51Z
[ "python", "django", "django-models", "entity-relationship" ]
Modeling a complex relationship in Django
1,053,344
<p>I'm working on a Web service in Django, and I need to model a very specific, complex relationship which I just can't be able to solve.</p> <p>Imagine three general models, let's call them Site, Category and Item. Each Site contains one or several Categories, but it can relate to them in one of two possible ways: on...
2
2009-06-27T18:05:54Z
1,061,061
<p>As as alternative implementation you could use django content types (generic relations) to accomplish the connection of the items. A bonus for using this implementation is that it allows you to utilize the category models in different ways depending on your data needs down the road. </p> <p>You can make using the ...
1
2009-06-29T23:24:52Z
[ "python", "django", "django-models", "entity-relationship" ]
Regex and a sequences of patterns?
1,053,481
<p>Is there a way to match a pattern (<code>e\d\d</code>) several times, capturing each one into a group? For example, given the string..</p> <pre><code>blah.s01e24e25 </code></pre> <p>..I wish to get four groups:</p> <pre><code>1 -&gt; blah 2 -&gt; 01 3 -&gt; 24 4 -&gt; 25 </code></pre> <p>The obvious regex to use...
4
2009-06-27T19:45:29Z
1,053,501
<p>Do it in two steps, one to find all the numbers, then one to split them:</p> <pre><code>import re def get_pieces(s): # Error checking omitted! whole_match = re.search(r'\w+\.(s\d+(?:e\d+)+)', s) return re.findall(r'\d+', whole_match.group(1)) print get_pieces(r"blah.s01e01") print get_pieces(r"blah.s0...
5
2009-06-27T19:53:39Z
[ "python", "regex", "sequences" ]
Regex and a sequences of patterns?
1,053,481
<p>Is there a way to match a pattern (<code>e\d\d</code>) several times, capturing each one into a group? For example, given the string..</p> <pre><code>blah.s01e24e25 </code></pre> <p>..I wish to get four groups:</p> <pre><code>1 -&gt; blah 2 -&gt; 01 3 -&gt; 24 4 -&gt; 25 </code></pre> <p>The obvious regex to use...
4
2009-06-27T19:45:29Z
1,053,505
<p>Number of captured groups equal to number of parentheses groups. Look at <code>findall</code> or <code>finditer</code> for solving your problem.</p>
1
2009-06-27T19:56:18Z
[ "python", "regex", "sequences" ]
Regex and a sequences of patterns?
1,053,481
<p>Is there a way to match a pattern (<code>e\d\d</code>) several times, capturing each one into a group? For example, given the string..</p> <pre><code>blah.s01e24e25 </code></pre> <p>..I wish to get four groups:</p> <pre><code>1 -&gt; blah 2 -&gt; 01 3 -&gt; 24 4 -&gt; 25 </code></pre> <p>The obvious regex to use...
4
2009-06-27T19:45:29Z
1,053,538
<p>non-grouping parentheses: (?:asdfasdg)</p> <p>which do not have to appear: (?:adsfasdf)?</p> <pre><code>c = re.compile(r"""(\w+).s(\d+) (?: e(\d+) (?: e(\d+) )? ...
1
2009-06-27T20:18:27Z
[ "python", "regex", "sequences" ]
Regex and a sequences of patterns?
1,053,481
<p>Is there a way to match a pattern (<code>e\d\d</code>) several times, capturing each one into a group? For example, given the string..</p> <pre><code>blah.s01e24e25 </code></pre> <p>..I wish to get four groups:</p> <pre><code>1 -&gt; blah 2 -&gt; 01 3 -&gt; 24 4 -&gt; 25 </code></pre> <p>The obvious regex to use...
4
2009-06-27T19:45:29Z
1,053,552
<p>After thinking about the problem, I think I have a simpler solution, using named groups.</p> <p>The simplest regex a user (or I) could use is:</p> <pre><code>(\w+\).s(\d+)\.e(\d+) </code></pre> <p>The filename parsing class will take the first group as the show name, second as season number, third as episode numb...
0
2009-06-27T20:32:22Z
[ "python", "regex", "sequences" ]
Regex and a sequences of patterns?
1,053,481
<p>Is there a way to match a pattern (<code>e\d\d</code>) several times, capturing each one into a group? For example, given the string..</p> <pre><code>blah.s01e24e25 </code></pre> <p>..I wish to get four groups:</p> <pre><code>1 -&gt; blah 2 -&gt; 01 3 -&gt; 24 4 -&gt; 25 </code></pre> <p>The obvious regex to use...
4
2009-06-27T19:45:29Z
1,053,988
<p>Perhaps something like that?</p> <pre><code>def episode_matcher(filename): m1= re.match(r"(?i)(.*?)\.s(\d+)((?:e\d+)+)", filename) if m1: m2= re.findall(r"\d+", m1.group(3)) return m1.group(1), m1.group(2), m2 # auto return None here &gt;&gt;&gt; episode_matcher("blah.s01e02") ('blah', ...
0
2009-06-28T01:11:38Z
[ "python", "regex", "sequences" ]
What does `@` mean in Python?
1,053,732
<p>like <code>@login_required</code>?</p>
1
2009-06-27T22:03:20Z
1,053,735
<p>It is decorator syntax.</p> <blockquote> <p>A function definition may be wrapped by one or more decorator expressions. Decorator expressions are evaluated when the function is defined, in the scope that contains the function definition. The result must be a callable, which is invoked with the function object as t...
30
2009-06-27T22:04:27Z
[ "python", "syntax" ]
What does `@` mean in Python?
1,053,732
<p>like <code>@login_required</code>?</p>
1
2009-06-27T22:03:20Z
1,053,739
<p>It's a decorator. More here: <a href="http://www.ibm.com/developerworks/linux/library/l-cpdecor.html" rel="nofollow">http://www.ibm.com/developerworks/linux/library/l-cpdecor.html</a></p>
1
2009-06-27T22:05:11Z
[ "python", "syntax" ]
What does `@` mean in Python?
1,053,732
<p>like <code>@login_required</code>?</p>
1
2009-06-27T22:03:20Z
1,053,742
<p>A decorator, also called pie syntax. it allows you to "decorate" a function with another function. You already had decoration with staticmethod() and classmethod(). The pie syntax makes it more easy to access and extend.</p>
1
2009-06-27T22:06:35Z
[ "python", "syntax" ]
What does `@` mean in Python?
1,053,732
<p>like <code>@login_required</code>?</p>
1
2009-06-27T22:03:20Z
1,053,744
<p>If you ask this type of question you will probably be interested in the other <a href="http://stackoverflow.com/questions/101268/hidden-features-of-python">hidden features of Python</a>.</p>
2
2009-06-27T22:07:30Z
[ "python", "syntax" ]
What does `@` mean in Python?
1,053,732
<p>like <code>@login_required</code>?</p>
1
2009-06-27T22:03:20Z
1,053,892
<p>Some resources for decorator: <a href="http://docs.python.org/glossary.html#term-decorator" rel="nofollow">decorator</a>, <a href="http://www.python.org/dev/peps/pep-0318/" rel="nofollow">PEP 318: Decorators for Functions and Methods</a>, <a href="http://wiki.python.org/moin/PythonDecorators" rel="nofollow">PythonDe...
0
2009-06-28T00:04:39Z
[ "python", "syntax" ]
What does `@` mean in Python?
1,053,732
<p>like <code>@login_required</code>?</p>
1
2009-06-27T22:03:20Z
1,055,389
<p>That specific decorator looks like it comes from Django.</p> <p>It might help you get a better understanding by reading the <a href="http://docs.djangoproject.com/en/dev/topics/auth/" rel="nofollow">Django documentation</a> about that decorator.</p>
1
2009-06-28T18:01:05Z
[ "python", "syntax" ]
Changing python interpreter windows
1,053,794
<p>I have two python installations, 2.5 and 2.6 I want to change the default python interpreter from 2.5 to 2.6. Anyone know how?</p>
3
2009-06-27T22:41:01Z
1,053,856
<p>PYTHONPATH is <strong>NOT</strong> what you are looking for. That is for varying where Python's "import" looks for packages and modules.</p> <p>You need to change the <strong>PATH</strong> variable in your environment so that it contains e.g. "....;c:\python26;...." instead of "....;c:\python25;....". Click on star...
6
2009-06-27T23:33:41Z
[ "python", "windows" ]
Changing python interpreter windows
1,053,794
<p>I have two python installations, 2.5 and 2.6 I want to change the default python interpreter from 2.5 to 2.6. Anyone know how?</p>
3
2009-06-27T22:41:01Z
1,053,888
<p>just FYI, since both c:\python25 and c:\python26 are on PATH, I copy C:\Python25\python.exe to C:\Python25\py25.exe, and copy C:\Python26\python.exe to C:\Python26\py26.exe Then just type py25(or py26) get the specific version.</p>
1
2009-06-28T00:00:05Z
[ "python", "windows" ]
Very large matrices using Python and NumPy
1,053,928
<p><a href="http://en.wikipedia.org/wiki/NumPy">NumPy</a> is an extremely useful library, and from using it I've found that it's capable of handling matrices which are quite large (10000 x 10000) easily, but begins to struggle with anything much larger (trying to create a matrix of 50000 x 50000 fails). Obviously, this...
60
2009-06-28T00:32:21Z
1,053,951
<p>Usually when we deal with large matrices we implement them as <a href="http://en.wikipedia.org/wiki/Sparse%5Fmatrix" rel="nofollow">Sparse Matrices</a>.</p> <p>I don't know if numpy supports sparse matrices but I found <a href="http://www.scipy.org/SciPy%5FTutorial" rel="nofollow">this</a> instead.</p>
1
2009-06-28T00:45:43Z
[ "python", "matrix", "numpy" ]
Very large matrices using Python and NumPy
1,053,928
<p><a href="http://en.wikipedia.org/wiki/NumPy">NumPy</a> is an extremely useful library, and from using it I've found that it's capable of handling matrices which are quite large (10000 x 10000) easily, but begins to struggle with anything much larger (trying to create a matrix of 50000 x 50000 fails). Obviously, this...
60
2009-06-28T00:32:21Z
1,053,953
<p>As far as I know about numpy, no, but I could be wrong. </p> <p>I can propose you this alternative solution: write the matrix on the disk and access it in chunks. I suggest you the HDF5 file format. If you need it transparently, you can reimplement the ndarray interface to paginate your disk-stored matrix into memo...
1
2009-06-28T00:46:30Z
[ "python", "matrix", "numpy" ]
Very large matrices using Python and NumPy
1,053,928
<p><a href="http://en.wikipedia.org/wiki/NumPy">NumPy</a> is an extremely useful library, and from using it I've found that it's capable of handling matrices which are quite large (10000 x 10000) easily, but begins to struggle with anything much larger (trying to create a matrix of 50000 x 50000 fails). Obviously, this...
60
2009-06-28T00:32:21Z
1,054,017
<p>You should be able to use numpy.memmap to memory map a file on disk. With newer python and 64-bit machine, you should have the necessary address space, without loading everything into memory. The OS should handle only keep part of the file in memory.</p>
28
2009-06-28T01:46:24Z
[ "python", "matrix", "numpy" ]
Very large matrices using Python and NumPy
1,053,928
<p><a href="http://en.wikipedia.org/wiki/NumPy">NumPy</a> is an extremely useful library, and from using it I've found that it's capable of handling matrices which are quite large (10000 x 10000) easily, but begins to struggle with anything much larger (trying to create a matrix of 50000 x 50000 fails). Obviously, this...
60
2009-06-28T00:32:21Z
1,054,070
<p>To handle sparse matrices, you need the <code>scipy</code> package that sits on top of <code>numpy</code> -- see <a href="http://docs.scipy.org/doc/scipy/reference/sparse.html" rel="nofollow">here</a> for more details about the sparse-matrix options that <code>scipy</code> gives you.</p>
21
2009-06-28T02:23:40Z
[ "python", "matrix", "numpy" ]
Very large matrices using Python and NumPy
1,053,928
<p><a href="http://en.wikipedia.org/wiki/NumPy">NumPy</a> is an extremely useful library, and from using it I've found that it's capable of handling matrices which are quite large (10000 x 10000) easily, but begins to struggle with anything much larger (trying to create a matrix of 50000 x 50000 fails). Obviously, this...
60
2009-06-28T00:32:21Z
1,054,079
<p>Are you asking how to handle a 2,500,000,000 element matrix without terabytes of RAM? </p> <p>The way to handle 2 billion items without 8 billion bytes of RAM is by not keeping the matrix in memory.</p> <p>That means much more sophisticated algorithms to fetch it from the file system in pieces.</p>
3
2009-06-28T02:32:13Z
[ "python", "matrix", "numpy" ]
Very large matrices using Python and NumPy
1,053,928
<p><a href="http://en.wikipedia.org/wiki/NumPy">NumPy</a> is an extremely useful library, and from using it I've found that it's capable of handling matrices which are quite large (10000 x 10000) easily, but begins to struggle with anything much larger (trying to create a matrix of 50000 x 50000 fails). Obviously, this...
60
2009-06-28T00:32:21Z
1,054,113
<p><code>numpy.array</code>s are meant to live in memory. If you want to work with matrices larger than your RAM, you have to work around that. There are at least two approaches you can follow:</p> <ol> <li><strong>Try a more efficient matrix representation</strong> that exploits any special structure that your matr...
46
2009-06-28T02:53:45Z
[ "python", "matrix", "numpy" ]
Very large matrices using Python and NumPy
1,053,928
<p><a href="http://en.wikipedia.org/wiki/NumPy">NumPy</a> is an extremely useful library, and from using it I've found that it's capable of handling matrices which are quite large (10000 x 10000) easily, but begins to struggle with anything much larger (trying to create a matrix of 50000 x 50000 fails). Obviously, this...
60
2009-06-28T00:32:21Z
1,054,114
<p>Stefano Borini's <a href="http://stackoverflow.com/questions/1053928/python-numpy-very-large-matrices/1053953#1053953">post</a> got me to look into how far along this sort of thing already is. </p> <p><a href="http://h5py.alfven.org/">This is it.</a> It appears to do basically what you want. HDF5 will let you st...
9
2009-06-28T02:54:20Z
[ "python", "matrix", "numpy" ]
Very large matrices using Python and NumPy
1,053,928
<p><a href="http://en.wikipedia.org/wiki/NumPy">NumPy</a> is an extremely useful library, and from using it I've found that it's capable of handling matrices which are quite large (10000 x 10000) easily, but begins to struggle with anything much larger (trying to create a matrix of 50000 x 50000 fails). Obviously, this...
60
2009-06-28T00:32:21Z
1,062,629
<p>PyTables and NumPy are the way to go.</p> <p>PyTables will store the data on disk in HDF format, with optional compression. My datasets often get 10x compression, which is handy when dealing with tens or hundreds of millions of rows. It's also very fast; my 5 year old laptop can crunch through data doing SQL-like G...
74
2009-06-30T09:11:55Z
[ "python", "matrix", "numpy" ]
Very large matrices using Python and NumPy
1,053,928
<p><a href="http://en.wikipedia.org/wiki/NumPy">NumPy</a> is an extremely useful library, and from using it I've found that it's capable of handling matrices which are quite large (10000 x 10000) easily, but begins to struggle with anything much larger (trying to create a matrix of 50000 x 50000 fails). Obviously, this...
60
2009-06-28T00:32:21Z
1,297,278
<p>Make sure you're using a 64-bit operating system and a 64-bit version of Python/NumPy. Note that on 32-bit architectures you can address typically 3GB of memory (with about 1GB lost to memory mapped I/O and such). </p> <p>With 64-bit and things arrays larger than the available RAM you can get away with virtual memo...
5
2009-08-19T00:27:02Z
[ "python", "matrix", "numpy" ]
Very large matrices using Python and NumPy
1,053,928
<p><a href="http://en.wikipedia.org/wiki/NumPy">NumPy</a> is an extremely useful library, and from using it I've found that it's capable of handling matrices which are quite large (10000 x 10000) easily, but begins to struggle with anything much larger (trying to create a matrix of 50000 x 50000 fails). Obviously, this...
60
2009-06-28T00:32:21Z
14,698,464
<p>It's a bit alpha, but <a href="http://blaze.pydata.org/">http://blaze.pydata.org/</a> seems to be working on solving this. </p>
5
2013-02-05T00:58:35Z
[ "python", "matrix", "numpy" ]
Very large matrices using Python and NumPy
1,053,928
<p><a href="http://en.wikipedia.org/wiki/NumPy">NumPy</a> is an extremely useful library, and from using it I've found that it's capable of handling matrices which are quite large (10000 x 10000) easily, but begins to struggle with anything much larger (trying to create a matrix of 50000 x 50000 fails). Obviously, this...
60
2009-06-28T00:32:21Z
39,841,187
<p>Sometimes one simple solution is using a custom time for your matrix items. Based on the range of numbers you need you can use a manual dtype and specially smaller for your items. Because Numpy considers the largest type for objetc, by default. Here is an example:</p> <pre><code>In [70]: a = np.arange(5) In [71]: ...
0
2016-10-03T22:09:11Z
[ "python", "matrix", "numpy" ]
With Python unittest, how do I create and use a "callable object that returns a test suite"?
1,053,983
<p>I'm learning Python and have been trying to understand more about the details of Python's <code>unittest</code> module. The documentation includes the following:</p> <blockquote> <p>For the ease of running tests, as we will see later, it is a good idea to provide in each test module a callable object that r...
4
2009-06-28T01:08:36Z
1,053,998
<p>The <a href="http://docs.python.org/library/unittest.html" rel="nofollow">documentation</a> is saying <code>suite()</code> should be a function in the module, rather than a method in your class. It appears to be merely a convenience function so you can later aggregate test suites for many modules:</p> <pre><code>al...
1
2009-06-28T01:18:48Z
[ "python" ]
With Python unittest, how do I create and use a "callable object that returns a test suite"?
1,053,983
<p>I'm learning Python and have been trying to understand more about the details of Python's <code>unittest</code> module. The documentation includes the following:</p> <blockquote> <p>For the ease of running tests, as we will see later, it is a good idea to provide in each test module a callable object that r...
4
2009-06-28T01:08:36Z
1,054,011
<p>The very first error message you got is meaningful, and explains a lot.</p> <pre><code>print MyTestCase.suite # &lt;unbound method MyTestCase.suite&gt; </code></pre> <p><em>Unbound</em>. It means that you cannot call it unless you bind it to an instance. It's actually the same for <code>MyTestCase.run</code>:</p> ...
5
2009-06-28T01:37:28Z
[ "python" ]
With Python unittest, how do I create and use a "callable object that returns a test suite"?
1,053,983
<p>I'm learning Python and have been trying to understand more about the details of Python's <code>unittest</code> module. The documentation includes the following:</p> <blockquote> <p>For the ease of running tests, as we will see later, it is a good idea to provide in each test module a callable object that r...
4
2009-06-28T01:08:36Z
1,054,014
<p>One thing that's important to note, <a href="http://somethingaboutorange.com/mrl/projects/nose/0.11.1/" rel="nofollow">nose</a> is a tool that really simplifies running tests. It allows you to specify exactly which tests to run from the command-line as well as walking through each directory and running each test.</...
1
2009-06-28T01:41:39Z
[ "python" ]
With Python unittest, how do I create and use a "callable object that returns a test suite"?
1,053,983
<p>I'm learning Python and have been trying to understand more about the details of Python's <code>unittest</code> module. The documentation includes the following:</p> <blockquote> <p>For the ease of running tests, as we will see later, it is a good idea to provide in each test module a callable object that r...
4
2009-06-28T01:08:36Z
2,114,395
<p>As already been mentioned, documentation refers to suite() as a method in the module, and unittest (strangely) doesn't seem to have any special recognition for this method, so you do have to call it explicitly. However, if you use a tool called "<a href="http://testoob.sourceforge.net/index.html" rel="nofollow">test...
1
2010-01-22T01:40:09Z
[ "python" ]
With Python unittest, how do I create and use a "callable object that returns a test suite"?
1,053,983
<p>I'm learning Python and have been trying to understand more about the details of Python's <code>unittest</code> module. The documentation includes the following:</p> <blockquote> <p>For the ease of running tests, as we will see later, it is a good idea to provide in each test module a callable object that r...
4
2009-06-28T01:08:36Z
5,665,094
<p>I would suggest using the following. This saves you from manually entering all the tests you add as you go along.</p> <pre><code>def suite(): suite = unittest.TestLoader().loadTestsFromTestCase(Your_Test_Case_Class) return suite </code></pre> <p>This gives you the flexibility to execute tests in the same ...
0
2011-04-14T14:51:59Z
[ "python" ]
printing bit representation of numbers in python
1,054,116
<p>I want to print the bit representation of numbers onto console, so that I can see all operations that are being done on bits itself.</p> <p>How can I possibly do it in python?</p>
37
2009-06-28T02:55:44Z
1,054,126
<p><strong>In Python 2.6+</strong>:</p> <pre><code>print bin(123) </code></pre> <p>Results in:</p> <pre><code>0b1111011 </code></pre> <p><strong>In python 2.x</strong></p> <pre><code>&gt;&gt;&gt; binary = lambda n: n&gt;0 and [n&amp;1]+binary(n&gt;&gt;1) or [] &gt;&gt;&gt; binary(123) [1, 1, 0, 1, 1, 1, 1] </code>...
19
2009-06-28T03:00:48Z
[ "python" ]
printing bit representation of numbers in python
1,054,116
<p>I want to print the bit representation of numbers onto console, so that I can see all operations that are being done on bits itself.</p> <p>How can I possibly do it in python?</p>
37
2009-06-28T02:55:44Z
1,054,127
<p><a href="http://docs.python.org/3.1/library/functions.html#bin" rel="nofollow">The <code>bin</code> function</a></p>
2
2009-06-28T03:02:03Z
[ "python" ]
printing bit representation of numbers in python
1,054,116
<p>I want to print the bit representation of numbers onto console, so that I can see all operations that are being done on bits itself.</p> <p>How can I possibly do it in python?</p>
37
2009-06-28T02:55:44Z
1,054,130
<p>This kind of thing?</p> <pre><code>&gt;&gt;&gt; ord('a') 97 &gt;&gt;&gt; hex(ord('a')) '0x61' &gt;&gt;&gt; bin(ord('a')) '0b1100001' </code></pre>
41
2009-06-28T03:02:54Z
[ "python" ]
printing bit representation of numbers in python
1,054,116
<p>I want to print the bit representation of numbers onto console, so that I can see all operations that are being done on bits itself.</p> <p>How can I possibly do it in python?</p>
37
2009-06-28T02:55:44Z
18,946,037
<p>From Python 2.6, with the <a href="http://docs.python.org/2/library/string.html#string-formatting">string.format method</a>:</p> <pre><code>"{0:b}".format(0x1234) </code></pre> <p>in particular, you might like to use padding, so that multiple prints of different numbers still line up:</p> <pre><code>"{0:16b}".for...
15
2013-09-22T16:26:14Z
[ "python" ]
printing bit representation of numbers in python
1,054,116
<p>I want to print the bit representation of numbers onto console, so that I can see all operations that are being done on bits itself.</p> <p>How can I possibly do it in python?</p>
37
2009-06-28T02:55:44Z
30,196,781
<p>Slightly off-topic, but might be helpful. Some time ago I made a user-friendly print function for 1D numpy arrays in binary form. I can define symbols, leading and groups as I like. Here is what I've found most readable form of binary representation.</p> <pre><code>def binprint (arr): # print array ...
0
2015-05-12T16:38:45Z
[ "python" ]
formencode invalid return type
1,054,210
<p>if an exception occurs in form encode then what will be the return type??</p> <p>suppose</p> <pre><code>if(request.POST): formvalidate = ValidationRule() try: new = formvalidate.to_python(request.POST) data = Users1( n_date = new['n_date'], heading = new['heading'], ...
0
2009-06-28T04:11:32Z
1,054,278
<p>I assume you are using formencode(<a href="http://formencode.org" rel="nofollow">http://formencode.org</a>)</p> <p>you can use unpack_errors to get per field error e.g.</p> <pre><code>import formencode from formencode import validators class UserForm(formencode.Schema): first_name = validators.String(not_empt...
3
2009-06-28T04:58:50Z
[ "python", "error-handling", "webforms", "formencode" ]
How frequently should Python decorators be used?
1,054,249
<p>I recently started experimenting with Python decorators (and higher-order functions) because it looked like they might make my Django unit tests more concise. e.g., instead of writing:</p> <pre><code>def visit1(): login() do_stuff() logout() </code></pre> <p>I could instead do</p> <pre><code>@handle_l...
3
2009-06-28T04:41:28Z
1,054,277
<p>If you have the same code at the beginning and end of many functions, I think that would justify the added complexity of using a decorator. </p> <p>Rather like using a nice (but perhaps complex) template for a website with a lot of pages, it really saves time and adds clarity in the end.</p>
0
2009-06-28T04:58:22Z
[ "python", "django", "decorator" ]
How frequently should Python decorators be used?
1,054,249
<p>I recently started experimenting with Python decorators (and higher-order functions) because it looked like they might make my Django unit tests more concise. e.g., instead of writing:</p> <pre><code>def visit1(): login() do_stuff() logout() </code></pre> <p>I could instead do</p> <pre><code>@handle_l...
3
2009-06-28T04:41:28Z
1,054,283
<p>Decorators are fine in their place and definitely not to be avoided -- when appropriate;-). I see your question as meaning essentially "OK so when <em>are</em> they appropriate"?</p> <p>Adding some prefix and/or postfix code around some but not all methods of some classes is a good example. Were it all methods, a <...
12
2009-06-28T05:02:09Z
[ "python", "django", "decorator" ]
How frequently should Python decorators be used?
1,054,249
<p>I recently started experimenting with Python decorators (and higher-order functions) because it looked like they might make my Django unit tests more concise. e.g., instead of writing:</p> <pre><code>def visit1(): login() do_stuff() logout() </code></pre> <p>I could instead do</p> <pre><code>@handle_l...
3
2009-06-28T04:41:28Z
1,054,372
<p>Alex already answered your question pretty well, what I would add is decorators, make your code MUCH easier to understand. (Sometimes, even if you are doing it only once).</p> <p>For example, initially, I write my Django views, without thinking about authorisation at all. And when, I am done writing them, I can see...
3
2009-06-28T06:12:16Z
[ "python", "django", "decorator" ]