How does help() indent doc strings?

Roy Smith roy at panix.com
Sun Feb 3 14:07:46 CET 2013


I'm trying to use argparse.RawDescriptionHelpFormatter to get my epilog 
string formatted the way I want.  This works:

def parse_cli():
    epilog = """\    
             This my very long epilog string
             which goes on for several lines.
             """

    parser = argparse.ArgumentParser(\
        formatter_class=argparse.RawDescriptionHelpFormatter,
        pilog=textwrap.dedent(epilog))

but it's annoying to have to type my triple-quoted string with the 
backslash for the first line (following the example from 
http://docs.python.org/2.7/library/textwrap.html).  It would be much(*) 
nicer to be able to do:

    epilog = """This my very long epilog string
                which goes on for several lines.
                """

and have dedent() figure out the indenting like help() does for 
docstrings.  How can I do that (in python 2.7)?

(*) For, I suppose, a relatively small value of much, but one which is 
bugging the heck out of me at the moment :-)



More information about the Python-list mailing list