import hashlib
from time import sleep
def getSHA256(filename):
h = hashlib.sha256()
b = bytearray(128*1024)
mv = memoryview(b)
with open(filename, 'rb', buffering=0) as f:
for n in iter(lambda : f.readinto(mv), 0):
h.update(mv[:n])
return h.hexdigest()
def listToString(s):
_s = ""
for ele in s: _s += ele
return _s
def readFile(filename):
with open(filename) as f: lines = f.readlines()
return listToString(lines)
filename = "default.txt"
_sha256 = getSHA256(filename)
_text = readFile(filename)
while True:
if getSHA256(filename) != _sha256: # условие сработает если файл будет изменён
_new = readFile(filename).replace(_text, "")
print("New in file: " + _new)
_sha256 = getSHA256(filename)
_text = readFile(filename)
sleep(0.15)