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/025579.html below:

[Python-Dev] PEP 292, Simpler String Substitutions

[Python-Dev] PEP 292, Simpler String Substitutionsholger krekel pyth@devel.trillke.net
Wed, 19 Jun 2002 12:21:51 +0200
Fredrik Lundh wrote:
> duncan wrote:
> 
> > What I really don't understand is why there is such pressure to get an 
> > alternative interpolation added as methods to str & unicode rather than 
> > just adding an interpolation module to the library?
> > e.g.
> > 
> > from interpolation import sub
> > def birth(self, name):
> >     country = self.countryOfOrigin['name']
> >     return sub('${name} was born in ${country}', vars())
> 
> that's too easy, of course ;-)
> 
> especially since someone has already added such a method, a
> long time ago (os.path.expandvars).
> 
> and there's already an interpolation engine in there; barry's loop,
> join and format stuff can replaced with a simple callback, and a
> call to sre.sub with the right pattern:
> 
>     def sub(string, mapping):
>         def repl(m, mapping=mapping):
>             return mapping[m.group(m.lastindex)]
>         return sre.sub(A_PATTERN, repl, string)
> 
> (if you like lambdas, you can turn this into a one-liner)
> 
> maybe it would be sufficient to add a number of "right patterns"
> to the standard library...

FWIW, +1

    holger




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