Python 3.12 introduces "t-strings," a new string literal type designed for templating. Prepending a string with t
(e.g., t"Hello {name}"
) signifies a t-string, which supports delayed interpolation and formatting. Unlike f-strings, t-strings don't immediately evaluate expressions within braces. Instead, they create a reusable template that can be formatted later using the .format()
method. This allows for constructing templates separately from their data, improving code organization and enabling scenarios like dynamic template creation or translation. T-strings also offer enhanced control over formatting via format specifiers within the braces, similar to existing str.format() functionality. While sharing some similarities with f-strings, t-strings prioritize reusability and deferred evaluation, providing a powerful alternative for template-based string construction.
Plain is a Python web framework focused on simplicity and productivity for building web applications and APIs. It embraces a "batteries-included" approach, offering built-in features like routing, templating, database access (using SQLite by default), form handling, and security measures against common vulnerabilities. Designed for a straightforward developer experience, Plain emphasizes minimal configuration and intuitive APIs, promoting rapid development and easy maintenance. It aims to provide a lightweight yet powerful foundation for projects ranging from small utilities to larger web products.
HN commenters generally expressed interest in Plain, praising its simplicity and focus on serving HTML. Several appreciated the "batteries included" approach for common tasks like forms and authentication, contrasting it favorably with Django's complexity. Some questioned the performance implications of generating HTML with Python, and others desired more details on the templating language. A few commenters noted the similarity to other Python frameworks like Flask or Pyramid, prompting discussion about Plain's unique selling points and potential niche. There was also some skepticism about the project's longevity given the prevalence of existing frameworks. However, the overall sentiment was positive, with many looking forward to trying it out.
Summary of Comments ( 212 )
https://news.ycombinator.com/item?id=43748512
Hacker News users generally expressed enthusiasm for Python's proposed t-strings (trimmed strings), viewing them as a valuable addition for template literals and multiline strings. Several commenters highlighted the potential for improved readability and maintainability, especially when dealing with SQL queries or HTML. Some discussed the syntax, suggesting alternatives and pondering potential edge cases and implementation details, like handling backslashes. A few pointed out the existing workarounds available and questioned whether this feature warranted inclusion in the core language, given the learning curve it might introduce for new users. There was also some discussion comparing t-strings to similar features in other languages, like C#'s verbatim strings and JavaScript's template literals.
The Hacker News post about Python's new t-strings (https://news.ycombinator.com/item?id=43748512) has generated a moderate amount of discussion. Several commenters express enthusiasm for the proposed feature, viewing it as a valuable addition to Python's string formatting capabilities. They highlight the potential for improved code readability and conciseness, especially in situations involving complex formatting or multiple variables.
One commenter draws a comparison to JavaScript's template literals, noting the similarities in syntax and functionality. They appreciate the ability to embed expressions directly within the string, eliminating the need for cumbersome concatenation or separate formatting calls. Another user echoes this sentiment, emphasizing the benefits for multi-line strings and the potential reduction in boilerplate code.
A few commenters delve into more technical aspects, discussing the potential implementation details and performance implications of t-strings. One user raises questions about how the feature would interact with existing string formatting mechanisms, such as f-strings and the
format()
method. They also speculate about the potential impact on parsing and compilation time.Some users express minor reservations or suggest alternative approaches. One commenter questions the necessity of introducing another string formatting option, given the existing capabilities of f-strings. They propose exploring enhancements to f-strings instead of adding a new feature. Another user suggests a different syntax for t-strings, arguing that the proposed syntax might be confusing or visually cluttered.
Overall, the comments generally reflect a positive reception to the idea of t-strings. While some minor concerns and alternative suggestions are raised, the majority of commenters express support for the feature and its potential to enhance Python's string handling capabilities. There is a clear appreciation for the improved readability and conciseness that t-strings could offer.