1 Oct
2009
1 Oct
'09
6:59 a.m.
Vinay Sajip
#Just typing this in, it's not tested or anything class DollarMessage: def __init__(self, fmt, *args, **kwargs): self.fmt = fmt self.args = args self.kwargs = kwargs
def __str__(self): return string.Template(self.fmt).substitute(*args, **kwargs)
Whoops, sorry, pressed the "post" button by accident on my previous post. The above substitute call should of course say string.Template(self.fmt).substitute(*self.args, **self.kwargs) and you can alias DollarMessage (or whatever name you choose) as _ or __, say. As far as the Formatter formatting goes, it's easy enough to subclass Formatter to format using whatever approach you want. Regards, Vinay Sajip