Python 如何获取可用的编码/解码编解码器列表?

Python 如何获取可用的编码/解码编解码器列表?,python,Python,open的文档说明: encoding is the name of the encoding used to decode or encode the file. This should only be used in text mode. The default encoding is platform dependent, but any encoding supported by Python can be passed. See the codecs module for the

open
的文档说明:

encoding is the name of the encoding used to decode or encode the
file. This should only be used in text mode.  The default encoding is
platform dependent, but any encoding supported by Python can be
passed.  See the codecs module for the list of supported encodings.
因此,我导入编解码器,然后如何理解作为要打开的
编码
参数传入的内容

help(codecs)
同时列出encode()的帮助

下面的文档页面还列出了支持的编码。 不平凡-

出于某种原因,无法列出Python解释器中的编解码器

编解码器模块允许使用以下方法查找已注册的编解码器:

import codecs

codecs.lookup("codec_name")
但是编解码器注册表是解释器核心中的一个私有列表 不向仅Python代码公开

查找代码位于:

尝试编写一个C简单函数来返回该内部列表的副本 很快发现解释器状态中的结构成员 保留供内部使用,不应被外部代码触及

因此,您只能猜测编解码器名称,并使用上面的“查找”功能