1

我的电脑上有这些文件:

some/random/path/config.py
my/path/defined/here/file1.py
my/other/path/here/file2.py

然后,我有:

#File: config.py
import sys
path1="my/path/defined/here/"
sys.path.append(path1)
path2="my/other/path/here"
sys.path.append(path2)

import file1

和,

#File: file1.py
import file2
file2.runFunction()

路径“my/path/defined/here/”在 config.py 中定义,但我想以某种方式将相同的路径添加到 file1.py,以便我可以在 file1.py 中导入 file2.py。我希望能够在 file1.py 中没有确切路径的情况下执行此操作,因为我将有多个 config.py py 文件。

4

0 回答 0