Skip to content

Instantly share code, notes, and snippets.

@vedgar
Created January 30, 2016 09:17
Show Gist options
  • Save vedgar/d6d20934eb7c96c3d13c to your computer and use it in GitHub Desktop.
Save vedgar/d6d20934eb7c96c3d13c to your computer and use it in GitHub Desktop.
Shared context
# First example: using an explicit namespace as a shared context
from types import SimpleNamespace as Context
def f():
shared = Context(x=5)
def g():
shared.x = 7
g()
# Second example: using the function itself as a shared context.
def outer():
outer.x = 5
def inner():
outer.x = 7
inner()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment