Help With EOF character: URGENT

dont bother dontbotherworld at
Mon Feb 23 00:10:10 CET 2004

Hi Buddies,
I am facing this problem and I dont know what to use
as EOF in python:
I want to read a file, and put all the individual
words in a dictionary with their index:
For example if the file is:

Hello there I am doing fine
How are you?

So I want to make an index like this:

1 Hello
2 there
3 I
4 am
5 doing
6 fine
7 How
8 are
9 you
10 ?

In order to do this: I have written a small code which
is here:
# python code for creating dictionary of words from an
#input file

import os
import sys
        fread = open('training_data', 'r')
except IOError:
        print 'Cant open file for reading'
print 'Okay reading the file'
while (a!="\003"):
#while 1:

                if(a=='\012'): #newline
                        #print s
                        #print 'The Line Ends'
                        fwrite=open('dictionary', 'a')

if(a=='\040'): #blank character
                        #print s
                        fwrite=open('dictionary', 'a')
print 'Wrote to Dictionary\n'


My problem is that I dont know what to use in place of
EOF. I have tried using Octal "\003" and "\004" but
that does not work. The code keeps on running. I want
it to stop reading when the EOF has reached.
Can someone help me out on this?
Also, I have to create a list: (A Map kind of thing
with an index associated with each word). Can some one
offer a tip or snippet on that.
I will be really grateful.


Do you Yahoo!?
Yahoo! Mail SpamGuard - Read only the mail you want.

More information about the Python-list mailing list