diff options
author | Chris Jerdonek <chris.jerdonek@gmail.com> | 2012-11-21 01:53:17 (GMT) |
---|---|---|
committer | Chris Jerdonek <chris.jerdonek@gmail.com> | 2012-11-21 01:53:17 (GMT) |
commit | d675a2c48a717cd6a960185abc59c50e82ad50d6 (patch) | |
tree | 1e8ad4ce4d6868ab89d4152c032541a4eb5e2c36 /Doc/reference | |
parent | 045aef3795ebb799fa89c4be47cfc9b2448ab1b2 (diff) | |
parent | 5fae0e58549c9270b188a1591ffa6cc4c2d9ab4e (diff) | |
download | cpython-d675a2c48a717cd6a960185abc59c50e82ad50d6.zip cpython-d675a2c48a717cd6a960185abc59c50e82ad50d6.tar.gz cpython-d675a2c48a717cd6a960185abc59c50e82ad50d6.tar.bz2 |
Merge from 3.3: Improve str() and object.__str__() docs (issue #13538).
Diffstat (limited to 'Doc/reference')
-rw-r--r-- | Doc/reference/datamodel.rst | 28 |
1 files changed, 18 insertions, 10 deletions
diff --git a/Doc/reference/datamodel.rst b/Doc/reference/datamodel.rst index beeaf83..25ec2d6 100644 --- a/Doc/reference/datamodel.rst +++ b/Doc/reference/datamodel.rst @@ -1140,10 +1140,11 @@ Basic customization modules are still available at the time when the :meth:`__del__` method is called. + .. index:: + single: repr() (built-in function); __repr__() (object method) -.. method:: object.__repr__(self) - .. index:: builtin: repr +.. method:: object.__repr__(self) Called by the :func:`repr` built-in function to compute the "official" string representation of an object. If at all possible, this should look like a @@ -1157,18 +1158,25 @@ Basic customization This is typically used for debugging, so it is important that the representation is information-rich and unambiguous. + .. index:: + single: string; __str__() (object method) + single: format() (built-in function); __str__() (object method) + single: print() (built-in function); __str__() (object method) + .. method:: object.__str__(self) - .. index:: - builtin: str - builtin: print + Called by :func:`str(object) <str>` and the built-in functions + :func:`format` and :func:`print` to compute the "informal" or nicely + printable string representation of an object. The return value must be a + :ref:`string <textseq>` object. - Called by the :func:`str` built-in function and by the :func:`print` function - to compute the "informal" string representation of an object. This differs - from :meth:`__repr__` in that it does not have to be a valid Python - expression: a more convenient or concise representation may be used instead. - The return value must be a string object. + This method differs from :meth:`object.__repr__` in that there is no + expectation that :meth:`__str__` return a valid Python expression: a more + convenient or concise representation can be used. + + The default implementation defined by the built-in type :class:`object` + calls :meth:`object.__repr__`. .. XXX what about subclasses of string? |