Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #http://learnpythonthehardway.org/book/ex16.html
- #to run it
- #C:\Python33>python PTHW16.py 1.txt.txt
- from sys import argv
- script, filename =argv
- print ("We are going to erase{}.".format(filename))
- print ("If you don't want us to do that, hit ctrl +c (^c).")
- print ("If you do want us to delete the file, hit RETURN")
- input ("?")
- print ("Opening the file...")
- target = open(filename,'w')
- print ("truncating the file...")
- target.truncate()
- print ("Now, I'm going to ask for three lines.")
- line1 = (input("line 1: "))
- line2 = (input("line 2: "))
- line3 = (input("line 3: "))
- print ("I'm going to write to the file!")
- target.write(line1)
- target.write("\n")
- target.write(line2)
- target.write("\n")
- target.write(line3)
- target.write("\n")
- print ("Now, let's close the file.")
- target.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement