[Tutor] Filtering text files

Danny Yoo dyoo at hkn.eecs.berkeley.edu
Wed Apr 14 17:49:23 EDT 2004



On Wed, 14 Apr 2004, Kooser, Ara S wrote:

>    I posted several question about filtering text files. I am still a
> little confused. I ran through some of the tutorials on python.org and I
> am still getting hung up. I am running python 2.3.3. When I try and run
> the program below I receive the prompt on the shell


Hi Ara,


Hmmm... Can you show us how you're running the program?  Just do a
cut-and-paste of the session, and that should be enough.



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
###

then something might be missing: although the definition of filterFile()
looks ok, unless there is an activating call to filterFile(), nothing will
happen.  Can you double check to see that the filterFile() function is
being called?


See:

    http://www.ibiblio.org/obp/thinkCSpy/chap03.htm

for more details about defining and calling functions.



If you have questions, please feel free to ask them; we'll try to help.
Good luck!




More information about the Tutor mailing list