python - What does "raw image data, as a byte string" mean? -
i doing program edit tags on mp3 using python, right using mutagen module , in order embed image cover art mp3 file using id3v4 standards have add apic frame using this.
but don't understand have put in parameters encoding
,mime
, data
.
i looked example here , came this:
frame= apic(3,"image/jpg",3,"cover",open("albumcover.jpg"))
but don't know first 3 means? why when put "utf-8"
doesn't work? , open()
function doesn't work, returns error this:
traceback (most recent call last): file "<pyshell#104>", line 1, in <module> frame= apic(3,"image/jpg",3,"cover",open("albumcover.jpg")) file "c:\python34\lib\site-packages\mutagen\id3\_frames.py", line 65, in __init__ setattr(self, checker.name, checker.validate(self, val)) file "c:\python34\lib\site-packages\mutagen\id3\_specs.py", line 184, in validate raise typeerror("%s has bytes" % self.name) typeerror: data has bytes
and when put "b"
frame= apic(3,"image/jpg",3,"cover",open("albumcover.jpg","b"))
it returns
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 1 of create/read/write/append mode , @ 1 plus
so should put there?
and tried open("albumcover.jpg").read()
, doesn't work.
you need open file in either of - read
(rb) or write
(wb) or append
(ab)modes (b - indicating binary file , read bytes instead of strings) .
for case, think read
mode sufficient, try -
frame= apic(3,"image/jpg",3,"cover",open("albumcover.jpg","rb").read())
the rb
indicates need open file in read mode , binary file, calling .read()
function on causes read bytes file , return it.
Comments
Post a Comment