function that reads contents of a text file
# Return the contents of the named text file
def fileContents(filename):
# Get the file object that corresponds to the file name
# We open it for reading as a text file. (We could also
# open binary files using "b" instead of "t" and we could
# open for writing, using "w" instead of "r")
fileObject = open(filename, "rt")
# Get the (possibly very long) text string that the file
# contains by reading it
contents = fileObject.read()
return contents
Link to this Page