How to split a byte string into separate bytes in python

前端 未结 3 867
挽巷
挽巷 2020-12-02 23:00

Ok so I\'ve been using python to try create a waveform image and I\'m getting the raw data from the .wav file using song = wave.open() and so

3条回答
  •  长情又很酷
    2020-12-02 23:49

    Here is a way that you can split the bytes into a list:

    data = b'\x00\x00\x00\x00\x00\x00'
    info = [data[i:i+2] for i in range(0, len(data), 2)]
    print info
    

    gives the result:

    ['\x00\x00', '\x00\x00', '\x00\x00']
    

提交回复
热议问题