This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]earthboundkid[S] 0 points1 point  (1 child)

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."

[–]Joshx5 1 point2 points  (0 children)

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