[Python-ideas] Printf function?

Masklinn masklinn at masklinn.net
Sun May 13 11:51:58 CEST 2012


On 2012-05-13, at 02:49 , Carl M. Johnson wrote:

> I was looking at this jokey page on the evolution of programming language syntax -- http://alan.dipert.org/post/153430634/the-march-of-progress -- and it made me think about where Python is now. The Python 2 version of the example from the page is
> 
> 	print "%10.2f" % x
> 
> and the Python 3 is
> 
> 	print("{:10.2f}".format(x))
> 
> Personally, I prefer the new style {} formatting to the old % formatting, but it is pretty busy when you want to do a print and format in one step. Why not add a printf function to the built-ins, so you could just write
> 
> 	printf("{:10.2f}", x)
> 
> Of course, writing a printf function for oneself is trivial and "not every three line function needs to be a built-in," but I do feel like this would be a win for Python's legibility.
> 
> 
> What do you all think?

I'm −1 on two counts personally:

1. Even with Python 3's slightly more verbose string formatting, I don't
think there's much (if any) gain in having a builtin merging print and
format
2. If I see a function called `printf` (or with `printf` pas part of its
name), I expect it to use printf-style format strings (that is, Python
2-style formatting). A function called printf with new-style format
string would be far more confusing than the current situation, I think.


More information about the Python-ideas mailing list