为什么os.path.iisabs()会给出不正确的输出


print(str(os.path.isabs("c:///\\xmls\hello.txt")))

此源代码返回True

为什么?

c:///\\xmls\hello.txt怎么可能是有效路径?

来自官方文档:

Return True if path is an absolute pathname. 
On Unix, that means it begins with a slash, 
on Windows that it begins with a (back)slash after chopping off a potential drive letter.

换句话说,即使是这个代码也会打印True

os.path.isabs("/hello world")

因为它从/开始

最新更新