How do I write raw binary data in Python?
问题 I've got a Python program that stores and writes data to a file. The data is raw binary data, stored internally as str . I'm writing it out through a utf-8 codec. However, I get UnicodeDecodeError: 'charmap' codec can't decode byte 0x8d in position 25: character maps to <undefined> in the cp1252.py file. This looks to me like Python is trying to interpret the data using the default code page. But it doesn't have a default code page. That's why I'm using str , not unicode . I guess my