Python 判断一个字节数组是否 beginsWith 另外一个字节数组,pythonbeginswith,python代码impo


python代码

import chilkatzipData = chilkat.CkByteData()gifData = chilkat.CkByteData()#  Zip files begin with these 4 bytes:zipBegin = chilkat.CkByteData()zipBegin.append('\x50\x4B\x03\x04',4)#  GIF files begin with "GIF89", which is this byte sequence:gifBegin = chilkat.CkByteData()gifBegin.append('\x47\x49\x46\x38\x39',5)success = zipData.loadFile("dude.zip")if (success == True):    if (zipData.beginsWith(zipBegin)):        print "Yes, this is a .zip archive!"    else:        print "No, this is not a .zip archive."else:    print "Failed to load dude.zip"success = gifData.loadFile("dude.gif")if (success == True):    if (gifData.beginsWith(gifBegin)):        print "Yes, this is a GIF image!"    else:        print "No, this is not a GIF image."else:    print "Failed to load dude.gif"

评论关闭