How evil is this use of sys.getrefcount?

2009-03-20 Thread Brian Cole
I'm trying to cache the construction and destruction of an expensive object coming out of a generator function. I can do the following to force a new object to be used if the object is being used somewhere else (based upon it's reference count). Here is the pseudo-code of what I am trying to accomp

IDLE doesn't show stderr output from extension modules

2008-12-19 Thread Brian Cole
I'm importing an extension module created with SWIG. When working with the module interactively in IDLE there should be warning and error messages printed to stderr by the extension module. However, these are not being caught by the IDLE window, they are going directly to the terminal that was used

GzipFile(fileobj=sys.stdin) Why not?

2008-10-10 Thread Brian Cole
Appears like a patch was submitted to allow GzipFile to work from pipes long ago. But there's no comment on why this was never accepted. Is there a good reason? http://mail.python.org/pipermail/patches/2006-June/020064.html -Brian -- http://mail.python.org/mailman/listinfo/python-list

Re: wrapping C functions in python

2008-04-09 Thread Brian Cole
pply some hints? > > > -Paul > > > Den 9. april. 2008 kl. 22.22 skrev Brian Cole: > > > > > > > > > > We use the following SWIG (www.swig.org) typemap to perform such > operations: > > > > %typemap(in) (int argc, char **argv) { >

Re: wrapping C functions in python

2008-04-09 Thread Brian Cole
We use the following SWIG (www.swig.org) typemap to perform such operations: %typemap(in) (int argc, char **argv) { if (!PySequence_Check($input)) { PyErr_SetString(PyExc_ValueError,"Expected a sequence"); return NULL; } $1 = PySequence_Length($input); $2 = (char**)alloca($1*sizeof

Re: Python Leopard DLL Hell

2008-04-09 Thread Brian Cole
Cole On Tue, Apr 8, 2008 at 7:52 PM, Michael Torrie <[EMAIL PROTECTED]> wrote: > Brian Cole wrote: > > That appears to be working correctly at first glance. The argument to > > dlopen is the correct shared library. Unfortunately, either python or > > OS X is lying t

Python Leopard DLL Hell

2008-04-08 Thread Brian Cole
Hello All, I'm running into a strange problem on Leopard with how Python loads shared libraries. I'll give you a background of what we are trying to accomplish before describing the problem. I am not certain whether this is an OS X problem, or a Python problem, though it appears with the combinati

Re: Catching a segfault in a Python library

2007-11-27 Thread Brian Cole
On Nov 25, 1:37 am, Donn Ingle <[EMAIL PROTECTED]> wrote: > MrJean1 wrote: > > Try catching SIGSEGV using the Python signal module > > > > An example (for SIGALRM) is on the next page > > > > However, it may n

Gotcha I never ran into before

2007-08-09 Thread Brian Cole
I've been programming in Python for about 6 years now. One of the features I adore the most is the very useful error messages and stack traces that make it easy to debug. However, today I ran into a difficult to trace bug because the stack trace was reporting the problem in the wrong place. class

Broken essays on python.org

2006-05-12 Thread Brian Cole
I'm not sure if this is the proper place to post this... A lot of the essays at http://www.python.org/doc/essays/ have a messed up layout in Firefox and IE. -Brian -- http://mail.python.org/mailman/listinfo/python-list

Compiling cx_Oracle and LD_LIBRARY_PATH

2006-01-21 Thread Brian Cole
nsion for that matter so that it's not required to set LD_LIBRARY_PATH? Is there a way I can make distutils do this for me? Thanks, Brian Cole -- http://mail.python.org/mailman/listinfo/python-list

Re: check to see if value can be an integer instead of string

2006-01-17 Thread Brian Cole
Python uses "Exceptions" to catch these "Exceptional" situations:http://docs.python.org/tut/node10.html -Brian Cole On 17 Jan 2006 18:51:44 -0800, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote: > thanks for the reply, but wont python fail out if you try to make an >

Re: Restarting scripts

2006-01-16 Thread Brian Cole
. Check out the signal module. There's probably other inventive ways to do this. It mostly depends on how your program is written. -Brian Cole On 1/16/06, Ron Griswold <[EMAIL PROTECTED]> wrote: > Thank you Brian. I gave this a shot and found that execlp was not able > to locate ei

Re: Restarting scripts

2006-01-16 Thread Brian Cole
If everything dies by a Python exception... if __name__ == '__main__': try: main(sys.argv) except: os.execlp("python", "python", sys.argv) Pretty nasty peice of code, but it works well for restarting your script. -Brian On 1/16/06, Ron Griswold <[EMAIL PROTECTED]> wrote:

Re: Extracting results from a large hotshot profile

2006-01-16 Thread Brian Cole
TED]> wrote: > Brian Cole wrote: > > >Thanks for the tip. I got the following error message when trying to > >run your profiler. > > > > > ... > > > File "c:\Documents and Settings\coleb2\My > > Documents\software\Python24\Lib\site > >

Re: Extracting results from a large hotshot profile

2006-01-16 Thread Brian Cole
ith installing wxPython and Numeric on my Linux box and see if that makes a difference. Thanks, Brian On 1/16/06, Mike C. Fletcher <[EMAIL PROTECTED]> wrote: > Brian Cole wrote: > ... > > >I did a hotshot profile. To make this profile took > >about a day. However, I

Extracting results from a large hotshot profile

2006-01-16 Thread Brian Cole
profile is 355 MB large. Is there anything I can do to extract that data? Thanks in advance, Brian Cole -- http://mail.python.org/mailman/listinfo/python-list

Efficient mechanism for str.startswith on a set.

2006-01-10 Thread Brian Cole
I need to iterate through a file, checking whether each line 'startswith()' a string that belongs to a set. Normally, the most efficient way I would do this would be: strs=set(['foo','bar']) for line in file: if line.strip() in strs: print line However, for this case I need to do a st