Percent formatting is fundamentally unsafe because if the argument is unexpectedly a tuple, you can cause a failure. I.e. "Value:\t%s" % val will explode if val is a tuple.
That said, I think there are too many formatting choices in Python. It's not very "one obvious way to do it."
Right, tuples require a clunkier syntax to be safe, and that's obviously problematic. I talked about this and the non-Pythonic nature of string formatting in the blog post above.
As ridiculous as it sounds to introduce a new standard (incoming XKCD), I really hope f-strings can replace the other styles altogether for new code. Probably a bit too hopeful, though
1
u/earthboundkid Nov 24 '16
Percent formatting is fundamentally unsafe because if the argument is unexpectedly a tuple, you can cause a failure. I.e.
"Value:\t%s" % valwill explode if val is a tuple.That said, I think there are too many formatting choices in Python. It's not very "one obvious way to do it."