Main citation: http://stackoverflow.com/questions/22185888/pythons-loader-what-is-it
What is
__loader__
?
__LOADER__ is the property that is set by the loader on the imported module, which returns the loader object itself when it accesses it.
Prior to Python version 3.3, __loader__ was not set in the built-in import mechanism (without this attribute). Instead, this property applies only to modules imported using the custom loader.
What is
loader
?
Loader is an object returned by the Finder Finder, which uses its Load_module () method to load a module into memory. For example: Importlib.abc.Loader is an abstract base class for loader.
What is
finder
?
The Finder is an object that uses its Find_module () method to try to find the loader for a module. For example: Importlib.abc.Finder is the abstract base class for the finder. Note: However it has been deprecated, it is best to use Importlib.abc.MetaPathFinder and Importlib.abc.PathEntryFinder.
How can I use the it,if at all?
The main use of __loader__ is introspection, however, there are two other common uses:
- The __loader__ can be used to collect data on specific module loaders.
- Prior to Python 3.3, this property could be used to check whether the module was imported by the Hasattr import mechanism.
If hasattr (OS, ' __loader__ ') returns True, this means that the OS module is imported using a custom loader (the built-in import mechanism does not set this property "that is, this attribute is not available"). because it does not, this means that the module is imported using the built-in import mechanism.
The following is a variable that runs de.py import in Python 2.7.9.
The following is a variable that runs demo.py import in Python 3.4.3
Note: The above tests do not work in Python 3.3+ due to changes made by Pep 302.
The __loader__ of Python