Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

gh-132661: docs: add a t-string tutorial#137213

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Closed

Conversation

@davepeck
Copy link
Contributor

@davepeckdavepeck commentedJul 29, 2025
edited
Loading

During thefirst pass at t-string docs, we wrote a potential addition to theFancier Output Formatting section of theInput/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 alsoTrey's useful comments on the tutorial.


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

@davepeck
Copy link
ContributorAuthor

davepeck commentedAug 17, 2025
edited
Loading

(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'ssomething useful here, though?)

@AA-Turner
Copy link
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

@davepeck
Copy link
ContributorAuthor

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.

>>> template.values
('World',)

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

Choose a reason for hiding this comment

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

This followed on fromf-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).

* 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``.

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`.


* 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

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.

Template String Literals
-------------------------

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

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)

...name:str
...

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

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-stringsinto generate HTML for the ``User``:
Imagine using f-strings to generate HTML for the ``User``:

defining a more complex ``html()`` function that returns a structured
representation of the HTML:

>>>from dataclassesimport dataclass

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.

@davepeck
Copy link
ContributorAuthor

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

@merwok
Copy link
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

@StanFromIreland
Copy link
Member

A t-string HOWTO seems like a good idea.

@encukou
Copy link
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

@davepeck
Copy link
ContributorAuthor

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

StanFromIreland and merwok reacted with thumbs up emoji

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@StanFromIrelandStanFromIrelandStanFromIreland left review comments

@lysnikolaoulysnikolaouAwaiting requested review from lysnikolaoulysnikolaou is a code owner

@AA-TurnerAA-TurnerAwaiting requested review from AA-TurnerAA-Turner is a code owner

Assignees

No one assigned

Labels

awaiting reviewdocsDocumentation in the Doc dirskip news

Projects

Status: Todo

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

5 participants

@davepeck@AA-Turner@merwok@StanFromIreland@encukou

[8]ページ先頭

©2009-2025 Movatter.jp