[Tutor] iterate problem

David Jansen djansen@pobox.com
Sun, 16 Jul 2000 11:44:21 +0900

While I read tutorials I am playing around with what I have learned. I am
trying to write a simple script that removes the >>>'s from the beginning of
lines in a text file (for example  an email message that has been forwarded
a number of times). Removing the first > from the beginning of a line is no
problem but I seem to enter an endless loop when I attempt to iterate over
the line to get rid of second and third >'s if they exist.  The problem line
is obviously the while line in strip() but I can't figure out what is wrong
with it.

Any help greatly appreciated.

David Jansen

import string, sys

groups = []
alphas = string.letters + string.digits

file = raw_input("enter file: ")
inp = open(file, "r")

def strip(input):
____while (len(input) > 0) and (input[0] not in alphas):
________if input[0] == ">":
____________input = input[1:]
____return input

for line in inp.readlines():
____result = strip(line)
____print result

sample text file:

>Interesting Stuff.
> > >The citrus soda 7-UP was created in 1929; "7" was selected because the
> > >original containers were 7 ounces. "UP" indicated the direction of the
> > >bubbles.
> > >
> > > Mosquito repellents don't repel. They hide you. The spray blocks the
> > >mosquito's sensors so they don't know you're there.
> > >
> > > Dentists have recommended that a toothbrush be kept at least 6 feet