来个简单的例子吧,有一个字符串'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))
在此处将rawstring转成Byte型数据得到一个rawdata的元组进行处理。
Format C Type Python Notes x pad byte no value c char string of length 1 b signed char integer B unsigned char integer h short integer H unsigned short integer i int integer I unsigned int long l long integer L unsigned long long q long long long (1) Q unsigned long long long (1) f float float d double float s char[] string p char[] string P void * integer