Answer the question
In order to leave comments, you need to log in
How can python 2.x argparser get either one required argument or one optional?
How can python 2.x argparser get EITHER one required argument OR one optional?
That is,
EITHER python @[email protected] is a required parameter
OR
python @[email protected] is an optional
parameter
Answer the question
In order to leave comments, you need to log in
What's the problem?
from argparse import ArgumentParser
parser = ArgumentParser(usage="Here is usagage")
parser.add_argument("positional",nargs="*")
parser.add_argument("--flag")
if __name__ == "__main__":
args = parser.parse_args()
if args.positional and not args.flag:
print("i'm positional")
elif args.flag and not args.flag:
print ("i'm flag")
else:
raise Exception("RTFM")
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question