os.path.abspath() 和 os.path.realpath() 区别

相同点

都能返回文件的绝对路径。

>>> import os

>>> os.path.realpath(__file__)
f:\work\tmp\test.py

>>> os.path.abspath(__file__)
 f:\work\tmp\test.py

输出:
f:\work\tmp\test.py
f:\work\tmp\test.py

不同点
example:
file_a
file_b -> file_a # 软连接指向a

>>> import os

>>> os.path.abspath(file_b)
/tmp/file_b

# 会得到指向的文件的路径
>>> os.path.realpath(file_b)
/tmp/file_a

猜你喜欢

转载自blog.csdn.net/qq_22918243/article/details/88919998