Ian Bicking: the old part of his blog

Comment

Actually it's quite easy to implement it by just defining your own interpolator class.

>>> class Interpolator:
def __init__(self, *items):
self.encodings = {"h": cgi.escape, "u": urllib.quote}
self.items = list(items)
def __getitem__(self, item):
return self.encodings[item](self.items.pop(0))


>>> "Some html: %(h)s\n An url: %(u)s" % Interpolator("", "an URL")
'Some html: \n An url: an%20URL'
>>>
Comment on % interpolation
by Joonas Paalasmaa