StringIO in 2.6 and beyond

MRAB google at mrabarnett.plus.com
Tue Dec 9 14:07:08 EST 2008


Bill McClain wrote:
> On 2008-12-09, Peter Otten <__peter__ at web.de> wrote:
> 
>>>>> out = io.StringIO()
>>>>> print(u"hello", file=out, end=u"\n")
>>>>> out.getvalue()
>> u'hello\n'
> 
> That has the benefit of working. Thank you!
> 
> That can't be the intended behavior of print(), can it? Insering non-unicode
> spaces and line terminators? I thought all text was unicode now. Or is that
> only in 3.0?
> 
In Python 2.x unmarked string literals are bytestrings. In Python 3.x 
they're Unicode. The intention is to make the transition from 2.x to 3.x 
easier by adding some features of 3.x to 2.x, but without breaking 
backwards compatibility (not entirely successfully!).



More information about the Python-list mailing list