emacs in python mode does the correct thing, says the styleguide.

Barry A. Warsaw barry at digicool.com
Wed May 2 10:43:41 EDT 2001


>>>>> "LC" == Laura Creighton <lac at cd.chalmers.se> writes:

    LC> But I do not think so.  Here is the example given:

    |     def __init__(self, width, height,
    |                  color='black', emphasis=None, highlight=0):
    |         if width == 0 and height == 0 and \
    |            color == 'red' and emphasis == 'strong' or \
    |            highlight > 100:
    |             raise ValueError, "sorry, you lose"
    |         if width == 0 and height == 0 and (color == 'red' or
    |                                            emphasis is None):
    |             raise ValueError, "I don't think so"
    |         Blob.__init__(self, widt, height,
    |                       color, emphasis, highlight)

    LC> I think that lining up continuation lines to match the first
    LC> open round parenthesis is rather silly.

It's the intended behavior.  I think it generally helps you understand
what construct the continuation is part of.
    
    LC> If instead of __init__ the function was called
    LC> ReallyDescriptiveLongNamedGraphicalWidgetWithBellsOnIt you
    LC> wouldn't have room to pass any arguments to it at all. :-)

What you do instead is leave the open paren as the last thing on the
line, and then everything else indents one indentation level to the
right.  E.g.

    def __init__(self, width, height,
                 color='black', emphasis=None, highlight=0):
        if width == 0 and height == 0 and \
           color == 'red' and emphasis == 'strong' or \
           highlight > 100:
            raise ValueError, "sorry, you lose"
        if width == 0 and height == 0 and (color == 'red' or
                                           emphasis is None):
            raise ValueError, "I don't think so"
        Blob.__init__(
            self, widt, height, color, emphasis, highlight)

    def ReallyDescriptiveLongNamedGraphicalWidgetWithBellsOnIt(
        self, arg1, arg2, arg3,
        arg4, arg5, arg6):
        some_stuff()

-Barry




More information about the Python-list mailing list