[Python-ideas] Processing surrogates in

Chris Angelico rosuav at gmail.com
Fri May 8 14:28:33 CEST 2015


On Fri, May 8, 2015 at 9:18 PM, Serhiy Storchaka <storchaka at gmail.com> wrote:
>> Can you give a simple example of a Python 2 program that provides output
>> that Python 3 will read as surrogates?
>
>
> f.write(u'𝄞'[:1].encode('utf-8'))
> json.dump(f, u'𝄞'[:1])
> pickle.dump(f, u'𝄞'[:1])

Not for me. In my Python 2, u'𝄞'[:1] == u'𝄞'. I suppose you're
talking only about the (buggy) narrow builds, in which case you don't
need to use string slicing at all. But in that case, all you're doing
is using a single "\uNNNN" escape code to create an unmatched
surrogate.

ChrisA


More information about the Python-ideas mailing list