Я пытаюсь создать простой многоуровневый пакет:
test_levels.py
level1/
__init__.py (empty file)
level2/
__init__.py (only contents: __all__ = ["leaf"])
leaf.py
leaf.py:
class Leaf(object):
print("read Leaf class")
pass
if __name__ == "__main__":
x = Leaf()
print("done")
test_levels.py:
from level1.level2 import *
x = Leaf()
Запуск leaf.py напрямую работает нормально, но запуск test_levels.py возвращает вывод ниже, где я не ожидал вывода:
read Leaf class
Traceback (most recent call last):
File "C:\Dev\intranet\test_levels.py", line 2, in <module>
x = Leaf()
NameError: name 'Leaf' is not defined
Может кто-то указать, что я делаю неправильно?