Re: [Tutor] Getting rid of the newline in file

2005-09-17 Thread Joseph Quigley
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

Re: [Tutor] Getting rid of the newline in file

2005-09-17 Thread Alan G
> f = file("foo", 'w') Using 'w' will destroy the contents of the file, I assume you are really using 'r'? > fileContents = f.readlines() Each line will be terminated by a newline, you can use rstrip() to remove it: > print fileContents[0].rstrip() + "Hi!" HTH, There is more on this topic i

[Tutor] Getting rid of the newline in file

2005-09-16 Thread Joseph Quigley
Hi. I'm using f = file("foo", 'w') fileContents = f.readlines() print fileContents[0] + "Hi!" and I get: Foo Hi! How can I get rid of that new line? fileContents[1] has Bar. I wrote the file using Joe (a *nix test editor) and for the new line I pressed Enter to add Bar. This is a pain as I don't