python:os.path.exists(path) 和 os.path.lexists(path) 的区别os.path.exists(path)Return True if path refers to an existing path.Returns False for broken symbolic links.On some platforms,this function may return False if permission is not granted

来源:学生作业帮助网 编辑:作业帮 时间:2024/05/10 01:00:18
python:os.path.exists(path) 和 os.path.lexists(path) 的区别os.path.exists(path)Return True if path refers to an existing path.Returns False for broken symbolic links.On some platforms,this function may return False if permission is not granted

python:os.path.exists(path) 和 os.path.lexists(path) 的区别os.path.exists(path)Return True if path refers to an existing path.Returns False for broken symbolic links.On some platforms,this function may return False if permission is not granted
python:os.path.exists(path) 和 os.path.lexists(path) 的区别
os.path.exists(path)
Return True if path refers to an existing path.Returns False for broken symbolic links.On some platforms,this function may return False if permission is not granted to execute os.stat() on the requested file,even if the path physically exists.
os.path.lexists(path)
Return True if path refers to an existing path.Returns True for broken symbolic links.Equivalent to exists() on platforms lackingos.lstat().
这是文档原文,还是不懂这两个函数的区别,求指教

python:os.path.exists(path) 和 os.path.lexists(path) 的区别os.path.exists(path)Return True if path refers to an existing path.Returns False for broken symbolic links.On some platforms,this function may return False if permission is not granted
主要的区别在于,exists()会自动判断失效的文件链接.如果检查的文件是一个软链接,但这个软连接指向的文件被删除了,会返回False.而lexists()不会做这个检查,只要软连接存在,即使它指向的文件不存在,也返回True.
当查询没有权限指向os.stat()时,exists()也会返回False.