Question

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.

Was it helpful?

Solution

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

OTHER TIPS

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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top