<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <html> <head> <link rel="STYLESHEET" href="api.css" type='text/css' /> <link rel="SHORTCUT ICON" href="../icons/pyfav.gif" /> <link rel='start' href='../index.html' title='Python Documentation Index' /> <link rel="first" href="api.html" title='Python/C API Reference Manual' /> <link rel='contents' href='contents.html' title="Contents" /> <link rel='index' href='genindex.html' title='Index' /> <link rel='last' href='about.html' title='About this document...' /> <link rel='help' href='about.html' title='About this document...' /> <LINK rel="next" href="iterator-objects.html"> <LINK rel="prev" href="method-objects.html"> <LINK rel="parent" href="otherObjects.html"> <LINK rel="next" href="iterator-objects.html"> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <meta name='aesop' content='information' /> <META name="description" content="Module Objects "> <META name="keywords" content="api"> <META name="resource-type" content="document"> <META name="distribution" content="global"> <title>7.5.4 Module Objects </title> </head> <body> <DIV CLASS="navigation"> <div id='top-navigation-panel'> <table align="center" width="100%" cellpadding="0" cellspacing="2"> <tr> <td class='online-navigation'><a rel="prev" title="7.5.3 Method Objects" href="method-objects.html"><img src='../icons/previous.png' border='0' height='32' alt='Previous Page' width='32' /></A></td> <td class='online-navigation'><a rel="parent" title="7.5 Other Objects" href="otherObjects.html"><img src='../icons/up.png' border='0' height='32' alt='Up One Level' width='32' /></A></td> <td class='online-navigation'><a rel="next" title="7.5.5 Iterator Objects" href="iterator-objects.html"><img src='../icons/next.png' border='0' height='32' alt='Next Page' width='32' /></A></td> <td align="center" width="100%">Python/C API Reference Manual</td> <td class='online-navigation'><a rel="contents" title="Table of Contents" href="contents.html"><img src='../icons/contents.png' border='0' height='32' alt='Contents' width='32' /></A></td> <td class='online-navigation'><img src='../icons/blank.png' border='0' height='32' alt='' width='32' /></td> <td class='online-navigation'><a rel="index" title="Index" href="genindex.html"><img src='../icons/index.png' border='0' height='32' alt='Index' width='32' /></A></td> </tr></table> <div class='online-navigation'> <b class="navlabel">Previous:</b> <a class="sectref" rel="prev" href="method-objects.html">7.5.3 Method Objects</A> <b class="navlabel">Up:</b> <a class="sectref" rel="parent" href="otherObjects.html">7.5 Other Objects</A> <b class="navlabel">Next:</b> <a class="sectref" rel="next" href="iterator-objects.html">7.5.5 Iterator Objects</A> </div> <hr /></div> </DIV> <!--End of Navigation Panel--> <H2><A NAME="SECTION009540000000000000000"><!--x--></A><A NAME="moduleObjects"><!--z--></A> <BR> 7.5.4 Module Objects </H2> <P> <a id='l2h-609'><!--x--></a>There are only a few functions special to module objects. <P> <dl><dt>PyTypeObject <b><tt id='l2h-610' class="cdata">PyModule_Type</tt></b></dt> <dd> This instance of <tt class="ctype">PyTypeObject</tt> represents the Python module type. This is exposed to Python programs as <code>types.ModuleType</code>. <a id='l2h-612'><!--x--></a></dd></dl> <P> <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"><td><nobr>int <b><tt id='l2h-613' class="cfunction">PyModule_Check</tt></b>(</nobr></td><td>PyObject *<var>p</var>)</td></tr></table></dt> <dd> Returns true if <var>p</var> is a module object, or a subtype of a module object. <span class="versionnote">Changed in version 2.2: Allowed subtypes to be accepted.</span> </dd></dl> <P> <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"><td><nobr>int <b><tt id='l2h-614' class="cfunction">PyModule_CheckExact</tt></b>(</nobr></td><td>PyObject *<var>p</var>)</td></tr></table></dt> <dd> Returns true if <var>p</var> is a module object, but not a subtype of <tt class="cdata">PyModule_Type</tt>. <span class="versionnote">New in version 2.2.</span> </dd></dl> <P> <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"><td><nobr>PyObject* <b><tt id='l2h-615' class="cfunction">PyModule_New</tt></b>(</nobr></td><td>char *<var>name</var>)</td></tr></table></dt> <dd> <div class="refcount-info"> <span class="label">Return value:</span> <span class="value">New reference.</span> </div> Return a new module object with the <tt class="member">__name__</tt> attribute set to <var>name</var>. Only the module's <tt class="member">__doc__</tt> and <tt class="member">__name__</tt> attributes are filled in; the caller is responsible for providing a <tt class="member">__file__</tt> attribute. <a id='l2h-617'><!--x--></a></dd></dl> <P> <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"><td><nobr>PyObject* <b><tt id='l2h-618' class="cfunction">PyModule_GetDict</tt></b>(</nobr></td><td>PyObject *<var>module</var>)</td></tr></table></dt> <dd> <div class="refcount-info"> <span class="label">Return value:</span> <span class="value">Borrowed reference.</span> </div> Return the dictionary object that implements <var>module</var>'s namespace; this object is the same as the <tt class="member">__dict__</tt> attribute of the module object. This function never fails. <a id='l2h-620'><!--x--></a> It is recommended extensions use other <tt class="cfunction">PyModule_*()</tt> and <tt class="cfunction">PyObject_*()</tt> functions rather than directly manipulate a module's <tt class="member">__dict__</tt>. </dd></dl> <P> <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"><td><nobr>char* <b><tt id='l2h-621' class="cfunction">PyModule_GetName</tt></b>(</nobr></td><td>PyObject *<var>module</var>)</td></tr></table></dt> <dd> Return <var>module</var>'s <tt class="member">__name__</tt> value. If the module does not provide one, or if it is not a string, <tt class="exception">SystemError</tt> is raised and <tt class="constant">NULL</tt> is returned. <a id='l2h-623'><!--x--></a> <a id='l2h-625'><!--x--></a></dd></dl> <P> <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"><td><nobr>char* <b><tt id='l2h-626' class="cfunction">PyModule_GetFilename</tt></b>(</nobr></td><td>PyObject *<var>module</var>)</td></tr></table></dt> <dd> Return the name of the file from which <var>module</var> was loaded using <var>module</var>'s <tt class="member">__file__</tt> attribute. If this is not defined, or if it is not a string, raise <tt class="exception">SystemError</tt> and return <tt class="constant">NULL</tt>. <a id='l2h-628'><!--x--></a> <a id='l2h-630'><!--x--></a></dd></dl> <P> <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"><td><nobr>int <b><tt id='l2h-631' class="cfunction">PyModule_AddObject</tt></b>(</nobr></td><td>PyObject *<var>module</var>, char *<var>name</var>, PyObject *<var>value</var>)</td></tr></table></dt> <dd> Add an object to <var>module</var> as <var>name</var>. This is a convenience function which can be used from the module's initialization function. This steals a reference to <var>value</var>. Returns <code>-1</code> on error, <code>0</code> on success. <span class="versionnote">New in version 2.0.</span> </dd></dl> <P> <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"><td><nobr>int <b><tt id='l2h-632' class="cfunction">PyModule_AddIntConstant</tt></b>(</nobr></td><td>PyObject *<var>module</var>, char *<var>name</var>, int <var>value</var>)</td></tr></table></dt> <dd> Add an integer constant to <var>module</var> as <var>name</var>. This convenience function can be used from the module's initialization function. Returns <code>-1</code> on error, <code>0</code> on success. <span class="versionnote">New in version 2.0.</span> </dd></dl> <P> <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"><td><nobr>int <b><tt id='l2h-633' class="cfunction">PyModule_AddStringConstant</tt></b>(</nobr></td><td>PyObject *<var>module</var>, char *<var>name</var>, char *<var>value</var>)</td></tr></table></dt> <dd> Add a string constant to <var>module</var> as <var>name</var>. This convenience function can be used from the module's initialization function. The string <var>value</var> must be null-terminated. Returns <code>-1</code> on error, <code>0</code> on success. <span class="versionnote">New in version 2.0.</span> </dd></dl> <P> <DIV CLASS="navigation"> <div class='online-navigation'><hr /> <table align="center" width="100%" cellpadding="0" cellspacing="2"> <tr> <td class='online-navigation'><a rel="prev" title="7.5.3 Method Objects" rel="prev" title="7.5.3 Method Objects" href="method-objects.html"><img src='../icons/previous.png' border='0' height='32' alt='Previous Page' width='32' /></A></td> <td class='online-navigation'><a rel="parent" title="7.5 Other Objects" rel="parent" title="7.5 Other Objects" href="otherObjects.html"><img src='../icons/up.png' border='0' height='32' alt='Up One Level' width='32' /></A></td> <td class='online-navigation'><a rel="next" title="7.5.5 Iterator Objects" rel="next" title="7.5.5 Iterator Objects" href="iterator-objects.html"><img src='../icons/next.png' border='0' height='32' alt='Next Page' width='32' /></A></td> <td align="center" width="100%">Python/C API Reference Manual</td> <td class='online-navigation'><a rel="contents" title="Table of Contents" rel="contents" title="Table of Contents" href="contents.html"><img src='../icons/contents.png' border='0' height='32' alt='Contents' width='32' /></A></td> <td class='online-navigation'><img src='../icons/blank.png' border='0' height='32' alt='' width='32' /></td> <td class='online-navigation'><a rel="index" title="Index" rel="index" title="Index" href="genindex.html"><img src='../icons/index.png' border='0' height='32' alt='Index' width='32' /></A></td> </tr></table> <div class='online-navigation'> <b class="navlabel">Previous:</b> <a class="sectref" rel="prev" href="method-objects.html">7.5.3 Method Objects</A> <b class="navlabel">Up:</b> <a class="sectref" rel="parent" href="otherObjects.html">7.5 Other Objects</A> <b class="navlabel">Next:</b> <a class="sectref" rel="next" href="iterator-objects.html">7.5.5 Iterator Objects</A> </div> </div> <hr /> <span class="release-info">Release 2.3.4, documentation updated on May 20, 2004.</span> </DIV> <!--End of Navigation Panel--> <ADDRESS> See <i><a href="about.html">About this document...</a></i> for information on suggesting changes. </ADDRESS> </BODY> </HTML>