我已经尝试过名为array
bit 的 Python 模块。它有一种将数组编码为字符串的方法。
>>>from array import array
>>>a=[1,2,3]
>>>a=array('B',a)
>>>print(a)
array('B',[1,2,3])
>>>print(a.tostring())
b'\x01\x02\x03'
>>>str(a.tostring())
"b'\x01\x02\x03'"
我想将.tostring()
数组的版本保存到文件中,但open().write()
只接受字符串。
有没有办法将此字符串解码为字节数组?
我想将它用于 OpenGL 数组(glBufferData
接受字节数组)
提前致谢。