gpt4 book ai didi

python - python 需要 __init__.py 包的原因是什么?

转载 作者:太空宇宙 更新时间:2023-11-03 12:32:26 24 4
gpt4 key购买 nike

<分区>

我知道 python 需要 __ init __.py 文件才能将目录识别为 python 包,这样我们就可以将子模块导入到我们的程序中。我可以看到与类以及如何使用 init 立即执行必要的代码。

但是,在 python 文档中,这一行让我感到困惑,

This is done to prevent directories with a common name, such as string, from unintentionally hiding valid modules that occur later on the module search path.

如此处所示 https://docs.python.org/2/tutorial/modules.html#packages

有人可以澄清一下吗?

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com