ark at acm.org
Wed Jan 19 11:57:38 EST 2005
"Steve Holden" <steve at holdenweb.com> wrote in message
news:3YvHd.80953$Jk5.28602 at lakeread01...
> The error you get is NOT a syntax error:
> >>> cmd = '%s format %s \
> ... over %d lines' % ('my', 'string', 2)
> >>> cmd
> 'my format string over 2 lines'
> The interpreter is probably complaining because it needs six values to
> fill out the format and you only provided four.
Also, I'm dubious about the idea of splitting a string literal across
multiple lines, as it's impossible to indent such a literal nicely without
putting stray spaces into its contents. So instead of writing
'this is a\
and not making it clear how many spaces you intend between 'a' and 'long',
how about writing this instead?
('this is a '
in which the contents are not in doubt. This code takes advantage of two
properties of Python:
1) Multiple string literals with only whitespace between them are
2) Ending a line inside unbalanced parentheses implicitly makes the next
line part of the same statement.
More information about the Python-list