[Python-ideas] Printf function?

Steven D'Aprano steve at pearwood.info
Sun May 13 09:22:45 CEST 2012


Carl M. Johnson wrote:

> Well, if that's the solution, why do we even have .format in the first
> place? I know there are a lot of people who still prefer % formatting, but
> I personally never liked it, and I prefer not to use it if I have any
> choice about it. But that's neither here nor there. My question is, being
> that we have .format, why not make it easier to use? 

Define "easier to use". Calling a method and passing its output to print seems 
to be pretty easy to me.

The major issue with printf is that it prints AND formats. That means you 
can't easily capture its output. A simpler approach is to have one function 
that handles the printing, and another function (or possibly a choice of 
multiple functions) that handles the formatting, then simply pass the output 
of the second to the first. That is to say, multiple simple tools that do one 
thing each are simpler *and* more flexible than a single tool to do multiple 
things: a hammer and a  wrench together are less complex than a combination 
hammer-wrench, and you can do more with them as separate tools than as a combo.



-- 
Steven




More information about the Python-ideas mailing list