Created
January 30, 2016 09:17
-
-
Save vedgar/d6d20934eb7c96c3d13c to your computer and use it in GitHub Desktop.
Shared context
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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