i am following a series of tutorials (http://learnpythonthehardway.org/book/ex16.html ) online and i am completely stuck. i have looked everywhere for the answer but cannot seem o find the solution. i apologise if this is a silly question and completely obvious but i am a total beginner.
the script below works fine except for one mistake. the .read () command on line 29 returns empty when the script is run.
if anyone could tell me why this is and how i could fix it i would be very happy.
kind regards. :)
from sys import argv
script, filename = argv
print "we are going to erase the %r" % filename
print "if you do not want to do that hit ctrl C ( ^c )."
print "if you do want to do that hit return."
raw_input ("?")
print "opening the file....."
target = open (filename, "r+")
print "truncating the file. goodbye!"
target.truncate ()
print "now i am going to ask you for 3 lines"
line1 = raw_input ("line 1:")
line2 = raw_input ("line 2:")
line3 = raw_input ("line 3:")
print "now, im going to write those 3 lines to the %s file:" % filename
target.write ("%s\n%s\n%s" % (line1, line2, line3))
print "now i am going to show you the contents of the file:"
print target.read()
print "and finally we close."
target.close()