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

2019-07-12 Thread Serhiy Storchaka
12.07.19 16:27, haael пише: Could we add __enter__ and __exit__ to the tuple type? Look at the following code: a = open('a.tmp', 'w') b = open('b.tmp', 'w') with (a, b) as (af, bf):     af.write("1")     bf.write("2") Even better example: with tuple(open(str(_n) + '.tmp', 'w') for _n

[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 rec

[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 have

[Python-ideas] Administrivia update: moderating subscriptions, and (some) new subscribers

2019-07-12 Thread C. Titus Brown
Hi all, in response to some of the recent spam, Brett and I have decided to put in place moderation for subscriptions, as well as moderating some of the newly subscribed accounts. We feel that moderation of all messages is too much, given the (occasional) high volume of python-ideas, and its u

[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

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

2019-07-12 Thread Anders Hovmöller
You should expand a bit. How is that better than with open(..) as a, open(..) as b: ? > On 12 Jul 2019, at 15:27, haael wrote: > > > Could we add __enter__ and __exit__ to the tuple type? > > Look at the following code: > > > a = open('a.tmp', 'w') > b = open('b.tmp', 'w') > > with (a, b

[Python-ideas] Make tuple a context manager

2019-07-12 Thread haael
Could we add __enter__ and __exit__ to the tuple type? Look at the following code: a = open('a.tmp', 'w') b = open('b.tmp', 'w') with (a, b) as (af, bf): af.write("1") bf.write("2") Even better example: with tuple(open(str(_n) + '.tmp', 'w') for _n in range(1000)) as f: for