In Python 2, is it possible to get the real path of a file object after an 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 of the file on disk, but the second one does not. Is there any way to get the path of the disk file after the chdir
? Ideally, I'd like a general answer, one that would work even if I didn't create the file object myself.
I don't have any actual use case for this, I'm just curious.