I cannot output the copied file in terminal,

from sys import argv
from os.path import exists
script, from_file, to_file = argv

print “copying from %s to %s” % (from_file, to_file)

in_file = open(from_file)
indata = in_file.read()

print ‘Are you Sure to copy the file %s to %s’ %(from_file, to_file)
print “If ‘yes’ hit ENTER, If ‘not’ hit CTRL-C to abort.”
raw_input(’**’)

out_file = open(to_file, ‘w’)
out_file.write(indata)

print “Ok your file is copied to %s” % to_file

print “if you want to see that copied file, then type that copied file name below…”

copied_file =raw_input(’>>>>>> ')

#copied_file =open(to_file)
#print copied_file.read()

text_of_file = open(copied_file)
print text_of_file.read()

#here i want to output text of my copied file _but there is nothing after i typed
#I am practing ex 15, 16 and 17, plz help me

Hello
I’m trying to help but I’ve looked at your code and I’m confused, what are you trying to achieve, you have referenced 3 questions, which question are you following and from which book?

What I’ve guessed, are you trying to modify and expand on q17
I think your using python 2 from your print statement syntax but why are you using %s and {to_file] syntax.
What are you using to write the code in as your speech marks look incorrect, you use single quotes on the second print statement and double quotes on the third print statement

I’ll try to help but you have to simplify so I can follow what your doing and also state what errors you are getting, I need to be able to replicate what you are doing and seeing.

best regards

Hi, can you please clean up your help request a bit to help others out? First, put these around your code:

[code]
# code here
[/code]

Next, type a message at the top that lays out what you want to do, what you tried doing already, and what is currently happening instead. Then I’ll see if I can give you some advice.

from sys import arg

script, from_file, to_file = argv

print "copying from %s to %s" % (from_file, to_file)

in_file = open(from_file)
indata = in_file.read()

print 'Are you Sure to copy the file %s to %s' %(from_file, to_file)
print "If 'yes' hit ENTER, If 'not' hit CTRL-C to abort."
raw_input('**')

out_file = open(to_file, 'w')
out_file.write(indata)

print "Ok your file is copied to %s" % to_file

print "if you want to see that copied file, then type that copied file name below.."
copied_file =raw_input('>>>>>>  ')

text_of_file = open(copied_file)
print text_of_file.read()

[HERE I WANT TO OPEN TEXT IN TERMINAL WITH THE ABOVE CODE AS EXERCISE 15 OF LPTHW BOOK WITH SIMPLE MODIFYING EXCERCISE 17…

Well I am learning LPTHW
I just modified the Ex 17 and want to do like as 15 to see the copied file through the code in terminal with that modified code.

If you hit the … to the left of “Reply” you can select Edit and then see how I fixed your code.

If you want to read back what you wrote to a file, then you should close it with: myfile.close()

Then you want to open it and read it again. The other option is to use: myfile.seek(0) to go back to the beginning, then your read will work.

Also, you should take more time to write these my friend. If you spend some time writing out:

  1. What you are doing.
  2. What’s going wrong.
  3. What you expect to happen.
  4. What you’ve tried already.
  5. Your code inside [code] and [/code].

Then you’ll find that you actually tend to solve the problems yourself, or at least other people can help you quicker. Try that on your next post.

from sys import argv
#from os.path import exists

script, from_file, to_file = argv

print “copying from %s to %s” % (from_file, to_file)

in_file = open(from_file)
indata = in_file.read()

print ‘Are you Sure to copy the file %s to %s’ %(from_file, to_file)
print “If ‘yes’ hit ENTER, If ‘not’ hit CTRL-C to abort.”
raw_input(’**’)

out_file = open(to_file, ‘w’)
out_file.write(indata)

print “Ok your file is copied to %s” % to_file

out_file.close()
in_file.close()

print “if you want to see that copied file, then type that copied file name below…”
copied_file =raw_input(’>>>>>> ')

copied_file =open(to_file)

print copied_file.read()

:grin IT WORKS…

[ THANK YOU ZED SHAW, YOUR TIPS WORKS AS I WANT, I JUST CONFUSED ABOUT TO PUT OPEN COMMAND AND CLOSE COMMAND ]