Created
July 15, 2021 08:01
-
-
Save rj76/e767f504cde92f92ae550e55018a0045 to your computer and use it in GitHub Desktop.
Find encodings for a char
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pkgutil | |
import encodings | |
import os | |
def all_encodings(): | |
modnames = set([modname for importer, modname, ispkg in pkgutil.walk_packages( | |
path=[os.path.dirname(encodings.__file__)], prefix='')]) | |
aliases = set(encodings.aliases.aliases.values()) | |
return modnames.union(aliases) | |
text = b'\xe1' | |
for enc in all_encodings(): | |
try: | |
msg = text.decode(enc) | |
except Exception: | |
continue | |
if msg == 'á': | |
print('Decoding {t} with {enc} is {m}'.format(t=text, enc=enc, m=msg)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment