[Python-Dev] PEP 292, Simpler String Substitutions

Oren Tirosh oren-py-d@hishome.net
Wed, 19 Jun 2002 03:51:21 -0400


On Wed, Jun 19, 2002 at 09:05:00AM +0200, Fredrik Lundh wrote:
> Barry wrote:
> 
> > def birth(self, name):
> >     country = self.countryOfOrigin['name']
> >     return '${name} was born in ${country}'.sub()
> 
> now explain why the above is a vast improvement over:
> 
>     def birth(self, name):
>         country = self.countryOfOrigin['name']
>         return join(name, ' was born in ', country)

Assuming join = lambda *args: ''.join(map(str, args)) 

1. Friendly for people coming from other languages (Perl/shell). Same reason 
why the != operator was added as an alternative to <>.

2. Less quotes and commas for the terminally lazy.

3. More flexible for data-driven use.  Either the template or the
dictionary can be data rather than hard-wired into the code.

	Oren