Zope style (was: tuning our site (was: help! advocacy resources needed fast))

Dylan Reinhardt python at dylanreinhardt.com
Fri Apr 4 12:11:30 EST 2003


On Fri, 2003-04-04 at 06:20, Michael Chermside wrote:
> 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

An excellent suggestion.  Thank you.

> 
> 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.

Funny... I've been using Python pretty much exclusively for a couple
years now... just *seeing* $var_name syntax gave me a brief case of the
Perl Willies. :-)  But the PEP makes it perfectly obvious why this might
be a good idea anyway.

Dylan






More information about the Python-list mailing list