Is there a command to see all the variables I've defined?
Example:
toto = 1
tutu = 2
tata = 3
Suppose I remember I have toto, but I forget the others' declarations (tutu and tata). Is there a command to print all my variables?
Is there a command to see all the variables I've defined?
Example:
toto = 1
tutu = 2
tata = 3
Suppose I remember I have toto, but I forget the others' declarations (tutu and tata). Is there a command to print all my variables?
>>> toto = 1
>>> tutu = 2
>>> tata = 3
>>> from pprint import pprint
>>> pprint(globals())
{'__builtins__': <module 'builtins' (built-in)>,
'__doc__': None,
'__loader__': <class '_frozen_importlib.BuiltinImporter'>,
'__name__': '__main__',
'__package__': None,
'__spec__': None,
'pprint': <function pprint at 0x7f59687bdc80>,
'tata': 3,
'toto': 1,
'tutu': 2}
>>> help(globals)
Help on built-in function globals in module builtins:
globals()
Return the dictionary containing the current scope's global variables.
NOTE: Updates to this dictionary *will* affect name lookups in the current
global scope and vice-versa.
(END)
You may use globals()
to view all the variables/functions accessible in your current file as:
>>> toto = 1
>>> tutu = 2
>>> tata = 3
>>> globals()
{
'__builtins__': <module '__builtin__' (built-in)>,
'tata': 3,
'toto': 1,
'__package__': None,
'__name__': '__main__',
'tutu': 2,
'__doc__': None
}