专注于高品质PHP技术等信息服务于一体 [STIEMAP] [RSS]

百度提供的广告:
python
当前位置:首页 > 技术文档 > python >  > 
python os.path.abspath realpath 区别
#home
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'
>>>
 
realpath 返回的是 使用软链 的真实地址
abspath 返回目标地址