def SnippetGen(text, start_tok, end_tok, inclusive=True):
 cur = 0
 while True:
  try:
   start_p = text.index(start_tok, cur)
   end_p = text.index(end_tok, (start_p + 1))
   cur = (end_p + len(end_tok))
   if inclusive:
    (yield text[start_p:cur])
   else:
    (yield text[(start_p + len(start_tok)):end_p])
  except ValueError as e:
   raise StopIteration(('no more snippets in text: %s' % e))

def SnippetGen ( text , start_tok , end_tok , inclusive = True ) : cur = 0 while True : try : start_p = text . index ( start_tok , cur ) end_p = text . index ( end_tok , ( start_p + 1 ) ) cur = ( end_p + len ( end_tok ) ) if inclusive : ( yield text [ start_p : cur ] ) else : ( yield text [ ( start_p + len ( start_tok ) ) : end_p ] ) except ValueError as e : raise StopIteration ( ( 'no more snippets in text: %s' % e ) )
generates consecutive snippets between start and end tokens .