#!/usr/bin/python
import argparse
parser=argparse.ArgumentParser(description='script to run')
parser.add_argument('inputFile', nargs='?', type=argparse.FileType('rt'))
parser.add_argument('inputString', action='store', nargs='?')
parser.add_argument('-option1', metavar='percent', type=float, action='store')
parser.add_argument('-option2', metavar='outFile1', type=argparse.FileType('w'))
parser.add_argument('-option3', action='store', default='<10')
args = parser.parse_args()
print(args)
for argv in [[], ['-h'], '/etc/passwd b'.split(), ['/etc/passwd']]:
print("*"*79)
try:
print(parser.parse_args(argv))
except SystemExit:
pass
IyEvdXNyL2Jpbi9weXRob24KCmltcG9ydCBhcmdwYXJzZQoKcGFyc2VyPWFyZ3BhcnNlLkFyZ3VtZW50UGFyc2VyKGRlc2NyaXB0aW9uPSdzY3JpcHQgdG8gcnVuJykKCnBhcnNlci5hZGRfYXJndW1lbnQoJ2lucHV0RmlsZScsIG5hcmdzPSc/JywgdHlwZT1hcmdwYXJzZS5GaWxlVHlwZSgncnQnKSkKcGFyc2VyLmFkZF9hcmd1bWVudCgnaW5wdXRTdHJpbmcnLCBhY3Rpb249J3N0b3JlJywgbmFyZ3M9Jz8nKSAKcGFyc2VyLmFkZF9hcmd1bWVudCgnLW9wdGlvbjEnLCBtZXRhdmFyPSdwZXJjZW50JywgdHlwZT1mbG9hdCwgYWN0aW9uPSdzdG9yZScpCnBhcnNlci5hZGRfYXJndW1lbnQoJy1vcHRpb24yJywgbWV0YXZhcj0nb3V0RmlsZTEnLCB0eXBlPWFyZ3BhcnNlLkZpbGVUeXBlKCd3JykpCnBhcnNlci5hZGRfYXJndW1lbnQoJy1vcHRpb24zJywgYWN0aW9uPSdzdG9yZScsIGRlZmF1bHQ9JzwxMCcpCmFyZ3MgPSBwYXJzZXIucGFyc2VfYXJncygpCnByaW50KGFyZ3MpCgpmb3IgYXJndiBpbiBbW10sIFsnLWgnXSwgJy9ldGMvcGFzc3dkIGInLnNwbGl0KCksIFsnL2V0Yy9wYXNzd2QnXV06CiAgICAgcHJpbnQoIioiKjc5KQogICAgIHRyeToKICAgICAgICAgcHJpbnQocGFyc2VyLnBhcnNlX2FyZ3MoYXJndikpCiAgICAgZXhjZXB0IFN5c3RlbUV4aXQ6CiAgICAgICAgIHBhc3M=
Namespace(inputFile=None, inputString=None, option1=None, option2=None, option3='<10')
*******************************************************************************
Namespace(inputFile=None, inputString=None, option1=None, option2=None, option3='<10')
*******************************************************************************
usage: prog.py [-h] [-option1 percent] [-option2 outFile1] [-option3 OPTION3]
[inputFile] [inputString]
script to run
positional arguments:
inputFile
inputString
optional arguments:
-h, --help show this help message and exit
-option1 percent
-option2 outFile1
-option3 OPTION3
*******************************************************************************
Namespace(inputFile=<open file '/etc/passwd', mode 'rt' at 0xb72f57b0>, inputString='b', option1=None, option2=None, option3='<10')
*******************************************************************************
Namespace(inputFile=<open file '/etc/passwd', mode 'rt' at 0xb72f57b0>, inputString=None, option1=None, option2=None, option3='<10')