A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from http://mail.python.org/pipermail/python-dev/2001-September/017425.html below:

[Python-Dev] why doesn't print pass unicode strings on to the file object?

[Python-Dev] why doesn't print pass unicode strings on to the file object?Guido van Rossum guido@python.org
Thu, 06 Sep 2001 12:12:03 -0400
> is there any reason why "print" cannot pass unicode
> strings on to the underlying write method?

Mostly that currently print religiously calls PyObject_Str() on the
objects to print, which always converts to 8-bit strings.

> it would be really nice if this piece of code worked as
> expected:
> 
> import sys
> 
> class Wrapper:
>     def __init__(self, file):
>         self.file = file
>     def write(self, data):
>         self.file.write(data.encode("iso-8859-1", "replace"))
> 
> sys.stdout = Wrapper(sys.stdout)
> 
> print u"åäö"
> 
> under 2.2a2 (and earlier versions), this gives me:
> 
> Traceback (most recent call last):
>   File "\test.py", line 8, in ?
>     print u"åäö"
> UnicodeError: ASCII encoding error: ordinal not in range(128)
> 
> (I'm willing to implement this, if the BDFL says so)

I think this would be a good idea, but please fix the various
outstanding SRE bugs first. :-)

--Guido van Rossum (home page: http://www.python.org/~guido/)



RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4