Break line across lines (not in '[]' or '{}')?

Fredrik Lundh fredrik at pythonware.com
Tue Jun 10 16:32:19 EDT 2003


Robert Oschler wrote:

> I have a Class with a lot of fields in the __slots__ attribute.  Is there a
> way to break the line across multiple lines?
>
> Class HasSlots():
>     __slots__ = 'one', 'two', 'three'
>     ...
>
> I'd like to do:
>
> Class HasSlots():
>     __slots__ = 'one', 'two', 'three'
>     ...
>
>     but this produces a syntax error.

what's the difference?  both examples give syntax errors, btw,
even if you fix the capitalization.  and the __slots__ attribute
doesn't do much unless you inherit from object (etc)...

anyway, here are a few ways to split the slot line (or any tuple
or list literal) across multiple lines:

    class HasSlots(object):
        __slots__ = ('one', 'two', 'three')
        __slots__ += ('four', 'five')

    class HasSlots(object):
        __slots__ = ('one', 'two', 'three',
            'four', 'five')

    class HasSlots(object):
        __slots__ = (
            'one', 'two', 'three', 'four',
            'five'
        )

</F>








More information about the Python-list mailing list