[issue39809] argparse: add max_text_width parameter to ArgumentParser
paul j3
report at bugs.python.org
Sun Mar 1 13:09:30 EST 2020
paul j3 <ajipanca at gmail.com> added the comment:
https://bugs.python.org/issue13041
is (I think) the latest issue/patch to deal with the help width.
I don't like the idea of adding more parameters to the `ArgumentParser` class. It's too complicated already.
There are a couple of ways that a user can do this already.
One is a custom version of the `parser.format_help`, though as your patch shows, that actually has to go through the `_get_formatter` method. Only `format_help` is listed in the public API.
Another is a subclass of HelpFormatter. It just needs to customize the `width` parameter.
I vaguely recall suggesting such a subclass in a previous bug/issue, but can't find that.
Subclassing HelpFormatter is an established way of customizing the format.
Here's a discussion of this on StackOverflow. It uses a simple lambda as `formatter_class`:
https://stackoverflow.com/questions/44333577/explain-lambda-argparse-helpformatterprog-width
formatter = lambda prog: argparse.HelpFormatter(prog, width=100)
and
https://stackoverflow.com/questions/32888815/max-help-position-is-not-works-in-python-argparse-library
----------
_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue39809>
_______________________________________
More information about the Python-bugs-list
mailing list