Python Forum
In ArgParse, can two compatible formatter_class values be used? - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: In ArgParse, can two compatible formatter_class values be used? (/thread-28707.html)



In ArgParse, can two compatible formatter_class values be used? - pjfarley3 - Jul-31-2020

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


RE: In ArgParse, can two compatible formatter_class values be used? - Gribouillis - Jul-31-2020

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...



RE: In ArgParse, can two compatible formatter_class values be used? - pjfarley3 - Jul-31-2020

Thank you very much, that worked flawlessly.

Marking this issue solved.

Peter