我在导入模块时遇到问题。如果我使用,
import fruit as f
print f.apple.juice.CALORIES_INT
这行得通。和
import fruit.apple.juice as j
print j.CALORIES_INT
不工作。它抛出AttributeError: 'module' object has no attribute 'apple'
。关于如何调试它的任何建议?
我的目录结构如下:
fruit
--- __init__.py
--- apple
---------__init__.py
--------- juice.py
---------------CALORIES_INT is a variable declared here
--- orange
--------- __init__.py
--------- shake.py
---------------trying to access CALORIES_INT here by importing it.
苹果是一个包。我可以导入其他包。