Discuss / Python / <struct>作业

<struct>作业

Topic source

Gin阿金

#1 Created at ... [Delete] [Delete and Lock User]

def bmp_info(data): info = struct.unpack('<ccIIIIIIHH', data[:30]) if info[0] == b'B' and info[1] == b'M': return {'width':info[6], 'height':info[7],'color':info[9]} else : print('This is not a bitmap!')

测试

bi = bmp_info(bmp_data) assert bi['width'] == 28 assert bi['height'] == 10 assert bi['color'] == 16 print('ok')

ok


  • 1

Reply