paul j3 added the comment:
An alternative to adding a 'ParagraphFormatter' class to 'argparse', is to
format the individual text blocks PRIOR to passing them to the 'parser', and
use the 'RawTextHelpFormatter'.
In the attached script I use a simple function that applies 'textwrap' to each
'line' of the text. Description, epilog, and argument help are formatted in
roughly the same manner as in paraformatter.py, but without as many bells and
whistles.
def mywrap(text,**kwargs):
# apply textwrap to each line individually
text = text.splitlines()
text = [textwrap.fill(line,**kwargs) for line in text]
return '\n'.join(text)
parser = argparse.ArgumentParser( formatter_class =
argparse.RawTextHelpFormatter,
description = mywrap(description),
epilog = mywrap(epilog, width=40))
I suspect there are tools for doing similar formatting, starting with
'markdown' or 'rsT' paragraphs (though HTML is the usual output). As the
formatting becomes more complex it is better to use existing tools than to
write something new for 'argparse'.
----------
Added file: http://bugs.python.org/file35236/wrap_sample.py
_______________________________________
Python tracker <[email protected]>
<http://bugs.python.org/issue12806>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com