Główne pojęcia
A simple Python script that uses the built-in hash() function to detect changes in a text file.
Streszczenie
The content describes a straightforward way to create a Python program that can detect changes in a text file. The key concepts covered are:
What we want: The goal is to write a Python program that can detect changes made to a text file, such as test.txt, and print a message when the file is modified.
The built-in hash() function: The hash() function in Python converts a value (in this case, the contents of the text file) into a unique hash value using the SHA-256 algorithm. The hash value will change if the contents of the file are modified.
Writing the gethash(filename) function: The author provides a simple function that reads the contents of a file in binary format and returns the hash value of the file's contents. This function can be used to check if the file has been changed.
The content then provides the actual code for the Python script, which uses the gethash(filename) function to detect changes in the text file.