[Tutor] Filtering text files

Kooser, Ara S askoose at sandia.gov
Wed Apr 14 17:28:10 EDT 2004


Hello,

   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 and no new file is created in my
directory. Here is the code from
http://www.ibiblio.org/obp/thinkCSpy/chap11.htm
<http://www.ibiblio.org/obp/thinkCSpy/chap11.htm> . I have in my directory a
file named lmps for the input file. Also do the names in the function have
to be the same as the names of the files being loaded? I have tried both.
Thanks

Ara

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 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/tutor/attachments/20040414/07143a2c/attachment.html


More information about the Tutor mailing list