os.path.isdir(path)异常

Window 10家庭中文版,Python 3.6.4,

 

当一个路径以多个斜杠(/)或反斜杠字符(\\)结尾时,os.path.isdir(path)函数仍然将它们判断为目录:

>>> os.path.isdir('C:/Python36/Lib/sqlite3//')
True
>>> os.path.isdir('C:/Python36/Lib/sqlite3///')
True
>>> os.path.isdir('C:/Python36/Lib/sqlite3///')
True
>>> os.path.isdir('C:\\Python36\\Lib\\sqlite3\\\\\\\\') # 8个反斜杠(转义后是4个反斜杠 )
True

 

孤的判断是返回False的,为何会如此?后续会继续dig~

 

----

 

Python官文信息:

os.path.isdir(path)
Return True if path is an existing directory. This follows symbolic links, so both islink() and isdir() can be true for the same path.

 

path-like object
An object representing a file system path. A path-like object is either a str or bytes object representing a path, or an object implementing the os.PathLike protocol. An object that supports the os.PathLike protocol can be converted to a str or bytes file system path by calling the os.fspath() function; os.fsdecode() and os.fsencode() can be used to guarantee a str or bytes result instead, respectively. Introduced by PEP 519.

 

class os.PathLike
An abstract base class for objects representing a file system path, e.g. pathlib.PurePath.

 

PEP 519 -- Adding a file system path protocol

 

转载于:https://www.cnblogs.com/luo630/p/9220225.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值