obtaining references to files may all be used up resulting in future errors being thrown as files can no longer be opened the following short code snippet illustrates the above ideasfile open('myfile txt'' +'print('file name:'file nameprint('file closed:'file closedprint('file mode:'file modefile close(print('file closed now:'file closedthe output from this isfile namemyfile txt file closedfalse file moderfile closed nowtrue reading files of coursehaving set up file object we want to be able to either access the contents of the file or write data to that file (or do bothreading data from text file is supported by the read()readline(and readlines(methodsthe read(method this method will return the entire contents of the file as single string the readline(method reads the next line of text from file it returns all the text on one line up to and including the newline character it can be used to read file line at time the readlines(method returns list of all the lines in filewhere each item of the list represents single line note that once you have read some text from file using one of the above operations then that line is not read again thus using readlines(would result in further readlines(returning an empty list whatever the contents of the file the following illustrates using the readlines(method to read all the text in text file into program and then print each line out in turnfile open('myfile txt'' 'lines file readlines(for line in linesprint(lineend=''file close(