This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author chris.jerdonek
Recipients chris.jerdonek, docs@python, jcea, pitrou
Date 2012-08-04.02:39:36
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1344047978.01.0.683229635888.issue15554@psf.upfronthosting.co.za>
In-reply-to
Content
The documentation for str.splitlines()--

http://docs.python.org/dev/library/stdtypes.html#str.splitlines

includes a statement that is not quite correct:

"Unlike split(), if the string ends with line boundary characters the returned list does not have an empty last element."

For example,

>>> '\n'.splitlines()
['']
>>> '\n\n'.splitlines()
['', '']
>>> '\r\n'.splitlines()
['']
>>> '\n\r\n'.splitlines()
['', '']
>>> '\r'.splitlines()
['']
>>> 'a\n\n'.splitlines()
['a', '']

Also, the note about split() only applies when split() is passed a separator.  For example--

>>> 'a\n'.split('\n')
['a', '']
>>> 'a\n'.split()
['a']

Finally, the function's behavior on the empty string is another difference worth mentioning that is not covered by the existing note.

I am attaching a patch that addresses these points.  Notice also that the patch phrases it not as whether the list *has* an empty last element, but whether an *additional* last element should be added, which is the more important point.
History
Date User Action Args
2012-08-04 02:39:38chris.jerdoneksetrecipients: + chris.jerdonek, jcea, pitrou, docs@python
2012-08-04 02:39:38chris.jerdoneksetmessageid: <1344047978.01.0.683229635888.issue15554@psf.upfronthosting.co.za>
2012-08-04 02:39:37chris.jerdoneklinkissue15554 messages
2012-08-04 02:39:36chris.jerdonekcreate