Python struct.unpack errors with TypeError: a bytes-like object is required, not 'str'

后端 未结 1 1620
执念已碎
执念已碎 2021-01-22 05:09

Can someone please help with the following line of code and Error? I am unfamiliar with python value conversions.

The specific line that generates the error is:

相关标签:
1条回答
  • 2021-01-22 05:37

    When you are using Python 2.x str is a byte array. For Python 3, you must use bytes like this:

    struct.unpack("<h", bytes([b, a]))[0]
    
    0 讨论(0)
提交回复
热议问题