I\'ve got a problem with a for
loop that skips the first line. I know why but I don\'t know how to fix it. And when I change it to a while
loop, or in
Looping over the file already reads lines. You don't need nor should you call f.readline()
again. You already have the line in line
, so just use that.
Moreover, you appear to have tab-separated data; consider using the csv module to split your rows; it can also convert your data to floats for you:
reader = csv.reader(f, delimiter='\t', quoting=csv.QUOTE_NONNUMERIC)
for row, (b, c) in enumerate(reader, 1):
worksheet.write(row, 0, b)
worksheet.write(row, 1, c)
The above uses enumerate()
to give you a counter per data row as well. The csv.QUOTE_NONNUMERIC
quoting option causes anything not in quotes in your input file to be auto-converted to float
objects.