[PATCH] allow partial replace in string.Template
Nick Coghlan
ncoghlan at iinet.net.au
Tue Feb 15 05:11:44 EST 2005
Stefan Behnel wrote:
>
>
> Nick Coghlan wrote
>
>> a) Patches are more likely to be looked at if placed on the SF patch
>> tracker.
>
>
> see your own b), I wanted to discuss them first.
Fair enough.
> Still, when I first tried out the Template class, I immediately stumbled
> over the fact that the substitute methods always return strings, and
> never Template objects. While it makes sense for their primary purpose,
> it totally restricts the usage of this module to one-show operations.
Except that it is easy to turn a string into a template using a constructor. . .
However, now that I think more about your 'partial_substitute' method it does
make sense as an alternative constructor:
@classmethod
def from_template(*args, **kwds):
cls, orig = args[:2]
return cls(orig.safe_substitute(*args[2:], **kwds))
Usable as:
new_templ = Template.from_template(orig_templ, *args, **kwds)
Versus:
new_templ = Template(orig_templ.safe_substitute(*args, **kwds))
Mutating the template in place seems questionable. Rebinding the name with the
above constructor would be more appropriate, IMO.
Hmm - I'm unconvinced, but it's probably still worth posting a patch and sending
it in Barry Warsaw's direction.
Cheers,
Nick.
--
Nick Coghlan | ncoghlan at email.com | Brisbane, Australia
---------------------------------------------------------------
http://boredomandlaziness.skystorm.net
More information about the Python-list
mailing list