A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://mail.python.org/pipermail/python-dev/2009-October/092431.html below:

[Python-Dev] transitioning from % to {} formatting

[Python-Dev] transitioning from % to {} formattingVinay Sajip vinay_sajip at yahoo.co.uk
Thu Oct 1 08:59:40 CEST 2009
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



More information about the Python-Dev mailing list

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4