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/092430.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:51:34 CEST 2009
Barry Warsaw <barry <at> python.org> writes:

> 
> This is a very interesting idea.
> 
> Note that one of the reasons to /at least/ support {}-strings also is  
> that %-strings are simply too error prone in many situations.  For  
> example, if I decide to support internationalization of log format  
> strings, and all I can use is %-strings, it's almost guaranteed that I  
> will have bugs because a translator forgot the trailing 's'.  This  
> exactly the motivation that led to PEP 292 $-strings.
> 
> In fact, while we're at it, it would be kind of cool if I could use $- 
> strings in log templates.  Antoine's idea of accepting a callable  
> might fit that bill nicely.

You're already covered if you use the PercentMessage/BraceMessage approach I
mentioned elsewhere in this thread. Suppose:

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



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