diff options
author | Georg Brandl <georg@python.org> | 2009-04-12 15:51:51 (GMT) |
---|---|---|
committer | Georg Brandl <georg@python.org> | 2009-04-12 15:51:51 (GMT) |
commit | abc387747dc573e05a4b31387797a0272062b2ef (patch) | |
tree | c12c0a0e45cb06edb87798a7831b1c8f79033015 /Doc/library | |
parent | 78532baeabc4234e3894c775f2bb7e0a21c12e0e (diff) | |
download | cpython-abc387747dc573e05a4b31387797a0272062b2ef.zip cpython-abc387747dc573e05a4b31387797a0272062b2ef.tar.gz cpython-abc387747dc573e05a4b31387797a0272062b2ef.tar.bz2 |
Add bytes/bytearray.maketrans() to mirror str.maketrans(), and deprecate
string.maketrans() which actually works on bytes. (Also closes #5675.)
Diffstat (limited to 'Doc/library')
-rw-r--r-- | Doc/library/stdtypes.rst | 27 | ||||
-rw-r--r-- | Doc/library/string.rst | 9 |
2 files changed, 23 insertions, 13 deletions
diff --git a/Doc/library/stdtypes.rst b/Doc/library/stdtypes.rst index a8c3146..72e2fb4 100644 --- a/Doc/library/stdtypes.rst +++ b/Doc/library/stdtypes.rst @@ -479,7 +479,7 @@ debugging, and in numerical work. exponent. -.. method:: float.fromhex(s) +.. classmethod:: float.fromhex(s) Class method to return the float represented by a hexadecimal string *s*. The string *s* may have leading and trailing @@ -967,7 +967,7 @@ functions based on regular expressions. 'example.com' -.. method:: str.maketrans(x[, y[, z]]) +.. staticmethod:: str.maketrans(x[, y[, z]]) This static method returns a translation table usable for :meth:`str.translate`. @@ -1514,8 +1514,8 @@ Wherever one of these methods needs to interpret the bytes as characters The bytes and bytearray types have an additional class method: -.. method:: bytes.fromhex(string) - bytearray.fromhex(string) +.. classmethod:: bytes.fromhex(string) + bytearray.fromhex(string) This :class:`bytes` class method returns a bytes or bytearray object, decoding the given string object. The string must contain two hexadecimal @@ -1524,7 +1524,9 @@ The bytes and bytearray types have an additional class method: >>> bytes.fromhex('f0 f1f2 ') b'\xf0\xf1\xf2' -The translate method differs in semantics from the version available on strings: + +The maketrans and translate methods differ in semantics from the versions +available on strings: .. method:: bytes.translate(table[, delete]) @@ -1533,8 +1535,7 @@ The translate method differs in semantics from the version available on strings: mapped through the given translation table, which must be a bytes object of length 256. - You can use the :func:`string.maketrans` helper function to create a - translation table. + You can use the :func:`bytes.maketrans` method to create a translation table. Set the *table* argument to ``None`` for translations that only delete characters:: @@ -1543,6 +1544,16 @@ The translate method differs in semantics from the version available on strings: b'rd ths shrt txt' +.. staticmethod:: bytes.maketrans(from, to) + + This static method returns a translation table usable for + :meth:`bytes.translate` that will map each character in *from* into the + character at the same position in *to*; *from* and *to* must be bytes objects + and have the same length. + + .. versionadded:: 3.1 + + .. _types-set: Set Types --- :class:`set`, :class:`frozenset` @@ -1847,7 +1858,7 @@ pairs within braces, for example: ``{'jack': 4098, 'sjoerd': 4127}`` or ``{4098: Return a shallow copy of the dictionary. - .. method:: fromkeys(seq[, value]) + .. classmethod:: fromkeys(seq[, value]) Create a new dictionary with keys from *seq* and values set to *value*. diff --git a/Doc/library/string.rst b/Doc/library/string.rst index 5867a5a..29bf160 100644 --- a/Doc/library/string.rst +++ b/Doc/library/string.rst @@ -548,13 +548,9 @@ rule: delimiter), and it should appear last in the regular expression. -String functions +Helper functions ---------------- -The following functions are available to operate on string objects. -They are not available as string methods. - - .. function:: capwords(s) Split the argument into words using :func:`split`, capitalize each word using @@ -568,3 +564,6 @@ They are not available as string methods. Return a translation table suitable for passing to :meth:`bytes.translate`, that will map each character in *from* into the character at the same position in *to*; *from* and *to* must have the same length. + + .. deprecated:: 3.1 + Use the :meth:`bytes.maketrans` static method instead. |