我想确定一个xml文件的mimetype,但是第一个参数是关于某个实例的错误。我是python新手,请帮忙。下面是我正在使用的代码及其引发的错误。
from mimetypes import MimeTypes
import urllib
FILENAME = 'Upload.xml'
url = urllib.pathname2url(FILENAME)
type = MimeTypes.guess_type(url)
print type
**ERROR :** Traceback (most recent call last):
File "/home/navi/Desktop/quicksort.py", line 20, in <module>
type = MimeTypes.guess_type(url)
TypeError: unbound method guess_type() must be called with MimeTypes instance as first argument (got str instance instead)
错误说明必须初始化
MimeTypes
类:尽管您可以跳过这个并直接使用
mimetypes.guess_type
:相关问题 更多 >
编程相关推荐