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
08d42930
Kaydet (Commit)
08d42930
authored
Ock 29, 2011
tarafından
Raymond Hettinger
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Add entry for str.format_map().
Add bullet list and reference to documentation section.
üst
598b513a
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
56 additions
and
37 deletions
+56
-37
3.2.rst
Doc/whatsnew/3.2.rst
+56
-37
No files found.
Doc/whatsnew/3.2.rst
Dosyayı görüntüle @
08d42930
...
@@ -442,25 +442,35 @@ Some smaller changes made to the core Python language are:
...
@@ -442,25 +442,35 @@ Some smaller changes made to the core Python language are:
(Suggested by Mark Dickinson and implemented by Eric Smith in :issue:`7094`.)
(Suggested by Mark Dickinson and implemented by Eric Smith in :issue:`7094`.)
.. XXX * :meth:`str.format_map` was added, allowing an arbitrary mapping object
* There is also a new :meth:`str.format_map` method that extends the
to be passed in to :meth:`str.format`. `somestring.format_map(mapping)`
capabilities of the existing :meth:`str.format` method by accepting arbitrary
is similar to `somestring.format(**mapping)`, except that in the latter
:term:`mapping` objects. This new method makes it possible to use string
case `mapping` is convert to a `dict` and in the former case `mapping`
formatting with any of one of Python's many dictionary-like tools such as
is used without modification. For example, to use a `defaultdict` with
:class:`~collections.defaultdict`, :class:`~shelve.Shelf`,
formatting::
:class:`~configparser.ConfigParser`, or :mod:`dbm`. It also useful with
custom :class:`dict` subclasses that normalize keys before look-up or that
>>> from collections import defaultdict
supply a :meth:`__missing__` method for unknown keys::
>>> mapping = defaultdict(lambda: 'Europe', name='Guido')
>>> '{name} was born in {country}'.format_map(mapping)
>>> import shelve
'Guido was born in Europe'
>>> d = shelve.open('tmp.shl')
>>> 'The {project_name} status is {status} as of {date}'.format_map(d)
This is similar to %-formatting with a single mapping argument::
'The testing project status is green as of February 15, 2011'
>>> '%(name)s was born in %(country)s' % mapping
>>> class LowerCasedDict(dict):
'Guido was born in Europe'
def __getitem__(self, key):
return dict.__getitem__(self, key.lower())
(Suggested by Raymond Hettinger and implemented by Eric Smith in
>>> lcd = LowerCasedDict(part='widgets', quantity=10)
:issue:`6081`.)
>>> 'There are {QUANTITY} {Part} in stock'.format_map(lcd)
'There are 10 widgets in stock'
>>> class PlaceholderDict(dict):
def __missing__(self, key):
return '<{}>'.format(key)
>>> 'Hello {name}, welcome to {location}'.format_map(PlaceholderDict())
'Hello <name>, welcome to <location>'
(Suggested by Raymond Hettinger and implemented by Eric Smith in
:issue:`6081`.)
* The interpreter can now be started with a quiet option, ``-q``, to suppress
* The interpreter can now be started with a quiet option, ``-q``, to suppress
the copyright and version information from being displayed in the interactive
the copyright and version information from being displayed in the interactive
...
@@ -2267,28 +2277,37 @@ Documentation
...
@@ -2267,28 +2277,37 @@ Documentation
The documentation continues to be improved.
The documentation continues to be improved.
A table of quick links has been added to the top of lengthy sections such as
* A table of quick links has been added to the top of lengthy sections such as
:ref:`built-in-funcs`. In the case of :mod:`itertools`, the links are
:ref:`built-in-funcs`. In the case of :mod:`itertools`, the links are
accompanied by tables of cheatsheet-style summaries to provide an overview and
accompanied by tables of cheatsheet-style summaries to provide an overview and
memory jog without having to read all of the docs.
memory jog without having to read all of the docs.
* In some cases, the pure Python source code can be a helpful adjunct to the
documentation, so now many modules now feature quick links to the latest
version of the source code. For example, the :mod:`functools` module
documentation has a quick link at the top labeled:
**Source code** :source:`Lib/functools.py`.
(Contributed by Raymond Hettinger; see
`rationale <http://rhettinger.wordpress.com/2011/01/28/open-your-source-more/>`_.)
* The docs now contain more examples and recipes. In particular, :mod:`re`
module has an extensive section, :ref:`re-examples`. Likewise, the
:mod:`itertools` module continues to be updated with new
:ref:`itertools-recipes`.
In some cases, the pure Python source code can be a helpful adjunct to the
* The :mod:`datetime` module now has an auxiliary implementation in pure Python.
documentation, so now many modules now feature quick links to the latest version
No functionality was changed. This just provides an easier-to-read alternate
of the source code. For example, the :mod:`functools` module documentation has
implementation.
a quick link at the top labeled: **Source code** :source:`Lib/functools.py`.
(Contributed by Raymond Hettinger.)
The docs now contain more examples and recipes. In particular, :mod:`re` module
(Contributed by Alexander Belopolsky in :issue:`9528`.)
has an extensive section, :ref:`re-examples`. Likewise, the :mod:`itertools`
module continues to be updated with new :ref:`itertools-recipes`.
The :mod:`datetime` module now has an auxiliary implementation in pure Python.
* The unmaintained :file:`Demo` directory has been removed. Some demos were
No functionality was changed. This just provides an easier-to-read
integrated into the documentation, some were moved to the :file:`Tools/demo`
alternate implementation. (Contributed by Alexander Belopolsky.)
directory, and others were removed altogether.
The unmaintained :file:`Demo` directory has been removed. Some demos were
(Contributed by Georg Brandl in :issue:`7962`.)
integrated into the documentation, some were moved to the :file:`Tools/demo`
directory, and others were removed altogether. (Contributed by Georg Brandl.)
IDLE
IDLE
...
...
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