Vinay Sajip <vinay_sajip <at> yahoo.co.uk> writes:

> #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



_______________________________________________
Python-Dev mailing list
Python-Dev@python.org
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com

Reply via email to