Conditionally skipping the contents of a with-statement

2009-08-21 Thread tsuraan
I'd like to write a Fork class to wrap os.fork that allows something like this: with Fork(): # to child stuff, end of block will automatically os._exit() # parent stuff goes here This would require (I think) that the __enter__ method of my Fork class to be able to return a value or raise an exc

Re: Urgent : How to do memory leaks detection in python ?

2008-03-15 Thread tsuraan
> Python doesn't have memory leaks. Yeah, interesting bit of trivia: python is the world's only non-trivial program that's totally free of bugs. Pretty exciting! But seriously, python 2.4, at least, does have some pretty trivially exposed memory leaks when working with strings. A simple example

Re: generating objects of a type from a name.

2007-07-26 Thread tsuraan
I'm not sure what a visual object is, but to create an instance of an object whose name is known, you can use "eval": >>> oname = 'list' >>> obj = eval(oname)() >>> obj [] >>> type(obj) Hope that helps! On 26/07/07, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote: > I'm trying to generate visual p

Malformed big5 reading bug

2007-05-29 Thread tsuraan
Python enters some sort of infinite loop when attempting to read data from a malformed file that is big5 encoded (using the codecs library). This behaviour can be observed under Linux and FreeBSD, using Python 2.4 and 2.5. A really simple example illustrating the bug follows: Python 2.4.4 (#1, M

Re: zip files as nested modules?

2007-04-02 Thread tsuraan
and b.py has some method (let's call it d) within it. I can, from python, do: That should be c.py, of course. Is this message getting no replies because it's confusing, it's poorly worded, it's a dumb question, or is it just that nobody knows the answer? I'm stuck on this, so any suggestions

zip files as nested modules?

2007-04-01 Thread tsuraan
Supposing that I have a directory tree like so: a/ __init__.py b/ __init__.py c.py and b.py has some method (let's call it d) within it. I can, from python, do: from a.b.c import d d() And, that works. Now, suppose I want to have a zipped module under a, called b.zip. Is there any

Re: f---ing typechecking

2007-02-16 Thread tsuraan
Agreed. This would be similar to: py> 1 + 1.0 Traceback: can only add int to int. Etc. But then again, the unimaginative defense would be that it wouldn't be python if you could catentate a list and a tuple. Of course, that behaviour would be quite defensible; auto-casting int to float is _w

Re: Suitability for long-running text processing?

2007-01-08 Thread tsuraan
I remember something about it coming up in some of the discussions of free lists and better behavior in this regard in 2.5, but I don't remember the details. Under Python 2.5, my original code posting no longer exhibits the bug - upon calling del(a), python's size shrinks back to ~4 MB, which i

Re: Suitability for long-running text processing?

2007-01-08 Thread tsuraan
My first thought was that interned strings were causing the growth, but that doesn't seem to be the case. Interned strings, as of 2.3, are no longer immortal, right? The intern doc says you have to keep a reference around to the string now, anyhow. I really wish I could find that thing I read

Re: Suitability for long-running text processing?

2007-01-08 Thread tsuraan
$ python Python 2.4.4c1 (#2, Oct 11 2006, 21:51:02) [GCC 4.1.2 20060928 (prerelease) (Ubuntu 4.1.1-13ubuntu5)] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> # Python is using 2.7 MiB ... a = ['1234' for i in xrange(10 << 20)] >>> # Python is using 42.9 MiB ..

Re: Suitability for long-running text processing?

2007-01-08 Thread tsuraan
I just tried on my system (Python is using 2.9 MiB) >>> a = ['a' * (1 << 20) for i in xrange(300)] (Python is using 304.1 MiB) >>> del a (Python is using 2.9 MiB -- as before) And I didn't even need to tell the garbage collector to do its job. Some info: It looks like the big difference betwe

Re: Suitability for long-running text processing?

2007-01-08 Thread tsuraan
After reading http://www.python.org/doc/faq/general/#how-does-python-manage-memory, I tried modifying this program as below: a=[] for i in xrange(33,127): for j in xrange(33,127): for k in xrange(33,127): for l in xrange(33, 127): a.append(chr(i)+chr(j)+chr(k)+chr(l)) import sys sys

Suitability for long-running text processing?

2007-01-08 Thread tsuraan
I have a pair of python programs that parse and index files on my computer to make them searchable. The problem that I have is that they continually grow until my system is out of memory, and then things get ugly. I remember, when I was first learning python, reading that the python interpreter