I can't make my code work. I open the file with r+ attribute, print what's already in it, take 2 lines from the user, but cannot write these files:
file1 = open('test.txt', 'r+')
print "\n This is your file:\n"
print file1.read()
print "Now type in 2 lines:"
line1 = raw_input("Line 1: ")
line2 = raw_input("Line 2: ")
print "Writing the lines"
file1.write(line1)
file1.write("\n")
file1.write(line2)
file1.write("\n")
print "\n This is your file again:\n"
print file1.read()
file1.close()
All I get is:
Traceback (most recent call last):
File "C:/Python27/new.py", line 10, in
file1.write(line1)
IOError: [Errno 0] Error