Commit | Line | Data |
---|---|---|
920dae64 AT |
1 | <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> |
2 | <html> | |
3 | <head> | |
4 | <link rel="STYLESHEET" href="api.css" type='text/css' /> | |
5 | <link rel="SHORTCUT ICON" href="../icons/pyfav.png" type="image/png" /> | |
6 | <link rel='start' href='../index.html' title='Python Documentation Index' /> | |
7 | <link rel="first" href="api.html" title='Python/C API Reference Manual' /> | |
8 | <link rel='contents' href='contents.html' title="Contents" /> | |
9 | <link rel='index' href='genindex.html' title='Index' /> | |
10 | <link rel='last' href='about.html' title='About this document...' /> | |
11 | <link rel='help' href='about.html' title='About this document...' /> | |
12 | <link rel="next" href="iterator-objects.html" /> | |
13 | <link rel="prev" href="method-objects.html" /> | |
14 | <link rel="parent" href="otherObjects.html" /> | |
15 | <link rel="next" href="iterator-objects.html" /> | |
16 | <meta name='aesop' content='information' /> | |
17 | <title>7.5.4 Module Objects </title> | |
18 | </head> | |
19 | <body> | |
20 | <DIV CLASS="navigation"> | |
21 | <div id='top-navigation-panel' xml:id='top-navigation-panel'> | |
22 | <table align="center" width="100%" cellpadding="0" cellspacing="2"> | |
23 | <tr> | |
24 | <td class='online-navigation'><a rel="prev" title="7.5.3 Method Objects" | |
25 | href="method-objects.html"><img src='../icons/previous.png' | |
26 | border='0' height='32' alt='Previous Page' width='32' /></A></td> | |
27 | <td class='online-navigation'><a rel="parent" title="7.5 Other Objects" | |
28 | href="otherObjects.html"><img src='../icons/up.png' | |
29 | border='0' height='32' alt='Up One Level' width='32' /></A></td> | |
30 | <td class='online-navigation'><a rel="next" title="7.5.5 Iterator Objects" | |
31 | href="iterator-objects.html"><img src='../icons/next.png' | |
32 | border='0' height='32' alt='Next Page' width='32' /></A></td> | |
33 | <td align="center" width="100%">Python/C API Reference Manual</td> | |
34 | <td class='online-navigation'><a rel="contents" title="Table of Contents" | |
35 | href="contents.html"><img src='../icons/contents.png' | |
36 | border='0' height='32' alt='Contents' width='32' /></A></td> | |
37 | <td class='online-navigation'><img src='../icons/blank.png' | |
38 | border='0' height='32' alt='' width='32' /></td> | |
39 | <td class='online-navigation'><a rel="index" title="Index" | |
40 | href="genindex.html"><img src='../icons/index.png' | |
41 | border='0' height='32' alt='Index' width='32' /></A></td> | |
42 | </tr></table> | |
43 | <div class='online-navigation'> | |
44 | <b class="navlabel">Previous:</b> | |
45 | <a class="sectref" rel="prev" href="method-objects.html">7.5.3 Method Objects</A> | |
46 | <b class="navlabel">Up:</b> | |
47 | <a class="sectref" rel="parent" href="otherObjects.html">7.5 Other Objects</A> | |
48 | <b class="navlabel">Next:</b> | |
49 | <a class="sectref" rel="next" href="iterator-objects.html">7.5.5 Iterator Objects</A> | |
50 | </div> | |
51 | <hr /></div> | |
52 | </DIV> | |
53 | <!--End of Navigation Panel--> | |
54 | ||
55 | <H2><A NAME="SECTION009540000000000000000"></A><A NAME="moduleObjects"></A> | |
56 | <BR> | |
57 | 7.5.4 Module Objects | |
58 | </H2> | |
59 | ||
60 | <P> | |
61 | <a id='l2h-672' xml:id='l2h-672'></a>There are only a few functions special to module objects. | |
62 | ||
63 | <P> | |
64 | <dl><dt>PyTypeObject <b><tt id='l2h-673' xml:id='l2h-673' class="cdata">PyModule_Type</tt></b></dt> | |
65 | <dd> | |
66 | This instance of <tt class="ctype">PyTypeObject</tt> represents the Python module | |
67 | type. This is exposed to Python programs as | |
68 | <code>types.ModuleType</code>. | |
69 | <a id='l2h-675' xml:id='l2h-675'></a></dd></dl> | |
70 | ||
71 | <P> | |
72 | <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> | |
73 | <dd> | |
74 | Return true if <var>p</var> is a module object, or a subtype of a module | |
75 | object. | |
76 | ||
77 | <span class="versionnote">Changed in version 2.2: | |
78 | Allowed subtypes to be accepted.</span> | |
79 | ||
80 | </dd></dl> | |
81 | ||
82 | <P> | |
83 | <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> | |
84 | <dd> | |
85 | Return true if <var>p</var> is a module object, but not a subtype of | |
86 | <tt class="cdata">PyModule_Type</tt>. | |
87 | ||
88 | <span class="versionnote">New in version 2.2.</span> | |
89 | ||
90 | </dd></dl> | |
91 | ||
92 | <P> | |
93 | <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> | |
94 | <dd> | |
95 | <div class="refcount-info"> | |
96 | <span class="label">Return value:</span> | |
97 | <span class="value">New reference.</span> | |
98 | </div> | |
99 | Return a new module object with the <tt class="member">__name__</tt> attribute set | |
100 | to <var>name</var>. Only the module's <tt class="member">__doc__</tt> and | |
101 | <tt class="member">__name__</tt> attributes are filled in; the caller is | |
102 | responsible for providing a <tt class="member">__file__</tt> attribute. | |
103 | <a id='l2h-680' xml:id='l2h-680'></a></dd></dl> | |
104 | ||
105 | <P> | |
106 | <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> | |
107 | <dd> | |
108 | <div class="refcount-info"> | |
109 | <span class="label">Return value:</span> | |
110 | <span class="value">Borrowed reference.</span> | |
111 | </div> | |
112 | Return the dictionary object that implements <var>module</var>'s | |
113 | namespace; this object is the same as the <tt class="member">__dict__</tt> | |
114 | attribute of the module object. This function never fails. | |
115 | <a id='l2h-683' xml:id='l2h-683'></a> It is recommended extensions use other <tt class="cfunction">PyModule_*()</tt> | |
116 | and <tt class="cfunction">PyObject_*()</tt> functions rather than directly | |
117 | manipulate a module's <tt class="member">__dict__</tt>. | |
118 | </dd></dl> | |
119 | ||
120 | <P> | |
121 | <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> | |
122 | <dd> | |
123 | Return <var>module</var>'s <tt class="member">__name__</tt> value. If the module does | |
124 | not provide one, or if it is not a string, <tt class="exception">SystemError</tt> | |
125 | is raised and <tt class="constant">NULL</tt> is returned. | |
126 | <a id='l2h-686' xml:id='l2h-686'></a> <a id='l2h-688' xml:id='l2h-688'></a></dd></dl> | |
127 | ||
128 | <P> | |
129 | <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> | |
130 | <dd> | |
131 | Return the name of the file from which <var>module</var> was loaded using | |
132 | <var>module</var>'s <tt class="member">__file__</tt> attribute. If this is not defined, | |
133 | or if it is not a string, raise <tt class="exception">SystemError</tt> and return | |
134 | <tt class="constant">NULL</tt>. | |
135 | <a id='l2h-691' xml:id='l2h-691'></a> <a id='l2h-693' xml:id='l2h-693'></a></dd></dl> | |
136 | ||
137 | <P> | |
138 | <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>, | |
139 | char *<var>name</var>, PyObject *<var>value</var>)</td></tr></table></dt> | |
140 | <dd> | |
141 | Add an object to <var>module</var> as <var>name</var>. This is a convenience | |
142 | function which can be used from the module's initialization | |
143 | function. This steals a reference to <var>value</var>. Return | |
144 | <code>-1</code> on error, <code>0</code> on success. | |
145 | ||
146 | <span class="versionnote">New in version 2.0.</span> | |
147 | ||
148 | </dd></dl> | |
149 | ||
150 | <P> | |
151 | <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>, | |
152 | char *<var>name</var>, long <var>value</var>)</td></tr></table></dt> | |
153 | <dd> | |
154 | Add an integer constant to <var>module</var> as <var>name</var>. This | |
155 | convenience function can be used from the module's initialization | |
156 | function. Return <code>-1</code> on error, <code>0</code> on success. | |
157 | ||
158 | <span class="versionnote">New in version 2.0.</span> | |
159 | ||
160 | </dd></dl> | |
161 | ||
162 | <P> | |
163 | <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>, | |
164 | char *<var>name</var>, char *<var>value</var>)</td></tr></table></dt> | |
165 | <dd> | |
166 | Add a string constant to <var>module</var> as <var>name</var>. This | |
167 | convenience function can be used from the module's initialization | |
168 | function. The string <var>value</var> must be null-terminated. Return | |
169 | <code>-1</code> on error, <code>0</code> on success. | |
170 | ||
171 | <span class="versionnote">New in version 2.0.</span> | |
172 | ||
173 | </dd></dl> | |
174 | ||
175 | <P> | |
176 | ||
177 | <DIV CLASS="navigation"> | |
178 | <div class='online-navigation'> | |
179 | <p></p><hr /> | |
180 | <table align="center" width="100%" cellpadding="0" cellspacing="2"> | |
181 | <tr> | |
182 | <td class='online-navigation'><a rel="prev" title="7.5.3 Method Objects" | |
183 | href="method-objects.html"><img src='../icons/previous.png' | |
184 | border='0' height='32' alt='Previous Page' width='32' /></A></td> | |
185 | <td class='online-navigation'><a rel="parent" title="7.5 Other Objects" | |
186 | href="otherObjects.html"><img src='../icons/up.png' | |
187 | border='0' height='32' alt='Up One Level' width='32' /></A></td> | |
188 | <td class='online-navigation'><a rel="next" title="7.5.5 Iterator Objects" | |
189 | href="iterator-objects.html"><img src='../icons/next.png' | |
190 | border='0' height='32' alt='Next Page' width='32' /></A></td> | |
191 | <td align="center" width="100%">Python/C API Reference Manual</td> | |
192 | <td class='online-navigation'><a rel="contents" title="Table of Contents" | |
193 | href="contents.html"><img src='../icons/contents.png' | |
194 | border='0' height='32' alt='Contents' width='32' /></A></td> | |
195 | <td class='online-navigation'><img src='../icons/blank.png' | |
196 | border='0' height='32' alt='' width='32' /></td> | |
197 | <td class='online-navigation'><a rel="index" title="Index" | |
198 | href="genindex.html"><img src='../icons/index.png' | |
199 | border='0' height='32' alt='Index' width='32' /></A></td> | |
200 | </tr></table> | |
201 | <div class='online-navigation'> | |
202 | <b class="navlabel">Previous:</b> | |
203 | <a class="sectref" rel="prev" href="method-objects.html">7.5.3 Method Objects</A> | |
204 | <b class="navlabel">Up:</b> | |
205 | <a class="sectref" rel="parent" href="otherObjects.html">7.5 Other Objects</A> | |
206 | <b class="navlabel">Next:</b> | |
207 | <a class="sectref" rel="next" href="iterator-objects.html">7.5.5 Iterator Objects</A> | |
208 | </div> | |
209 | </div> | |
210 | <hr /> | |
211 | <span class="release-info">Release 2.4.2, documentation updated on 28 September 2005.</span> | |
212 | </DIV> | |
213 | <!--End of Navigation Panel--> | |
214 | <ADDRESS> | |
215 | See <i><a href="about.html">About this document...</a></i> for information on suggesting changes. | |
216 | </ADDRESS> | |
217 | </BODY> | |
218 | </HTML> |