You can extend the list of file types imghdr can recognize by appending to this variable:
imghdr.test
A list of functions performing the individual tests. Each function takes two arguments: the byte-stream and an open file-like object. When what() is called with a byte-stream, the file-like object will be None.
The test function should return a string describing the image type if the test succeeded, or None if it failed.
我想这是为了允许将自定义函数添加到} module -
imghdr.tests
。从documentation of ^{从文档中可以看出,
imghdr
模块允许扩展到tests
列表。我认为添加参数f
可以用于添加到这个列表中的这些自定义函数。在看看^{} function -
可以看出,当我们向
what()
函数发送文件名时,它只读取文件的前32个字节,只发送test
函数的h
参数中的32个字节,我认为附加的f
参数可能适用于第一个32
字节不足以确定图像格式的情况(尤其是对于自定义测试)。在相关问题 更多 >
编程相关推荐