Discuss / Python / 小练习代码

小练习代码

Topic source

感觉脑子不好用啊,这么点点也要这里那里有问题,弄了有点久,pdb调试没发现有进入函数的功能呢,不太方便

在import struct
import pdb

def bmpinfo(image):
        with open(image,'rb') as f:
                b=f.read(30)
        s=struct.unpack('<ccIIIIIIHH',b)
        if(s[0]+s[1]==b'BM'):
                print('%s is a windows bmp image!!'%image)
                print('the size is %s*%s'%(s[6],s[7]))
                print('the number of color is %d'%s[9])
        elif(s[0]+[1]==b'BA'):
                print('%s is a OS/2 bmp image!!'%image)
                print('the size is %s*%s'%(s[6],s[7]))
                print('the number of color is %d'%s[9])
        else:
                print('%s is not s bmp image'%image)
if(__name__=='__main__'):
        bmpinfo('test.bmp')

  • 1

Reply