4

Python has a unicode built-in function that converts an byte stream to unicode string.

enter image description here

I just hope I can query all the available encoding on my system. But how to.

The reason for this question is: Some one using MAC OS X sent me an email with content-encoding 'iso-2022-cn', and I find that Python 2.7 on Windows 7 does not recognize that encoding.

>>> print unicode(bs2022, 'iso-2022-cn')

Traceback (most recent call last):
  File "<pyshell#97>", line 1, in <module>
    print unicode(bs2022, 'iso-2022-cn')
LookupError: unknown encoding: iso-2022-cn

So I'd like to find out whether Python uses a different name for 'iso-2022-cn' by looking at all encoding he can support.

Jimm Chen
  • 3,411
  • 3
  • 35
  • 59

1 Answers1

5

Here is a list for python 2.7

also you can do this

from encodings.aliases import aliases
>>> def find(q):
        q = encodings.normalize_encoding(q)
...     return [(k,v)for k,v in aliases.iteritems() if q in v or q in k]

>>>> find('100')
[('ksx1001', 'euc_kr'), ('iso_ir_100', 'latin_1'), ('ks_x_1001', 'euc_kr')]
Victor Castillo Torres
  • 10,581
  • 7
  • 40
  • 50
  • Sad, something like ``iso2022_cn`` is not listed on that page. And, is there a way to query that list from executing Python code? – Jimm Chen Jun 19 '13 at 03:24
  • 1
    add `q = encodings.normalize_encoding(q)` otherwise you might miss an encoding even if it is in the `aliases` map. Also [`aliases` do not give you the full list](http://stackoverflow.com/q/1728376/4279) – jfs Jun 19 '13 at 03:45