[Tutor] Filtering text files

Alan Gauld alan.gauld at blueyonder.co.uk
Thu Apr 15 03:20:11 EDT 2004


>    I am running the file in IDLE. I go to run, run module. Here is
the shell
> screen:

> >>> ================================ RESTART
> ================================
> >>>
> >>>

OK, That looks like the explanation. ;-)

At a guess:
You have defined a function in your code but you are not
calling the function. So when you run the module all it
does is load the function definition, it doesn't execute
the function. (Assuming the code you semnt is the complete
module)

Could that be it?

What I mean is that after loading the module you need
to add a line like this:

mymodule.filterFile("somefile.txt","result.txt")

to actually execute it...

HTH,

Alan G
Author of the Learn to Program web tutor
http://www.freenetpages.co.uk/hp/alan.gauld

> If the complete program that you are executing is this:
>
> ###
> > def filterFile(lmps, newFile):
> >   f1 = open(lmps, "r")
> >   f2 = open(newFile, "w")
> >   while 1:
> >     text = f1.readline()
> >     if text == "":
> >       break
> >     if text[0] == 'I':
> >       continue
> >     f2.write(text)
> >   f1.close()
> >   f2.close()
> >   return
> ###
>




More information about the Tutor mailing list