Skip to content

Instantly share code, notes, and snippets.

@badbye
Created January 6, 2017 06:25
Show Gist options
  • Select an option

  • Save badbye/e1226fa172faf85a863ec5783a71adbf to your computer and use it in GitHub Desktop.

Select an option

Save badbye/e1226fa172faf85a863ec5783a71adbf to your computer and use it in GitHub Desktop.
how `local()` works?
>>> def f():
... a = 1
... locals()['a'] = 123
... print locals()
...
>>> f()
{'a': 1}
>>> def f():
... locals()['a'] = 123
... print locals()
...
>>> f()
{'a': 123}
>>> def f():
... a = 1
... locals()['b'] = 123
... print locals()
...
>>> f()
{'a': 1, 'b': 123}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment