#!/usr/bin/env python3 # -*- conding: utf-8 -*- '练习内建模块之struct' __author__ = 'sergiojune' import struct,base64 # 这个模块是将bytes与其他二进制数据互相转换 # 将任意数据类型转为bytes i = 10249999 b = struct.pack('>I', i) # 第一个参数为处理指令 print(b) s = 123.456 b = struct.pack('f', s) print(b) # 将bytes转为其他任意类型 s = struct.unpack('f', b) print(s) s = b'\x42\x4d\x38\x8c\x0a\x00\x00\x00\x00\x00\x36\x00\x00\x00\x28\x00\x00\x00\x80\x02\x00\x00\x68\x01\x00\x00\x01\x00\x18\x00' un = struct.unpack('