[Python-Dev] Removing the implicit str() call from printing API
M.-A. Lemburg
mal@lemburg.com
Sat, 10 Feb 2001 13:43:39 +0100
So far, noone has commented on this idea.
I would like to go ahead and check in patch which passes through
Unicode objects to the file-object's .write() method while leaving
the standard str() call for all other objects in place.
--
Marc-Andre Lemburg
______________________________________________________________________
Company: http://www.egenix.com/
Consulting: http://www.lemburg.com/
Python Pages: http://www.lemburg.com/python/
"M.-A. Lemburg" wrote:
>
> There was some discussion about this subject before, but nothing
> much happened, so here we go again...
>
> Printing in Python is a rather complicated task. It involves many
> different APIs, flags, etc. Deep down in the printing machinery
> there is a hidden call to str() which converts the to be printed
> object into a string object.
>
> This is fine for non-string objects like numbers, but causes trouble
> when it comes to printing Unicode objects due to the auto-conversions
> this causes.
>
> There is a patch on SF which tries to remedy this, but it introduces
> a special attribute to maintain backward compatibility:
>
> http://sourceforge.net/patch/?func=detailpatch&patch_id=103685&group_id=5470
>
> I don't really like the idea to add such an attribute to the
> file object. Instead, I think that we should simply pass along
> Unicode objects as-is to the file object's .write() method and
> have the method take care of the conversion.
>
> This will break some code, since not all file-like objects expect
> non-strings as input to the .write() method, but I think this small
> code breakage is worth it as it allows us to redirect printing
> to streams which convert Unicode input into a specific output
> encoding.
>
> Thoughts ?
>
> --
> Marc-Andre Lemburg
> ______________________________________________________________________
> Company: http://www.egenix.com/
> Consulting: http://www.lemburg.com/
> Python Pages: http://www.lemburg.com/python/
>
> _______________________________________________
> Python-Dev mailing list
> Python-Dev@python.org
> http://mail.python.org/mailman/listinfo/python-dev