如何在python中导入父模块或兄弟模块?

问题描述

我的模块结构如下(这是一种简化):

parent (main module)
-- child1 (child module)
-- -- grandchild1 (child module of child1)

-- child2 (child module)
-- -- grandchild2 (child module of child2)

每个模块都是一个文件夹,其中包含一个带有模块名称的python文件和一个__init__文件,该文件从该文件夹的主脚本中导入*

现在假设我要从child1导入parent,我使用的代码是from child1 import child1

我的问题是:

  1. 如何从child1导入grandchild1(即使用父模块中的函数)?
  2. 如何从child1导入grandchild*2*(请注意2)?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...