> I have a file full of lines beginning with the letter "b". I want a > RE that will return the whole line if it begins with b. > > I find if I do eg: > > >>>> m = re.search("^b", "b spam spam spam") >>>> m.group() >>>> > 'b' > > How do I get it to return the whole line if it begins with a b? > > S. for line in file: if line.strip()[0] == 'b': print line
or print [a for a in file if a.strip()[0] == b] if you want to use list comprehension. As for the RE way, I've no idea. _______________________________________________ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor