【发布时间】:2013-11-17 19:11:00
【问题描述】:
我在导入模块时遇到问题。 如果我使用,
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.
apple 是一个包。不过我可以导入其他包。
【问题讨论】:
-
您遇到的问题是正常的 Python 行为,与 Pyramid 无关。我为你重新标记了它。 :-)
-
在这种情况下
apple是什么?我想说,它不是一个模块。 -
apple.py真的是fruit下的目录名,还是打错了? -
对不起。那是一个错字。已更新问题。
标签: python package python-import