Skip to content
Projeler
Gruplar
Parçacıklar
Yardım
Yükleniyor...
Oturum aç / Kaydol
Gezinmeyi değiştir
C
cpython
Proje
Proje
Ayrıntılar
Etkinlik
Cycle Analytics
Depo (repository)
Depo (repository)
Dosyalar
Kayıtlar (commit)
Dallar (branch)
Etiketler
Katkıda bulunanlar
Grafik
Karşılaştır
Grafikler
Konular (issue)
0
Konular (issue)
0
Liste
Pano
Etiketler
Kilometre Taşları
Birleştirme (merge) Talepleri
0
Birleştirme (merge) Talepleri
0
CI / CD
CI / CD
İş akışları (pipeline)
İşler
Zamanlamalar
Grafikler
Paketler
Paketler
Wiki
Wiki
Parçacıklar
Parçacıklar
Üyeler
Üyeler
Collapse sidebar
Close sidebar
Etkinlik
Grafik
Grafikler
Yeni bir konu (issue) oluştur
İşler
Kayıtlar (commit)
Konu (issue) Panoları
Kenar çubuğunu aç
Batuhan Osman TASKAYA
cpython
Commits
9f74deba
Kaydet (Commit)
9f74deba
authored
Mar 28, 2017
tarafından
Barry Warsaw
Kaydeden (comit)
GitHub
Mar 28, 2017
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Improve the documentation for template strings (#856)
bpo-19824 bpo-20314 bpo-12518
üst
8cea5929
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
28 additions
and
15 deletions
+28
-15
stdtypes.rst
Doc/library/stdtypes.rst
+5
-4
string.rst
Doc/library/string.rst
+19
-11
NEWS
Misc/NEWS
+4
-0
No files found.
Doc/library/stdtypes.rst
Dosyayı görüntüle @
9f74deba
...
@@ -2076,10 +2076,11 @@ expression support in the :mod:`re` module).
...
@@ -2076,10 +2076,11 @@ expression support in the :mod:`re` module).
The formatting operations described here exhibit a variety of quirks that
The formatting operations described here exhibit a variety of quirks that
lead to a number of common errors (such as failing to display tuples and
lead to a number of common errors (such as failing to display tuples and
dictionaries correctly). Using the newer :ref:`formatted
dictionaries correctly). Using the newer :ref:`formatted string literals
string literals <f-strings>` or the :meth:`str.format` interface
<f-strings>`, the :meth:`str.format` interface, or :ref:`template strings
helps avoid these errors. These alternatives also provide more powerful,
<template-strings>` may help avoid these errors. Each of these
flexible and extensible approaches to formatting text.
alternatives provides their own trade-offs and benefits of simplicity,
flexibility, and/or extensibility.
String objects have one unique built-in operation: the ``%`` operator (modulo).
String objects have one unique built-in operation: the ``%`` operator (modulo).
This is also known as the string *formatting* or *interpolation* operator.
This is also known as the string *formatting* or *interpolation* operator.
...
...
Doc/library/string.rst
Dosyayı görüntüle @
9f74deba
...
@@ -657,9 +657,15 @@ Nesting arguments and more complex examples::
...
@@ -657,9 +657,15 @@ Nesting arguments and more complex examples::
Template strings
Template strings
----------------
----------------
Templates provide simpler string substitutions as described in :pep:`292`.
Template strings provide simpler string substitutions as described in
Instead of the normal ``%``\ -based substitutions, Templates support ``$``\
:pep:`292`. A primary use case for template strings is for
-based substitutions, using the following rules:
internationalization (i18n) since in that context, the simpler syntax and
functionality makes it easier to translate than other built-in string
formatting facilities in Python. As an example of a library built on template
strings for i18n, see the
`flufl.i18n <http://flufli18n.readthedocs.io/en/latest/>`_ package.
Template strings support ``$``-based substitutions, using the following rules:
* ``$$`` is an escape; it is replaced with a single ``$``.
* ``$$`` is an escape; it is replaced with a single ``$``.
...
@@ -735,14 +741,17 @@ Here is an example of how to use a Template::
...
@@ -735,14 +741,17 @@ Here is an example of how to use a Template::
>>> Template('$who likes $what').safe_substitute(d)
>>> Template('$who likes $what').safe_substitute(d)
'tim likes $what'
'tim likes $what'
Advanced usage: you can derive subclasses of :class:`Template` to customize the
Advanced usage: you can derive subclasses of :class:`Template` to customize
placeholder syntax, delimiter character, or the entire regular expression used
the placeholder syntax, delimiter character, or the entire regular expression
to parse template strings. To do this, you can override these class attributes:
used to parse template strings. To do this, you can override these class
attributes:
* *delimiter* -- This is the literal string describing a placeholder introducing
* *delimiter* -- This is the literal string describing a placeholder
delimiter. The default value is ``$``. Note that this should *not* be a
introducing delimiter. The default value is ``$``. Note that this should
regular expression, as the implementation will call :meth:`re.escape` on this
*not* be a regular expression, as the implementation will call
string as needed.
:meth:`re.escape` on this string as needed. Note further that you cannot
change the delimiter after class creation (i.e. a different delimiter must
be set in the subclass's class namespace).
* *idpattern* -- This is the regular expression describing the pattern for
* *idpattern* -- This is the regular expression describing the pattern for
non-braced placeholders (the braces will be added automatically as
non-braced placeholders (the braces will be added automatically as
...
@@ -787,4 +796,3 @@ Helper functions
...
@@ -787,4 +796,3 @@ Helper functions
or ``None``, runs of whitespace characters are replaced by a single space
or ``None``, runs of whitespace characters are replaced by a single space
and leading and trailing whitespace are removed, otherwise *sep* is used to
and leading and trailing whitespace are removed, otherwise *sep* is used to
split and join the words.
split and join the words.
Misc/NEWS
Dosyayı görüntüle @
9f74deba
...
@@ -879,6 +879,10 @@ C API
...
@@ -879,6 +879,10 @@ C API
Documentation
Documentation
-------------
-------------
-
bpo
-
19824
,
bpo
-
20314
,
bpo
-
12518
:
Improve
the
documentation
for
,
and
links
to
,
template
strings
by
emphasizing
their
utility
for
internationalization
,
and
by
clarifying
some
usage
constraints
.
-
bpo
-
28929
:
Link
the
documentation
to
its
source
file
on
GitHub
.
-
bpo
-
28929
:
Link
the
documentation
to
its
source
file
on
GitHub
.
-
bpo
-
25008
:
Document
smtpd
.
py
as
effectively
deprecated
and
add
a
pointer
to
-
bpo
-
25008
:
Document
smtpd
.
py
as
effectively
deprecated
and
add
a
pointer
to
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment