类似于
this问题,我试图读取ID3v2标记头并且无法弄清楚如何在python中获取单个字节.
我首先将所有十个字节读入一个字符串.然后我想解析各个信息.
我可以在字符串中获取两个版本号字符,但后来我不知道如何获取这两个字符并从中获取整数.
结构包似乎是我想要的,但我不能让它工作.
这是我的代码到目前为止(我对python btw很新…所以请放轻松我):
def __init__(self, ten_byte_string):
self.whole_string = ten_byte_string
self.file_identifier = self.whole_string[:3]
self.major_version = struct.pack('x', self.whole_string[3:4]) #this
self.minor_version = struct.pack('x', self.whole_string[4:5]) # and this
self.flags = self.whole_string[5:6]
self.len = self.whole_string[6:10]
打印出任何值,除了明显废话,因为它们没有正确格式化.