python中os.path.abspath与os.path.realpath 区别

python中os.path.abspath与os.path.realpath 区别
cd /home
mkdir a
mkdir b
touch a/1.txt
ln -s /home/a/1.txt /home/b/1.txt

python
进入实时模式
>>> import os
>>> os.path.abspath("a/1.txt")
'/root/a/1.txt'
>>> os.path.abspath("b/1.txt")
'/root/b/1.txt'
>>> os.path.realpath("b/1.txt")
'/root/a/1.txt'
>>> os.path.realpath("a/1.txt")
'/root/a/1.txt'
>>>

os.path.realpath 返回的是使用软链的真实地址
os.path.abspath 返回目标地址

猜你喜欢

转载自www.cnblogs.com/WebLinuxStudy/p/12107671.html