Kys3r Kys3r - 1 month ago 6
Python Question

How to see all variable on interpreter python? (what is the command?)

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?

Answer

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
}