这是我的目录结构:
scripts/ bpydata/ bpymodules/ myCustomScripts/ lib/ __init__.py customLib.py plugin/ __init__.py myParser.py __init__.py runner.py ... my_import_script.py ...
我从我的“导入”脚本开始,它将导入myCustomScripts包。
从那里,我导入runner,它将导入myParser。
myParser需要在customLib中定义的内容,因此它将使用相对导入来获取它
from .lib import customLib
但是它不起作用,因为我从我的\u import_脚本开始,所以它将搜索它的父目录,而不是搜索myParser的父目录。
当myParser需要.lib时,如何确保我是从myParser的目录而不是从我的\u import_脚本的目录升级一个目录?
要从父包导入,请使用
..
。如果我没有误解你,这应该行得通:见http://docs.python.org/tutorial/modules.html。在
相关问题 更多 >
编程相关推荐