手机
当前位置:查字典教程网 >脚本专栏 >python >Python struct.unpack
Python struct.unpack
摘要:1.设置fomat格式,如下:复制代码代码如下:#取前5个字符,跳过4个字符华,再取3个字符format='5s4x3s'2.使用struc...

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

【Python struct.unpack】相关文章:

Python中的Function定义方法第1/2页

Python splitlines使用技巧

python self,cls,decorator的理解

Python translator使用实例

Python中的Numpy入门教程

python zip文件 压缩

Python 开发Activex组件方法

Python备份Mysql脚本

Python help()函数用法详解

python 控制语句

精品推荐
分类导航