argparse

parsing argument in python

我只是一个虾纸丫 提交于 2019-12-14 03:42:55
问题 I have a problem I am trying to find a solution. I am not sure if I can do it with argparse. I want to be able to specify an option myprog -a 1 myprog -a 2 Now when I have a = 1 , I want to be able to specify b and c . But when a = 2 , I can only specify d . myprog -a 1 -b 3 -c 0 myprog -a 2 -d 3

CLI option that is an aggregation of two other options and precedence, in python

☆樱花仙子☆ 提交于 2019-12-14 03:14:00
问题 I'm using argparse to parse CLI options in my Python scripts. I would create a flag that is equivalent to specifying two other flags. So python myscript.py --flagc is equivalent to python myscript.py --flaga --flagb This is my code: args = parser.parse_args() if args.flagc: args.flaga = True args

Handling argparse conflicts

只谈情不闲聊 提交于 2019-12-13 23:34:51
问题 If I import a Python module that is already using argparse , however, I would like to use argparse in my script as well ...how should I go about doing this? I'm receiving a unrecognized arguments error when using the following code and invoking the script with a -t flag: Snippet: #!/usr/bin/env

Best way to make argument parser accept absolute number and percentage?

人走茶凉 提交于 2019-12-13 22:33:28
问题 I am trying to write a Nagios style check to use with Nagios. I have working script that takes in something like -w 15 -c 10 and interprets that as "Warning at 15%, Critical at 10%". But I just realized that in the built-in Nagios plugins, the same arguments would mean "Warning at 15MB, Critical

How can I define global options with sub-parsers in python argparse?

心不动则不痛 提交于 2019-12-13 14:25:54
问题 I'm trying to figure out how to add global option in a sub-parser scenario with pythons arparse library. Right now my code looks like this: def parseArgs(self): parent_parser = argparse.ArgumentParser(add_help=False) parent_parser.add_argument('--debug', default=False, required=False, action=

How to include one positional argument into argparse mutually exclusive group?

不打扰是莪最后的温柔 提交于 2019-12-13 12:07:32
问题 I know that does not make sense multiple positional arguments into a mutually exclusive group because you can't say who is who. But I need to include ONE positional argument into that. What I need: $ myprogram -h usage: myprogram [-h] [--delete value | --update value | value] Where positional

Python argparse as a function

血红的双手。 提交于 2019-12-13 11:48:33
问题 Is there anything inherently wrong with getting command-line arguments in this way? I mean by putting the argument parsing into its own function. Would it be considered non-Pythonic or more so? #!/usr/bin/python import argparse def getArgs(argv=None): parser = argparse.ArgumentParser(description=

Is there any way to instruct argparse (Python 2.7) to remove found arguments from sys.argv?

时间秒杀一切 提交于 2019-12-13 11:36:26
问题 I'm fully midstream in the development process for what is turning into a fairly substantial Python 2.7 project. Right now I have all of my unittest classes lumped together in their own module, tests.py , which stands at about 3300 lines. This is crazy big, impossible to navigate, all around bad