Updating a file through a Python algorithm