为了账号安全,请及时绑定邮箱和手机立即绑定

python3 from .a import b 使用 __import__() 函数如何写?

python3 from .a import b 使用 __import__() 函数如何写?

翻翻过去那场雪 2019-02-24 12:42:33
如题所写 python3 中 from .a import b 语句如何使用 __import__() 内置函数写呢? 已知下面这两个path的导入结果是一致的: from os import path path = getattr(__import__("os"), "path") 那目前有这样的目录结构: run.py app/__init__.py app/index.py app/ins.py run.py: from app import root root() app/__init__.py: from .ins import ins from .index import root app/index.py: from . import ins def root(): print(ins) app/ins.py ins = "test func" 在 __init__.py 中使用 from .index import root 是可以正常导入的,那如何将这个 from import 语句替换为 使用 __import__() 函数来写呢?(from 的时候 是从 .index 里面导入的,请不要忘记这个点)
查看完整描述

1 回答

  • 1 回答
  • 0 关注
  • 466 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信