python - 导入多个模块中的所有功能
问题描述
我想在多个模块中导入所有功能。
这是我的结构:
global/
__init__.py
test/
__init__.py
a.py
b.py
我建立 :
test/__init__.py
from .a import *
from .b import *
和,
global/__init__.py
from .test import *
我可以从所有模块调用 alls 函数。但是,我希望只有一行直接导入所有模块中的所有函数,而不是逐个模块调用。
解决方案
这是你要找的吗?
app.py
:
from test.a import *
from test.b import *
foo()
bar()
您现在可以在a.py
和b.py
模块中指定尽可能多的函数,而无需实际调用前缀模块。
test/a.py
:
def foo():
print('foo')
test/b.py
:
def bar():
print('bar')
输出:
foo
bar
推荐阅读
- db2 - 在 bluemix 云上访问 dashdb 的日志
- python - 如何使用 Python 读取带有 NULL 字符的二进制文件
- javascript - 如何将文件上传与尚未创建的表单提交相关联?
- javascript - KendoDropDownList 默认选择值在控制器上无法正常工作
- ffmpeg - 使用 ffmpeg 合并 mp4 文件(按顺序)
- c# - DOT NET LinkButton 在应用程序中呈现不同
- html - 没有前缀“file:///”的图像不显示在 HTML 中
- google-oauth - 当 GoogleAuthorizationCodeFlow 调用已批准的应用程序时未发布刷新令牌
- python - 从无量纲生成一维数组
- r - 用以前的非 NA 可用值 R 填充 NA