Changeset 391 for python/trunk/Doc/c-api/import.rst
- Timestamp:
- Mar 19, 2014, 11:31:01 PM (11 years ago)
- Location:
- python/trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
python/trunk
-
Property svn:mergeinfo
set to
/python/vendor/Python-2.7.6 merged eligible /python/vendor/current merged eligible
-
Property svn:mergeinfo
set to
-
python/trunk/Doc/c-api/import.rst
r2 r391 7 7 8 8 9 .. c function:: PyObject* PyImport_ImportModule(const char *name)9 .. c:function:: PyObject* PyImport_ImportModule(const char *name) 10 10 11 11 .. index:: … … 14 14 single: modules (in module sys) 15 15 16 This is a simplified interface to :c func:`PyImport_ImportModuleEx` below,16 This is a simplified interface to :c:func:`PyImport_ImportModuleEx` below, 17 17 leaving the *globals* and *locals* arguments set to *NULL* and *level* set 18 18 to 0. When the *name* … … 35 35 36 36 37 .. c function:: PyObject* PyImport_ImportModuleNoBlock(const char *name)38 39 This version of :c func:`PyImport_ImportModule` does not block. It's intended37 .. c:function:: PyObject* PyImport_ImportModuleNoBlock(const char *name) 38 39 This version of :c:func:`PyImport_ImportModule` does not block. It's intended 40 40 to be used in C functions that import other modules to execute a function. 41 41 The import may block if another thread holds the import lock. The function 42 :c func:`PyImport_ImportModuleNoBlock` never blocks. It first tries to fetch43 the module from sys.modules and falls back to :c func:`PyImport_ImportModule`42 :c:func:`PyImport_ImportModuleNoBlock` never blocks. It first tries to fetch 43 the module from sys.modules and falls back to :c:func:`PyImport_ImportModule` 44 44 unless the lock is held, in which case the function will raise an 45 45 :exc:`ImportError`. … … 48 48 49 49 50 .. c function:: PyObject* PyImport_ImportModuleEx(char *name, PyObject *globals, PyObject *locals, PyObject *fromlist)50 .. c:function:: PyObject* PyImport_ImportModuleEx(char *name, PyObject *globals, PyObject *locals, PyObject *fromlist) 51 51 52 52 .. index:: builtin: __import__ … … 66 66 67 67 .. versionchanged:: 2.6 68 The function is an alias for :c func:`PyImport_ImportModuleLevel` with68 The function is an alias for :c:func:`PyImport_ImportModuleLevel` with 69 69 -1 as level, meaning relative import. 70 70 71 71 72 .. c function:: PyObject* PyImport_ImportModuleLevel(char *name, PyObject *globals, PyObject *locals, PyObject *fromlist, int level)72 .. c:function:: PyObject* PyImport_ImportModuleLevel(char *name, PyObject *globals, PyObject *locals, PyObject *fromlist, int level) 73 73 74 74 Import a module. This is best described by referring to the built-in Python … … 84 84 85 85 86 .. c function:: PyObject* PyImport_Import(PyObject *name)86 .. c:function:: PyObject* PyImport_Import(PyObject *name) 87 87 88 88 .. index:: … … 99 99 100 100 101 .. c function:: PyObject* PyImport_ReloadModule(PyObject *m)101 .. c:function:: PyObject* PyImport_ReloadModule(PyObject *m) 102 102 103 103 .. index:: builtin: reload … … 109 109 110 110 111 .. c function:: PyObject* PyImport_AddModule(const char *name)111 .. c:function:: PyObject* PyImport_AddModule(const char *name) 112 112 113 113 Return the module object corresponding to a module name. The *name* argument … … 119 119 120 120 This function does not load or import the module; if the module wasn't already 121 loaded, you will get an empty module object. Use :c func:`PyImport_ImportModule`121 loaded, you will get an empty module object. Use :c:func:`PyImport_ImportModule` 122 122 or one of its variants to import a module. Package structures implied by a 123 123 dotted name for *name* are not created if not already present. 124 124 125 125 126 .. c function:: PyObject* PyImport_ExecCodeModule(char *name, PyObject *co)126 .. c:function:: PyObject* PyImport_ExecCodeModule(char *name, PyObject *co) 127 127 128 128 .. index:: builtin: compile … … 134 134 module could still be created in error cases. Starting with Python 2.4, *name* 135 135 is removed from :attr:`sys.modules` in error cases, and even if *name* was already 136 in :attr:`sys.modules` on entry to :c func:`PyImport_ExecCodeModule`. Leaving136 in :attr:`sys.modules` on entry to :c:func:`PyImport_ExecCodeModule`. Leaving 137 137 incompletely initialized modules in :attr:`sys.modules` is dangerous, as imports of 138 138 such modules have no way to know that the module object is an unknown (and 139 139 probably damaged with respect to the module author's intents) state. 140 140 141 The module's :attr:`__file__` attribute will be set to the code object's 142 :c:member:`co_filename`. 143 141 144 This function will reload the module if it was already imported. See 142 :c func:`PyImport_ReloadModule` for the intended way to reload a module.145 :c:func:`PyImport_ReloadModule` for the intended way to reload a module. 143 146 144 147 If *name* points to a dotted name of the form ``package.module``, any package … … 149 152 150 153 151 .. cfunction:: long PyImport_GetMagicNumber() 154 .. c:function:: PyObject* PyImport_ExecCodeModuleEx(char *name, PyObject *co, char *pathname) 155 156 Like :c:func:`PyImport_ExecCodeModule`, but the :attr:`__file__` attribute of 157 the module object is set to *pathname* if it is non-``NULL``. 158 159 160 .. c:function:: long PyImport_GetMagicNumber() 152 161 153 162 Return the magic number for Python bytecode files (a.k.a. :file:`.pyc` and … … 156 165 157 166 158 .. c function:: PyObject* PyImport_GetModuleDict()167 .. c:function:: PyObject* PyImport_GetModuleDict() 159 168 160 169 Return the dictionary used for the module administration (a.k.a. … … 162 171 163 172 164 .. c function:: PyObject* PyImport_GetImporter(PyObject *path)173 .. c:function:: PyObject* PyImport_GetImporter(PyObject *path) 165 174 166 175 Return an importer object for a :data:`sys.path`/:attr:`pkg.__path__` item … … 175 184 176 185 177 .. c function:: void _PyImport_Init()186 .. c:function:: void _PyImport_Init() 178 187 179 188 Initialize the import mechanism. For internal use only. 180 189 181 190 182 .. c function:: void PyImport_Cleanup()191 .. c:function:: void PyImport_Cleanup() 183 192 184 193 Empty the module table. For internal use only. 185 194 186 195 187 .. c function:: void _PyImport_Fini()196 .. c:function:: void _PyImport_Fini() 188 197 189 198 Finalize the import mechanism. For internal use only. 190 199 191 200 192 .. c function:: PyObject* _PyImport_FindExtension(char *, char *)201 .. c:function:: PyObject* _PyImport_FindExtension(char *, char *) 193 202 194 203 For internal use only. 195 204 196 205 197 .. c function:: PyObject* _PyImport_FixupExtension(char *, char *)206 .. c:function:: PyObject* _PyImport_FixupExtension(char *, char *) 198 207 199 208 For internal use only. 200 209 201 210 202 .. c function:: int PyImport_ImportFrozenModule(char *name)211 .. c:function:: int PyImport_ImportFrozenModule(char *name) 203 212 204 213 Load a frozen module named *name*. Return ``1`` for success, ``0`` if the 205 214 module is not found, and ``-1`` with an exception set if the initialization 206 215 failed. To access the imported module on a successful load, use 207 :c func:`PyImport_ImportModule`. (Note the misnomer --- this function would216 :c:func:`PyImport_ImportModule`. (Note the misnomer --- this function would 208 217 reload the module if it was already imported.) 209 218 210 219 211 .. c type:: struct _frozen220 .. c:type:: struct _frozen 212 221 213 222 .. index:: single: freeze utility … … 225 234 226 235 227 .. c var:: struct _frozen* PyImport_FrozenModules228 229 This pointer is initialized to point to an array of :c type:`struct _frozen`236 .. c:var:: struct _frozen* PyImport_FrozenModules 237 238 This pointer is initialized to point to an array of :c:type:`struct _frozen` 230 239 records, terminated by one whose members are all *NULL* or zero. When a frozen 231 240 module is imported, it is searched in this table. Third-party code could play … … 233 242 234 243 235 .. c function:: int PyImport_AppendInittab(char *name, void (*initfunc)(void))244 .. c:function:: int PyImport_AppendInittab(const char *name, void (*initfunc)(void)) 236 245 237 246 Add a single module to the existing table of built-in modules. This is a 238 convenience wrapper around :c func:`PyImport_ExtendInittab`, returning ``-1`` if247 convenience wrapper around :c:func:`PyImport_ExtendInittab`, returning ``-1`` if 239 248 the table could not be extended. The new module can be imported by the name 240 249 *name*, and uses the function *initfunc* as the initialization function called 241 250 on the first attempted import. This should be called before 242 :c func:`Py_Initialize`.243 244 245 .. c type:: struct _inittab251 :c:func:`Py_Initialize`. 252 253 254 .. c:type:: struct _inittab 246 255 247 256 Structure describing a single entry in the list of built-in modules. Each of 248 257 these structures gives the name and initialization function for a module built 249 258 into the interpreter. Programs which embed Python may use an array of these 250 structures in conjunction with :c func:`PyImport_ExtendInittab` to provide259 structures in conjunction with :c:func:`PyImport_ExtendInittab` to provide 251 260 additional built-in modules. The structure is defined in 252 261 :file:`Include/import.h` as:: … … 258 267 259 268 260 .. c function:: int PyImport_ExtendInittab(struct _inittab *newtab)269 .. c:function:: int PyImport_ExtendInittab(struct _inittab *newtab) 261 270 262 271 Add a collection of modules to the table of built-in modules. The *newtab* … … 265 274 Returns ``0`` on success or ``-1`` if insufficient memory could be allocated to 266 275 extend the internal table. In the event of failure, no modules are added to the 267 internal table. This should be called before :c func:`Py_Initialize`.276 internal table. This should be called before :c:func:`Py_Initialize`.
Note:
See TracChangeset
for help on using the changeset viewer.