首页 > 解决方案 > 为什么 os.path.isabs() 给出不正确的输出?

问题描述

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

此源代码返回True.

这是为什么?

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

标签: pythonpath

解决方案


来自官方文档:

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")

因为它以/


推荐阅读