(original) (raw)

changeset: 77290:0df7594e4ebd branch: 2.7 parent: 77265:1a4e99460438 user: R David Murray rdmurray@bitdance.com date: Fri Jun 01 16:21:06 2012 -0400 files: Doc/library/stdtypes.rst description: #14957: clarify splitlines docs. Initial patch by Michael Driscoll, I added the example. diff -r 1a4e99460438 -r 0df7594e4ebd Doc/library/stdtypes.rst --- a/Doc/library/stdtypes.rst Thu May 31 09:17:29 2012 -0700 +++ b/Doc/library/stdtypes.rst Fri Jun 01 16:21:06 2012 -0400 @@ -1185,7 +1185,13 @@ Return a list of the lines in the string, breaking at line boundaries. Line breaks are not included in the resulting list unless *keepends* is given and - true. + true. This method uses the universal newlines approach to splitting lines. + Unlike :meth:`~str.split`, if the string ends with line boundary characters + the returned list does ``not`` have an empty last element. + + For example, ``'ab c\n\nde fg\rkl\r\n'.splitlines()`` returns + ``['ab c', '', 'de fg', 'kl']``, while the same call with ``splinelines(True)`` + returns ``['ab c\n', '\n, 'de fg\r', 'kl\r\n']``. .. method:: str.startswith(prefix[, start[, end]]) /rdmurray@bitdance.com