7.5.5. Module Objects

There are only a few functions special to module objects.

PyTypeObject PyModule_Type
int PyModule_Check(PyObject *p)

Return true if p is a module object, or a subtype of a module object.

Changed in version 2.2: Allowed subtypes to be accepted.

int PyModule_CheckExact(PyObject *p)

Return true if p is a module object, but not a subtype of PyModule_Type.

New in version 2.2.

PyObject* PyModule_New(const char *name)
PyObject* PyModule_GetDict(PyObject *module)
char* PyModule_GetName(PyObject *module)
char* PyModule_GetFilename(PyObject *module)
int PyModule_AddObject(PyObject *module, const char *name, PyObject *value)

Add an object to module as name. This is a convenience function which can be used from the module’s initialization function. This steals a reference to value. Return -1 on error, 0 on success.

New in version 2.0.

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

Add an integer constant to module as name. This convenience function can be used from the module’s initialization function. Return -1 on error, 0 on success.

New in version 2.0.

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

Add a string constant to module as name. This convenience function can be used from the module’s initialization function. The string value must be null-terminated. Return -1 on error, 0 on success.

New in version 2.0.

int PyModule_AddIntMacro(PyObject *module, macro)

Add an int constant to module. The name and the value are taken from macro. For example PyModule_AddIntMacro(module, AF_INET) adds the int constant AF_INET with the value of AF_INET to module. Return -1 on error, 0 on success.

New in version 2.6.

int PyModule_AddStringMacro(PyObject *module, macro)
Add a string constant to module.

New in version 2.6.