32.9.pyclbr — Python class browser support¶
Source code:Lib/pyclbr.py
Thepyclbr module can be used to determine some limited informationabout the classes, methods and top-level functions defined in a module. Theinformation provided is sufficient to implement a traditional three-paneclass browser. The information is extracted from the source code ratherthan by importing the module, so this module is safe to use with untrustedcode. This restriction makes it impossible to use this module with modulesnot implemented in Python, including all standard and optional extensionmodules.
pyclbr.readmodule(module,path=None)¶Read a module and return a dictionary mapping class names to classdescriptor objects. The parametermodule should be the name of amodule as a string; it may be the name of a module within a package. Thepath parameter should be a sequence, and is used to augment the valueof
sys.path, which is used to locate module source code.
pyclbr.readmodule_ex(module,path=None)¶Like
readmodule(), but the returned dictionary, in addition tomapping class names to class descriptor objects, also maps top-levelfunction names to function descriptor objects. Moreover, if the modulebeing read is a package, the key'__path__'in the returneddictionary has as its value a list which contains the package searchpath.
32.9.1.Class Objects¶
TheClass objects used as values in the dictionary returned byreadmodule() andreadmodule_ex() provide the following dataattributes:
Class.module¶The name of the module defining the class described by the class descriptor.
Class.name¶The name of the class.
Class.super¶A list of
Classobjects which describe the immediate baseclasses of the class being described. Classes which are named assuperclasses but which are not discoverable byreadmodule()arelisted as a string with the class name instead of asClassobjects.
Class.methods¶A dictionary mapping method names to line numbers.
Class.file¶Name of the file containing the
classstatement defining the class.
32.9.2.Function Objects¶
TheFunction objects used as values in the dictionary returned byreadmodule_ex() provide the following attributes:
Function.module¶The name of the module defining the function described by the functiondescriptor.
Function.name¶The name of the function.
Function.file¶Name of the file containing the
defstatement defining the function.
