<!DOCTYPE html PUBLIC
"-//W3C//DTD HTML 4.0 Transitional//EN">
<link rel=
"STYLESHEET" href=
"api.css" type='text/css'
/>
<link rel=
"SHORTCUT ICON" href=
"../icons/pyfav.png" type=
"image/png" />
<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 name='aesop' content='information'
/>
<title>7.5.4 Module Objects
</title>
<div id='top-navigation-panel' xml:id='top-navigation-panel'
>
<table align=
"center" width=
"100%" cellpadding=
"0" cellspacing=
"2">
<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>
<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>
<!--End of Navigation Panel-->
<H2><A NAME=
"SECTION009540000000000000000"></A><A NAME=
"moduleObjects"></A>
<a id='l2h-
672' xml:id='l2h-
672'
></a>There are only a few functions special to module objects.
<dl><dt>PyTypeObject
<b><tt id='l2h-
673' xml:id='l2h-
673'
class=
"cdata">PyModule_Type
</tt></b></dt>
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-
675' xml:id='l2h-
675'
></a></dd></dl>
<dl><dt><table cellpadding=
"0" cellspacing=
"0"><tr valign=
"baseline"><td><nobr>int
<b><tt id='l2h-
676' xml:id='l2h-
676'
class=
"cfunction">PyModule_Check
</tt></b>(
</nobr></td><td>PyObject *
<var>p
</var>)
</td></tr></table></dt>
Return true if
<var>p
</var> is a module object, or a subtype of a module
<span class=
"versionnote">Changed in version
2.2:
Allowed subtypes to be accepted.
</span>
<dl><dt><table cellpadding=
"0" cellspacing=
"0"><tr valign=
"baseline"><td><nobr>int
<b><tt id='l2h-
677' xml:id='l2h-
677'
class=
"cfunction">PyModule_CheckExact
</tt></b>(
</nobr></td><td>PyObject *
<var>p
</var>)
</td></tr></table></dt>
Return 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>
<dl><dt><table cellpadding=
"0" cellspacing=
"0"><tr valign=
"baseline"><td><nobr>PyObject*
<b><tt id='l2h-
678' xml:id='l2h-
678'
class=
"cfunction">PyModule_New
</tt></b>(
</nobr></td><td>char *
<var>name
</var>)
</td></tr></table></dt>
<div class=
"refcount-info">
<span class=
"label">Return value:
</span>
<span class=
"value">New reference.
</span>
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-
680' xml:id='l2h-
680'
></a></dd></dl>
<dl><dt><table cellpadding=
"0" cellspacing=
"0"><tr valign=
"baseline"><td><nobr>PyObject*
<b><tt id='l2h-
681' xml:id='l2h-
681'
class=
"cfunction">PyModule_GetDict
</tt></b>(
</nobr></td><td>PyObject *
<var>module
</var>)
</td></tr></table></dt>
<div class=
"refcount-info">
<span class=
"label">Return value:
</span>
<span class=
"value">Borrowed reference.
</span>
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-
683' xml:id='l2h-
683'
></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>.
<dl><dt><table cellpadding=
"0" cellspacing=
"0"><tr valign=
"baseline"><td><nobr>char*
<b><tt id='l2h-
684' xml:id='l2h-
684'
class=
"cfunction">PyModule_GetName
</tt></b>(
</nobr></td><td>PyObject *
<var>module
</var>)
</td></tr></table></dt>
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-
686' xml:id='l2h-
686'
></a> <a id='l2h-
688' xml:id='l2h-
688'
></a></dd></dl>
<dl><dt><table cellpadding=
"0" cellspacing=
"0"><tr valign=
"baseline"><td><nobr>char*
<b><tt id='l2h-
689' xml:id='l2h-
689'
class=
"cfunction">PyModule_GetFilename
</tt></b>(
</nobr></td><td>PyObject *
<var>module
</var>)
</td></tr></table></dt>
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-
691' xml:id='l2h-
691'
></a> <a id='l2h-
693' xml:id='l2h-
693'
></a></dd></dl>
<dl><dt><table cellpadding=
"0" cellspacing=
"0"><tr valign=
"baseline"><td><nobr>int
<b><tt id='l2h-
694' xml:id='l2h-
694'
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>
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>. Return
<code>-
1</code> on error,
<code>0</code> on success.
<span class=
"versionnote">New in version
2.0.
</span>
<dl><dt><table cellpadding=
"0" cellspacing=
"0"><tr valign=
"baseline"><td><nobr>int
<b><tt id='l2h-
695' xml:id='l2h-
695'
class=
"cfunction">PyModule_AddIntConstant
</tt></b>(
</nobr></td><td>PyObject *
<var>module
</var>,
char *
<var>name
</var>, long
<var>value
</var>)
</td></tr></table></dt>
Add an integer constant to
<var>module
</var> as
<var>name
</var>. This
convenience function can be used from the module's initialization
function. Return
<code>-
1</code> on error,
<code>0</code> on success.
<span class=
"versionnote">New in version
2.0.
</span>
<dl><dt><table cellpadding=
"0" cellspacing=
"0"><tr valign=
"baseline"><td><nobr>int
<b><tt id='l2h-
696' xml:id='l2h-
696'
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>
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. Return
<code>-
1</code> on error,
<code>0</code> on success.
<span class=
"versionnote">New in version
2.0.
</span>
<div class='online-navigation'
>
<table align=
"center" width=
"100%" cellpadding=
"0" cellspacing=
"2">
<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>
<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>
<span class=
"release-info">Release
2.4.2, documentation updated on
28 September
2005.
</span>
<!--End of Navigation Panel-->
See
<i><a href=
"about.html">About this document...
</a></i> for information on suggesting changes.