What is the difference between a finder and a meta hook?

Here import-hooks says that meta-hooks are registered in sys.meta_path . Crawlers are also stored in this list. So what is the difference between a meta hook and a finder? Are they the same? And why are they stored in one place?

+4
source share
2 answers

In the document you are quoting:

Meta hooks are registered by adding new finder objects to sys.meta_path

So, I would say yes, they are the same.

+1
source

They are subtle. This document contains a detailed discussion of the import mechanism.

Meta hooks are called at the start of import processing. As a result, they can participate in all types of imports, including imports, such as built-in modules or frozen modules, as well as starting processing sys.path based disk space sys.path . In principle, at this level

During the processing of each sys.path entry, path hooks are processed during the import process. They are able to return an object that will be fully responsible for placing the modules in this particular path entry. For example, if sys.path contains [/usr/lib/Python3, /home/user/mypython] , you can specify a path hook that could execute non-standard materials for finding modules in your mypython project

Both hooks allow you to provide a finder that can take full responsibility for placing modules in specific contexts. For example, a meta path is used to import modules from zip files.

+1
source

Source: https://habr.com/ru/post/1494818/


All Articles