[Python-3000] PEP 3138- String representation in Python 3000

Guido van Rossum guido at python.org
Fri May 23 06:30:35 CEST 2008


On Thu, May 22, 2008 at 6:46 PM, Atsuo Ishimoto <ishimoto at gembook.org> wrote:
> On Fri, May 23, 2008 at 6:18 AM, Guido van Rossum <guido at python.org> wrote:
>
>>>> 2. If you don't want any non-ASCII printed to a file, set the file's
>>>> encoding to ASCII and the error handler to backslashescape.
>>
>> On Thu, May 22, 2008 at 12:59 PM, Antoine Pitrou <solipsis at pitrou.net> wrote:
>>> Since some people still seem wary that repr() might return non-ascii
>>> results, perhaps we could also:
>>>
>>> 3. Add a builtin function named ascii() and a formatting code "%a" that
>>> both call repr() internally and then convert all non-ascii characters to
>>> \uXXXX escapes.
>>
>> I'd call that a stretch goal, but it seems an easy one.
>
> Martin may against for new builtin function. Perhaps
> string.asciirepr() might better?

That's not a pretty name (and aren't we going to get rid of the string
module after all?). But it's a minor detail.

>> Could someone (Atsuo?) write up a new version for the PEP, adding the
>> conclusions reached in this thread and recapping some of the
>> discussion? I think this can get in before the first beta release, and
>> that seems doable.
>>
>
> I'll revise the PEP and the patch soon.

Great!

> One point still remains is default error handler for sys.stdout. I can
> live with 'strict' error handler, but I think raising exceptions for
> evenry un-supported characters by default is too exacting.

I think to avoid exceptions you should arrange for the encoding to be
capable of encoding all characters (e.g. utf8 or utf16).

IMO it's important to trust that you didn't write garbage, unless you
specifically asked for it.

It's different for stderr, there I think the most lenient error
handling should be the default.

PS> I couldn't get backslashescape to work -- is this just a proposal?

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


More information about the Python-3000 mailing list