Argparser python usage

Posted by Jingbiao on August 22, 2021, Reading time: Less than 1 minute.

import

1
import argparse

Initialise argparser

1
parser = argparse.ArgumentParser()

Add arguments for the parser

1
2
parser.add_argument('--value', '-v', type=str, default='def',
                    help='write help here')

Get arguments

1
2
args = parser.parse_args()
val =  args.value