python - Write a very basic copy from one file into another using command line arguments -
i new python , trying create basic re-create 1 file file program. code right is
import sys if len(sys.argv) !=3: print 'usage: filecopy source destination' else: try: infile = open(sys.argv[1]) outfile = open(sys.argv[2], 'w') except ioerror: print 'source file not exist' getline(infile, line) infile.close() outfile.close()
as can see trying output why programme won't work if user tries utilize wrong.
i wrote c++ programme doing same thing this, , worked fine, have transfer same logic different syntax.
i trying write line of infile string line , write output file.
don't seek "write c++" in python. task @ hand:
import sys if len(sys.argv) !=3: print('usage: filecopy source destination') else: try: open(sys.argv[1], 'r') inf, open(sys.argv[2], 'w') outf: line in inf: outf.write(line) except ioerror: print('{} not exist or cannot read'.format(sys.argv[1]))
python
No comments:
Post a Comment