GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
GeezerVison is showing github.com — gh-132661: docs: add a t-string tutorial by davepeck · Pull Request #137213 · python/cpython Conversation
|
|
(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?) |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
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 |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
Not at all; please do! The more eyes and authors the better here, I think. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| >>> template.values | ||
| ('World',) | ||
|
|
||
| * The :meth:`str.format` method of strings requires more manual |
There was a problem 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.
There was an error while loading. Please reload this page.
| * 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``. |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
| :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.
There was an error while loading. Please reload this page.
|
|
||
| * 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 |
There was a problem 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.
There was an error while loading. Please reload this page.
| Template String Literals | ||
| ------------------------- | ||
|
|
||
| :ref:`Template string literals <t-strings>` (also called t-strings for short) |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
| :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.
There was an error while loading. Please reload this page.
| ... name: str | ||
| ... | ||
|
|
||
| Imagine using f-strings in to generate HTML for the ``User``: |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
| 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.
There was an error while loading. Please reload this page.
| defining a more complex ``html()`` function that returns a structured | ||
| representation of the HTML: | ||
|
|
||
| >>> from dataclasses import dataclass |
There was a problem 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.
There was an error while loading. Please reload this page.
|
Thanks @StanFromIreland -- that is all helpful feedback. Lots of work still to do here to massage this into something usable. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
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) |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
A t-string HOWTO seems like a good idea. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
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. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
I'm happy to close this and regroup on a future potential tutorial doc. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
Successfully merging this pull request may close these issues.
There was an error while loading. Please reload this page.