これは私のディレクトリの視覚的表現です:
これはtest1.pyのコードスニペットです
....
def foo():
f=read("./test1.dat","r")
....
これがtest2.pyのコードです
import imp
TEST1 = imp.load_source('test1', '../test1.py')
def test2():
TEST1.foo()
test2.py の実行
cd subdir
python test2.py
got IOERROR: No such file or directory : "./test1.dat"
私の質問は:
たとえば、test2.pyをその親ディレクトリに移動するなど、ディレクトリの構造を変更しない場合、モジュールtest2で呼び出すときにモジュールtest1に正しいファイルを見つけさせることは可能ですか?