os.path.abspath(__ file__)显示的路径与实际路径不同

I am having issue in fetching the correct path of the file using os.path.abspath(__file__).

文件:Assessment.py

实际路径:/Users/akshay.dubey/xyz/Assessment.py

python版本-3.7.1

当我在终端上运行脚本时,它将显示一条不同的路径,例如/Users/akshay.dubey/xyz/assignment/dataset/Assessment.py,并且那里没有文件Assessment.py。

Just to add, I have code to change current working directory to /Users/akshay.dubey/xyz/assignment/dataset but ideally that should not cause the value for os.path.abspath(__file__) to change. And when I remove the cwd it shows the correct value.

评论