def do_something(lines):
output = []
for line in lines:
# Do whatever you need to do.
newline = line.upper()
output.append(newline)
return '\n'.join(output) #
listfiles = ['aba', 'cbr', 'wos', 'grebedit', 'scor']
for f in listfiles:
try:
infile = open(f, 'r')
outfile = open(f+'.out', 'w')
processed = do_something(infile.readlines())
outfile.write(processed)
infile.close()
outfile.close()
except:
# Do some error handling here
print 'Error!'
请允许我告诉你去tutorial。一旦您对一般的文件IO感到满意,这里有一个基本的工作流供您扩展。在
如果需要从某个目录中的所有文件构建列表,请使用
^{pr2}$os
模块。在相关问题 更多 >
编程相关推荐