我需要检查csv文件上的第一个值。它需要匹配一个特定的字符串"ddd.ddddd";所有数字。所有CSV值以"CSV"开头和结尾">
CSV 的样本字符串
"123.12345"
到目前为止的代码是
import re
import csv
strformat = re.compile('"d{3}.d{5}"')
with open(final_file, newline='') as fin:
for f in csv.reader(fin[0]):
if strformat is not None:
print ("Match")
else:
print ("No Match")
你需要像这样反转你的代码,
# The expression is changed
strformat = re.compile(r'd{3}.d{5}')
with open(final_file, newline='') as fin:
for row in csv.reader(fin):
# You have to check match like this
if strformat.match(row[0]):
print ("Match")
else:
print ("No Match")