python - Write a very basic copy from one file into another using command line arguments -


I am new to Python and am trying to create one file of the original file in another file program. My code now

  import sys if len (sys.argv)! = 3: Print 'Usage: File Source Source Destination' Otherwise: Try: infile = open (sys.argv [1]) Outfile = open (sys.argv [2], 'w') except for IOError: print 'source File does not exist 'getline (infile, line) infile.close () outfile.close ()  

As you can expect that I am trying to output that if the program If the tries to misuse, then why the program will not work.

I have just written a C ++ program, and it worked fine, but now I have to transfer the same logic to a different syntax.

I am trying to write a line of infile in the string line and then output it I write in the file.

Do not try "c ++" to write in Python. For work in hand:

  import sys if len (sys.argv)! = 3: print ('use: filecopy source destination') else: try: open with (sys.argv [1], 'r') as inf, open (sys.argv [2], 'w') For outf: inf in line: except for outf.write (line) IOError: print ('{} does not exist or not' read.format (sys.argv [1]))  

Comments

Popular posts from this blog

java - Can't add JTree to JPanel of a JInternalFrame -

javascript - data.match(var) not working it seems -

javascript - How can I pause a jQuery .each() loop, while waiting for user input? -