Permalink
Browse files

added exercise 16

  • Loading branch information...
1 parent 7270a48 commit 1eedb4f769592023fc10cf55b6cde5f030d18db0 Jason Herskowitz committed Jan 11, 2011
Showing with 45 additions and 0 deletions.
  1. +42 −0 ex16.py
  2. +3 −0 test.txt
View
42 ex16.py
@@ -0,0 +1,42 @@
+from sys import argv
+
+script, filename = argv
+
+print "We're going to erase %r." % filename
+print "If you don't want that, hit CTRL-C (^ C)."
+print "If you do want that, hit RETURN."
+
+raw_input ("?")
+
+print "Opening the file..."
+target = open(filename, 'w')
+
+print "Trunctating the file. Goodbye!"
+target.truncate()
+
+print "Now I'm going to ask your for threee lines."
+
+line1= raw_input ("line1: ")
+line2 = raw_input ("line2: ")
+line3 = raw_input ("line3: ")
+
+print "I'm going to write these to a file."
+
+target.write (line1)
+target.write ("\n")
+target.write (line2)
+target.write ("\n")
+target.write (line3)
+target.write ("\n")
+
+
+print "And finally, we close it."
+target.close()
+
+message = open(filename)
+print message.read()
+message.close()
+print "Done!"
+
+
+
View
3 test.txt
@@ -0,0 +1,3 @@
+I think
+I figured
+it out.

0 comments on commit 1eedb4f

Please sign in to comment.