How do I convert an iterator over bytes into a str?

Jan Kaliszewski zuo at chopin.edu.pl
Tue Aug 18 19:52:42 EDT 2009


19-08-2009 o 00:24:20 markscottwright <markscottwright at gmail.com> wrote:

> What's the correct way to turn an iterator over bytes into a string?
> This works, but, ewww:
>     In [8]: "".join(iter("four score and seven years ago"))
>     Out[8]: 'four score and seven years ago'

But it is the correct way (and even recommended over s=s+t or s+=t, when
applicable
-- see:  
http://docs.python.org/library/stdtypes.html#sequence-types-str-unicode-list-tuple-buffer-xrange).

Cheers,
*j

-- 
Jan Kaliszewski (zuo) <zuo at chopin.edu.pl>



More information about the Python-list mailing list