Last active
August 29, 2015 14:04
-
-
Save felipecruz/09c6bf530aad32368bab to your computer and use it in GitHub Desktop.
Bind in outer scope variables from a dict
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
def bind_local_names(params): | |
'''create outer scope vars from a dict''' | |
import sys | |
for k, v in params.items(): | |
sys._getframe(1).f_locals[k] = v | |
params = dict(b='test', c=10) | |
bind_local_names(params) | |
assert b == 'test' | |
assert c == 10 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment