Re: [Tutor] string.Template

2013-04-23 Thread Prasad, Ramit
Albert-Jan Roskam wrote: > > On 24/04/13 00:14, Albert-Jan Roskam wrote: > >> Hello, > >> > >> Is there a better, *built-in* alternative for the code below? The > >> recursion > > works, > >> but it feels like reinventing the wheel. > > > > What makes you think it is reinventing the wheel? > >

Re: [Tutor] string.Template

2013-04-23 Thread Albert-Jan Roskam
> Subject: Re: [Tutor] string.Template > > On 24/04/13 00:14, Albert-Jan Roskam wrote: >> Hello, >> >> Is there a better, *built-in* alternative for the code below? The recursion > works, >> but it feels like reinventing the wheel. > > What m

Re: [Tutor] string.Template

2013-04-23 Thread Steven D'Aprano
On 24/04/13 00:47, Chris “Kwpolska” Warrick wrote: 1. locals() is hacky and you shouldn’t use it. Actually this, or something like this, is exactly one of the use-cases for the locals() function. Using locals() as a read-only mapping of name:value pairs is perfectly safe. It's only unsafe i

Re: [Tutor] string.Template

2013-04-23 Thread Steven D'Aprano
On 24/04/13 00:14, Albert-Jan Roskam wrote: Hello, Is there a better, *built-in* alternative for the code below? The recursion works, but it feels like reinventing the wheel. What makes you think it is reinventing the wheel? The following looks like a perfectly sensible use for recursion. If

Re: [Tutor] string.Template

2013-04-23 Thread Chris “Kwpolska” Warrick
On Tue, Apr 23, 2013 at 4:14 PM, Albert-Jan Roskam wrote: > Hello, > > Is there a better, *built-in* alternative for the code below? The recursion > works, > but it feels like reinventing the wheel. > > import string > > def translate(template, *args): > """Recursively $-substitute using as

[Tutor] string.Template

2013-04-23 Thread Albert-Jan Roskam
Hello, Is there a better, *built-in* alternative for the code below? The recursion works, but it feels like reinventing the wheel. import string def translate(template, *args):     """Recursively $-substitute using as a replacement"""     syntax = string.Template(template).substitute(*args)