您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息

Python struct.unpack

2025/10/21 12:23:29发布20次查看
1. 设置fomat格式,如下:
复制代码 代码如下:
# 取前5个字符,跳过4个字符华,再取3个字符
format = '5s 4x 3s'
2. 使用struck.unpack获取子字符串
复制代码 代码如下:
import struct
print struct.unpack(format, 'test astring')
#('test', 'ing')
来个简单的例子吧,有一个字符串'he is not very happy',处理一下,把中间的not去掉,然后再输出。
复制代码 代码如下:
import struct
thestring = 'he is not very happy'
format = '2s 1x 2s 5x 4s 1x 5s'
print ' '.join(struct.unpack(format, thestring))
输出结果:
he is very happy
该用户其它信息

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录 Product