[Tutor] Filtering text files

Kooser, Ara S askoose at sandia.gov
Wed Apr 14 18:13:40 EDT 2004


   I am running the file in IDLE. I go to run, run module. Here is the shell
screen: Maybe it's WinXP (*grin*). I will try this on my linux box at home.
I am currently waiting for my linux box to arrive at work. I will read up on
functions. Thank you for your help and the pointers. 


Python 2.3.3 (#51, Dec 18 2003, 20:22:39) [MSC v.1200 32 bit (Intel)] on
Type "copyright", "credits" or "license()" for more information.

    Personal firewall software may warn about the connection IDLE
    makes to its subprocess using this computer's internal loopback
    interface.  This connection is not visible on any external
    interface and no data is sent to or received from the Internet.
IDLE 1.0.2      
>>> ================================ RESTART

-----Original Message-----
From: Danny Yoo [mailto:dyoo at hkn.eecs.berkeley.edu] 
Sent: Wednesday, April 14, 2004 3:49 PM
To: Kooser, Ara S
Cc: 'tutor at python.org'
Subject: Re: [Tutor] Filtering text files

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



for more details about defining and calling functions.

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

More information about the Tutor mailing list