contextlib.nested deprecated

2012-03-23 Thread Thomas Rachel
Hi, I understand why contextlib.nested is deprecated. But if I write a program for an old python version w/o the multiple form of with, I have (nearly) no other choice. In order to avoid the following construct to fail: with nested(open("f1"), open("f2")) as (f1, f

Re: contextlib.nested()

2008-11-07 Thread brasse
On Nov 7, 10:33 am, Peter Otten <[EMAIL PROTECTED]> wrote: > brasse wrote: > > with nested(Foo('a'), Foo('b', True)) as (a, b): > >     print a.tag > >     print b.tag > > If been watching this thread for a while, and I think that your problems > will go away if you write actual nested with-blocks:

Re: contextlib.nested()

2008-11-07 Thread Peter Otten
brasse wrote: > with nested(Foo('a'), Foo('b', True)) as (a, b): >     print a.tag >     print b.tag If been watching this thread for a while, and I think that your problems will go away if you write actual nested with-blocks: with Foo("a") as a: with Foo("b") as b: print a.tag

Re: contextlib.nested()

2008-11-07 Thread brasse
On Nov 6, 5:45 pm, "Diez B. Roggisch" <[EMAIL PROTECTED]> wrote: > > If you had a class that wanted to acquire some external resources that > > must be released at some point, how would you rewrite the code from my > > example? > > If you *can*, use a context. Use __enter__ and __exit__. Try really

Re: contextlib.nested()

2008-11-06 Thread Diez B. Roggisch
> Diez, Robert, > > OK. The practice of "going live" or doing non-trivial initialization > in __enter__ is new to me. I'm new to Python with a C++ background, so > that shouldn't be a surprise. :-) > > Ideally I would like to put all initialization in __init__ since then > I would be able to use

Re: contextlib.nested()

2008-11-06 Thread brasse
On Nov 6, 11:43 am, Robert Lehmann <[EMAIL PROTECTED]> wrote: > On Thu, 06 Nov 2008 01:02:34 -0800, brasse wrote: > > Hello! > > > I have been running in to some problems when using contextlib.nested(). > > My problem arises when using code similar to this

Re: contextlib.nested()

2008-11-06 Thread Robert Lehmann
On Thu, 06 Nov 2008 01:02:34 -0800, brasse wrote: > Hello! > > I have been running in to some problems when using contextlib.nested(). > My problem arises when using code similar to this: > > from __future__ import with_statement > > from contextlib import nest

Re: contextlib.nested()

2008-11-06 Thread Diez B. Roggisch
brasse wrote: > Hello! > > I have been running in to some problems when using > contextlib.nested(). My problem arises when using code similar to > this: > > from __future__ import with_statement > > from contextlib import nested > > class Foo(object): >

contextlib.nested()

2008-11-06 Thread brasse
Hello! I have been running in to some problems when using contextlib.nested(). My problem arises when using code similar to this: from __future__ import with_statement from contextlib import nested class Foo(object): def __init__(self, tag, fail=False): print 'ctor&