文件明明存在,但是用os.path.exists() 返回False,通过试验发现,路径或者文件名中还有中文就会返回fasle,所以文件夹的名称或者文件名最好不要含有中文
试验代码如下,这四个文件都是存在的
print "E:/ruanjian/2222.txt存在吗?%s" % os.path.exists("E:/ruanjian/2222.txt")
print "E:/学习资料/2222.txt存在吗?%s" % os.path.exists("E:/学习资料/2222.txt")
print "E:/ruanjian/python模块的作用.doc存在吗?%s" % os.path.exists("E:/ruanjian/python模块的作用.doc")
print "E:/学习资料/python模块的作用.doc存在吗?%s" % os.path.exists("E:/学习资料/python模块的作用.doc")
试验结果