def work(start="",end="",fp=""): if not start or not end or not fp: return str_lst = [] has_start = False for line in open(fp): if line.find(start) != -1: str_lst.append(line) has_start = True elif has_start and line.find(end) != -1: str_lst.append(line[:line.index(end)]) has_start = False return "".join(str_lst) elif has_start: str_lst.append(line) return "".join(str_lst) def main(): """This is main method""" start = "-=+&*-=+&*-=+&*-=+&*-=+&*-=+&*-=+&*-=+&*-=+&*-=+&*angela" end = "-=+&*-=+&*-=+&*-=+&*-=+&*-=+&*-=+&*-=+&*-=+&*-=+&*" fp = "temp.txt" s = work(start,end,fp) print s if __name__=='__main__': main()