Python 读取二进制文件

filename = raw_input('enter file name:') f=open(filename, 'rb') f.seek(0, 0) index = 0 for i in range(0, 16): print "%3s" % hex(i), print for i in range(0, 16): print "%-3s" % "#", print while True: temp = f.read(1) if len(temp) == 0: break else: print "%3s" % temp.encode('hex'), index += 1 if index == 16: index = 0 print f.close()

你可能感兴趣的:(Python,学习,python,hex,input,file)