[英]How to import function to main namespace of my module?
I am using python 2.7, and am building a module with a lot of subdirectories. 我正在使用python 2.7,并且正在构建带有许多子目录的模块。 The structure looks something like this: 结构看起来像这样:
mainmodule/
__init__.py
submodule/
__init__.py
somefunction.py
someotherfuntion.py
Now when importing i would, rather than having this: 现在,当我导入时,而不是这样:
>>> from mainmodule.submodule.somefunction import func
>>> func(do_some_stuff)
i want this: 我要这个:
>>> import mainmodule
>>> mainmodule.func(do_some_stuff)
Thanks in advance! 提前致谢!
然后,您应该在主模块的__init__.py
导入并公开您的函数:
from .submodule.somefunction import func
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.