0

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?

Kys3r
  • 223
  • 3
  • 6

2 Answers2

2
>>> 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)
Sharad
  • 9,282
  • 3
  • 19
  • 36
0

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
}
Moinuddin Quadri
  • 46,825
  • 13
  • 96
  • 126