[Python-ideas] Add "namereplace" error handler

Andrew Barnert abarnert at yahoo.com
Tue Jun 11 18:19:34 CEST 2013


On Jun 11, 2013, at 4:21, Serhiy Storchaka <storchaka at gmail.com> wrote:

> I propose to add "namereplace" error handler which is similar to "backslashreplace" error handler but use \N escapes instead of \x/\u/\U escapes.
> 
> >>> '−1'.encode('ascii', 'backslashreplace')
> b'\\u22121'
> >>> '−1'.encode('ascii', 'namereplace')
> b'\\N{MINUS SIGN}1'
> 
> In some cases such representation is more readable.
> 
> What are you think about this? Are there suggestions for better name?

I believe \N escape sequences are called "name escape", and the official description of the semantics in the docs is "Character named name in the Unicode database", so "namereplace" seems like a perfect name for this error handler.



More information about the Python-ideas mailing list