以treelib为例
C:PROGRAMDATAANACONDA3ENVSPYTHON39LIBSITE-PACKAGESTREELIB │ exceptions.py │ misc.py │ node.py │ plugins.py │ tree.py │ __init__.py
要是没有init文件,有四种方式调用tree.py,都是最原始的方法
import treelib.tree import treelib.tree as tree from arithmetic.tree import Tree from arithmetic import tree
如果有了init.py文件,可以在里边做一个中间步骤
#init.py from .tree import Tree#.tree即当前文件夹下的tree.py #from .node import Node
当你此时import treelib时,就已经做完了from treelib.tree import Tree.所以在其他文件中,你就可以这样用
#xxx.py import treelib tree = Tree()参考文献:
https://zhuanlan.zhihu.com/p/115350758



