How to get rid the new line

Paul Rubin phr-n2002b at NOSPAMnightsong.com
Thu Jun 27 19:38:02 EDT 2002


"James T. Dennis" <jadestar at idiom.com> writes:
>  Could try this:
> 
> 	def chomp(line):
> 		if line[-1]=='\n':
> 			line=line[:-1]
> 		return line
> 
>  (or variations thereon, to satisfy other semantic requirements).

If you don't mind removing all trailing whitespace, there's also

  line = line.strip()

or more portably

   import string
   line = string.strip(line)



More information about the Python-list mailing list