Reputation:
Is it possible to check in Python whether a given charset exists/is installed.
For example:
check('iso-8859-1') -> True
check('bla') -> False
Upvotes: 0
Views: 2608
Reputation:
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')
Upvotes: 5