Searching/reading binary data in Python

前端 未结 8 1865
情歌与酒
情歌与酒 2020-12-25 12:15

I\'m reading in a binary file (a jpg in this case), and need to find some values in that file. For those interested, the binary file is a jpg and I\'m attempting to pick out

8条回答
  •  清酒与你
    2020-12-25 13:03

    In Python 3.x you can search a byte string by another byte string like this:

    >>> byte_array = b'this is a byte array\r\n\r\nXYZ\x80\x04\x95 \x00\x00\x00\x00\x00'
    >>> byte_array.find('\r\n\r\n'.encode())
    20
    >>>
    

提交回复
热议问题