For instance, when I run in a python's top-level program file, I can use __name__ to get the string "__main__", but how do I get the current list of toplevel global variables?
Asked
Active
Viewed 458 times
1 Answers
2
You might want to have a look at this thread: Viewing all defined variables
Quoting the best answer:
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
-
1In the future, please vote to close as a duplicate, don't copy and paste another answer! – juanpa.arrivillaga May 08 '19 at 02:44