分页: 1 / 1

大家一起测试一下,看看哪里有问题

发表于 : 2013-05-20 19:51
mad_frog
我有一个文本文件all.txt,内容如下:
"F:\\log\\jx2\\\\2013_05\\bishop_1-3\\Bishop_2013_05_15.txt"
"F:\\log\\jx2\\2013_05\\bishop_3-1\\Bishop_2013_05_15.txt"
"F:\\log\\jx2\\2013_05\\bishop_4-1\\Bishop_2013_05_15.txt"

这些路径下面的文件都存在(手动判断返回值也是:True “check ok”),但是python脚本每次检查都是不存在的“check fail”,实在不知道如何判断了,求助各位大神!

代码: 全选

import os
f = open(r'D:\python\all.txt')
r="r"
for line in f.readlines():
        aaa= r+line
        if os.path.exists(aaa):
                print "%s check ok" %line
        else:
                print "%s check fail" %line
f.close()

Re: 大家一起测试一下,看看哪里有问题

发表于 : 2013-05-20 20:41
oneleaf
aaa= r+line 错误了。
直接
if os.path.exists(line.strip()):
即可