pyclbr
— Python 模块浏览支持
¶
源代码: Lib/pyclbr.py
The
pyclbr
模块提供 python 编码模块定义的有关函数、类及方法的有限信息。这些信息足以实现模块浏览器。信息是从 Python 源代码提取的,而不是通过导入模块,因此本模块可以安全地用于不可信代码。此限定使之不可能将本模块用于未在 Python 中实现的模块,包括所有标准和可选扩展模块。
- pyclbr. readmodule ( 模块 , path = None ) ¶
-
Return a dictionary mapping module-level class names to class descriptors. If possible, descriptors for imported base classes are included. Parameter 模块 is a string with the name of the module to read; it may be the name of a module within a package. If given, path is a sequence of directory paths prepended to
sys.path, which is used to locate the module source code.This function is the original interface and is only kept for back compatibility. It returns a filtered version of the following.
- pyclbr. readmodule_ex ( 模块 , path = None ) ¶
-
Return a dictionary-based tree containing a function or class descriptors for each function and class defined in the module with a
deforclassstatement. The returned dictionary maps module-level function and class names to their descriptors. Nested objects are entered into the children dictionary of their parent. As with readmodule, 模块 names the module to be read and path is prepended to sys.path. If the module being read is a package, the returned dictionary has a key'__path__'whose value is a list containing the package search path.
Added in version 3.7: Descriptors for nested definitions. They are accessed through the new children attribute. Each has a new parent attribute.
The descriptors returned by these functions are instances of Function and Class classes. Users are not expected to create instances of these classes.
函数对象 ¶
- class pyclbr. 函数 ¶
-
类
Functioninstances describe functions defined by def statements. They have the following attributes:- file ¶
-
Name of the file in which the function is defined.
- 模块 ¶
-
描述函数定义的模块名称。
- 名称 ¶
-
函数的名称。
- lineno ¶
-
The line number in the file where the definition starts.
- parent ¶
-
For top-level functions,
None. For nested functions, the parent.3.7 版添加。