模块对象

There are only a few functions special to module objects.

PyTypeObject PyModule_Type

此实例的 PyTypeObject 表示 Python 模块类型。暴露这给 Python 程序作为 types.ModuleType .

int PyModule_Check ( PyObject *p )

返回 True 若 p 是模块对象,或模块对象的子类型。

2.2 版改变: Allowed subtypes to be accepted.

int PyModule_CheckExact ( PyObject *p )

返回 True 若 p 是模块对象,但不是子类型的 PyModule_Type .

2.2 版新增。

PyObject * 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__ 属性。

PyObject * 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__ .

char* 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 被返回。

char* 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 .

int PyModule_AddObject ( PyObject *module , const char *name , PyObject *value )

将对象添加到 module as name 。这是可以从模块初始化函数中使用的方便函数。这窃取引用对于 value 。返回 -1 当出错时, 0 当成功时。

2.0 版新增。

int PyModule_AddIntConstant ( PyObject *module , const char *name , long value )

将整数常量添加到 module as name 。这是可以从模块初始化函数中使用的方便函数。返回 -1 当出错时, 0 当成功时。

2.0 版新增。

int PyModule_AddStringConstant ( PyObject *module , const char *name , const char *value )

将字符串常量添加到 module as name 。这是可以从模块初始化函数中使用的方便函数。字符串 value must be null-terminated. Return -1 当出错时, 0 当成功时。

2.0 版新增。

int PyModule_AddIntMacro ( PyObject *module , macro )

将整数常量添加到 module 。名称和值取自 macro 。例如 PyModule_AddIntMacro(module, AF_INET) 添加 int 常量 AF_INET 采用值的 AF_INET to module 。返回 -1 当出错时, 0 当成功时。

2.6 版新增。

int PyModule_AddStringMacro ( PyObject *module , macro )

将字符串常量添加到 module .

2.6 版新增。

上一话题

文件对象

下一话题

迭代器对象

本页