我试图运行在Python下面的代码,并正在错误:Python的CSV错误:序列预计
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
请发布带有完整回溯的完整错误消息。 – BrenBarn 2013-02-09 02:33:59
'else:pass'在你的代码中什么也不做。你是否想要做别的事情? – 2013-02-09 02:37:18
它应该跳过打开的文件中的当前行并转到下一行。我想这是我将要遇到的下一个问题! – 2013-02-09 02:41:09