Re: Re: Context manager able to write to the caller's namespace

2018-01-18 Thread Chris Angelico
On Fri, Jan 19, 2018 at 5:00 PM, wrote: > Hello, > > Thank you for your mail. I will answer as fast as possible. If you're going to subscribe to a mailing list, PLEASE disable your autoresponder. Otherwise, messages like this will get marked as Spam, and your legit mail will end up getting tarr

Re: Context manager able to write to the caller's namespace

2018-01-18 Thread Steven D'Aprano
On Fri, 19 Jan 2018 16:49:49 +1100, Chris Angelico wrote: [...] > 1) Context manager was called from global scope, and needs access to > globals() or locals() as returned in the caller A! /facepalm Of course the caller can just pass locals() to the context manager. Why didn't I think o

Re: Context manager able to write to the caller's namespace

2018-01-18 Thread Chris Angelico
On Fri, Jan 19, 2018 at 3:48 PM, Steven D'Aprano wrote: > I want to define a context manager in one module: > > # a.py > def CM: > def __enter__(self): > return self > def __exit__(self, *args): > pass > > > Then call it from another module: > > # b.py > import a > with a.C

Context manager able to write to the caller's namespace

2018-01-18 Thread Steven D'Aprano
I'm looking for a solution, or at least hints, to this problem. I want to define a context manager in one module: # a.py def CM: def __enter__(self): return self def __exit__(self, *args): pass Then call it from another module: # b.py import a with a.CM() as spam: