On 06/06/2014 01:42 AM, Johannes Bauer wrote:
<snip>
Ah, I didn't know rstrip() accepted parameters and since you wrote
line.rstrip() this would also cut away whitespaces (which sadly are
relevant in odd cases).
No problem. If a parameter is used in the strip() family, than _only_ those characters are
stripped. Example:
>>> s = 'some text \n'
>>> print('"{}"'.format(s.rstrip())) # No parameter, strip all whitespace
"some text"
>>> print('"{}"'.format(s.rstrip('\n'))) # Parameter is newline, only strip
newlines
"some text "
-=- Larry
BTW, the strip() parameter (which must be a string) is not limited to whitespace, it can be used
with any set of characters.
--
https://mail.python.org/mailman/listinfo/python-list