Module Objects¶
There are only a few functions special to module objects.
- 
PyTypeObject PyModule_Type¶
 This instance of
PyTypeObjectrepresents the Python module type. This is exposed to Python programs astypes.ModuleType.
- 
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)¶
 Return a new module object with the
__name__attribute set to name. Only the module’s__doc__and__name__attributes are filled in; the caller is responsible for providing a__file__attribute.
- 
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 otherPyModule_*()andPyObject_*()functions rather than directly manipulate a module’s__dict__.
- 
char *PyModule_GetName(PyObject *module)¶
 Return module’s
__name__value. If the module does not provide one, or if it is not a string,SystemErroris raised and NULL is returned.
- 
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, raiseSystemErrorand return NULL.
- 
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
-1on error,0on 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
-1on error,0on 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
-1on error,0on success.New in version 2.0.
