How to get rid the new line
Bjorn Pettersen
BPettersen at NAREX.com
Sun Jun 30 17:04:52 EDT 2002
> From: Frank Tobin [mailto:ftobin at neverending.org]
>
> 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.
I submitted a patch for this (that handled mac, win, and unix line
endings) but it was declined by the BDFL. I suspect one of the reasons
were that I named it chomp...
-- bjorn
More information about the Python-list
mailing list