1

I am wanting to generate and store a CRC (or similar) value for a given list of files which can be used as a comparison at a later point. Writing a function to do this is simple enough, but is there a more standard way to do it within the Python libs?

The value generated does not need to be of any particular standard.

4

2 回答 2

6

recommend hashlib, it implements a common interface to many different secure hash and message digest algorithms. Included are the FIPS secure hash algorithms SHA1 and MD5. a demo code:

import hashlib
m = hashlib.md5()
for line in open('data.txt', 'rb'):
    m.update(line)
print m.hexdigest()
##ouput
1ab8ad413648c44aa9b90ce5abe50eea
于 2009-07-09T10:36:24.663 回答
1

If you don't need one-way security you could also use zlib.crc32 or zlib.adler32, as documented here.

于 2009-07-09T10:43:38.860 回答