iHnR
iHnR

Reputation: 495

List the variables in higher scopes

I'm trying to write a function that will list all the variables within my current python session. To my understanding I can use the 'dir()' and 'locals()' function to do this. However, when I call these from a function, they only show the variables within the scope of that function. How can I list the variables in the main function from within another function?

Upvotes: 0

Views: 43

Answers (1)

Terry Spotts
Terry Spotts

Reputation: 4075

Try the built-in globals() function: https://docs.python.org/3.7/library/functions.html?highlight=globals#globals

Upvotes: 1

Related Questions