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

Antoine Pitrou solipsis at pitrou.net
Thu Oct 1 12:48:44 CEST 2009

Vinay Sajip <vinay_sajip <at> yahoo.co.uk> writes:
> This seems perhaps usable for a Formatter instantiation (infrequent) but a
> problem for the case where you want to convert format_str + args -> message
> (potentially frequent, and less readable).

Why is it a problem? I don't understand. It certainly is less pleasant to write
"{foo}".format or "{0} {1}".format than it is to write "{0} {1}" alone, but it's
still prettier and easier to remember than the special wrappers people are
proposing here.

> Another problem is that logging
> calls already use keyword arguments (extra, exc_info) and so backward
> compatibility might be compromised.

Then logging can just keep recognizing those special keyword arguments, and
forward the others to the formatting function.

> It also feels like passing a callable could
> encourage patterns of usage which restrict our flexibility for future changes:

Which future changes are you thinking about? AFAIK, there hasn't been a single
change in logging output formatting in years. Rejecting a present change on the
basis that it "restricts our flexibility for future changes" sounds like the
worst kind of argument to me :-)

> That's more flexible, to be sure, but more specialized formatting
> requirements are already catered for using e.g. the PercentMessage/BraceMessage
> approach.

Except that having to wrap format strings with "PercentMessage" or
"BraceMessage" is horrible. Python is not Java.



More information about the Python-Dev mailing list