Suppose I have a symlink /path/to/symlink
that points to a directory /path/to/dir
. In a python codebase I was looking at, it writes some file to the real path like below:
import os
symlink_path = '/path/to/symlink'
target_path = os.path.realpath(symlink_path)
file_path = os.path.join(target_path, "file.txt")
with open(file_path, 'w'):
# write some stuff
I don’t understand why the realpath is needed here. Why can’t we simply do
import os
symlink_path = '/path/to/symlink'
file_path = os.path.join(symlink_path, "file.txt")
with open(file_path, 'w'):
# write some stuff
and not worry about the realpath?