Using SkipTo as the first element of the analyzer is bold and may indicate that searchString or scanString will be a better choice than parseString (searchString and scanString allow you to determine only the part of the input that interests you, and the rest will be skipped automatically, but you should make sure that your definition of "what you want" uniquely and not accidentally extracts unwanted bits.) Here is your parser implemented with searchString:
NAND_TIME= (Literal("NAND TIMES") + Word(nums)+Literal(":").suppress()+Word(nums)).setParseAction(lambda t: print_cal('NAND TIME')) TEST_TIME= (Literal("TEST TIMES") + Word(nums)+Literal(":").suppress()+Word(nums)).setParseAction(lambda t: print_cal('TEST TIME')) testing =NAND_TIME | TEST_TIME testdata = f.read() for match in testing.searchString(testdata): print match.asList()
'|' great for use in this case, as there is no confusion between starting with NAND or starting with TEST.
You may also consider simply parsing this file line by line:
for line in f: if not line: continue print line print testing.searchString(line).asList() print
source share