Python how to encode 0x90(\x90) as macOS Roman Enc

2019-09-15 01:11发布

In python, if giving 0x90(or \x90), how to encode it into a string as macOS Roman Encoding to \xc3\xaa, aka ê?

I tried bytes('\x90').encode('mac-roman'), it just throw errors.

chr(0x90).encode('mac-roman') is still the same failure.

Please help, thanks!

2条回答
Viruses.
2楼-- · 2019-09-15 01:51

It depends on what you final goal is, but as such it is encoded, so you first need to decode it, i mean, e.g.

chr(0x90).decode('mac-roman')

You were almost there.

查看更多
对你真心纯属浪费
3楼-- · 2019-09-15 02:00

Actually, after searching two web pages: http://unicode.org/Public/MAPPINGS/VENDORS/APPLE/ROMAN.TXT it shows:

0x90 0x00EA # LATIN SMALL LETTER E WITH CIRCUMFLEX

and http://www.fileformat.info/info/unicode/char/ea/index.htm,:

UTF-8 (hex) 0xC3 0xAA (c3aa)

UTF-8 (binary) 11000011:10101010

UTF-16 (hex) 0x00EA (00ea)

and trying decoding/encoding, I found it's:

'\x90'.decode('mac-roman').encode('utf-8')

查看更多
登录 后发表回答