How to convert some character into five digit unicode one in Python 3.3?

后端 未结 2 1371
别跟我提以往
别跟我提以往 2020-12-20 21:00

I\'d like to convert some character into five digit unicode on in Python 3.3. For example,

import re
print(re.sub(\'a\', u\'\\u1D15D\', \'abc\' ))

2条回答
  •  天命终不由人
    2020-12-20 21:51

    Python unicode escapes either are 4 hex digits (\uabcd) or 8 (\Uabcdabcd); for a codepoint beyond U+FFFF you need to use the latter (a capital U), make sure to left-fill with enough zeros:

    >>> '\U0001D15D'
    '

提交回复
热议问题