[Python-ideas] Query available codecs and error handlers
Steven D'Aprano
steve at pearwood.info
Fri Aug 29 07:45:27 CEST 2014
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.
Use-cases
---------
(1) At the interactive interpreter, it is often useful to experiment
with different codecs. Being able to get a list of available codecs
avoids the frustration of having to look them up elsewhere, or guess.
(2) Applications which offer to read or write text files may wish to
allow the user to select an encoding. With no obvious way of finding out
what encodings are available, the application is limited to hard-coding
some, and hoping that they don't get renamed or removed.
Why sets, rather than lists?
----------------------------
Sets emphasis that the names are in no particular order. Since the names
should always be strings and therefore hashable, and the order is
irrelevant, there is no particular need for a list.
Should they be frozensets rather than sets?
-------------------------------------------
I don't care :-)
Using sets may make it easier for the application to filter the results
in some way, but I really don't think it matters.
Thoughts or comments?
--
Steven
More information about the Python-ideas
mailing list