A template string, or t-string, enables you to mix the template with a perform that operates on the template’s construction, not simply its output. You possibly can write a template handler that permits all variables positioned within the template, or solely variables of a selected kind, or solely variables that match some output, to be manipulated at output time. You possibly can additionally deal with the variables and the interpolating textual content as separate, otherwise typed objects.
As an illustration, if in case you have the template t"My title is {user_name}, and I am from {user_locale}"
, you could possibly have the variables user_name
and user_locale
mechanically cleaned of any HTML earlier than show. You possibly can additionally carry out transformations on the My title is
and and I am from
parts of the output mechanically, as these could be tagged with the particular kind Interpolation
.
Template strings will make it far simpler to jot down template engines, e.g., Jinja2, or to duplicate a lot of the performance of these template engines instantly in Python with out the overhead of third-party libraries.