How to know which variables are defined?

0

Is there a function that returns the name of the variables defined in a Python instance? Something similar to the command who in MatLab that returns the names of the variables defined by the user.

    
asked by anonymous 04.08.2017 / 18:17

2 answers

3

According to Stack in English would look like this:

  • dir() returns a list of variables in the scope
  • globals() returns a dictionary of global variables
  • locals() returns a dictionary of local variables
04.08.2017 / 18:22
2

You have, I do not know if you would like it:

  • dir() lists the variables of the specific scope
  • globals() returns global variables (which should be avoided)
  • locals() returns function variables
04.08.2017 / 18:21