[issue9399] Provide a 'print' action for argparse

paul j3 report at bugs.python.org
Sun Jul 20 00:17:11 CEST 2014


paul j3 added the comment:

As Steven notes, the patch lacks tests.  It also lacks documentation.  

The 2 things that this class does different from 'version' are
- write without passing the text through 'textwrap'
- write to a user defined file

There is a difference in opinion between Éric and Steven as to whether the class should use write directly or use the HelpFormatter.

I don't think it needs further action at this time.  There doesn't seem to be a lot of interest in it.  Also there are a number of ways of accomplishing the task without adding an Action class.

- the class is a simple adaptation of the 'version' class

- a user defined class works just as well

- 'version' with Raw formatter, and shell redirection also works

- it is also easy to write the text to a file after parse_args.

I've attached a file that illustrates a number of these alternatives.  It includes a 'callable' class.
-----------------

The discussion got me thinking about a selective version of the RAW formatting, analogous to the HTML <pre> tag.  With this the user could mark a given text (description, epilog, help, version etc) as pre-formatted, without having to change the formatter_class.

    parser.add_argument('--license', action='version',
        version=Pre(formatted_text))

I probably should submit that in a new issue.

----------
Added file: http://bugs.python.org/file35997/try_write.py

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


More information about the Python-bugs-list mailing list