A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://mail.python.org/pipermail/python-dev/2002-June/025601.html below:

[Python-Dev] PEP 292, Simpler String Substitutions

[Python-Dev] PEP 292, Simpler String SubstitutionsFredrik Lundh fredrik@pythonware.com
Wed, 19 Jun 2002 15:13:25 +0200
guido wrote:


> > > def birth(self, name):
> > >     country =3D self.countryOfOrigin['name']
> > >     return '${name} was born in ${country}'.sub()
> >=20
> > now explain why the above is a vast improvement over:
> >=20
> >     def birth(self, name):
> >         country =3D self.countryOfOrigin['name']
> >         return join(name, ' was born in ', country)
>=20
> One word: I18n.

really?  who's doing the localization in:

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

maybe barry meant

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

but in that case, I completely fail to see why he couldn't
just as well do the substitution inside the "_" function:

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

where _ could be defined as:

    def _(string, mapping=3DNone):
        if mapping is None:
            ...
        def repl(m, mapping=3Dmapping):
            return mapping[m.group(m.lastindex)]
        return sre.sub(A_PATTERN, repl, do_translation(string))

instead of

    def _(string, mapping=3DNone):
        if mapping is None:
            ...
        return do_translation(string).sub(mapping)

</F>





RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4