There are only a few functions special to module objects.
PyModule_Type
¶
此实例的
PyTypeObject
表示 Python 模块类型。暴露这给 Python 程序作为
types.ModuleType
.
PyModule_Check
(
PyObject
*p
)
¶
返回 True 若 p 是模块对象,或模块对象的子类型。
2.2 版改变: Allowed subtypes to be accepted.
PyModule_CheckExact
(
PyObject
*p
)
¶
返回 True 若
p
是模块对象,但不是子类型的
PyModule_Type
.
2.2 版新增。
PyModule_New
(
const char
*name
)
¶
返回新的模块对象采用
__name__
属性设置为
name
. Only the module’s
__doc__
and
__name__
attributes are filled in; the caller is responsible for providing a
__file__
属性。
PyModule_GetDict
(
PyObject
*module
)
¶
Return the dictionary object that implements
module
’s namespace; this object is the same as the
__dict__
attribute of the module object. This function never fails. It is recommended extensions use other
PyModule_*()
and
PyObject_*()
functions rather than directly manipulate a module’s
__dict__
.
PyModule_GetName
(
PyObject
*module
)
¶
返回
module
’s
__name__
value. If the module does not provide one, or if it is not a string,
SystemError
is raised and
NULL
被返回。
PyModule_GetFilename
(
PyObject
*module
)
¶
Return the name of the file from which
module
was loaded using
module
’s
__file__
attribute. If this is not defined, or if it is not a string, raise
SystemError
并返回
NULL
.
PyModule_AddObject
(
PyObject
*module
, const char
*name
,
PyObject
*value
)
¶
将对象添加到
module
as
name
。这是可以从模块初始化函数中使用的方便函数。这窃取引用对于
value
。返回
-1
当出错时,
0
当成功时。
2.0 版新增。
PyModule_AddIntConstant
(
PyObject
*module
, const char
*name
, long
value
)
¶
将整数常量添加到
module
as
name
。这是可以从模块初始化函数中使用的方便函数。返回
-1
当出错时,
0
当成功时。
2.0 版新增。
PyModule_AddStringConstant
(
PyObject
*module
, const char
*name
, const char
*value
)
¶
将字符串常量添加到
module
as
name
。这是可以从模块初始化函数中使用的方便函数。字符串
value
must be null-terminated. Return
-1
当出错时,
0
当成功时。
2.0 版新增。