[Tutor] Taking off carriage returns/newlines
Danny Yoo
dyoo@hkn.eecs.berkeley.edu
Wed, 11 Jul 2001 15:18:57 -0700 (PDT)
On Thu, 12 Jul 2001, kevin parks wrote:
> Now i can use f.readline()[:-1] also to change line endings, no? But
> doesn't DOS use both carriage return and newline? so wouldn't you have
> to use: f.readline()[:-2] in case of DOS?
Yes. However, you can avoid the problem of choosing between -1 and -2 by
using a string's rstrip() method. rstrip() removes all whitespace from
the right side of the string, and can be used like this:
f.readline().rstrip()