In Python 2, is it possible to get the real path to a file object after os.chdir() ? Consider:
$ python >>> f = file('abc', 'w') >>> f.name 'abc' >>> from os import path >>> path.realpath(f.name) '/home/username/src/python/abc' >>> os.chdir('..') >>> path.realpath(f.name) '/home/username/src/abc'
The first call to realpath returns the path to the file on disk, and the second does not. Is there a way to get the path to the disk file after chdir ? Ideally, I would like to get a general answer that would work even if I didn't create the file myself.
I have no actual use for this, I'm just curious.
source share