Python 字节流写入文件

用struct模块

三个函数 pack()、unpack()、calcsize()

#  按照给定的格式(fmt),把数据封装成字符串(实际上是类似于c结构体的字节流)
pack(fmt, v1, v2, ...)
 
# 按照给定的格式(fmt)解析字节流string,返回解析出来的tuple
unpack(fmt, string)      

# 计算给定的格式(fmt)占用多少字节的内存
calcsize(fmt)

 

struct 类型表

 

FormatC TypePython typeStandard sizeNotes
xpad byteno value  
ccharstring of length 11 
bsigned charinteger1(3)
Bunsigned charinteger1(3)
?_Boolbool1(1)
hshortinteger2(3)
Hunsigned shortinteger2(3)
iintinteger4(3)
Iunsigned intinteger4(3)
llonginteger4(3)
Lunsigned longinteger4(3)
qlong longinteger8(2), (3)
Qunsigned long longinteger8(2), (3)
ffloatfloat4(4)
ddoublefloat8(4)
schar[]string1 
pchar[]string  
Pvoid *integer (5), (3)

转载于:https://www.cnblogs.com/fieldtianye/p/8276598.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值