[Baypiggies] Discussion for newbies/beginner night talks
Tung Wai Yip
tungwaiyip at yahoo.com
Sat Feb 10 18:41:25 CET 2007
On Sat, 10 Feb 2007 08:14:16 -0800, Paul McNett <p at ulmcnett.com> wrote:
> Aahz wrote:
>> On Fri, Feb 09, 2007, Dennis Reinhardt wrote:
>>> You illustration does not show how a long triple quoted string gets
>>> supplied with parameters. Stylistically, I often prefer substituting
>>> parameters on a line by line basis because there is better locality,
>>> making
>>> the code easier to understand and read.
>
> How about this contrived example:
>
> def getHeader(self, **kwargs):
> html = """<!-- BOF header -->
>
> <html>
> <head>
> <title>%(title)s</title>
> <meta name="description" value="%(title)s">
> <meta name="keywords" value="%(keywords)s">
> </head>
>
> <body>
> %(navigation_bar)s
>
> <!-- EOF header -->
> """
> return html % kwargs
>
>
>> Strings like SQL and HTML that do not normally get presented to the user
>> don't need to care about whitespace AT ALL.
>
> I think that with longish triple-quoted strings, ignoring the code
> indentation is the best. But that's me.
I'm with you. I often embed long fragement of SQL or HTML into Python
source code. I can easily read the embedded text fragement as a whole
without a lot of quotes inserted if I would have to break them into
individual lines. Even better, it avoids the obfuscation of escaping the "
character with \". I think triple quote is one of the feature I like most
in Python.
One caveat - since you use % to format the arguments, the individual %
characters in the text block would have to escaped. Something you'd likely
to encounter when embedding CSS.
Wai Yip
More information about the Baypiggies
mailing list