In Python tutorials it is usually highly recommended to wrap file reading/writing operations into With statement:
with open(“testfile.txt”) as file: data = fi