I'm trying to extract unit information from a text file. This function always returns 'm' regardless of the real unit in the file. What am I doing wrong?
def get_seba_unit(file):
with open(file) as f:
unit = ''
lines = f.readlines()
if lines[10].find('m'):
unit = 'm'
elif lines[10].find('cm'):
unit = 'cm'
elif lines[10].find('°C'):
unit = '°C'
print('found Unit: ' + unit + ' for sensor: ' + file)
return(unit)
findreturns position of occurence or-1if sequence not found.-1inifis interpreted asTrue.