Tuesday, November 3, 2015

argparse documentation

https://docs.python.org/2/library/argparse.html#action
https://docs.python.org/3/library/argparse.html

http://stackoverflow.com/questions/7427101/dead-simple-argparse-example-wanted-1-argument-3-results
http://stackoverflow.com/questions/12818146/python-argparse-ignore-unrecognised-arguments
https://docs.python.org/2/howto/argparse.html

add_mutually_exclusive_group:
http://www.frattv.com/python-argparse-command-line-argument-that-can-be-either-named-or-positional/

#description and epilog (additional message such as script objective):
https://docs.python.org/2/library/argparse.html#epilog

when -h or --help is used: description shows at the top and epilog show at the bottop of the usual message.

text without description  overrides the script file name:

parser = argparse.ArgumentParser('My first argparse attempt')

C:\Windows\System32>C:\Users\test\Desktop\a.py
usage: My first argparse attempt [-h] [--SeeMan SEEMAN] sdsd
My first argparse attempt: error: too few arguments

#parse undefined args from command line:
parser = argparse.ArgumentParser()
args, unknown = parser.parse_known_args()
in place of:
args = = parser.parse_args()

#argument type check in argparse:
https://docs.python.org/2/library/argparse.html#type





No comments:

Post a Comment