pth='D:\mytemp\lunwenfcache\convert\20160907' #该路径明明存在
print os.path.isdir(pth) #=>False #但这里却提示该路径不存在?
后来,发现实际上 pth 字符串当中,'\201'实际上被转义了,所以第二句代码就返回 False.
如果这样定义 pth 就不会出错:
pth=r'D:\mytemp\lunwenfcache\convert\20160907'
或者这样定义也不会出错:
pth='D:\mytemp\lunwenfcache\convert\20160907'
然而,在使用 python 的过程中,类似这样的字符串被悄悄转义的情况,表面上看起来似乎难以发觉.
不知高手有什么好的经验?
多谢您的回复!