Python在使用os包的过程中,经常遇到返回文件路径的方法,那os.path.abspath()和os.path.realpath()的区别是什么
1.os.path.abspath()
-
返回一个目录的绝对路径
-
Return an
absolute path.
-
>>> os.path.abspath(
"/etc/sysconfig/selinux")
-
'/etc/sysconfig/selinux'
-
>>> os.getcwd()
-
'/root'
-
>>> os.path.abspath(
"python_modu")
-
'/root/python_modu'
2.os.path.realpath()
-
返回指定文件的标准路径,而非软链接所在的路径
-
Return the canonical path
of the specified filename, eliminating any
-
symbolic links encountered
in the path.
-
>>> os.path.realpath(
"/etc/sysconfig/selinux")
-
'/etc/selinux/config'
-
>>> os.path.realpath(
"/usr/bin/python")
-
'/usr/bin/python2.7'