names of methods, exported functions
Michael Hoffman
cam.ac.uk at mh391.invalid
Wed Apr 27 05:45:05 EDT 2005
Mayer wrote:
> Is there a way to see at the python prompt the names of all the public
> methods of a class or the names exported by a module? I know that
> GUI-based IDEs have a nifty way of displaying these in the form of a
> drop-down list, but I'm looking for some function or method that will
> simply return a list of strings.
Modules generally do not export names[1]. You import a module and
perhaps specific names within the module. The module can specify which
names are "public" by the use of the underscore naming convention and
the magic __all__ name, which can contain a list of those names which
will be imported by default through "from module import *."
That said, dir() is the function you are looking for. If you want to
restrict to only methods on the class, and not just all attributes,
you'll have to check the type of each attribute.
--
Michael Hoffman
[1] OK, I have written modules that set a variable in __main__ using
sys.modules but other than that...
More information about the Python-list
mailing list