diff -r edf669b13482 Doc/library/stdtypes.rst --- a/Doc/library/stdtypes.rst Tue Dec 23 16:28:28 2014 +0200 +++ b/Doc/library/stdtypes.rst Tue Dec 23 19:20:54 2014 -0500 @@ -1944,22 +1944,22 @@ "They're Bill's Friends." -.. method:: str.translate(map) - - Return a copy of the *s* where all characters have been mapped through the - *map* which must be a dictionary of Unicode ordinals (integers) to Unicode - ordinals, strings or ``None``. Unmapped characters are left untouched. - Characters mapped to ``None`` are deleted. +.. method:: str.translate(table) + + Return a copy of the string in which each character has been + mapped through the given translation table. The table must be + an object that implements lookup/indexing via :meth:`__getitem__`, + typically a :term:`mapping` or :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; or + 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 character-to-character mappings in different formats. - .. note:: - - 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() diff -r edf669b13482 Objects/unicodeobject.c --- a/Objects/unicodeobject.c Tue Dec 23 16:28:28 2014 +0200 +++ b/Objects/unicodeobject.c Tue Dec 23 19:20:54 2014 -0500 @@ -13065,10 +13065,12 @@ PyDoc_STRVAR(translate__doc__, "S.translate(table) -> str\n\ \n\ -Return a copy of the string S, where all characters have been mapped\n\ -through the given translation table, which must be a mapping of\n\ -Unicode ordinals to Unicode ordinals, strings, or None.\n\ -Unmapped characters are left untouched. Characters mapped to None\n\ +Return a copy of the string S in which each character has been mapped\n\ +through the given translation table. The table must implement +lookup/indexing via __getitem__, for instance a dictionary or list,\n\ +mapping Unicode ordinals to\n\ +Unicode ordinals, strings, or None. If this operation raises\n\ +LookupError, the character is left untouched. Characters mapped to None\n\ are deleted."); static PyObject*