[Tutor] Filtering text files

Kooser, Ara S askoose at sandia.gov
Thu Apr 15 13:05:26 EDT 2004


Hello,

   Thank you for help with the calling of the function. I went through your
tutorial and that exlained the problems I was having. Now I am running into
another problem. My output file is blank. The current version of the code I
am using is below on Python 2.3.3. The python shell shows the final print
statement and then a out.txt is created but is blank. I am guessing that
something is wrong with my write command. Thanks again.

Ara

    def filterFile(lmps,out):
        inp = open("lmps.txt", "r") 
        outp = open("out.txt", "w") 
        while 1: 
            text = inp.readline()
            if text =="":
                break 
            if text[0] =="I":
                continue
        outp.write(text)
        inp.close()
        outp.close()
        return
    filterFile("lmps.txt","out.txt")
    print "One file has been filtered" 





More information about the Tutor mailing list