Mercurial > cpython-lru_cache-weakref
annotate Doc/c-api/module.rst @ 65035:87f4b32905df 2.7
Cosmetic fix to use print function.
| author | Hirokazu Yamamoto <ocean-city@m2.ccsnet.ne.jp> |
|---|---|
| date | Fri, 01 Oct 2010 10:48:47 +0000 |
| parents | ee9ced92843a |
| children | fb709d9fe92a |
| rev | line source |
|---|---|
|
44796
13dc65fe8599
Split the monstrous C API manual files in smaller parts.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
1 .. highlightlang:: c |
|
13dc65fe8599
Split the monstrous C API manual files in smaller parts.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
2 |
|
13dc65fe8599
Split the monstrous C API manual files in smaller parts.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
3 .. _moduleobjects: |
|
13dc65fe8599
Split the monstrous C API manual files in smaller parts.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
4 |
|
13dc65fe8599
Split the monstrous C API manual files in smaller parts.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
5 Module Objects |
|
13dc65fe8599
Split the monstrous C API manual files in smaller parts.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
6 -------------- |
|
13dc65fe8599
Split the monstrous C API manual files in smaller parts.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
7 |
|
13dc65fe8599
Split the monstrous C API manual files in smaller parts.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
8 .. index:: object: module |
|
13dc65fe8599
Split the monstrous C API manual files in smaller parts.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
9 |
|
13dc65fe8599
Split the monstrous C API manual files in smaller parts.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
10 There are only a few functions special to module objects. |
|
13dc65fe8599
Split the monstrous C API manual files in smaller parts.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
11 |
|
13dc65fe8599
Split the monstrous C API manual files in smaller parts.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
12 |
|
13dc65fe8599
Split the monstrous C API manual files in smaller parts.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
13 .. cvar:: PyTypeObject PyModule_Type |
|
13dc65fe8599
Split the monstrous C API manual files in smaller parts.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
14 |
|
13dc65fe8599
Split the monstrous C API manual files in smaller parts.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
15 .. index:: single: ModuleType (in module types) |
|
13dc65fe8599
Split the monstrous C API manual files in smaller parts.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
16 |
|
13dc65fe8599
Split the monstrous C API manual files in smaller parts.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
17 This instance of :ctype:`PyTypeObject` represents the Python module type. This |
|
13dc65fe8599
Split the monstrous C API manual files in smaller parts.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
18 is exposed to Python programs as ``types.ModuleType``. |
|
13dc65fe8599
Split the monstrous C API manual files in smaller parts.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
19 |
|
13dc65fe8599
Split the monstrous C API manual files in smaller parts.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
20 |
| 44971 | 21 .. cfunction:: int PyModule_Check(PyObject *p) |
|
44796
13dc65fe8599
Split the monstrous C API manual files in smaller parts.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
22 |
|
13dc65fe8599
Split the monstrous C API manual files in smaller parts.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
23 Return true if *p* is a module object, or a subtype of a module object. |
|
13dc65fe8599
Split the monstrous C API manual files in smaller parts.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
24 |
|
13dc65fe8599
Split the monstrous C API manual files in smaller parts.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
25 .. versionchanged:: 2.2 |
|
13dc65fe8599
Split the monstrous C API manual files in smaller parts.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
26 Allowed subtypes to be accepted. |
|
13dc65fe8599
Split the monstrous C API manual files in smaller parts.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
27 |
|
13dc65fe8599
Split the monstrous C API manual files in smaller parts.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
28 |
| 44971 | 29 .. cfunction:: int PyModule_CheckExact(PyObject *p) |
|
44796
13dc65fe8599
Split the monstrous C API manual files in smaller parts.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
30 |
|
13dc65fe8599
Split the monstrous C API manual files in smaller parts.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
31 Return true if *p* is a module object, but not a subtype of |
|
13dc65fe8599
Split the monstrous C API manual files in smaller parts.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
32 :cdata:`PyModule_Type`. |
|
13dc65fe8599
Split the monstrous C API manual files in smaller parts.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
33 |
|
13dc65fe8599
Split the monstrous C API manual files in smaller parts.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
34 .. versionadded:: 2.2 |
|
13dc65fe8599
Split the monstrous C API manual files in smaller parts.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
35 |
|
13dc65fe8599
Split the monstrous C API manual files in smaller parts.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
36 |
|
13dc65fe8599
Split the monstrous C API manual files in smaller parts.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
37 .. cfunction:: PyObject* PyModule_New(const char *name) |
|
13dc65fe8599
Split the monstrous C API manual files in smaller parts.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
38 |
|
13dc65fe8599
Split the monstrous C API manual files in smaller parts.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
39 .. index:: |
|
13dc65fe8599
Split the monstrous C API manual files in smaller parts.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
40 single: __name__ (module attribute) |
|
13dc65fe8599
Split the monstrous C API manual files in smaller parts.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
41 single: __doc__ (module attribute) |
|
13dc65fe8599
Split the monstrous C API manual files in smaller parts.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
42 single: __file__ (module attribute) |
|
13dc65fe8599
Split the monstrous C API manual files in smaller parts.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
43 |
|
13dc65fe8599
Split the monstrous C API manual files in smaller parts.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
44 Return a new module object with the :attr:`__name__` attribute set to *name*. |
|
13dc65fe8599
Split the monstrous C API manual files in smaller parts.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
45 Only the module's :attr:`__doc__` and :attr:`__name__` attributes are filled in; |
|
13dc65fe8599
Split the monstrous C API manual files in smaller parts.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
46 the caller is responsible for providing a :attr:`__file__` attribute. |
|
13dc65fe8599
Split the monstrous C API manual files in smaller parts.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
47 |
|
13dc65fe8599
Split the monstrous C API manual files in smaller parts.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
48 |
|
13dc65fe8599
Split the monstrous C API manual files in smaller parts.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
49 .. cfunction:: PyObject* PyModule_GetDict(PyObject *module) |
|
13dc65fe8599
Split the monstrous C API manual files in smaller parts.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
50 |
|
13dc65fe8599
Split the monstrous C API manual files in smaller parts.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
51 .. index:: single: __dict__ (module attribute) |
|
13dc65fe8599
Split the monstrous C API manual files in smaller parts.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
52 |
|
13dc65fe8599
Split the monstrous C API manual files in smaller parts.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
53 Return the dictionary object that implements *module*'s namespace; this object |
|
13dc65fe8599
Split the monstrous C API manual files in smaller parts.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
54 is the same as the :attr:`__dict__` attribute of the module object. This |
|
13dc65fe8599
Split the monstrous C API manual files in smaller parts.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
55 function never fails. It is recommended extensions use other |
|
13dc65fe8599
Split the monstrous C API manual files in smaller parts.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
56 :cfunc:`PyModule_\*` and :cfunc:`PyObject_\*` functions rather than directly |
|
13dc65fe8599
Split the monstrous C API manual files in smaller parts.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
57 manipulate a module's :attr:`__dict__`. |
|
13dc65fe8599
Split the monstrous C API manual files in smaller parts.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
58 |
|
13dc65fe8599
Split the monstrous C API manual files in smaller parts.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
59 |
|
13dc65fe8599
Split the monstrous C API manual files in smaller parts.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
60 .. cfunction:: char* PyModule_GetName(PyObject *module) |
|
13dc65fe8599
Split the monstrous C API manual files in smaller parts.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
61 |
|
13dc65fe8599
Split the monstrous C API manual files in smaller parts.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
62 .. index:: |
|
13dc65fe8599
Split the monstrous C API manual files in smaller parts.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
63 single: __name__ (module attribute) |
|
13dc65fe8599
Split the monstrous C API manual files in smaller parts.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
64 single: SystemError (built-in exception) |
|
13dc65fe8599
Split the monstrous C API manual files in smaller parts.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
65 |
|
13dc65fe8599
Split the monstrous C API manual files in smaller parts.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
66 Return *module*'s :attr:`__name__` value. If the module does not provide one, |
|
13dc65fe8599
Split the monstrous C API manual files in smaller parts.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
67 or if it is not a string, :exc:`SystemError` is raised and *NULL* is returned. |
|
13dc65fe8599
Split the monstrous C API manual files in smaller parts.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
68 |
|
13dc65fe8599
Split the monstrous C API manual files in smaller parts.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
69 |
|
13dc65fe8599
Split the monstrous C API manual files in smaller parts.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
70 .. cfunction:: char* PyModule_GetFilename(PyObject *module) |
|
13dc65fe8599
Split the monstrous C API manual files in smaller parts.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
71 |
|
13dc65fe8599
Split the monstrous C API manual files in smaller parts.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
72 .. index:: |
|
13dc65fe8599
Split the monstrous C API manual files in smaller parts.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
73 single: __file__ (module attribute) |
|
13dc65fe8599
Split the monstrous C API manual files in smaller parts.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
74 single: SystemError (built-in exception) |
|
13dc65fe8599
Split the monstrous C API manual files in smaller parts.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
75 |
|
13dc65fe8599
Split the monstrous C API manual files in smaller parts.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
76 Return the name of the file from which *module* was loaded using *module*'s |
|
13dc65fe8599
Split the monstrous C API manual files in smaller parts.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
77 :attr:`__file__` attribute. If this is not defined, or if it is not a string, |
|
13dc65fe8599
Split the monstrous C API manual files in smaller parts.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
78 raise :exc:`SystemError` and return *NULL*. |
|
13dc65fe8599
Split the monstrous C API manual files in smaller parts.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
79 |
|
13dc65fe8599
Split the monstrous C API manual files in smaller parts.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
80 |
|
13dc65fe8599
Split the monstrous C API manual files in smaller parts.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
81 .. cfunction:: int PyModule_AddObject(PyObject *module, const char *name, PyObject *value) |
|
13dc65fe8599
Split the monstrous C API manual files in smaller parts.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
82 |
|
13dc65fe8599
Split the monstrous C API manual files in smaller parts.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
83 Add an object to *module* as *name*. This is a convenience function which can |
|
13dc65fe8599
Split the monstrous C API manual files in smaller parts.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
84 be used from the module's initialization function. This steals a reference to |
|
13dc65fe8599
Split the monstrous C API manual files in smaller parts.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
85 *value*. Return ``-1`` on error, ``0`` on success. |
|
13dc65fe8599
Split the monstrous C API manual files in smaller parts.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
86 |
|
13dc65fe8599
Split the monstrous C API manual files in smaller parts.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
87 .. versionadded:: 2.0 |
|
13dc65fe8599
Split the monstrous C API manual files in smaller parts.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
88 |
|
13dc65fe8599
Split the monstrous C API manual files in smaller parts.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
89 |
|
13dc65fe8599
Split the monstrous C API manual files in smaller parts.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
90 .. cfunction:: int PyModule_AddIntConstant(PyObject *module, const char *name, long value) |
|
13dc65fe8599
Split the monstrous C API manual files in smaller parts.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
91 |
|
13dc65fe8599
Split the monstrous C API manual files in smaller parts.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
92 Add an integer constant to *module* as *name*. This convenience function can be |
|
13dc65fe8599
Split the monstrous C API manual files in smaller parts.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
93 used from the module's initialization function. Return ``-1`` on error, ``0`` on |
|
13dc65fe8599
Split the monstrous C API manual files in smaller parts.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
94 success. |
|
13dc65fe8599
Split the monstrous C API manual files in smaller parts.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
95 |
|
13dc65fe8599
Split the monstrous C API manual files in smaller parts.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
96 .. versionadded:: 2.0 |
|
13dc65fe8599
Split the monstrous C API manual files in smaller parts.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
97 |
|
13dc65fe8599
Split the monstrous C API manual files in smaller parts.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
98 |
|
13dc65fe8599
Split the monstrous C API manual files in smaller parts.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
99 .. cfunction:: int PyModule_AddStringConstant(PyObject *module, const char *name, const char *value) |
|
13dc65fe8599
Split the monstrous C API manual files in smaller parts.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
100 |
|
13dc65fe8599
Split the monstrous C API manual files in smaller parts.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
101 Add a string constant to *module* as *name*. This convenience function can be |
|
13dc65fe8599
Split the monstrous C API manual files in smaller parts.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
102 used from the module's initialization function. The string *value* must be |
|
13dc65fe8599
Split the monstrous C API manual files in smaller parts.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
103 null-terminated. Return ``-1`` on error, ``0`` on success. |
|
13dc65fe8599
Split the monstrous C API manual files in smaller parts.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
104 |
|
13dc65fe8599
Split the monstrous C API manual files in smaller parts.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
105 .. versionadded:: 2.0 |
|
44875
c3ce56c7ecd1
Don't repeat yourself
Christian Heimes <christian@cheimes.de>
parents:
44796
diff
changeset
|
106 |
| 44971 | 107 .. cfunction:: int PyModule_AddIntMacro(PyObject *module, macro) |
|
44875
c3ce56c7ecd1
Don't repeat yourself
Christian Heimes <christian@cheimes.de>
parents:
44796
diff
changeset
|
108 |
|
50522
ee9ced92843a
Merged revisions 68133-68134,68141-68142,68145-68146,68148-68149,68159-68162,68166,68171-68174,68179,68195-68196,68210,68214-68215,68217-68222 via svnmerge from
Georg Brandl <georg@python.org>
parents:
44971
diff
changeset
|
109 Add an int constant to *module*. The name and the value are taken from |
|
44875
c3ce56c7ecd1
Don't repeat yourself
Christian Heimes <christian@cheimes.de>
parents:
44796
diff
changeset
|
110 *macro*. For example ``PyModule_AddConstant(module, AF_INET)`` adds the int |
|
c3ce56c7ecd1
Don't repeat yourself
Christian Heimes <christian@cheimes.de>
parents:
44796
diff
changeset
|
111 constant *AF_INET* with the value of *AF_INET* to *module*. |
|
c3ce56c7ecd1
Don't repeat yourself
Christian Heimes <christian@cheimes.de>
parents:
44796
diff
changeset
|
112 Return ``-1`` on error, ``0`` on success. |
|
c3ce56c7ecd1
Don't repeat yourself
Christian Heimes <christian@cheimes.de>
parents:
44796
diff
changeset
|
113 |
|
c3ce56c7ecd1
Don't repeat yourself
Christian Heimes <christian@cheimes.de>
parents:
44796
diff
changeset
|
114 .. versionadded:: 2.6 |
|
c3ce56c7ecd1
Don't repeat yourself
Christian Heimes <christian@cheimes.de>
parents:
44796
diff
changeset
|
115 |
| 44971 | 116 .. cfunction:: int PyModule_AddStringMacro(PyObject *module, macro) |
|
44875
c3ce56c7ecd1
Don't repeat yourself
Christian Heimes <christian@cheimes.de>
parents:
44796
diff
changeset
|
117 |
|
c3ce56c7ecd1
Don't repeat yourself
Christian Heimes <christian@cheimes.de>
parents:
44796
diff
changeset
|
118 Add a string constant to *module*. |
|
c3ce56c7ecd1
Don't repeat yourself
Christian Heimes <christian@cheimes.de>
parents:
44796
diff
changeset
|
119 |
|
c3ce56c7ecd1
Don't repeat yourself
Christian Heimes <christian@cheimes.de>
parents:
44796
diff
changeset
|
120 .. versionadded:: 2.6 |
|
c3ce56c7ecd1
Don't repeat yourself
Christian Heimes <christian@cheimes.de>
parents:
44796
diff
changeset
|
121 |
