[Python-Dev] PEP 292, Simpler String Substitutions

Fredrik Lundh fredrik@pythonware.com
Wed, 19 Jun 2002 09:05:00 +0200


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)

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

</F>