The Python Language Reference Manual by Chris Sheridan

The Python Language Reference Manual by Chris Sheridan

Author:Chris Sheridan [Sheridan, Chris]
Language: eng
Format: epub, mobi, pdf
ISBN: 9781326570972
Publisher: Lulu.com
Published: 2016-02-19T23:00:00+00:00


If a path entry finder is returned by one of the path entry hook callables on sys.path_hooks, then the following

protocol is used to ask the finder for a module loader, which is then used to load the module.

5.5.2 Path entry finder protocol

In order to support imports of modules and initialized packages and also to contribute portions to namespace packages,

path entry finders must implement the find_loader() method.

find_loader() takes one argument, the fully qualified name of the module being imported. find_loader()

returns a 2-tuple where the first item is the loader and the second item is a namespace portion. When the first item

(i.e. the loader) is None, this means that while the path entry finder does not have a loader for the named module, it

knows that the path entry contributes to a namespace portion for the named module. This will almost always be the

case where Python is asked to import a namespace package that has no physical presence on the file system. When a

path entry finder returns None for the loader, the second item of the 2-tuple return value must be a sequence, although

it can be empty.

If find_loader() returns a non-None loader value, the portion is ignored and the loader is returned from the path

based finder, terminating the search through the path entries.

For backwards compatibility with other implementations of the import protocol, many path entry finders also support

the same, traditional find_module() method that meta path finders support. However path entry finder

find_module() methods are never called with a path argument (they are expected to record the appropriate

path information from the initial call to the path hook).

The find_module() method on path entry finders is deprecated, as it does not allow the path entry finder to contribute

portions to namespace packages. Instead path entry finders should implement the find_loader() method

as described above. If it exists on the path entry finder, the import system will always call find_loader() in

preference to find_module().



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.