Is it possible to check in Python whether a given charset exists/is installed.
For example:
check('iso-8859-1') -> True
check('bla') -> False
views:
370answers:
1
+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
2009-03-10 16:06:01