为什么 os.path.isabs() 给出错误的输出?
Why does os.path.isabs() give incorrect output?
print(str(os.path.isabs("c:///\\xmls\hello.txt")))
此源代码returnsTrue
.
这是为什么?
c:///\\xmls\hello.txt
怎么可能是有效路径?
来自 official 文档:
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")
因为它以 /
开头
print(str(os.path.isabs("c:///\\xmls\hello.txt")))
此源代码returnsTrue
.
这是为什么?
c:///\\xmls\hello.txt
怎么可能是有效路径?
来自 official 文档:
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")
因为它以 /