import os
import sys
a = os.listdir("C:\\Python27\\forms2")
i = 0
big_file = open("c:\\Python27\\forms2\\%s" %a[i], 'r')
small_file3 = open("c:\\Python27\\forms3\\%s" %a[i], 'w')
linez = big_file.read()
for line in linez:
if 'TextControl' in linez:
small_file3.write(line)
if 'http://' in linez:
small_file3.write(line)
i = i + 1
big_file.close()
small_file3.close()
输出是
Traceback (most recent call last):
File "C:\Python27\testreadwrite", line 13, in <module>
small_file3.write(line)
ValueError: I/O operation on closed file
“testreadwrite”是脚本的名称。为什么它在应该注入“a”列表变量的地方注入?