Basically instead:
context1.a context1.b() context2.a context2.b()
I want to write:
with context1(): a b() with context2(): a b()
Ideally, I would do this by selecting the "locals dictionary" with an object with a custom __get__ , but I don't know how to do this or if it's possible.
Why ?: I implemented a kind of predicate dispatch (for fun), but I can only use explicitly naming the context every time: context.a() + context.b() annoying to write all the time.
source share