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?
>
>
> 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
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
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
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
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)