python中struct.unpack的用法
来源:互联网 发布:appstore数据查询平台 编辑:程序博客网 时间:2024/05/21 08:22
Format用法详解
Python 初始化多维数组代码
python中struct.unpack的用法
python中struct.unpack的用法
Python中按一定的格式取出某字符串中的子字符串,使用struck.unpack是非常高效的。
1. 设置fomat格式,如下:
2. 使用struck.unpack获取子字符串
来个简单的例子吧,有一个字符串'He is not very happy',处理一下,把中间的not去掉,然后再输出。
输出结果:
He is very happy
1. 设置fomat格式,如下:
# 取前5个字符,跳过4个字符华,再取3个字符
format= '5s 4x 3s'
format= '5s 4x 3s'
2. 使用struck.unpack获取子字符串
import struct
print struct.unpack(format,'Test astring')
#('Test', 'ing')
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))
theString= 'He is not very happy'
format='2s 1x 2s 5x 4s 1x 5s'
print' '.join(struct.unpack(format, theString))
输出结果:
He is very happy
利用unpack(),读入一个bin文件,rawstring是一个str型的字串:
rawfile = open("lcd.raw","rb")
rawstring = rawfile.read()
rawstring = rawfile.read()
rawdata = struct.unpack(len(rawstring)*'B',rawstring)
在此处将rawstring转成Byte型数据得到一个rawdata的元组进行处理。
0 0
- python中struct.unpack的用法
- python中struct.unpack的用法
- python中struct.unpack的用法
- Python中struct.pack()和struct.unpack()用法详细说明
- python struct中pack和unpack
- python struct中pack和unpack
- python struct中pack和unpack
- Python struct.unpack
- Python struct pack/unpack
- Python使用struct处理二进制(pack和unpack用法)
- Python使用struct处理二进制(pack和unpack用法)
- Python使用struct处理二进制(pack和unpack用法)
- Python使用struct处理二进制(pack和unpack用法)
- Python使用struct处理二进制(pack和unpack用法)
- Python使用struct处理二进制(pack和unpack用法)
- Python使用struct处理二进制(pack和unpack用法)
- Python使用struct处理二进制(pack和unpack用法)
- Python使用struct处理二进制(pack和unpack用法)
- Solution:Error occurred during deployment: Exception while preparing the app : Invalid resource
- 矩阵归零
- android httpclient get post 代码
- JS定时器使用,定时定点,固定时刻,循环执行
- (一)简单工厂模式
- python中struct.unpack的用法
- zoj 3798 Abs Problem( ZOJ Monthly, August 2014 - A)
- Makefile 中:= ?= += =的区别
- java基础编程学习过程中的知识点 -- 个人总结
- memcpy函数实现及其优化
- vcredist_x86.exe 静默安装方法
- Decorator模式
- 简单上传
- Mysql中文汉字转拼音的实现(每个汉字转换全拼)