How to extract the raw bytes of the decoded unicode?

Peng Yu pengyu.ut at gmail.com
Sat Feb 24 11:49:25 EST 2018


Hi,

I can extracted the encoded value as bytes. But is there a way to
extracted the decoded value (for á, it is C1)? Thanks.

$ cat ./dumpunicode.py
#!/usr/bin/env python3

while True:
    c = sys.stdin.read(1)
    if c:
        print(c)
        print('0x' + ''.join(['%x' % x for x in reversed(bytes(c,
encoding='utf-8'))]))
    else:
        break
$ ./dumpunicode.py <<< á
á
0xa1c3


0xa


-- 
Regards,
Peng



More information about the Python-list mailing list