Python Argparse - Set default value of a parameter to another parameter -
i've added parameter -c, want add parameter called -ca. how can set default value of -ca -c? want if -ca not specified, assign -c -ca.
parser.add_argument("-c", type=str) parser.add_argument("-ca", type=str, default=xxx)
thanks.
normally, single dash flags single characters. -ca
unwise, though not illegal. in normal posix practice interpreted -c a
or -c -a
.
also argparse
allows flagged arguments (optionals
) occur in order.
parsing starts out assigning defaults. when relevant flag encountered, new value overwrites default. given order, it's impossible 1 argument take on value of default.
in general interactions between arguments best handled after parsing. there mutually_exclusive
grouping, no mutually_inclusive
. can build in sort of interaction via custom action
classes, implementing work post-parsing testing.
in sum, simplest thing use default default
, none
, , test
if args.ca none: args.ca = args.c
Comments
Post a Comment