globals() v.s. locals() v.s. vars()
-
globals()
always returns the dictionary of the module namespace -
locals()
always returns a dictionary of the current namespace -
vars()
returns either a dictionary of the current namespace (if called with no argument) or the dictionary of the argument.
相关栗子阅读: python globals
参考
- stackoverflow 上的问题:What's the difference between globals(), locals(), and vars()?
网友评论