I'm trying to learn some programming by going through the exercises in Learn Python The Hard Way. I'm doing a little wrap-up exercise on my own by writing my own script, but unfortunately I have run into some problems related to printing files.
What I would like to achieve with my script is to:
- create a new file;
- copy the content from an existing file into that newly-created file;
- add some extra text by the user to the new file; and finally
- print the content of the new file.
I managed to achieve everything except the last bit: printing the new file. All I get is a blank space in the terminal window. The code is shown below:
v1 = raw_input("Specify which file to copy: ")
txt = open(v1).read()
print "This is the content of the file:"
print txt
v2 = raw_input("Choose a name for your new file, end it with txt")
nyfile = open(v2, "w+")
nyfile.write(txt)
nyfile.write(raw_input("Lets add some new text to the file: "))
txt2 = nyfile.read()
print txt2