3 ms·
> I'm not sure if t-strings help here? That's correct, they don't. Evaluation of t-string expressions is immediate, just like with f-strings. Since we have th
by davepeck 2y ago
> I'm not sure if t-strings help here?
That's correct, they don't. Evaluation of t-string expressions is immediate, just like with f-strings.
Since we have the full generality of Python at our disposal, a typical solution is to simply wrap your t-string in a function or a lambda.
(An early version of the PEP had tools for deferred evaluation but these were dropped for being too complex, particularly for a first cut.)
- krick 2y agoAnd that actually makes "Template Strings" a misnomer in my mind. I mean, deferred (and repeated) evaluation of a template is the thing that makes template a template. Kinda messy PEP, IMO, I'm less excited by it than I'd like to be. The goal is clear, but the whole design feels backwards.
- davepeck 2y agoNaming is hard; for instance, JavaScript also has its own template strings, which are also eagerly evaluated.