[Tutor] Getting rid of the newline in file

Joseph Quigley cpu.crazy at gmail.com
Sat Sep 17 16:55:35 CEST 2005

Alan G wrote:

>> f = file("foo", 'w')
> Using 'w' will destroy the contents of the file, I assume you are 
> really using 'r'?

Ah yes.. sorry.

> Each line will be terminated by a newline, you can use rstrip() to 
> remove it:
>> print fileContents[0].rstrip() + "Hi!"
Thanks a lot! This really helps.

More information about the Tutor mailing list