[Doc-SIG] Docs for methods of string and unicode objects
M.-A. Lemburg
mal@lemburg.com
Mon, 21 Aug 2000 10:15:50 +0200
"Denis S. Otkidach" wrote:
>
> Dear Fred,
>
> I have noticed that interface of translate method applied to unicode
> object differs from interface of the same method applied to string object.
> In the former case translation table should be an object with mapping
> interface (not a string), and characters to be deleted are denoted by None
> value in translation table (not a separate string argument). Hmm... That's
> why translate method doesn't work for UserString instances reffering to
> unicode object.
True.
This should be fixed according to the doc-strings available
on both objects. There should probably also be a note that using
a charmap codec for translating strings/Unicode is the better
way to go...
"".translate :
S.translate(table [,deletechars]) -> string
Return a copy of the string S, where all characters occurring
in the optional argument deletechars are removed, and the
remaining characters have been mapped through the given
translation table, which must be a string of length 256.
u"".translate :
S.translate(table) -> unicode
Return a copy of the string S, where all characters have been mapped
through the given translation table, which must be a mapping of
Unicode ordinals to Unicode ordinals or None. Unmapped characters
are left untouched. Characters mapped to None are deleted.
> The methods encode, isdecimal, and isnumeric are applicable only to
> unicode objects. The later two methods are not mentioned in documentation.
.encode() is available for strings too. The other two are not,
because the information is not available (there are numeric chars
in many code pages which are not digits, e.g. the fraction chars).
"".encode :
S.encode([encoding[,errors]]) -> string
Return an encoded string version of S. Default encoding is the current
default string encoding. errors may be given to set a different error
handling scheme. Default is 'strict' meaning that encoding errors raise
a ValueError. Other possible values are 'ignore' and 'replace'.
--
Marc-Andre Lemburg
______________________________________________________________________
Business: http://www.lemburg.com/
Python Pages: http://www.lemburg.com/python/