Understand Python package

Import Import relative and absolute
absolute import must start from the top pack, you must know what the top package in place. Top entry packet is the same level and executable package
relative introduced
. Current
.. superior
... on the upper
....

// import does not support relative import
import .package2 (syntax error will be reported)

from .package2.package4.m2 import m ( )

The reason why the relative path may be positioned according __name__to a result of the positioning module is executed after the entry of his name is not python his name is the name of the module is forced into python __main__so python inlet import file may not use a relative path.

Published 65 original articles · won praise 3 · views 50000 +

Guess you like

Origin blog.csdn.net/web_orange/article/details/78132431