Argparse defaults

Joseph L. Casale jcasale at activenetwerx.com
Sun Jan 4 18:58:55 CET 2015


Does a facility exist to add an argument with a default being a function
that leverages the final parsed Namespace?

For example:

    group  = parser.add_argument_group(' some_group ')
    group.add_argument(
        '--some_group',
        nargs='*',
        type=str
    )
    group.add_argument(
        '-- some_group_def',
        default=func
    )

    args = parser.parse_args()

where func returns a value 'a' if args.some_group or 'b' otherwise?

Obviously I can break that out after but I am curious if the facility exists?

Thanks,
jlc



More information about the Python-list mailing list