Your FS
value is a string that includes the newline character from the file still, so test for a string value:
if FS == '0\n':
or strip the newline:
if FS.strip() == '0':
or turn FS
into a float first:
if float(FS) == 0:
or strip line
while splitting:
line = line.strip().split(';')
Further tips:
Just loop over
lines
directly; don't userange()
:for line in lines: line = line.strip() # do something with `line`
Even if you still need an index as well, you use
enumerate()
to generate the index:for i, line in enumerate(lines): line = line.strip() # do something with `line` and `i`.
You can use the
csv
module to handle splitting data files into rows:import csv with open(somefile, 'rb') as inputfile: reader = csv.reader(inputfile, delimiter=';') for row in reader: leansz, FW, FS = map(float, (row[9], row[34], row[35])) if not FS: continue LnSzRa = leansz / (FS / 2)