【发布时间】:2014-10-20 18:00:17
【问题描述】:
不重复:file not opens after if statement
我有一个来自数据库的文件列表,需要一个一个打开并读取所有文件。
问题:即使文件存在,我也无法打开和读取文件。
files 包括:
1.txt
2.txt
3.txt
我的代码:
path=r'C:\Python27'
for files in cursor.fetchall():
sfile= files[1]
if os.path.exists(os.path.join(path,sfile)):
with open(sfile,'r') as f:
if 'cat' in f:
print 'meow'
错误:
with open(sfile,'r') as f:
IOError: [Errno 2] No such file or directory: '1.txt'
>>>
请帮我纠正我的错误!
【问题讨论】:
标签: python python-2.7 io