Python Forum

Full Version: In ArgParse, can two compatible formatter_class values be used?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
When setting up argparse, I would like to use BOTH formatter_class=argparse.ArgumentDefaultsHelpFormatter AND formatter_class=RawDescriptionHelpFormatter so that the user sees argument default values AND I can code multiline pre-indented "description" and "epilog" values.

If that possible, what is the correct syntax? Or can only one formatter_class value be used?

TIA for any assistance you can provide.

Peter
Looking into arpgarse's code, we see that ArgumentDefaultsHelpFormatter overrides a single method _get_help_string() and RawDescriptionHelpFormatter overrides only _fill_text(). It may depend on the python version, but I think you could try this
class MyFormatter(ArgumentDefaultsHelpFormatter, RawDescriptionHelpFormatter):
    pass

...formater_class=MyFormatter...
Thank you very much, that worked flawlessly.

Marking this issue solved.

Peter