Python script works - now refactoring to try to avoid changing the file on disk