Python mimetypes.init()是一个过时的函数吗?

时间:2022-02-27 10:46:33

I'm struggling to understand what the init() function does in the python mimetypes package. Is it an outdated function that isn't needed in more recent versions of python?

我很难理解init()函数在python mimetypes包中的作用。它是一个在更新版本的python中不需要的过时功能吗?

2 个解决方案

#1


2  

mimetypes.init() is useful if you want to add MIME type / extension mappings beyond the default. If you don't need to do that, then there's no need to call mimetypes.init(); just use the utility functions normally, and they'll call it themselves if necessary. If you do need to do that, aside from mimetypes.init() there's also mimetypes.read_mime_types() and mimetypes.add_type().

如果要添加超出默认值的MIME类型/扩展名映射,mimetypes.init()非常有用。如果你不需要这样做,那么就不需要调用mimetypes.init();只需正常使用实用程序功能,如有必要,他们会自行调用。如果你确实需要这样做,除了mimetypes.init()之外,还有mimetypes.read_mime_types()和mimetypes.add_type()。

This applies to Python 2 and 3.

这适用于Python 2和3。

#2


0  

According to the mimetypes module documentation:

根据mimetypes模块文档:

The functions described below provide the primary interface for this module. If the module has not been initialized, they will call init() if they rely on the information init() sets up.

下面描述的功能提供了该模块的主要接口。如果模块尚未初始化,如果它们依赖于init()设置的信息,它们将调用init()。


mimetypes.init(files=None)

Initialize the internal data structures. If given, files must be a sequence of file names which should be used to augment the default type map. If omitted, the file names to use are taken from knownfiles; on Windows, the current registry settings are loaded. Each file named in files or knownfiles takes precedence over those named before it. Calling init() repeatedly is allowed.

初始化内部数据结构。如果给定,文件必须是一系列文件名,应该用于扩充默认类型映射。如果省略,则使用的文件名取自knownfiles;在Windows上,加载当前的注册表设置。在files或knownfiles中命名的每个文件优先于在它之前命名的文件。允许重复调用init()。

Specifying an empty list for files will prevent the system defaults from being applied: only the well-known values will be present from a built-in list.

为文件指定空列表将阻止应用系统默认值:仅内置列表中将显示已知值。

It's there both in Python 2.7 and Python 3.x.

它存在于Python 2.7和Python 3.x中。

#1


2  

mimetypes.init() is useful if you want to add MIME type / extension mappings beyond the default. If you don't need to do that, then there's no need to call mimetypes.init(); just use the utility functions normally, and they'll call it themselves if necessary. If you do need to do that, aside from mimetypes.init() there's also mimetypes.read_mime_types() and mimetypes.add_type().

如果要添加超出默认值的MIME类型/扩展名映射,mimetypes.init()非常有用。如果你不需要这样做,那么就不需要调用mimetypes.init();只需正常使用实用程序功能,如有必要,他们会自行调用。如果你确实需要这样做,除了mimetypes.init()之外,还有mimetypes.read_mime_types()和mimetypes.add_type()。

This applies to Python 2 and 3.

这适用于Python 2和3。

#2


0  

According to the mimetypes module documentation:

根据mimetypes模块文档:

The functions described below provide the primary interface for this module. If the module has not been initialized, they will call init() if they rely on the information init() sets up.

下面描述的功能提供了该模块的主要接口。如果模块尚未初始化,如果它们依赖于init()设置的信息,它们将调用init()。


mimetypes.init(files=None)

Initialize the internal data structures. If given, files must be a sequence of file names which should be used to augment the default type map. If omitted, the file names to use are taken from knownfiles; on Windows, the current registry settings are loaded. Each file named in files or knownfiles takes precedence over those named before it. Calling init() repeatedly is allowed.

初始化内部数据结构。如果给定,文件必须是一系列文件名,应该用于扩充默认类型映射。如果省略,则使用的文件名取自knownfiles;在Windows上,加载当前的注册表设置。在files或knownfiles中命名的每个文件优先于在它之前命名的文件。允许重复调用init()。

Specifying an empty list for files will prevent the system defaults from being applied: only the well-known values will be present from a built-in list.

为文件指定空列表将阻止应用系统默认值:仅内置列表中将显示已知值。

It's there both in Python 2.7 and Python 3.x.

它存在于Python 2.7和Python 3.x中。