python - How to compare two versions of same file (old and new), and detect if there were some changes? -
i new @ both, python , stackoverflow, please have on mind. tried myself , manage it, works if hardcode hash number of previous version 1 in hash1, , compare hash number of version. wolud program every time save hash number of version , every run compare newer version, , if file changed something.
this code
import hashlib hash1 = '3379b3b9b9c82650831db2aba0cf4e99' hasher = hashlib.md5() open('word.txt', 'rb') afile: buf = afile.read() hasher.update(buf) hash2 = hasher.hexdigest() if hash1 == hash2: print('same version') else print('diffrent version')
just save hash file file.txt , when need compare hash read file.txt , compare 2 strings. here example of how read , write files in python. http://www.pythonforbeginners.com/files/reading-and-writing-files-in-python
Comments
Post a Comment