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

2024-05-01 22:02:46 发布

您现在位置:Python中文网/ 问答频道 /正文

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


Tags: 函数版本initmimetypes
2条回答

根据^{} module documentation

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.


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.

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.

Python 2.7和{a3}都有。在

如果要添加超出默认值的MIME类型/扩展映射,^{}非常有用。如果不需要这样做,那么就不需要调用mimetypes.init();只需正常使用实用程序函数,必要时它们会自己调用它。如果你需要这样做,除了mimetypes.init()之外还有{a2}和{a3}。在

这适用于Python2和3。在

相关问题 更多 >