python-3.x - 如何在python中重定向导入
问题描述
我在许多文件中有一个代码和一个导入from test import testfunc
。我现在想将其更改为from lib import flow
不接触文件而只接触启动脚本。我该怎么做呢?顺便说一句,这是python 3
我已经尝试过sys.module['test.testfunc'] = lib.flow
,但这无济于事
from test import testfunc
test01 = testfunc()
如何让它像
from lib import flow
test01 = flow()
文件目录
root
├─main.py
├─lib.py
├─test.py
└─test_plugins
└─foo.py
主文件
from lib import flow
sys.module['test.func'] = lib.flow
import test_plugins.foo
库文件
def flow(input):
print(input)
测试.py
def func(test):
print(type(test))
test_plugins/foo.py
from test import func
func(007)
但现在我想要 foo.py 做
from lib import flow
flow(007)
解决方案
推荐阅读
- openshift - 使用基于 postgresql-persistent 模板的新模板时未找到脚本错误
- android - 干净架构表示、领域和数据模块中模型类的命名约定
- c# - 如何处理将文件添加到单元测试中的对象?
- angular - Angular 基于 id 获取类别描述
- c# - 如何在 PHP 中转换 C# Security.GetSecureString 函数
- laravel - 尝试覆盖 JSON 有效负载中的 icon_url Slack Webhook 不起作用
- reactjs - 碳定位在函数内部不起作用 [Laravel-reactjs]
- c# - 内存限制:1 MB C# 应用程序
- asp.net-mvc - 如何在 IIS 7 上部署的应用程序中禁用自定义错误页面 asp.net mvc
- javascript - 如何在一个函数中组合两个 ajax 函数?