I would like that the following action is only done/run once per file I am parsing.
str_buyer = pyp.oneOf("buyer:;" need to watch this, and maybe make onlyonce work
"acheteur :".split(';'), caseless=True).suppress() +\
alphanums + pyp.restOfLine
buyer = pyp.OnlyOnce(str_buyer.setParseAction(self.str_buyerAction))
But the parse action is still run twice, once for "buyer information" and once for "buyer".
What am I doing wrong?
My work around is to just check a variable in "self.str_buyerAction", that works fine for me.
But I am still intrigued on how one would use OnlyOnce.
OnlyOnce is really a modifier on the parse action, not on the expression. Try:
buyer = str_buyer.setParseAction(pyp.OnlyOnce(self.str_buyerAction))
Aha, that is how that is used.
Great, it is much cleaner/self documenting then setting a flag in str_buyerAction (which was my work around).
Log in to post a comment.
Sign up for the SourceForge newsletter:
You seem to have CSS turned off.
Please don't fill out this field.