Q:

Problems with reading and writing a text file in Python

This answer was solved by doing print (file.read())
I have a project called 'PyDOS'. I recently discovered that you can read and write files in Python, I implemented this and the writing bit worked. But when trying the read part, it gives a syntax. The code that's messing up the reading part is:
print file.read

This is the code with the first error:
def textviewer():
   print ("Text Viewer.")
   file_name = input("Enter a text file to view: ")
   file = open(file_name, "r")
   print file.read #This returns 'Syntax Error' when pressing F5
   input("Press enter to close")

def edit(): #However, the writing function works just fine.
        os.system('cls' if os.name == 'nt' else 'clear')
        print ("EDIT")
        print ("-------------")
        print ("Note: Naming this current document the same as a different document will replace the other document with this one.")
        filename = input("Plese enter a file name.")
        file = open(filename, "w")
        print ("Now, Write 5 lines.")
        line1 = input()
        line2 = input()
        line3 = input()
        file.write(line1)
        file.write("\n")
        file.write(line2)
        file.write("\n")
        file.write(line3)
        file.close()
        print ("File saved!")
        time.sleep(3)

It returns syntax error, I tried file.read() but instead showed:
<built-in method read of _io.TextIOWrapper object at 0x10ada08>

A:

<built-in method read of _io.TextIOWrapper object at 0x10ada08>

That's the string representation of a function. What you want isn't the function itself, but rather to call the function.
In other words, you want file.read() instead of file.read.
Also, in Python 3.x, print is a function, not a keyword, so you want print(file.read()), not print file.read().
Incidentally, file is the name of a built-in function (albeit a deprecated one), so you should use a different variable name.

