tags:

views:

370

answers:

1

Is it possible to check in Python whether a given charset exists/is installed. For example:
check('iso-8859-1') -> True
check('bla') -> False

+3  A: 

You can use the lookup() function in the codecs module. It throws an exception if a codec does not exist:

import codecs
def exists_encoding(enc):
    try:
        codecs.lookup(enc)
    except LookupError:
        return False
    return True
exists_encoding('latin1')
unbeknown