Python Goodies

Listing Defined Variables

dir() will give you the list of in scope variables:
globals() will give you a dictionary of global variables
locals() will give you a dictionary of local variables

To get the names:

for name in vars().keys():
print(name)
To get the values:

for value in vars().values():
print(value)

Leave a Reply