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

Vinay Sajip vinay_sajip at yahoo.co.uk
Thu Oct 1 09:07:52 CEST 2009

Brett Cannon <brett <at> python.org> writes:

> As for the PercentMessage/BraceMessage, I would make sure that you
> just simply take the string format and simply apply the arguments
> later to cut down on the amount of parentheses butting up against each
> other: ``logger.debug(BraceMessage("The {} is {}"), "answer", 42)``.

The problem with that is that BraceMessage.__str__() wouldn't know what
arguments to use to produce the message.

> cost of wrapping all strings for a while. I suspect most people will
> simply import the wrapping class and give it some short name like
> people do with gettext.


logger.debug(__("The {} is {}", "answer", 42))

isn't ideal but perhaps liveable with. And hopefully with a decent editor, the
paren-butting annoyance will be minimized.


Vinay Sajip

More information about the Python-Dev mailing list