Nov-09-2019, 08:44 PM
The best way to do it is with the 'with' statement. You don't need to call the close() method and the file is automatically closed.
with open("cd4.txt", "w") as fhand: code...code...code