Hello

In a program "code.py" I read an external file "foo.txt" supposed to be located in the same directory that "code.py"

python/src/code.py
python/src/foo.txt

In "code.py": f = open('foo.txt', 'r')

But if I run "python code.py" in an other dir than src/
say in python/, it will not work because file "foo.txt" will be searched in dir python/ and not in dir python/src/

I think it is possible to build an absolute path for "foo.txt" using __file__ so that the program works wherever you launch "python code.py"

Is it the correct way to handle this problem ?

thx




--
https://mail.python.org/mailman/listinfo/python-list

Reply via email to