The .__dict__ attribute of an object stores its namespace. This includes modules. There is a 'builtin' module called __main__ that stores the main namespace.
Use globals() and locals() to see what is in the respective dictionaries.
The inspect library module is used do access regularly needed items. The Pythonic term is introspection and python is quite good at it.
For example, a function can look at the arguments that it was called with in some very cool ways, but this a very advanced topic.
The .__dict__ attribute of an object stores its namespace. This includes modules. There is a 'builtin' module called __main__ that stores the main namespace.
Use globals() and locals() to see what is in the respective dictionaries.
The inspect library module is used do access regularly needed items. The Pythonic term is introspection and python is quite good at it.
For example, a function can look at the arguments that it was called with in some very cool ways, but this a very advanced topic.
This is pretty cool:
>>> help(vars)
Help on built-in function vars in module __builtin__:
vars(...)
vars([object]) -> dictionary
Without arguments, equivalent to locals().
With an argument, equivalent to object.__dict__ .
Comment