▲ | stavros 8 days ago | ||||||||||||||||
Yeah, I generally like most of the stuff that goes into Python, but I have to admit I can't really see the usefulness in this (or, at least, enough usefulness to warrant making it standard). One of the PEP's developers, Lysandros, presented this in our local meetup, so I am passingly familiar with it, but still, I might be missing something. I guess the crux of it is that I don't understand why it's `t"some string"` instead of `Template("some string")`. What do we gain by the shorthand? | |||||||||||||||||
▲ | zahlman 8 days ago | parent | next [-] | ||||||||||||||||
> What do we gain by the shorthand? Because it's new syntax, it allows for parsing the literal ahead of time and eagerly evaluating the substitutions. Code like
essentially gets translated into
That is: subsequent changes to `bar` won't affect the result of evaluating the template, but that evaluation can still apply custom rules. | |||||||||||||||||
| |||||||||||||||||
▲ | illegally 8 days ago | parent | prev [-] | ||||||||||||||||
I guess this could be useful in SQL for escaping values, I saw a project on the comments here. With templates:
Without templates:
So one less argument to pass if we use templates.But yeah it does seem a bit confusing, and maybe kinda not pythonic? Not sure. | |||||||||||||||||
|