read()
read() returns a string with all contents of the file
The text file file.txt
:
This is the first line. This is the second line.
is read by:
aFile = file("file.txt", "r") # open the file # for reading aString = aFile.read() # read the file aFile.close() # close the file # for reading print aString
printing:
This is the first line. This is the second line.