“原始图像数据,作为字节字符串”是什么意思?

2024-10-02 06:35:43 发布

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

我正在使用Python编写一个程序来编辑mp3上的标签,现在我正在使用诱变剂模块,为了将图像作为封面嵌入到使用id3v4标准的mp3文件中,我必须添加APIC框架using this。在

但是我不明白我必须在参数encodingmime和{}中加入什么。在

我从这里看了一个例子,想到了这个:

frame= APIC(3,"image/jpg",3,"Cover",open("albumcover.jpg"))

但我不知道前三个是什么意思?为什么当我把"utf-8"放进去时它不起作用?并且open()函数不起作用,它返回如下错误:

^{pr2}$

当我把"b"

frame= APIC(3,"image/jpg",3,"Cover",open("albumcover.jpg","b"))

返回它

Traceback (most recent call last):
  File "<pyshell#106>", line 1, in <module>
    frame= APIC("utf-8","image/jpg",3,"Cover",open("albumcover.jpg","b"))
ValueError: Must have exactly one of create/read/write/append mode and at most one plus

那我该放什么呢?在

我也试过了,但没用。在


Tags: 模块image程序编辑mostcover标签open
2条回答

参数3表示它是相册的封面read the documentation。在

您需要以-read(rb)或write(wb)或append(ab)模式打开文件(b-表示它是一个二进制文件,我们从中读取字节而不是字符串)。在

对于您的情况,我认为read模式就足够了,所以请尝试-

frame= APIC(3,"image/jpg",3,"Cover",open("albumcover.jpg","rb").read())

rb表示我们需要以读取模式打开该文件,并且它是一个二进制文件,对其调用.read()函数会导致它从文件中读取字节并返回。在

相关问题 更多 >

    热门问题