[Python-Dev] Re: PEP 292, Simpler String Substitutions

Ka-Ping Yee ping@zesty.ca
Tue, 18 Jun 2002 21:36:51 -0700 (PDT)

On Tue, 18 Jun 2002, Barry A. Warsaw wrote:
> 	def birth(self, name):
> 	    country = self.countryOfOrigin['name']
> 	    return '${name} was born in ${country}'
> 	birth('Guido')
>     returns
> 	'Guido was born in the Netherlands'

I assume you in fact meant

	    return '${name} was born in ${country}'.sub()

for the third line above?

> 	print s.sub({'name': 'Guido',
> 		     'country': 'the Netherlands'})

Have you considered the possibility of accepting keyword arguments
instead?  They would be slightly more pleasant to write:

        print s.sub(name='Guido', country='the Netherlands')

This is motivated because i imagine relative frequencies of use
to be something like this:

    1.  sub()                      [most frequent]
    2.  sub(name=value, ...)       [nearly as frequent]
    3.  sub(dictionary)            [least frequent]

If you decide to use keyword arguments, you can either allow both
keyword arguments and a single dictionary argument, or you can
just accept keyword arguments and people can pass in dictionaries
using **.

-- ?!ng