[Python-ideas] Printf function?

Cameron Simpson cs at zip.com.au
Sun May 13 03:50:10 CEST 2012


On 12May2012 14:49, Carl M. Johnson <cmjohnson.mailinglist at gmail.com> 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.

I'm -1 on it:

  - as you say, it could be a three line function

  - %-formatting isn't going away

  - neither %-formatting nor {}-formatting is anything to do with the
    print statement; they are both string actions
    So the printf idea does not achieve anything anyway.

Observe my Python 3.2:

  [/home/cameron]janus*> python3.2
  Python 3.2.2 (default, May  2 2012, 09:04:59) 
  [GCC 4.5.3] on linux2
  Type "help", "copyright", "credits" or "license" for more information.
  >>> x=1.5
  >>> print("%10.2f" % x)
        1.50
  >>> 

Printf isn't needed.

Cheers,
-- 
Cameron Simpson <cs at zip.com.au> DoD#743
http://www.cskk.ezoshosting.com/cs/

Senior ego adepto, ocius ego eram.



More information about the Python-ideas mailing list