Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #22067
| From | Thomas Rachel <nutznetz-0c1b6768-bfa9-48d5-a470-7603bd3aa915@spamschutz.glglgl.de> |
|---|---|
| Newsgroups | comp.lang.python |
| Subject | contextlib.nested deprecated |
| Date | 2012-03-23 10:56 +0100 |
| Organization | A newly installed InterNetNews server |
| Message-ID | <jkhhco$at1$1@r03.glglgl.gl> (permalink) |
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, f2):
(f1 wouldn't be closed if opening f2 fails)
I could imagine writing a context manager which moves initialization
into its __enter__:
@contextmanager
def late_init(f, *a, **k):
r = f(*a, **k)
with r as c: yield c
Am I right thinking that
with nested(late_init(open, "f1"), late_init(open, "f2")) as (f1, f2):
will suffice here to make it "clean"?
TIA,
Thomas
Back to comp.lang.python | Previous | Next | Find similar | Unroll thread
contextlib.nested deprecated Thomas Rachel <nutznetz-0c1b6768-bfa9-48d5-a470-7603bd3aa915@spamschutz.glglgl.de> - 2012-03-23 10:56 +0100
csiph-web