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
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:
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
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
> 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
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
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
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):
>
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&