Answer the question
In order to leave comments, you need to log in
How to rename the search result for a token in pyparser?
Help me solve a simple problem, you need to rename the search result to another word, here is an example:
test_string = 'Hello, Мир'
tokens = pp.Word(pp.alphas).setResultsName('Привет') + pp.Word(',').suppress() + pp.restOfLine()
pprint(tokens.parseString(test_string).asList())
['Hello', 'World']
['Hello World']
tokens = pp.Word(pp.alphas).setParseAction(lambda t: 'Привет') + pp.Word(',').suppress() + pp.restOfLine()
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question