[Python-ideas] Re: Make tuple a context manager

2019-07-14 Thread Andrew Barnert via Python-ideas
On Jul 12, 2019, at 06:27, haael wrote: > > with tuple(open(str(_n) + '.tmp', 'w') for _n in range(1000)) as f: >for n, fn in enumerate(f): >f.write(str(n)) Another thought here: There may be good examples for what you want—although I suspect every such example will be much better

[Python-ideas] Re: Make tuple a context manager

2019-07-14 Thread Serhiy Storchaka
13.07.19 23:25, Kyle Stanley пише: Serhiy Storchaka wrote: Are your aware of contextlib.nested()? And why it was deprecated and removed? Was contextlib.nested() removed primarily due to to the inconsistencies mentioned in https://bugs.python.org/issue5251 or was it something else? Yes, it

[Python-ideas] Re: Make tuple a context manager

2019-07-13 Thread Kyle Stanley
Serhiy Storchaka wrote: > Are your aware of contextlib.nested()? And why it was deprecated and > removed? Was contextlib.nested() removed primarily due to to the inconsistencies mentioned in https://bugs.python.org/issue5251 or was it something else?

[Python-ideas] Re: Make tuple a context manager

2019-07-12 Thread Andrew Barnert via Python-ideas
On Friday, July 12, 2019, 07:48:52 AM PDT, Joao S. O. Bueno wrote: > Modifying the fundamental tuples for doing that is certainly overkill -  > but maybe a context-helper function in contextlib that would proper handle > all the > corner cases of some code as I've pasted now at: > Python

[Python-ideas] Re: Make tuple a context manager

2019-07-12 Thread Joao S. O. Bueno
Modifying the fundamental tuples for doing that is certainly overkill - but maybe a context-helper function in contextlib that would proper handle all the corner cases of some code as I've pasted now at: https://gist.github.com/jsbueno/53c059380be042e2878c08b5c10f36bf (the link above actually

[Python-ideas] Re: Make tuple a context manager

2019-07-12 Thread Andrew Barnert via Python-ideas
On Jul 12, 2019, at 06:27, haael wrote: > > Tuple as context manager would invoke __enter__ for each of its elements and > return a tuple of the results. > > On exit, the __exit__ method would be invoked for every element. > > We could even generalize it to every kind of iterable. So instead