我正在尝试在 Python 中运行以下代码,但出现错误:
csv.Error: sequence expected
有谁知道我的代码有什么问题?(该文件先前已导入程序中)。
import csv
file = open('/home/btoms/Desktop/TomsBen/2000/01/01/20000101acme.mts', 'r')
variables = []
file.readline() #Skip a line
file.readline()
file.readline() #Skip another line
for line in file:
tmp = line.split()
tmp_STID = str(tmp[0])
tmp_T = float(tmp[4])
tmp_RH = float(tmp[3])
tmp_Times = float(tmp[2])
variables.append(tmp_STID)
variables.append(tmp_Times)
variables.append(tmp_T)
variables.append(tmp_RH)
if tmp_T < 6.2 and tmp_RH > 60.0:
dataCSV = open('ProgramCheck.csv', 'w')
writer = csv.writer(dataCSV, dialect='excel')
writer.writerow(['Station ID', 'Time', 'Temperature' , 'Relative Humidity'])
for values in variables:
writer.writerow(values)
else:
pass
file.close()
错误出现为:
Traceback (most recent call last):
File "checkcsv.py", line 30, in <module>
writer.writerow(values)
_csv.Error: sequence expected