[Python-ideas] Query available codecs and error handlers

Chris Angelico rosuav at gmail.com
Fri Aug 29 09:27:19 CEST 2014


On Fri, Aug 29, 2014 at 3:45 PM, Steven D'Aprano <steve at pearwood.info> wrote:
> Unless I am badly misinformed, there is no way to programmatically check
> what codecs and error handlers are available. I propose two functions in
> the codecs module:
>
> get_codecs()
> get_error_handlers()
>
> which each return a set of the available codec, or error handler, names.

A quick look at the codecs module suggests that this may not be as
simple as returning a list/set; when _codecs.lookup() is called, it
does a search. So this is actually like asking how to list importable
modules. It may not be possible, but if it is, I would suggest calling
it "list_codecs" or something, as it's basically going to be tracing
the search path and enumerating every codec it finds.

But it sounds like a quite useful facility. +1.

ChrisA


More information about the Python-ideas mailing list