Created
December 25, 2017 23:05
-
-
Save peci1/b05ee12ba1f37d399b971bee93ab070b to your computer and use it in GitHub Desktop.
Print the characters corresponding to the given byte sequence in all encodings known to the python interpreter.
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
#!/usr/bin/env python3 | |
import encodings | |
import pkgutil | |
bytes_to_decode = b"\xc4\x9b" | |
codecs = [] | |
for importer, modname, ispkg in pkgutil.iter_modules(encodings.__path__): | |
try: | |
mod = __import__('encodings.' + modname, level=0, fromlist=['*']) | |
try: | |
getregentry = mod.getregentry | |
except AttributeError: | |
# Not a codec module | |
continue | |
codecs.append(modname) | |
except: | |
pass | |
for f in codecs: | |
try: | |
dec = bytes_to_decode.decode(f) | |
print(f + ": " + dec) | |
except: | |
pass |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment