blist =
[1,
2,
3,
255]
the_bytes = bytes(blist)
#无法改变
the_byte_array = bytearray(blist)
#可以当列表添加
import struct
valid_png_header = b'\x89PNG\r\n\x1a\n'
data = b'\x89PNG\r\n\x1a\n\x00\x00\x00\rIHDR'
+ \
b'\x00\x00\x00\x9a\x00\x00\x00\x8d\x08\x02\x00\x00\x00\xc0'
if data[:8]
== valid_png_header:
width, height = struct.unpack('>LL', data[16:24])
print('Valid PNG, width', width,
'height', height)
else:
print('Not a valid PNG')
>LL 是一个格式串,它用于指导unpack()正确解读字节序列并将它们组装成Python的数据类型
>
用于指明整数是以大端(big-endian)方案存储的
每个L代表一个4字节的无符号长(unsigned long)整数
#逆转
import struct
struct.pack('>L',
154)
原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。
原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。