码迷,mamicode.com
首页 > 其他好文 > 详细

struct模块拆分字符串为指定字符数的字符串或元组

时间:2017-12-27 21:36:38      阅读:137      评论:0      收藏:0      [点我收藏+]

标签:post   gpo   bsp   ...   body   color   ring   int   har   

import struct

# unpack() parses the string to a tuple
format = 1s2s1s1s
line = 12345
col = struct.unpack(format, line)
print col

# calcsize() returns the number of characters
# in a given format string
format = 30s30s20s1s
print struct.calcsize(format)

struct.unpack(format,string)按照format格式将string解压为元组。

struct.pack(format,v1,v2,...) 按照format格式将v1,v2压缩成单一字符串

struct.calcsize(format) 返回format的字符总数。

 

struct模块拆分字符串为指定字符数的字符串或元组

标签:post   gpo   bsp   ...   body   color   ring   int   har   

原文地址:https://www.cnblogs.com/koujiaodahan/p/8127627.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!