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")
因为它以
/
开头
pycharm 在 python 控制台中将“/Users/name/folder”显示为 True。当在 python 中作为脚本运行时,它会产生 False —— 东西坏了?
Mac OSX