python - 为什么 os.path.isabs() 给出不正确的输出?
问题描述
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")
因为它以/
推荐阅读
- json - 标签“架构”中的 JSON 无效
- python - 获取 pygame.Surface 错误。我该如何解决?
- cassandra - Cassandra node running, but cant connect?
- java - 为需要文件位置的方法编写单元测试
- c# - 从列表中取出 x 个项目,其中每个项目对某个属性都有唯一的值
- python - 对python非常陌生,想添加一个名为“Total”的新列,它是其他总数的总和
- python-3.x - 用 Sympy 计算有限集的笛卡尔积
- ios - 加载本地文件到app CoreData的代码逻辑是什么?
- python - 从 Python 中的文本文件中过滤掉坏词
- python - 从网页中提取特定文本