I've a script which reads temperature data:
def get_temp(socket, channels): data = {} for ch in channels: socket.sendall('KRDG? %s\n' % ch) time.sleep(0.2) temp = socket.recv(32).rstrip('\r\n') data[ch] = float(temp) Sometimes, the script fails on the line which converts the values to float:
File "./projector.py", line 129, in get_temp
data[ch] = float(temp)
ValueError: invalid literal for float(): +135.057E+0
+078.260E+0
+00029
but this is NOT an invalid literal. If I enter this into any python shell,
float(+135.057E+0) then it correctly returns 135.057.
So what is the problem?
float('+135.057E+0'), notfloat(+135.057E+0), which of course works since it's already a float. but that conversion from string works too.print(repr(temp))to check for non-printing characters.float('+135.057E+0\0')fails with the same error message.