"S Borg" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
>  If I have a string, what is the strongest way to assure the
> removal of any line break characters?
>
> Line break characters must always be the last character in a line, so
> would
> this:    str = linestring[:-1]
>
>  work?

Er, yes, if you don't mind (a) mangling any string that *doesn't* have a
newline as the last character, and (b) messing up any subsequent part of
your program that tries to use the built-in str() function (because you just
reassigned that name to something else).

I'd suggest:

    foo = linestring.rstrip("\n")

You can also add to the quoted string any other characters you want to have
stripped; for example,

    foo = linestring.rstrip("\n\r\t")

Or if you want to strip off *all* whitespace characters, just leave it out:

    foo = linestring.rstrip()

Russ




-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to