[Tutor] can you explain string replacement syntax and commaseparated statements
Alan Gauld
alan.gauld at freenet.co.uk
Sun Aug 6 17:42:19 CEST 2006
> can you explain string replacement syntax and commaseparated
> statements
string substitution replaces the 5 %s comvbinations with the 5
values after the % sign
A simplied example is:
s = "hello %s, welcome to %s" % ('world','python')
Your example just uses triple quotes to allow the string
to wrap and has more substitutions. The 5 values are also
less direct but all yield strings eventually!
The comma separated assignment looks like a mistake to me!
A simplified form looks like:
s = "Hello", s += "world"
Which yields a syntax error.
Are you sure its not a semi-colon, in which case it just combines
the two instructions on a single line.
If so its very bad coding style IMHO but is legal.
HTH,
Alan G.
> text = """From: the bugman <y... at example.com>
> To: the bugfixer <y... at example.com>
> Subject: bug: %s: %s (%s)
> Content-Type: multipart/mixed; boundary="----here----"
>
> ------here----
> Content-Type: text/plain
> Content-Disposition: inline
>
> %s
>
> %s
>
> ------here----
> Content-Type: text/html; name="bug.html"
> Content-Disposition: attachment; filename="bug.html"
>
> """ % (tb[0], tb[1], web.ctx.path, web.ctx.method+'
> '+web.ctx.home+web.ctx.f
> ullpath,
> ''.join(traceback.format_exception(*tb)),
> text += str(web.djangoerror())
>
>
>
>
> ---------------------------------
> Do you Yahoo!?
> Everyone is raving about the all-new Yahoo! Mail Beta.
More information about the Tutor
mailing list