How is this advantageous over str.format?
How is this advantageous over str.format?
Posted Jan 23, 2025 20:33 UTC (Thu) by siddh (subscriber, #169663)In reply to: How is this advantageous over str.format? by rrolls
Parent article: A revamped Python string-formatting proposal
It's not IMO. In fact for complex code you'd anyways have to create intermediary variables to make the code cleaner (what if name has to be item.original_name sometimes?).
I do agree t-strings looks cleaner, but from the passing to function POV, it just feels like new syntactic sugar to me for a function call.
Also, it's named "template" but IIUC it is just a locally bound object invalid outside of its scope, like you can't pass it around generically and have the vars substituted without wrapping in a function call which then leads to same thing.
So all-in-all the advantage just boils down to introducing the new type so str can be explicitly disallowed? For eg. sqlite3 could throw exception on using str. That will indeed force less mistakes in processing unsantised input where it's done, but may also make the already-assumed dumb programmer more careless...
But I do get your point now and appreciate it more. Thanks!
