RSS Planet Python

Real Python: Python 3.14 Preview: Template Strings (T-Strings)

Python 3.14 introduces t-strings, a new way to handle and process input values safely, unlike f-strings which produce a str object. T-strings resolve to a Template instance, allowing for customization and security. One of the key benefits of t-strings is preventing security vulnerabilities like SQL injection and XSS attacks. They are also useful in fields like structured logging. T-strings are a generalization of f-strings, designed to safely handle and process input values. The main components of a t-string include static string parts and interpolations, accessible through the Template class. You process t-strings by iterating over their components, using attributes like .strings, .interpolations, and .values for safe and customized handling. Python t-strings enhance both security and flexibility in string processing tasks. Before Python 3.14, the language provided several tools for string templates, including the string formatting operator, str.format(), f-strings, string.Template, and format(). These tools have their own strengths and weaknesses, and t-strings offer a new and improved way to handle string templates.
realpython.com
realpython.com
Real Python: Python 3.14 Preview: Template Strings (T-Strings)
Create attached notes ...