[Python-ideas] Re: statement-scoped context managers

2020-02-08 Thread Random832
On Sat, Feb 8, 2020, at 18:06, Random832 wrote: > My own expectation, for what it's worth, would be something like [snip] After thinking about it some more, I realized that my idea can basically be translated to "all with-expressions in the statement get added to an implicit ExitStack, which is

[Python-ideas] Re: statement-scoped context managers

2020-02-08 Thread Random832
On Sat, Feb 8, 2020, at 17:14, Soni L. wrote: > On 2020-02-08 6:53 p.m., Bruce Leban wrote: > > On Sat, Feb 8, 2020 at 1:22 PM Chris Angelico wrote: > >> Exactly how much code would be wrapped in the 'with' block? > > > > This is an intriguing idea, and in the example it's fairly easy to wrap

[Python-ideas] Re: statement-scoped context managers

2020-02-08 Thread Soni L.
On 2020-02-08 6:53 p.m., Bruce Leban wrote: On Sat, Feb 8, 2020 at 1:22 PM Chris Angelico > wrote: On Sun, Feb 9, 2020 at 8:04 AM Random832 mailto:random...@fastmail.com>> wrote: > > On Fri, Feb 7, 2020, at 13:03, Todd wrote: > What if you could writ

[Python-ideas] Re: statement-scoped context managers (was: Re: Pickle to/from filename or path)

2020-02-08 Thread Bruce Leban
On Sat, Feb 8, 2020 at 1:22 PM Chris Angelico wrote: > On Sun, Feb 9, 2020 at 8:04 AM Random832 wrote: > > > > On Fri, Feb 7, 2020, at 13:03, Todd wrote: > > > What if you could write pickle.dump(myobj, with open('myfile.p', 'wb'))? > > > > Or other similar examples such as (with open('myfile'))

[Python-ideas] Re: statement-scoped context managers (was: Re: Pickle to/from filename or path)

2020-02-08 Thread Andrew Barnert via Python-ideas
On Feb 8, 2020, at 13:25, Chris Angelico wrote: > > On Sun, Feb 9, 2020 at 8:04 AM Random832 wrote: >> >>> On Fri, Feb 7, 2020, at 13:03, Todd wrote: >>> approaches like opening within the dump or load, which the wiki >>> still recommends [1]. >>> >>> So something like: >>> >>> with open('my

[Python-ideas] Re: statement-scoped context managers (was: Re: Pickle to/from filename or path)

2020-02-08 Thread Chris Angelico
On Sun, Feb 9, 2020 at 8:04 AM Random832 wrote: > > On Fri, Feb 7, 2020, at 13:03, Todd wrote: > > approaches like opening within the dump or load, which the wiki > > still recommends [1]. > > > > So something like: > > > > with open('myfile.p', 'wb') as f: > > pickle.dump(myobj, f) > > > > Would