How to discard parparesing parseResults during parsing?

Is it possible to describe pyparsing so as not to store ParseResults or manually drop them?

I am parsing a large file of elements and can do all the post processing for each element through a parsing action. Therefore, as soon as the element has been parsed, I no longer need this ParseResult and would like to drop it, because I press the memory limit of the machine on which I am turned on.

+5
source share
1 answer

Do you use parsing actions to process tokens as they are parsed? If so, you can delete the contents of the parsed tokens using del:

def parseActionThatDeletesTheParsedTokens(tokens):
    # ...
    # do something interesting with the tokens
    # ...

    # delete the contents of the parsed tokens
    del tokens[:]

scanString parseString. :

OneOrMore(blockOfText).parseString(bigHonkingString)

:

for tokens, matchstart, matchend in blockOfText.scanString(bigHonkingString):
    # do stuff with the tokens

scanString , 3-, , . , , , . , , .

+4

All Articles