[Tutor] Re: file filter

alan.gauld@bt.com alan.gauld@bt.com
Wed, 26 Dec 2001 17:02:42 -0000


> i can get the copy part. It is just the filter part i am 
> confused about. You see, if the line begins with 'c' or ';' i 
> want to ignore the whole line.

> def boksa(infilename, outfilename):
>     ...
> 	for aLine in infile.xreadlines() :
        if aLine[0] not in ';c'  #sequence of tested chars
> 		f.write( aLine )
> 	infile.close()
> 	f.close()

Should do it.

You could do more sophisticated things by using the 
string.find() function or the re module. But the principle 
is the same, just test the line before writing it.

Alan G.