Lookup all available registered Codecs at once?

Fredrik Lundh fredrik at pythonware.com
Thu Jun 14 15:40:55 EDT 2001


Michael Ströder wrote:
> Is there a way to look up all registered Codecs (in module codecs)
> at once?

Something like this might work:

import os
import encodings

names = encodings._cache.keys()

for file in os.listdir(os.path.dirname(encodings.__file__)):
    name, ext = os.path.splitext(file)
    if ext == ".py" and name not in names:
        try:
            encodings.search_function(name)
        except SystemError:
            pass
        else:
            names.append(name)

print "codecs:", names
print "aliases:", encodings.aliases.aliases.keys()

if you wish to speed it up, you can skip the call to search_function,
and just filter out "__init__" and "aliases".

Hope this helps!

</F>

<!-- (the eff-bot guide to) the python standard library:
http://www.pythonware.com/people/fredrik/librarybook.htm
-->





More information about the Python-list mailing list