[Tutor] Text processing basic Q

Bob Gailer bgailer@alum.rpi.edu
Mon Apr 14 12:22:01 2003


--=======58CB2582=======
Content-Type: text/plain; x-avg-checked=avg-ok-58308FD; charset=us-ascii; format=flowed
Content-Transfer-Encoding: 8bit


>[snip] a script to
>
> > 1. load the file
> > 2. start at the beginning of the file
> > 3. if line start with * then delete
> > 4. move to the next line in the file
> > 5. save the file
>
>file_name = ...
>
>input_file = file(file_name)
>filtered_lines = [l for l in input_file if not l.startswith('*')] ### 
>SHOULD BE input_file.readlines()
>input_file.close()
>
>output_file = file(file_name, 'w')
>for l in filtered_lines :### COULD BE output_file.writelines(filtered_lines)
>      output_file.write(l)
>output_file.close()

Bob Gailer
bgailer@alum.rpi.edu
303 442 2625

--=======58CB2582=======
Content-Type: text/plain; charset=us-ascii; x-avg=cert; x-avg-checked=avg-ok-58308FD
Content-Disposition: inline


---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.467 / Virus Database: 266 - Release Date: 4/1/2003

--=======58CB2582=======--