2021
03-16
03-16
Python os.path.exists()函数总是返回false的解决方案
如下面所示,如果我们用file的readline或readlines,在每一行后面都有一个\n回车符直接os.path.exists(readline)时总会返回false>>>fromos.pathimportexists>>>exists('dog.png')True>>>exists('dog.png\n')False使用item.strip('\n')#前面的item为我定义的变量去掉后再传递给os.path.exists(item)就OK了。补充:当os.path.exists(path)的path中包含有空格时返回结果为False的解决方案之前有个问题一直没有解决,当路径中...
继续阅读 >