How to get self reference from within a module?
gherron at digipen.edu
Tue Jan 23 00:46:21 CET 2007
Lavoie Érick wrote:
> i would like to now how to get a self reference from within a
> module. The goal is to be able to generate a list of all declared
> function within the module.
I think this is what you're asking for:
If you import a module, say
then sys is an object you can refer to. Like man objects in Python, you
can do some ,so called, introspection. For instance you can ask for the
list of all the attributes (function, classes, and such) with the vars
That yields a dictionary of all objects in the module, from which you
can access and iterate through the names (keys) and values.
If you want more capabilities, you should also look at the inspect module.
Gary Herron, PhD.
Department of Computer Science
DigiPen Institute of Technology
More information about the Python-list