Something that I don't understand :
In a shell :
mkdir -p /tmp/toto/titi/tutu
touch /tmp/toto/tata
ln -s /tmp/toto/tata /tmp/toto/titi/tutu/
python
Then in python:
import os
zeList = os.listdir("/tmp/toto/titi/tutu/")
print os.path.realpath(zeList[0])
>'/tata'
print os.path.abspath(zeList[0])
>'/tata'
The expected result should be : /tmp/toto/tata (or /tmp/toto/titi/tutu/tata). Can anyone explain this result ?
os.listdir()
returns base filenames, not full paths:Without a path, the file is then considered relative to the current working directory:
Join the filename with the path first:
Now the symbolic link is properly replaced: