Jump to content

Python: Difference between revisions

157 bytes added ,  7 January 2021
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.


<pre>
<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')
#...
 
</pre>
# 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: