[Tutor] Some questions about importlib

Quentin Agren quentin.agren at gmail.com
Sun Oct 21 01:24:08 EDT 2018


Hi,

My name Quentin, and this is my first post to this list so please redirect
me if this is not the proper audience.

I have been studying the 'importlib' standard library package this past
week, and although I find it very readable I am puzzled by some questions
that I'd like to share.

- [Chicken and egg] Does the 'import' statement in Python make use of
'importlib'? If so, how are the imports in 'importlib' itself carried out?
(for example in __init__.py)

- Why does 'importlib' use 'nt' or 'psoix' (see
'_bootstrap_external._setup()') rather than the portable 'os', and
reimplement some of the latter's functionality, for example '_path_join',
or '_path_split'. Another example is in 'SourceFileLoader.set_data()' where
the logic of 'os.mkdirs' is reproduced to create all necessary intermediary
directories in a file path.

- Similarly, would not using the 'struct' module simplify the
packing/unpacking of bytecode. For example by defining BYTECODE_HEADER_FMT
= '4sII' (Python 3.6)

Thanks for any insights you may share and have a nice sunday,
Quentin


More information about the Tutor mailing list