views:

334

answers:

2

I have a script that uses the cmd Python module. The cmd module uses a triple quoted multiline string as it's help text. Something like this

def x(self, strags = None):
    """class
    help text here
    and some more help text here"""

When running the script, the command 'help x' will print the string. It will, however, print the newlines in front of the last two lines as well. I can overcome this by not indenting these lines, but that'll make my code ugl{y,ier}.

How to overcome this indenting problem? How do the pro Python coders handle this?

+1  A: 

I'd handle it by having consistent indents, like this:

def x(self, strags = None):
    """
    class
    help text here
    and some more help text here
    """

Sure, it takes two lines more, but it also injects clarity (in my opinion) by making the doc comment stand out quite well.

unwind
+2  A: 

Personally I try to follow PEP 8 which refers the reader to PEP 257 for Docstring Conventions. It has an entire section on multi-line docstrings.

Gerry