Python struct.unpack,python3 socket

来源:未知 浏览 123次 时间 2021-06-10 20:41

1. 设置fomat格式如下:
代码如下:
# 取前5个字符电子商务推广如下:
代码如下:
# 取前5个字符跳过4个字符华网络推广软文跳过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

转载请注明:seo-网站优化-网站建设 » Python struct.unpack

标签: format如下happy字符