简体   繁体   中英

No follow up value in command line argument in Python

I am using argparse module in my Python code for command line arguments. I have some arguments that have some follow up values, ex. -x <value> . I have a situation in which follow up value is not required but I am not able to understand how do I implement it in the code.
The following can be the situations:
python abc.py -x 123 -f or python abc.py -x 123
-f is not compulsory but if it is given, no follow up value is required.

Have you tried using action="store_true" in add_argument . This makes the argument take no follow up value and if it is present then it stores true for what ever variable you specify in dest variable of add_argument . See argparse store options.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM