我有如下内容(简化版)
class ParseClass(object):
def __init__(self, tokens):
# do some processing on tokens
expr = Word().setParseAction(ParseClass)
?比如一些背景等等-
class ParseClass(object):
def __init__(self, tokens, context):
# do some processing on tokens based on context
expr = Word().setParseAction(ParseClass, context)
?
最佳答案
我希望,如果前者起作用,那么后者可以通过:
expr = Word().setParseAction(lambda tokens: ParseClass(tokens,context) )
但我不知道pyparsing。(I'll happily delete this if it doesn't work)
关于python - 在pyparsing中将用户定义的参数传递给setParseAction,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/10805368/