Can anyone please tell me whats wrong with this block of code. It is for reading line starting with 'READ' on a csv file. The error I am getting is return _compile(pattern, flags).match(string) TypeError: expected string or buffer
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()
Indent your code number 1...
This may work...
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()
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.