argparse

How to access a python argparse argument with a dot in the name

落爺英雄遲暮 提交于 2020-02-16 05:42:22
问题 Python's argparse lets me define argument names containing a dot in the name. But how can I access these ? import argparse parser = argparse.ArgumentParser() parser.add_argument("inputfile.txt") parser.add_argument("outputfile.txt") args = parser.parse_args(['hello', 'world']) # now args is: #

Python (3.6.3) argparse: default value of optional parameter to be another parameter's value

不羁岁月 提交于 2020-02-06 07:58:51
问题 I have a function that takes as parameters an input folder (required) and output folder (optional), but I want the default value of the (optional) output folder to be the input folder. I can do this of course using, e.g. p = argparse.ArgumentParser(description="blah") p.add_argument('inpath',

Is it possible to use argparse to capture an arbitrary set of optional arguments?

安稳与你 提交于 2020-01-25 06:54:13
问题 Is it possible to use argparse to capture an arbitrary set of optional arguments? For example both the following should be accepted as inputs: python script.py required_arg1 --var1 value1 --var2 value2 --var3 value3 python script.py required_arg1 --varA valueA --var2 value2 --varB valueB a priori

Is it possible to use argparse to capture an arbitrary set of optional arguments?

二次信任 提交于 2020-01-25 06:54:10
问题 Is it possible to use argparse to capture an arbitrary set of optional arguments? For example both the following should be accepted as inputs: python script.py required_arg1 --var1 value1 --var2 value2 --var3 value3 python script.py required_arg1 --varA valueA --var2 value2 --varB valueB a priori

Python argparse check if flag is present while also allowing an argument

谁说胖子不能爱 提交于 2020-01-24 19:56:48
问题 How do I check if the flag --load is present? #!/usr/bin/env python3 import argparse import os parser = argparse.ArgumentParser(description='Process some integers.') parser.add_argument('-l', '--load', nargs='?', metavar='path', help='Load all JSON files recursively in path') args = parser.parse