[Python-Dev] PEP 292, Simpler String Substitutions

Barry A. Warsaw barry@zope.com
Wed, 19 Jun 2002 08:10:48 -0400


>>>>> "FL" == Fredrik Lundh <fredrik@pythonware.com> writes:

    >> def birth(self, name): country = self.countryOfOrigin['name']
    >> return '${name} was born in ${country}'.sub()

    FL> 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)

One use case: you can't internationalize that.  You /can/ translate
'${name} was born in ${country}', which might end up in some languages
like '${country} was ${name} born in'.

    FL> (for extra bonus, explain how sub() can be made to
    FL> execute substantially faster than a join() function)

All I care is that it runs as fast as the % operator.
-Barry