Re: Destruction of generator objects

2007-08-11 Thread Kay Schluehr
On Aug 11, 2:50 pm, Stefan Bellon <[EMAIL PROTECTED]> wrote: > So why is the destructor not called when the generator is even > explicitly 'del'ed? Does somebody else still hold a reference on it? You ( we ) have produced a reference cycle. In that case __del__ doesn't work properly ( according t

Re: Destruction of generator objects

2007-08-11 Thread Stefan Bellon
On Sat, 11 Aug, Marc 'BlackJack' Rintsch wrote: > On Sat, 11 Aug 2007 14:50:33 +0200, Stefan Bellon wrote: > > But then, even when terminating the interpreter, __del__ is not > > called. > > Because that is not guaranteed by the language reference. The reason > why it is a bad idea to depend on

Re: Destruction of generator objects

2007-08-11 Thread Marc 'BlackJack' Rintsch
On Sat, 11 Aug 2007 14:50:33 +0200, Stefan Bellon wrote: > On Sat, 11 Aug, Kay Schluehr wrote: > >> But why shall the destructor be called? Your example does not indicate >> that a ListGenerator object is somewhere destroyed neither explicitely >> using del nor implicitely by destroying the scope

Re: Destruction of generator objects

2007-08-11 Thread Stefan Bellon
On Sat, 11 Aug, Kay Schluehr wrote: > But why shall the destructor be called? Your example does not indicate > that a ListGenerator object is somewhere destroyed neither explicitely > using del nor implicitely by destroying the scope it is living in. After having constructed the list itself, the

Re: Destruction of generator objects

2007-08-11 Thread Kay Schluehr
On Aug 11, 2:00 pm, Stefan Bellon <[EMAIL PROTECTED]> wrote: > On Sat, 11 Aug, Kay Schluehr wrote: > > Honestly, I'd recommend wrapping the generator into a function object, > > create the resource on construction ( or pass it ) and destroy it > > implementing __del__. > > > def gen_value(self): >

Re: Destruction of generator objects

2007-08-11 Thread Stefan Bellon
On Sat, 11 Aug, Kay Schluehr wrote: > Honestly, I'd recommend wrapping the generator into a function object, > create the resource on construction ( or pass it ) and destroy it > implementing __del__. > > def gen_value(self): > while True: > yield self.iter.next() > > class Generator

Re: Destruction of generator objects

2007-08-11 Thread Kay Schluehr
On Aug 11, 12:16 pm, Stefan Bellon <[EMAIL PROTECTED]> wrote: > On Sat, 11 Aug, Kay Schluehr wrote: > > On Aug 9, 1:14 am, Stefan Bellon <[EMAIL PROTECTED]> wrote: > > > Sorry, I forgot to mention that I am forced to using Python 2.4. > > It doesn't matter. You can use try...finally as well in Pyth

Re: Destruction of generator objects

2007-08-11 Thread Stefan Bellon
On Sat, 11 Aug, Kay Schluehr wrote: > On Aug 9, 1:14 am, Stefan Bellon <[EMAIL PROTECTED]> wrote: > > Sorry, I forgot to mention that I am forced to using Python 2.4. > It doesn't matter. You can use try...finally as well in Python 2.4. > It's just not possible to use except and finally clauses i

Re: Destruction of generator objects

2007-08-11 Thread Kay Schluehr
On Aug 9, 1:14 am, Stefan Bellon <[EMAIL PROTECTED]> wrote: > On Wed, 08 Aug, MRAB wrote: > > Simple! :-) > > Sorry, I forgot to mention that I am forced to using Python 2.4. > > -- > Stefan Bellon It doesn't matter. You can use try...finally as well in Python 2.4. It's just not possible to use ex

Re: Destruction of generator objects

2007-08-10 Thread Alex Martelli
Stefan Bellon <[EMAIL PROTECTED]> wrote: > On Thu, 09 Aug, Graham Dumpleton wrote: > > > result = application(environ, start_response) > > try: > > for data in result: > > if data:# don't send headers until body appears > > write(data) > > i

Re: Destruction of generator objects

2007-08-08 Thread Stefan Bellon
On Thu, 09 Aug, Graham Dumpleton wrote: > result = application(environ, start_response) > try: > for data in result: > if data:# don't send headers until body appears > write(data) > if not headers_sent: > write('') # send heade

Re: Destruction of generator objects

2007-08-08 Thread Graham Dumpleton
On Aug 8, 8:28 am, Stefan Bellon <[EMAIL PROTECTED]> wrote: > Hi all, > > I'm generating a binding from Python to C using SWIG. On the C side I > have iterators over some data structures. On the Python side I > currently use code like the following: > > def get_data(obj): > result = []

Re: Destruction of generator objects

2007-08-08 Thread Stefan Bellon
On Wed, 08 Aug, MRAB wrote: > Simple! :-) Sorry, I forgot to mention that I am forced to using Python 2.4. -- Stefan Bellon -- http://mail.python.org/mailman/listinfo/python-list

Re: Destruction of generator objects

2007-08-08 Thread MRAB
On Aug 7, 11:28 pm, Stefan Bellon <[EMAIL PROTECTED]> wrote: > Hi all, > > I'm generating a binding from Python to C using SWIG. On the C side I > have iterators over some data structures. On the Python side I > currently use code like the following: > > def get_data(obj): > result = []

Destruction of generator objects

2007-08-07 Thread Stefan Bellon
Hi all, I'm generating a binding from Python to C using SWIG. On the C side I have iterators over some data structures. On the Python side I currently use code like the following: def get_data(obj): result = [] iter = make_iter(obj) while more(iter): item =