No attributes are set because you set the argument_default
value to argparse.SUPPRESS
, which means that attributes are never set unless they have an explicit value.
Set can set an explicit default=None
value per argument to gain the attributes again for these specific options:
group1.add_argument('-p', '--project', dest='proj',
nargs='?', const='all', type=str,
help='list of project(s)', default=None)
group1.add_argument('-c', '--component', dest='comp',
nargs='?', const='all', type=str,
help='list of Component(s)', default=None)
and the args.proj
and args.comp
attributes will once more always be set. None
is a false value, so the if args.proj
test will not pass moving to the other branch, for example.
The alternative is to use hasattr()
to see if the attribute is set:
if hasattr(args, 'proj'):