Python strings and coding conventions

Ben Finney bignose+hates-spam at benfinney.id.au
Sun Jan 11 05:22:54 EST 2009


Robert Kern <robert.kern at gmail.com> writes:

> I usually use implicit concatenation:
> 
> s = ('some long text that '
>      'needs to be split')

I do something very similar:

    fleebnorg.spam = (
        'some long text that'
        ' needs to be split')

The differences are:

I prefer to have indents as 4 spaces no matter how long the preceding
line is; but I also want the opening quote for the start of the string
to line up with subsequent open quotes for that string.

So I have all the portions of the string line up at the same (new)
indent level. To make that simpler without thinking about it every
time I change the first line, I simply break after the opening
parenthesis.

I prefer the continued portions to have the connecting space (or
whatever characters are contextually “connecting” in the text); this
is a greater visual cue that the string doesn't stand alone.

-- 
 \     “I went camping and borrowed a circus tent by mistake. I didn't |
  `\      notice until I got it set up. People complained because they |
_o__)                           couldn't see the lake.” —Steven Wright |
Ben Finney



More information about the Python-list mailing list