Mar-09-2021, 08:34 PM
Hello,
I want to automatically convert relative paths to absolute paths.
dirname = os.path.dirname(__file__)
os.path.join(dirname, r'relative/path/file.txt')
This worked fine but I used this in several places so I thought it makes sense to put it in a separate module. So I did. But when I import it, __file__ points to the module, not to the calling file.
I could give __file__ as an argument enverytime I call that function but it would be easier if I don't have to do that. Any ideas?
Thats the (very simple) function:
I want to automatically convert relative paths to absolute paths.
dirname = os.path.dirname(__file__)
os.path.join(dirname, r'relative/path/file.txt')
This worked fine but I used this in several places so I thought it makes sense to put it in a separate module. So I did. But when I import it, __file__ points to the module, not to the calling file.
I could give __file__ as an argument enverytime I call that function but it would be easier if I don't have to do that. Any ideas?
Thats the (very simple) function:
import os def AbsPath(relPath): dirName = os.path.dirname(__file__) absPath = os.path.join(dirName, relPath) return absPath