Hacker News new | ask | show | jobs
by beambot 5037 days ago
Despite being a day-to-day python programmer (scientific computing with some django on the side), apparently I've been living under a rock. When did .format supersede normal printf-style string formatting, ie. "%f" % (3.14)? Is the latter now deprecated?
2 comments

Hints have appeared suggesting that interpolation will be deprecated at some point in python 3, e.g. from this article:

http://docs.python.org/dev/py3k/whatsnew/3.0.html#changes-al...

PEP 3101: Advanced String Formatting. [...] The plan is to eventually make this the only API for string formatting, and to start deprecating the % operator in Python 3.1.

As far as I know, interpolation is not actually deprecated yet though.

> When did .format supersede normal printf-style string formatting

It was backported, but the superseding is mostly for Python 3.

> Is the latter now deprecated?

Not at all, and not expected to be, though str.format is recommended going forward: http://docs.python.org/py3k/library/stdtypes.html#old-string...

> As the new String Formatting syntax is more flexible and handles tuples and dictionaries naturally, it is recommended for new code. However, there are no current plans to deprecate printf-style formatting.