5,321
edits
Line 570: | Line 570: | ||
[https://pypi.org/project/ConfigArgParse/ ConfigArgParse] is the same as argparse except it allows you to use config files as args. | [https://pypi.org/project/ConfigArgParse/ ConfigArgParse] is the same as argparse except it allows you to use config files as args. | ||
< | <syntaxhighlight lang="python"> | ||
parser = configargparse.ArgParser() | parser = configargparse.ArgParser() | ||
parser.add('-c', '--config', is_config_file=True, help='config file path') | parser.add('-c', '--config', is_config_file=True, help='config file path') | ||
#... | |||
</ | # Parse all args, throw exception on unknown args. | ||
parser.parse_args() | |||
# Parse only known args. | |||
parser.parse_known_args() | |||
</syntaxhighlight> | |||
If you want to use bools without store-true or store-false, you need to define an str2bool function: | If you want to use bools without store-true or store-false, you need to define an str2bool function: |