How to get rid the new line

Frank Tobin ftobin at neverending.org
Sun Jun 30 16:45:43 EDT 2002


Fredrik Lundh, on 2002-06-29, wrote:

> or add the single character needed to make chomp a
> bit more robust:
> 
>     def chomp(line):
>         if line[-1:] == '\n':
>             line = line[:-1]
>         return line

I think the fact that the first few tries here were *wrong* about how to
implement a chomp indicates that it really should part of Python.  Just
because it's easy to implement doesn't mean it can't be part of the, say,
string methods.  I mean, look at str.{upper,lower,isdigit}, etc.  A chomp
method would be popular; rstrip or implementing your own doesn't cut it.

-- 
Frank Tobin			http://www.neverending.org/~ftobin/




More information about the Python-list mailing list