Python 3.2 bug? Reading the last line of a file
Jussi Piitulainen
jpiitula at ling.helsinki.fi
Thu May 26 01:09:34 EDT 2011
tkpmep at hotmail.com writes:
> Looking through the docs did not clarify my understanding of the
> issue. Why can I not split on '\t' when reading in binary mode?
You can split on b'\t' to get a list of byteses, which you can then
decode if you want them as strings.
You can decode the bytes to get a string and then split on '\t' to get
strings.
>>> b'tic\ttac\ttoe'.split(b'\t')
[b'tic', b'tac', b'toe']
>>> b'tic\ttac\ttoe'.decode('utf-8').split('\t')
['tic', 'tac', 'toe']
More information about the Python-list
mailing list