Python 3.2 bug? Reading the last line of a file

Ethan Furman ethan at stoneleaf.us
Wed May 25 19:58:55 EDT 2011


tkpmep at hotmail.com wrote:
> Thanks for the guidance - it was indeed an issue with reading in
> binary vs. text., and I do now succeed in reading the last line,
> except that I now seem unable to split it, as I demonstrate below.
> Here's what I get when I read the last line in text mode using 2.7.1
> and in binary mode using 3.2 respectively under IDLE:
> 
> 3.2
> b'Name\t31/12/2009\t0\t0\t0\r\n'
> 
> under 3.2, with its binary read, I get
>--> x.split('\t')
> Traceback (most recent call last):
>   File "<pyshell#26>", line 1, in <module>
>     x.split('\t')
> TypeError: Type str doesn't support the buffer API

You are trying to split a bytes object with a str object -- the two are 
not compatible.  Try splitting with the bytes object b'\t'.

~Ethan~



More information about the Python-list mailing list