This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author lemburg
Recipients ajaksu2, facundobatista, hthompson, lemburg, loewis, vstinner
Date 2009-02-12.14:01:19
SpamBayes Score 1.8035573e-13
Marked as misclassified No
Message-id <49942BAE.7070107@egenix.com>
In-reply-to <200902121422.25671.victor.stinner@haypocalc.com>
Content
On 2009-02-12 14:22, STINNER Victor wrote:
> STINNER Victor <victor.stinner@haypocalc.com> added the comment:
> 
>> Python3 fixes the "print" statement to be a function, which allows
>> much better extensibility of the concept.
>>
>> You can have the same in Python2 with a little effort: just create
>> your own myprint() function and have it process Unicode in whatever
>> way you want.
> 
> About myprint(): sure, it's possible to write a custom issue. But the feature 
> request was to use obj.__unicode__() instead of obj.__str__() for an "unicode 
> aware stream".
> 
> The problem with Python2 is that there is not clear separation between "bytes 
> stream" ("raw stream"?) and "unicode aware stream" (like io.open or 
> codecs.open). I think that fixing this issue (#637094) was one of the goal of 
> the new I/O library (io in Python3).

True, but the point of the original request was that the stream
should decide how to print the object, ie. you pass the object to
the stream's .write() method instead of first running str() on
it and then passing this to the .write() method.

This is easy to have using a custom print function and indeed
a good way to proceed if you want to port to Python3 at some
later point.

> Using __unicode__() for some object and __str__() for some other sounds 
> strange/dangerous to me. I prefer bytes-only stream or unicode-only stream, 
> but not bytes-and-sometimes-unicode stream.

If you use a StreamWriter instance in Python2 which uses one of
the Unicode codecs, then it will accept ASCII strings or Unicode
as input for .write(), ie. the stream decides on how to process
the input.

> Python2 has only bytes stream. Python3 has both: open(name, 'rb') is bytes 
> only, and open(name, 'r') is unicode only.

That's not entirely correct. Python2's codecs.py module provides
streams which can implement several different type combinations
for input and output.

> lemburg> Does your message mean that you want to reopen the issue?

No, I just wanted to correct your statement :-)
History
Date User Action Args
2009-02-12 14:01:22lemburgsetrecipients: + lemburg, loewis, facundobatista, vstinner, ajaksu2, hthompson
2009-02-12 14:01:20lemburglinkissue637094 messages
2009-02-12 14:01:19lemburgcreate