[Python-ideas] Add "namereplace" error handler

Amaury Forgeot d'Arc amauryfa at gmail.com
Tue Jun 11 13:47:03 CEST 2013


It's easy to implement in Python code:

import codecs, unicodedata

def namereplace_errors(exc):
    replace = "\\N{{{}}}".format(
        unicodedata.name(exc.object[exc.start]))
    return replace, exc.start + 1

codecs.register_error('namereplace', namereplace_errors)



2013/6/11 Serhiy Storchaka <storchaka at gmail.com>

> 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?
>
> ______________________________**_________________
> Python-ideas mailing list
> Python-ideas at python.org
> http://mail.python.org/**mailman/listinfo/python-ideas<http://mail.python.org/mailman/listinfo/python-ideas>
>



-- 
Amaury Forgeot d'Arc
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20130611/b5c1fb14/attachment.html>


More information about the Python-ideas mailing list