Prevent `os.chdir` from resolving symbolic link

折月煮酒 提交于 2019-12-11 00:16:10

问题


On all the machines on my cluster, my home directory is mounted from the NFS server as /home/drive1/username. On the NFS server, the folder /home/drive1/username is a symbolic link to /drive1/username.

Running:

$ python -c "import os; os.chdir('/home/drive1/username'); print(os.getcwd())"

on any machine other than the NFS server prints:

/home/drive1/username

but on the NFS server, the same command prints:

/drive1/username

Is there any way to prevent Python os.chdir from walking the symbolic link? This makes it difficult to specify the correct path when submit jobs from the NFS server to the worker nodes.


Edit:

Note that

cd /home/drive1/username
pwd

works as expected on all machines.

来源:https://stackoverflow.com/questions/45336802/prevent-os-chdir-from-resolving-symbolic-link

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!