Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
526f9d88
Commit
526f9d88
authored
Aug 05, 2015
by
Zachary Ware
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Issue #21279: Flesh out str.translate docs
Initial patch by Kinga Farkas, Martin Panter, and John Posner.
parent
3c3b1bc8
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
17 additions
and
15 deletions
+17
-15
Doc/library/stdtypes.rst
Doc/library/stdtypes.rst
+11
-10
Objects/unicodeobject.c
Objects/unicodeobject.c
+6
-5
No files found.
Doc/library/stdtypes.rst
View file @
526f9d88
...
@@ -1976,21 +1976,22 @@ expression support in the :mod:`re` module).
...
@@ -1976,21 +1976,22 @@ expression support in the :mod:`re` module).
"They're Bill's Friends."
"They're Bill's Friends."
.. method:: str.translate(
map
)
.. method:: str.translate(
table
)
Return a copy of the *s* where all characters have been mapped through the
Return a copy of the string in which each character has been mapped through
*map* which must be a dictionary of Unicode ordinals (integers) to Unicode
the given translation table. The table must be an object that implements
ordinals, strings or ``None``. Unmapped characters are left untouched.
indexing via :meth:`__getitem__`, typically a :term:`mapping` or
Characters mapped to ``None`` are deleted.
:term:`sequence`. When indexed by a Unicode ordinal (an integer), the
table object can do any of the following: return a Unicode ordinal or a
string, to map the character to one or more other characters; return
``None``, to delete the character from the return string; or raise a
:exc:`LookupError` exception, to map the character to itself.
You can use :meth:`str.maketrans` to create a translation map from
You can use :meth:`str.maketrans` to create a translation map from
character-to-character mappings in different formats.
character-to-character mappings in different formats.
.. note::
See also the :mod:`codecs` module for a more flexible approach to custom
character mappings.
An even more flexible approach is to create a custom character mapping
codec using the :mod:`codecs` module (see :mod:`encodings.cp1251` for an
example).
.. method:: str.upper()
.. method:: str.upper()
...
...
Objects/unicodeobject.c
View file @
526f9d88
...
@@ -13077,11 +13077,12 @@ unicode_maketrans_impl(PyObject *x, PyObject *y, PyObject *z)
...
@@ -13077,11 +13077,12 @@ unicode_maketrans_impl(PyObject *x, PyObject *y, PyObject *z)
PyDoc_STRVAR
(
translate__doc__
,
PyDoc_STRVAR
(
translate__doc__
,
"S.translate(table) -> str
\n
\
"S.translate(table) -> str
\n
\
\n
\
\n
\
Return a copy of the string S, where all characters have been mapped
\n
\
Return a copy of the string S in which each character has been mapped
\n
\
through the given translation table, which must be a mapping of
\n
\
through the given translation table. The table must implement
\n
\
Unicode ordinals to Unicode ordinals, strings, or None.
\n
\
lookup/indexing via __getitem__, for instance a dictionary or list,
\n
\
Unmapped characters are left untouched. Characters mapped to None
\n
\
mapping Unicode ordinals to Unicode ordinals, strings, or None. If
\n
\
are deleted."
);
this operation raises LookupError, the character is left untouched.
\n
\
Characters mapped to None are deleted."
);
static
PyObject
*
static
PyObject
*
unicode_translate
(
PyObject
*
self
,
PyObject
*
table
)
unicode_translate
(
PyObject
*
self
,
PyObject
*
table
)
...
...
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