I am pretty sure the solution is easy but somehow the usual float doesn't work.
output = open('output.txt', 'wt')
with open('input.txt', 'r') as file:
file = file.readlines()
for x in range(0,len(file)):
if file[x][0:6] == 'NUMBER':
print(file[x][11:18])
float(file[x][11:18])
print will give me '11111' , but float gives me error ValueError: could not convert string to float: What is happening here. I need it as float to do some math operation.
Update. I guess it's because i am trying to convert an empty space. The first line cause this error. float('') will give error.
NUMBER
*
NUMBER 111111111111111111111
reprof the string that it couldn't convert. If that's not printing, tryprint(repr(file[x][11:18]))to see therepr. Might be some non-printing character (e.g.\0) embedded in the string;floatignores leading and trailing whitespace, but not arbitrary non-numeric text or embedded whitespace.tryandexceptcondition to ignore if there is no number in the line