file can opened for readingmode=' (file has to existwritingmode=' (existing file is truncatedappendingmode='aclosing file myfile close(example py open file for reading infile open('input dat'' 'open file for writing outfile open('output dat'' 'open file for appending appfile open('output dat'' 'close files infile close(