python strings

Consultant (amrit@xvt.com)
Wed, 20 Apr 1994 15:59:22 -0600 (MDT)

>
> So what do you think of the triple quote convention? To be specific,
> I'm thinking of the following rules. Either single or double quotes
> can be tripled to start a different kind of quoted string. Inside
> such strings, backslash escapes still work, and <backslash><newline>
> is ignored, but unescaped <newline> is kept in the string (rather than
> being an error). Sequences of 1 or 2 quotes do not terminate the
> string. A sequence of three quotes can be enclosed by quoting at
> least one of them with a backslash. There is no variable substitution
> but of course you can use a triple-quoted string as format string or
> concatenate it with a back-ticked expression.
>

Well, having variable substitution inside strings would be a useful
feature for multi-line strings (only) For single line strings, the
'%' printf operator works well, but look at this multi-line string:

"""The %d numbers of %s objects gets harder and harder to read
as the number of %s lines gets greater than about %d lines long due
to the loss of %s as you are scanning through the text.""" % \
(5, 'python', 'text', 3, 'context')

This is much better:

n = 2
language = 'python'

"""The {n} numbers of {language} objects is usually easy to read in
long strings because you can see which variable gets substituted in
a given point."""

Where inside of a long string, """ TX1 {expr} TX2 """ is equivalant
to """ TX1 """ + `expr` + """ TX2 """