Module Objects — Python 3.16.0a0 documentation

docs.python.org

Tin mới

Python Module Index

3.16.0a0 Documentation

Python/C API reference manual

Concrete Objects Layer

module.__package__

Return a new module object with module.__name__ set to name. The module’s __name__, __doc__, __package__ and __loader__ attributes are filled in (all but __name__ are set to None). The caller is responsible for setting a

UnicodeEncodeError

Deprecated since version 3.2: PyModule_GetFilename() raises UnicodeEncodeError on unencodable filenames, use PyModule_GetFilenameObject() instead.

Module definition¶

Modules created using the C API are typically defined using an array of PySlot structs, which provides a “description” of how a module should be created. See Definition slots for more information on slots in general.

Defining extension modules

Modules created using the C API are typically defined using an array of PySlot structs, which provides a “description” of how a module should be created. See Definition slots for more information on slots in general.

importlib.machinery.ModuleSpec

Slot ID for the name of the new module, as a NUL-terminated UTF8-encoded const char *.

Isolating Extension Modules

The module supports being imported in subinterpreters, but only when they share the main interpreter’s GIL. (See Isolating Extension Modules.)

Free-threaded CPython

The module depends on the presence of the global interpreter lock (GIL), and may access global state without synchronization.

PyTypeObject.tp_traverse

Slot ID for a traversal function to call during GC traversal of the module object.

PyType_GetModuleByToken()

Each module may have an associated token: a pointer-sized value intended to identify of the module state’s memory layout. This means that if you have a module object, but you are not sure if it “belongs” to your extensio

PyUnicode_FromString()

Add an object to module as name. This is a convenience function which can be used from the module’s initialization function.

PyObject_SetAttr()

Add an object to module as name. This is a convenience function which can be used from the module’s initialization function.

attached thread state

Attaches the module object passed to the function to the interpreter state. This allows the module object to be accessible via PyState_FindModule().