Context module¶
Provide simple way to passing context between method calls
Context usage:
ctx = Context(value=1)
with ctx as c:
call_a_function(ctx=c)
A bit more readable version:
ctx = Context(value=1)
with ctx.copywith(value=2, new_value=3) as c:
call_a_function(ctx=c)
-
class
context.base.
Context
(*args, **kwargs)[source]¶ Context provide basic functionality managing through calls. Can be used as a context manager.
Predefined items: global and local
ctx = Context(value=1, global={'value': 1}, local={'value': 1}) with ctx.copywith(value=2, new_value=3) as c: ctx['global']['value'] # contains 1 ctx['local'] # It's an empty dict call_a_function(ctx=c)