質問: hashlib.md5() for line in open('data.txt', 'rb'): m.update(line) print m.hexdigest() zlib.crc32を使用して同様のものを取得することは可能ですか?
回答: 解決:import os, sys import zlib def crc(filename, excludeline="", includeline=""): try: fd = open(filename,"rb") except ioerror: print "unable to open the file in readmode:", filename return eachline = fd.readline() prev = none while eachline: if excludeline and eachline.startswith(excludeline): continue if not prev: prev = zlib.crc32(eachline) else: prev = zlib.crc32(eachline, prev) eachline = fd.readline() fd.close() return format(prev & 0xffffffff, '08x') #returns 8 digits crc for eachfile in sys.argv[1:]: print crc(eachfile) (excludeline = ""、includeline = "")が何であるか本当にわからない...