How to get rid the new line
Fredrik Lundh
fredrik at pythonware.com
Sat Jun 29 08:06:24 EDT 2002
Peter Hansen wrote:
> > Could try this:
> >
> > def chomp(line):
> > if line[-1]=='\n':
> > line=line[:-1]
> > return line
>
> Just make sure you pass chomp() only lines that are not equal
> to the empty string ''.
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
</F>
More information about the Python-list
mailing list