ValueError: unconverted data remains:

datetime, python

Solution

`strip` does not work in place, you have to assign it to actually remove the new line character:

line = line.strip()

Problem

I have a text file with two columns of time values like this: 21:28:07.638502 21:28:07.636 Yes, one column has extra digits for the time. I'm trying to just read all lines, get the time difference in microseconds ... etc. If I try something like the following, I would get error. ``` import datetime format="%H:%M:%S.%f" with open(file) as fh: for line in fh.readlines(): line.strip() [a,b]=line.split(' ') dta=datetime.datetime.strptime(a,format) dtb=datetime.datetime.strptime(b,format) diff=dta-dtb print(diff.microseconds) ``` I'm not sure what the "Unconverted data" comes from. There's nothing after the "remains:" in the error message. What exactly is data remains? ``` Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/root/.pyenv/versions/3.5.1/lib/python3.5/_strptime.py", line 500, in _strptime_datetime tt, fraction = _strptime(data_string, format) File "/root/.pyenv/versions/3.5.1/lib/python3.5/_strptime.py", line 340, in _strptime data_string[found.end():]) ValueError: unconverted data remains: ```

Original source