Obviously I'm aware already that strftime
and strptime
doesn't like byte strings as parameters, however i'm in a pickle here because I sort of need to read a file content which has different character encodings saved in it and i need to handle them all, and send the time portion of each line in this text-file to strptime()
.
A quick fix would be to split the string, making sure the time simply contains numbers and dashes, but is it possible to somehow pass the byte object without trying to figure out the encoding to strptime()
?
with open('file.txt', 'rb') as fh:
for line in fh:
time.strptime(line, '%Y-%m-%d ...')
This would obviously fail. I thought of doing repr(line)
but that causes the string to look like b'2014-01-07 ...'
, which i could strip..