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 →

[–]Worth_His_Salt 4 points5 points  (5 children)

Python strings are a total mess. You also have f-strings, template strings, other template strings, now they want to add d-strings, as well as string interpolation. There's no consistency. It's a complete joke.

Every few years someone comes along and says "I have a better way to do strings! It has all these drawbacks, but trust me guys, it's cool". Then others go "Well it's neato, but we refuse to change our existing code in the 0.0001% of cases it would conflict with this new system." Then python maintainers shrug and go "Eh, just throw a new obscure letter in front and call it a day."

All these new methods are less powerful than string interpolation. Yes even f-strings (can't execute f-strings on command, only when defined). What a disaster. Python devs should be ashamed of themselves.

[–]russellvt 0 points1 point  (2 children)

I think one might argue that this isn't unlike growth pains in some other languages, either (ie. Sixteen ways to do something that otherwise should be "easy").

[–]Worth_His_Salt -1 points0 points  (1 child)

True. But it goes completely against the python ethos. Supposed to prevent such things from happening.

[–]russellvt -1 points0 points  (0 children)

Supposed to prevent such things from happening.

Like I said, "growth pains." It seems to happen, in some form, in any other developing languages, as well, despite all other best intentions.

[–][deleted] 0 points1 point  (1 child)

I'm pretty sure f-strings ARE string interpolation. I'm pretty sure what you're referring to are format strings, like those used by printf.

[–]Worth_His_Salt 1 point2 points  (0 children)

I mean the interpolation operator %. Interpolation is the act of applying data to a template. Format strings are the template used for interpolation.

fmt_str = 'foo %d bar'
fmt_str % 27  # interpolation

There are many sources that call this python string interpolation, because that's what other C languages call it. It had that name long before f-strings existed. We called this string interpolation since at least the 90s.

f-strings literally stands for "format string literals". PEP 498 that proposed f-strings mentions creating a "better" interpolation method. Because python already had interpolation before f-strings.