源码网商城,靠谱的源码在线交易网站 我的订单 购物车 帮助

源码网商城

Python struct.unpack

  • 时间:2022-06-14 10:05 编辑: 来源: 阅读:
  • 扫一扫,手机访问
摘要:Python struct.unpack
1. 设置fomat格式,如下:
[u]复制代码[/u] 代码如下:
# 取前5个字符,跳过4个字符华,再取3个字符 format = '5s 4x 3s'
2. 使用struck.unpack获取子字符串
[u]复制代码[/u] 代码如下:
import struct print struct.unpack(format, 'Test astring') #('Test', 'ing')
来个简单的例子吧,有一个字符串'He is not very happy',处理一下,把中间的not去掉,然后再输出。
[u]复制代码[/u] 代码如下:
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
  • 全部评论(0)
联系客服
客服电话:
400-000-3129
微信版

扫一扫进微信版
返回顶部