answered Aug 10 '17
It is a good practice to use the close() method to close a file. After the f.write line add:
f.close()