I am attempting to run the following code in Python, and am getting the error:
csv.Error: sequence expected
Does anyone have any idea what is wrong with my code? (The file was previously imported into the program).
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()
The error comes up as:
Traceback (most recent call last):
File "checkcsv.py", line 30, in <module>
writer.writerow(values)
_csv.Error: sequence expected
else: pass
does nothing in your code. Did you mean it to do something else? – Mike DeSimone Feb 9 '13 at 2:37