Python __init__.py 包导入问题

今天写代码的时候遇到了一个问题,我自己写了一个包address。

其中__init__.py内容如下:

__all__ = ['cpca', 'regulate']

然后在外面文件夹建立了一个test.py准备使用这个包

发现导入遇到了一些问题

在test.py中只用import导入会报错找不到

import address

print(address.regulate.index_address)

报错:module 'address' has no attribute 'regulate'

而通过from xxx import 就没有问题

from address import regulate

print(regulate.index_address)

很好奇这个问题,虽然不影响正常编写,但是出于求真心理,很想知道是为什么,如果有知道的小伙伴希望可以解答一下,谢谢~

猜你喜欢

转载自blog.csdn.net/blowfire123/article/details/93861219