latin1 and cp1252 inconsistent?

Ian Kelly ian.g.kelly at gmail.com
Fri Nov 16 20:08:36 EST 2012


On Fri, Nov 16, 2012 at 5:33 PM, Nobody <nobody at nowhere.com> wrote:
> If you need to support either, you can parse it as ISO-8859-1 then
> explicitly convert C1 codes to their Windows-1252 equivalents as a
> post-processing step, e.g. using the .translate() method.

Or just create a custom codec by taking the one in
Lib/encodings/cp1252.py and modifying it slightly.


>>> import codecs
>>> import cp1252a
>>> codecs.register(lambda n: cp1252a.getregentry() if n == "cp1252a" else None)
>>> b'\x81\x8d\x8f\x90\x9d'.decode('cp1252a')
'♕♖♗♘♙'



More information about the Python-list mailing list