argparse: setting optional argument with value of mandatory argument

Viewed 8675

With Python's argparse, I would like to add an optional argument that, if not given, gets the value of another (mandatory) argument.

parser.add_argument('filename',
                    metavar = 'FILE',
                    type    = str,
                    help    = 'input file'
                    )

parser.add_argument('--extra-file', '-f',
                    metavar = 'ANOTHER_FILE',
                    type    = str,
                    default = ,
                    help    = 'complementary file (default: FILE)'
                    )

I could of course manually check for None after the arguments are parsed, but isn't there a more pythonic way of doing this?

2 Answers
Related