zoukankan      html  css  js  c++  java
  • os.path.exists(path) 和 os.path.lexists(path) 的区别

    使用os.path.exists()方法可以直接判断文件是否存在。
    代码如下:
    >>> import os
    >>> os.path.exists(r'C:1.TXT')
    False
    >>>

    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().
    主要的区别在于,exists()会自动判断失效的文件链接。如果检查的文件是一个软链接,但这个软连接指向的文件被删除了,会返回False。而lexists()不会做这个检查,只要软连接存在,即使它指向的文件不存在,也返回True。


  • 相关阅读:
    1265 四点共面
    1003 阶乘后面0的数量
    1080 两个数的平方和
    1090 3个数和为0
    1087 1 10 100 1000
    1082 与7无关的数
    OpenLayers工作原理
    CI(持续集成)CD(持续交付)
    打包命令
    文件与目录管理重点
  • 原文地址:https://www.cnblogs.com/timssd/p/4709629.html
Copyright © 2011-2022 走看看