diff -r 7ce22d0899e4 Doc/library/stdtypes.rst --- a/Doc/library/stdtypes.rst Fri Mar 14 21:54:41 2014 -0500 +++ b/Doc/library/stdtypes.rst Sat Dec 13 03:20:03 2014 +0000 @@ -1907,22 +1907,18 @@ "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. +.. method:: str.translate(table) + + Return a copy of the string where all characters have been mapped through the + *table*, a lookup table. The lookup table must be a subscriptable object, + for instance a dictionary or a list, mapping Unicode ordinals (integers) + to Unicode ordinals, strings or ``None``. If a character is not in the table, + the subscript operation should raise :exc:`LookupError`, and the character is left untouched. Characters mapped to ``None`` are deleted. 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 7ce22d0899e4 Objects/unicodeobject.c --- a/Objects/unicodeobject.c Fri Mar 14 21:54:41 2014 -0500 +++ b/Objects/unicodeobject.c Sat Dec 13 03:20:03 2014 +0000 @@ -13036,10 +13036,11 @@ "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\ -are deleted."); +through the given translation table. The table must be a subscriptable\n\ +object, for instance a dictionary or a list, mapping Unicode ordinals to\n\ +Unicode ordinals, strings, or None. If a character is not in the table,\n\ +the subscript operation should raise LookupError, and the character is\n\ +left untouched. Characters mapped to None are deleted."); static PyObject* unicode_translate(PyObject *self, PyObject *table)