[Python-Dev] Printing and __unicode__
Martin v. Loewis
martin@v.loewis.de
13 Nov 2002 20:21:39 +0100
"M.-A. Lemburg" <mal@lemburg.com> writes:
> StringIO should be considered a non-Unicode aware stream,
> so it should not implement .encoding. Instead, PyFile_WriteObject()
> will simply call __str__ on the Unicode object and thus use
> the default encoding for conversion (this is what StringIO
> does currently).
This is not what StringIO does currently:
>>> s=StringIO.StringIO()
>>> print >>s,u"Hallo"
>>> s.getvalue()
u'Hallo\n'
print special-cases Unicode objects and passes them to the stream. So
printing Unicode objects on a StringIO builds up a Unicode value.
> If somebody wants to use a StringIO object as Unicode aware
> stream
StringIO *is* Unicode-aware.
Regards,
Martin