The main reason I’ve preferred the .format method in a couple of recent PRs
and my own work is completely separate from readability. I feel the %
operator is inappropriately overloaded when used both as the proper
‘modulo’ operator as well as a common shortcut to control string
formatting. It always felt odd to me, like Python’s C roots were showing.
It’s true, .format is not always more readable. However, I’ve found this is
more of an adjustment than objectively true. The only danger is that
explicit numbers must be used for all inserted brackets instead of empty
brackets to retain Python 2.6 compatibility.
I don’t really mind either way, just food for thought.
Josh
On Wednesday, September 3, 2014 5:57:56 AM UTC-4, Stefan van der Walt wrote:
On Wed, Sep 3, 2014 at 1:20 AM, Michael Aye
It's part of the Python tutorial for many years and common standard I'd say. It's basic use might be cumbersome at first, but its power is great.
Things like "My name is {0[name]}".format(dict(name='Fred'))
With great power comes great responsibility! I find the above very close to unreadable.
Compare to:
"My name is %s" % name
or
"My name is %(name)s" % {'name': 'Fred'}
Stéfan
participants (1)
-
Josh Warner