supressing '\n' at the end

George Yoshida ml at dynkin.com
Sat Nov 6 17:48:27 EST 2004


Irmen de Jong wrote:
  > Where does the \n come from? I presume the 'aString' object contains
> it. Then you can do:
> 
> file.write(aString[:-1])
> 
> (but only if aString always contains a '\n' at the end, ofcourse)

   file.write(aString.rstrip('\n'))

seemes more natural and safer to me.

-- George



More information about the Python-list mailing list