Skip to content

Instantly share code, notes, and snippets.

@hayd
Created July 19, 2012 11:55
Show Gist options
  • Save hayd/3143331 to your computer and use it in GitHub Desktop.
Save hayd/3143331 to your computer and use it in GitHub Desktop.
grabbing f's environment from within g
def f():
a = 2
b = 1
def g():
#a = 3
b = 2
c = 1
print dict(globals(), **locals()) #prints a=1, but we want a=2 (from f)
g()
a = 1
f()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment