argparse.ArgumentParser formatter_class argument

Peter Otten __peter__ at web.de
Sun Dec 17 04:12:07 EST 2017


Seb wrote:

> As far as I can see it is currently impossible to apply more than one
> class to an ArgumentParser.  For example, I'd like to use both
> RawDescriptionHelpFormatter *and* ArgumentDefaultsHelpFormatter in an
> ArgumentParser, but it seems that's impossible, as one can only choose a
> single one.  Any suggestions?

Try 

class MyHelpFormatter(
        argparse.RawDescriptionHelpFormatter,
        argparse.ArgumentDefaultsHelpFormatter
):
    pass

parser = argparse.ArgumentParser(formatter_class=MyHelpFormatter)

If there are any conflicts you have to write more code...




More information about the Python-list mailing list