Zope style (was: tuning our site (was: help! advocacy resources needed fast))
Michael Chermside
mcherm at mcherm.com
Fri Apr 4 09:20:50 EST 2003
Dylan Reinhardt writes:
> Hello, <dtml-var fname>. This is demonstration of MySoft version
> <dtml-var software-version>. Just think, <dtml-var fname>, now
> you can shift paradigms and think outside the box at
> <dtml-var company> without leaving your office.
>
> vs.
>
> my_output = """Hello, %s. This is demonstration of MySoft
> version %s. Just think, %s, now you can shift
> paradigms and think outside the box at %s without
> leaving your office.""" % (fname, version, fname, company)
> return my_output
>
> --------
>
> I find the former to be far more readable and more easily maintained...
> particularly as the size of the sample increases. Inserting additional
> variables or moving around existing ones is easy in the first sample and
> must be done carefully in the second.
I think you just need a minor style change in your python code. I find
the following about as readable as your DHTML code:
my_output = """Hello, %(fname)s. This is demonstration of MySoft
version %(software_version)s. Just think, %(fname)s, now
you can shift paradigms and think outside the box at
%(company)s without leaving your office.""" % nameMap
return my_output
Of course, PEP 292 makes this marginally better:
my_output = """Hello, $fname. This is demonstration of MySoft
version $software_version. Just think, $fname, now
you can shift paradigms and think outside the box at
$company without leaving your office.""".sub(nameMap)
return my_output
Now that's really quite readable and maintainable.
-- Michael Chermside
More information about the Python-list
mailing list