vars(), globals() and locals()
Return the namespace dictionaries of an object, the module, or the current function.
Intermediate
vars(obj) # obj.__dict__
globals()["x"] # module-level variable lookup
Useful for debugging and metaprogramming; avoid writing to them in normal code.
Spotted a mistake or want to add detail? Suggest an improvement — Content Contributors' edits are reviewed by editors before they go live.
Discussion (0)
Sign in or join free to ask questions and discuss this topic.