[PyQt] PyQt cannot trasform QString into str when reading emoji symbol from QClipboard

Pavel Roskin proski at gnu.org
Thu Jan 22 20:07:04 GMT 2015


Phil,

The correct behavior is getting a valid unicode string without
surrogates. That string should contain exactly one character,
'\U0001f637'

>>> print('\U0001f637')
😷
>>> print(len('\U0001f637'))
1
>>> print('\U0001f637'.encode('utf-8'))
b'\xf0\x9f\x98\xb7'
>>> print(list(map(hex, '\U0001f637'.encode('utf-16'))))
['0xff', '0xfe', '0x3d', '0xd8', '0x37', '0xde']

Ilya is getting a unicode string with surrogate pairs inside it. So
it's not encodable. Ilya, please run this on the string you are
getting from clipboard:

print(list(map(lambda x: hex(ord(x)), list(string))))

Pavel


More information about the PyQt mailing list