Help With EOF character: URGENT

Jorge Godoy godoy at
Mon Feb 23 02:09:28 CET 2004

On Sunday 22 February 2004 21:21, Eric @ Zomething wrote:

> Dont, I think you want to iterate over your file, rather than look for an
> EOF marker, unless you have a technical reason not to.
> I'll leave it to someone else to provide a better solution, but here is a
> Q&D newbie approach to a text file break-out of words:
>>>> fileOne=open('C:\\testfile.txt')
>>>> print fileString
> Hello there I am doing fine
> How are you?
>>>> wordString=fileString.replace('\n',' ')
>>>> print wordString
> Hello there I am doing fine How are you?
>>>> wordList=wordString.split(' ')
>>>> print wordList
> ['Hello', 'there', 'I', 'am', 'doing', 'fine', 'How', 'are', 'you?', '']

It works fine for small files... If it gets a "little" bigger it will start
using too much RAM. Maybe using a loop with readline() instead of reading
it all into memory is a better choice. 

I would complement my previous post with advice for him not to count os
specific codes for each and every file since such codes can change from OS
to OS, but it seemed that it was something in a controlled environment...
Anyway, it would be better to use "\n", "\r", etc. instead of their octal

Be seeing you,
Godoy.      <godoy at>

More information about the Python-list mailing list