任何人都可以告诉我这段代码有什么问题。这是用于阅读' READ'在csv文件上。我得到的错误是 return _compile(pattern,flags).match(string) TypeError:期望的字符串或缓冲区
import csv
import re
f1 = open("1.csv", "rb")
reader = csv.reader(f1)
header = reader.next()
f2 = open("out.csv", "wb")
writer = csv.writer(f2)
writer.writerow(header)
for row in reader:
if re.match(r'^.*READ $', row):
writer.writerow(row)
f1.close()
f2.close()
答案 0 :(得分:0)
缩进您的代码1 ...
这可能有用......
import csv
import re
f1 = open("1.csv", "rb")
reader = csv.reader(f1)
header = reader.next()
f2 = open("out.csv", "wb")
writer = csv.writer(f2)
writer.writerow(header)
for row in reader:
if re.match(r'^.*READ $', str(row)):
writer.writerow(row)
f1.close()
f2.close()