On 26.10.16 23:47, Peter Otten wrote:
def mynamereplace(exc):
return u"".join(
"\\N{%s}" % unicodedata.name(c)
for c in exc.object[exc.start:exc.end]
), exc.end
codecs.register_error("namereplace", mynamereplace)
Not all characters has standard na
Tim Chase wrote:
> On 2016-10-25 20:14, Peter Otten wrote:
>> Tim Chase wrote:
>> > I like the clarity of using the "\N{...}" notation when creating
>> > string literals involving Unicode chars.
>> >
>> > Is there a built-in way to get such strings back from Python?
>>
>> >>> 'mañana'.encode("as
On 2016-10-25 20:14, Peter Otten wrote:
> Tim Chase wrote:
> > I like the clarity of using the "\N{...}" notation when creating
> > string literals involving Unicode chars.
> >
> > Is there a built-in way to get such strings back from Python?
>
> >>> 'mañana'.encode("ascii", "namereplace").decode
Tim Chase wrote:
> I like the clarity of using the "\N{...}" notation when creating
> string literals involving Unicode chars.
>
> Is there a built-in way to get such strings back from Python?
>
> >>> s = 'ma\N{LATIN SMALL LETTER N WITH TILDE}ana'
> >>> s
> 'mañana'
> >>> magic(s)
> 'ma\\N{
I like the clarity of using the "\N{...}" notation when creating
string literals involving Unicode chars.
Is there a built-in way to get such strings back from Python?
>>> s = 'ma\N{LATIN SMALL LETTER N WITH TILDE}ana'
>>> s
'mañana'
>>> magic(s)
'ma\\N{LATIN SMALL LETTER N WITH TILDE}ana'