GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — gh-132661: docs: add a t-string tutorial by davepeck · Pull Request #137213 · python/cpython

Conversation

@davepeck

@davepeck davepeck commented Jul 29, 2025 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

During the first pass at t-string docs, we wrote a potential addition to the Fancier Output Formatting section of the Input/Output Tutorial.

It didn't quite feel ready, and maybe wasn't in the right corner of the docs, so we decided to break it out into a separate PR and wrestle it to its final form. :-)

CC @encukou and @AA-Turner -- happy to drop this entirely, or massage it into something better.

See also Trey's useful comments on the tutorial.

  • Issue: Implement PEP 750 – Template Strings #132661

📚 Documentation preview 📚: https://cpython-previews--137213.org.readthedocs.build/

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@davepeck
Possible t-string addition to tutorial/intputoutput.rst
27c044a
@bedevere-app bedevere-app Bot added docs Documentation in the Doc dir skip news labels Jul 29, 2025
@github-project-automation github-project-automation Bot added this to Docs PRs Jul 29, 2025
@github-project-automation github-project-automation Bot moved this to Todo in Docs PRs Jul 29, 2025
@bedevere-app bedevere-app Bot mentioned this pull request Jul 29, 2025
Implement PEP 750 – Template Strings #132661
Closed
@davepeck
davepeck marked this pull request as ready for review August 17, 2025 16:30
@davepeck
davepeck requested review from AA-Turner and lysnikolaou as code owners August 17, 2025 16:30
@bedevere-app bedevere-app Bot added the awaiting review label Aug 17, 2025
@davepeck

davepeck commented Aug 17, 2025 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor Author

(Marking as ready so we get some eyes on this. I think there are a lot of directions we can take this content, including simply deciding not to include it in the Python docs whatsoever. Hopefully there's something useful here, though?)

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@AA-Turner

AA-Turner commented Aug 17, 2025

Copy link
Copy Markdown
Member

I'll add this to my to-do list. I have a few reorganisation thoughts after a quick skim, but I want to look at things properly before doing so. Would you mind if I push directly to the branch? GH makes it hard to effectively suggest that kind of change.

A

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@davepeck

davepeck commented Aug 17, 2025

Copy link
Copy Markdown
Contributor Author

Would you mind if I push directly to the branch?

Not at all; please do! The more eyes and authors the better here, I think.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

StanFromIreland
StanFromIreland reviewed Sep 5, 2025
View reviewed changes
Comment thread Doc/tutorial/inputoutput.rst
>>> template.values
('World',)

* The :meth:`str.format` method of strings requires more manual

@StanFromIreland StanFromIreland Sep 5, 2025

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This followed on from f-strings, but now it may be confusing, as it makes it seem like this works like the previous (i.e. t-strings with the changes).

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread Doc/tutorial/inputoutput.rst
* When greater control is needed, :ref:`template string literals <tut-t-strings>`
can be useful. T-strings -- which begin with ``t`` or ``T`` -- share the
same syntax as f-strings but, unlike f-strings, produce a
:class:`~string.templatelib.Template` instance rather than a simple ``str``.

@StanFromIreland StanFromIreland Sep 5, 2025

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
:class:`~string.templatelib.Template` instance rather than a simple ``str``.
:class:`~string.templatelib.Template` instance rather than a simple :class:`str`.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread Doc/tutorial/inputoutput.rst

* When greater control is needed, :ref:`template string literals <tut-t-strings>`
can be useful. T-strings -- which begin with ``t`` or ``T`` -- share the
same syntax as f-strings but, unlike f-strings, produce a

@StanFromIreland StanFromIreland Sep 5, 2025

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is confusing, since the term: f-strings has not been introduced in the previous point.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread Doc/tutorial/inputoutput.rst
Template String Literals
-------------------------

:ref:`Template string literals <t-strings>` (also called t-strings for short)

@StanFromIreland StanFromIreland Sep 5, 2025

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
:ref:`Template string literals <t-strings>` (also called t-strings for short)
:ref:`Template string literals <t-strings>` (also called *t-strings* for short)

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread Doc/tutorial/inputoutput.rst
... name: str
...

Imagine using f-strings in to generate HTML for the ``User``:

@StanFromIreland StanFromIreland Sep 5, 2025

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Imagine using f-strings in to generate HTML for the ``User``:
Imagine using f-strings to generate HTML for the ``User``:

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread Doc/tutorial/inputoutput.rst
defining a more complex ``html()`` function that returns a structured
representation of the HTML:

>>> from dataclasses import dataclass

@StanFromIreland StanFromIreland Sep 5, 2025

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a very complex example for this stage in the tutorial, many things have not been introduced yet.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@davepeck

davepeck commented Sep 7, 2025

Copy link
Copy Markdown
Contributor Author

Thanks @StanFromIreland -- that is all helpful feedback. Lots of work still to do here to massage this into something usable.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@merwok

merwok commented Oct 15, 2025

Copy link
Copy Markdown
Member

The proposed doc and its length makes me think that the t-string tutorial should not be in the python tutorial, but in another document. (See logging for example of doc split between tutorial, cookbook, reference)

StanFromIreland reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@StanFromIreland

StanFromIreland commented Oct 15, 2025

Copy link
Copy Markdown
Member

A t-string HOWTO seems like a good idea.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@encukou

encukou commented Oct 15, 2025

Copy link
Copy Markdown
Member

I'll third that. t-strings, as introduced here, are useful if you're writing a library; it's not really about putting data in fancy messages.

StanFromIreland reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@davepeck

davepeck commented Oct 15, 2025

Copy link
Copy Markdown
Contributor Author

I'm happy to close this and regroup on a future potential tutorial doc.

StanFromIreland and merwok reacted with thumbs up emoji
All reactions
  • 👍 2 reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@davepeck davepeck closed this Oct 15, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@StanFromIreland StanFromIreland StanFromIreland left review comments
@lysnikolaou lysnikolaou Awaiting requested review from lysnikolaou lysnikolaou is a code owner
@AA-Turner AA-Turner Awaiting requested review from AA-Turner AA-Turner is a code owner

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

awaiting review docs Documentation in the Doc dir skip news

Projects

Docs PRs
Status: Todo

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

5 participants

@davepeck @AA-Turner @merwok @StanFromIreland @encukou
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.