python sturct模組操作C資料

2022-05-07 16:48:17 字數 606 閱讀 4195

python中struct方便對底層資料進行操作,比如把乙個數 i = 65536儲存為乙個4b的int型資料

s0 = struct.pack(",i)  

s0為乙個字串,長度為4,即佔四個位元組,這樣方便傳輸與儲存二進位制資料。

"為大端,i為無符號整型。

還有其它型別引數:

c:char      b:signed byte                 b:unsigned byte

h:short    h:unsigned short            i:int; i:unsigned int

l:long       l:unsigned long              f:float

d:double  

s:string (array of char)   

p: pascal string (with count byte)

q:long long    q:unsigned long long

unpack用於還原資料

假設收到s0這個字串

i2 = struct.unpack(",s0)  

i2為乙個元組型,i2[0]即還原的整型數字

python模組之heapq模組(堆)基本操作

1 匯入模組 import heapq 匯入模組2 heapq 提供的常用方法 heapq.heapify head 將陣列轉化成堆 刪除堆頂,也就是最小值 往堆中增元素 heapq.nlargest n,head 查堆中最大的n個數 heapq.nsmallest n,head 查堆中最小的n個數...

python之模組datetime 常見操作

coding utf 8 python 27 xiaodeng python之模組datetime import datetime name datetime fast implementation of the datetime type.help datetime datetime模組下的幾個類...

Python xlrd模組匯入過程及常用操作

簡介 讀取excle文件,支援xls,xlsx格式 安裝 pip3 install xlrd 匯入 import xlrd xlrd 模組方法 讀取excel file route info.xls 讀取excel資訊,生成物件 read book xlrd.open workbook file 獲...