[issue12806] argparse: Hybrid help text formatter

paul j3 report at bugs.python.org
Tue May 13 03:38:47 CEST 2014


paul j3 added the comment:

An alternative to passing a Formatter instance to the parser is to use a wrapper function.  `HelpFormatter.__init__` takes several keyword args. '_get_formatter' does not use those.  However we could define:

    def format_wrapper(**kwargs):
        # class 'factory' used to give extra parameters
        def fnc(prog):
            cls = argparse.HelpFormatter
            return cls(prog, **kwargs)
        return fnc

and use that to set the 'width' of the formatter object.

    parser =  argparse.ArgumentParser( formatter_class =  format_wrapper(width=40))

----------

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue12806>
_______________________________________


More information about the Python-bugs-list mailing list