Teks sumber — English
Terjemahan — Bahasa Indonesia
A C extension for CPython is a shared library (for example, a ``.so`` file on Linux, ``.pyd`` DLL on Windows), which is loadable into the Python process (for example, it is compiled with compatible compiler settings), and which exports an :dfn:`export hook` function (or an old-style :ref:`initialization function <extension-pyinit>`).
For example, a module called ``spam`` would be defined like this::
For example::
Sebagai contoh::
By default, extension modules are not singletons. For example, if the :py:attr:`sys.modules` entry is removed and the module is re-imported, a new module object is created and, typically, populated with fresh method and type objects. The old module is subject to normal garbage collection. This mirrors the behavior of pure-Python modules.
*module_name* is the module's full dotted name, taken from :py:attr:`ModuleSpec.name <importlib.machinery.ModuleSpec.name>` (or the equivalent argument of the importing function). Note that names that the initialization function uses to create the module (for example, :c:member:`PyModuleDef.m_name`) are not taken into account.
As part of the first initialization, Python also adds the module to :data:`sys.modules` under its name. For example, given a single-phase module ``_testsinglephase`` [#testsinglephase]_ that defines a function ``sum`` and an exception class ``error``:
Subsequent imports that specify a different initialization function (for example, using :c:func:`PyImport_CreateModuleFromInitfunc`) may call either the cached function or the provided "new" one.