Skip to content

Instantly share code, notes, and snippets.

@mpettis
Last active September 19, 2021 21:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mpettis/7c897c14588f0fe256c68faee7227552 to your computer and use it in GitHub Desktop.
Save mpettis/7c897c14588f0fe256c68faee7227552 to your computer and use it in GitHub Desktop.
Local variable scoping in Python. Keeps from polluting namespaces.
# https://pypi.org/project/scoping/
# See also: https://github.com/bskinn/tempvars
from scoping import scoping
aofl = [{"a":1, "b":2}, {"a":3, "b":4}]
with scoping():
for d in aofl:
x = d
scoping.keep('x')
print(d)
print(x)
print('d' in dir())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment