Determine if encoding exists in python

Is it possible to check in Python whether this encoding exists or is installed. For example:
check ('iso-8859-1') โ†’ True
check ('bla') โ†’ False

0
python character-encoding
Mar 10 '09 at 16:00
source share
1 answer

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

 import codecs def exists_encoding(enc): try: codecs.lookup(enc) except LookupError: return False return True exists_encoding('latin1') 
+3
Mar 10 '09 at 16:06
source share



All Articles