Advertisement
pleabargain

python 3 the hard way lesson 16

May 3rd, 2013
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.81 KB | None | 0 0
  1. #http://learnpythonthehardway.org/book/ex16.html
  2. #to run it
  3. #C:\Python33>python PTHW16.py 1.txt.txt
  4.  
  5. from sys import argv
  6.  
  7. script, filename =argv
  8.  
  9. print ("We are going to erase{}.".format(filename))
  10.  
  11. print ("If you don't want us to do that, hit ctrl +c (^c).")
  12. print ("If you do want us to delete the file, hit RETURN")
  13.  
  14. input ("?")
  15.  
  16. print ("Opening the file...")
  17. target = open(filename,'w')
  18.  
  19. print ("truncating the file...")
  20. target.truncate()
  21.  
  22. print ("Now, I'm going to ask for three lines.")
  23.  
  24. line1 = (input("line 1: "))
  25. line2 = (input("line 2: "))
  26. line3 = (input("line 3: "))
  27.  
  28. print ("I'm going to write to the file!")
  29.  
  30. target.write(line1)
  31. target.write("\n")
  32. target.write(line2)
  33. target.write("\n")
  34. target.write(line3)
  35. target.write("\n")
  36.  
  37. print ("Now, let's close the file.")
  38. target.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement