【问题标题】:How do I read the result of a python struct?如何读取 python 结构的结果?
【发布时间】:2020-01-24 13:15:02
【问题描述】:

谁能告诉我如何读取结果 b'\x9a\x99\x99?的

import struct
data = struct.pack("@f", 1.2)
print(data)

\x9a 代表什么?还是\x99?如何将其翻译回1.2

【问题讨论】:

    标签: python python-3.x struct byte


    【解决方案1】:

    数据以二进制格式存储。要取回值,请使用struct.unpack

    import struct
    data = struct.pack("@f",1.2)
    print(struct.unpack("@f",data))
    

    相关:Why won't Python display this text correctly? (UTF-8 Decoding Issue)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2010-09-28
      • 2017-08-10
      • 2023-03-31
      • 1970-01-01
      • 2021-02-01
      • 2013-06-19
      相关资源
      最近更新 更多