Files

The following code shows how to read, modify and close the files with their particular order.

Always open the file with read, append or write, modify, then close the file.

example_file = "file-name.txt"

Opens file and "r" read (error if does not exist), "a" append and "w" write

infile = open(example_file, "r")

Returns one line, if called twice, it reads first two lines of the file

infile.readline() 
infile.close() # closes the file