[issue21279] str.translate documentation incomplete

bob gailer report at bugs.python.org
Thu Apr 17 03:01:22 CEST 2014


New submission from bob gailer:

Documentation for str.translate only mentions a dictionary for the translation table. Actually any iterable can be used, as long as its elements are integer, None or str.

Recommend wording:

str.translate(translation_table)

Return a copy of the s where all characters have been "mapped" through the translation_table - which must be either a dictionary mapping Unicode ordinals (integers) to Unicode ordinals, strings or None,
or an iterable. In this case the ord() of each character in s is used as an index into the iterable; the corresponding element of the iterable replaces the character. If ord() of the character exceeds the index range of the iterator, no substitution is made.

Example: to shift any of the first 255 ASCII characters to the next:

>>> 'Now is the time for all good men'.translate(range(1, 256))
'Opx!jt!uif!ujnf!gps!bmm!hppe!nfo'

COMMENT: I placed mapped in quotes as technically this only applies to dictionaries. Not sure what the best word is.

----------
assignee: docs at python
components: Documentation
messages: 216630
nosy: bgailer, docs at python
priority: normal
severity: normal
status: open
title: str.translate documentation incomplete
type: enhancement
versions: Python 3.3

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue21279>
_______________________________________


More information about the Python-bugs-list mailing list