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

Antoine Pitrou solipsis at pitrou.net
Thu Oct 1 15:07:50 CEST 2009


Hello,

> Well, it's less readable, as I said in parentheses. It would work, of course.
> And the special wrappers needn't be too intrusive:
> 
> __ = BraceMessage
> 
> logger.debug(__("Message with {0} {1}", 1, "argument"))

Ah, I hadn't thought about that. It looks a bit less awful indeed.
I'm of the opinion, however, that %-formatting should remain the default and
shouldn't need a wrapper.

There's another possibility, which is to build the wrapping directly around the
logger. That is, if I want a %-style logger, I do:

   logger = logging.getLogger("smtp")
   logger.debug("incoming email from %s", sender_address)

and I want a {}-style logger, I do:

   logger = logging.getLogger("smtp", style="{}")
   logger.debug("incoming email from {addr}", addr=sender_address)

(of course, different users of the "smtp" logger can request different
formatting styles when calling getLogger().)

We could combine the various proposals to give users flexible APIs. Of course,
it generally smells of "there's more than one way to do it".

> It's the Rumsfeldian "We don't know what we don't know" 

Is this guy in the Python community? :-)

> I'm just trying to think ahead, and can't claim to have got a definitive answer
> up my sleeve.

Sure, we have some time until 2.7/3.2 anyway.

Regards

Antoine.




More information about the Python-Dev mailing list