How to convert sys.argv to argparse in python -


i have

file1 = sys.argv[1] file2 = sys.argv[2]  file2 = sys.argv[3] 

how can put in argparse?

ready-opened file objects:

import argparse, sys  parser = argparse.argumentparser(description='process src dst') parser.add_argument('src', type=argparse.filetype('r'),                     default=sys.stdin) parser.add_argument('dst', type=argparse.filetype('w'),                     default=sys.stdout) options = parser.parse_args() 

then use options.src , options.dst already-open file objects.

prints following when use --help command-line switch:

usage: somescript.py [-h] src dst  process src dst  positional arguments:   src   dst  optional arguments:   -h, --help  show message , exit 

Comments

Popular posts from this blog

css - Which browser returns the correct result for getBoundingClientRect of an SVG element? -

gcc - Calling fftR4() in c from assembly -

Function that returns a formatted array in VBA -