我的项目结构如下:
root_dir/
└── app/
├── __init__.py
├── mymodule.py
在mymodule.py中,我具有以下功能:
def hello():
print('hello world')
如果我从根目录中调用python,我希望执行以下操作:
>>> import app
>>> app.mymodule.hello()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: module 'app' has no attribute 'mymodule'
是否仍有调用hello函数的方法
jonrsharpe comment是对的。引用包时,您引用的是
__init__.py
模块,而此模块不包含对mymodule
的任何引用。这就是为什么你首先不能做app.mymodule
相关问题 更多 >
编程相关推荐