Module#
- class Module(*args, **kwargs)#
The Module struct is an opaque data structure to represent a
dynamically-loaded module.
It should only be accessed via the following functions.
To ensure correct lock ordering, these functions must not be called from
global constructors (for example, those using GCC’s
__attribute__((constructor)) attribute).
Methods#
- class Module
- classmethod build_path(directory: str | None, module_name: str) str#
A portable way to build the filename of a module. The platform-specific prefix and suffix are added to the filename, if needed, and the result is added to the directory, using the correct separator character.
The directory should specify the directory where the module can be found. It can be
Noneor an empty string to indicate that the module is in a standard platform-specific directory, though this is not recommended since the wrong module may be found.For example, calling
build_path()on a Linux system with adirectoryof/liband amodule_nameof “mylibrary” will return/lib/libmylibrary.so. On a Windows system, using\Windowsas the directory it will return\Windows\mylibrary.dll.Deprecated since version 2.76: Use
open()instead withmodule_nameas the basename of the file_name argument. See %G_MODULE_SUFFIX for why.- Parameters:
directory – the directory where the module is. This can be
Noneor the empty string to indicate that the standard platform-specific directories will be used, though that is not recommendedmodule_name – the name of the module
- make_resident() None#
Ensures that a module will never be unloaded. Any future
close()calls on the module will be ignored.