I'm having trouble getting setResultsName to work for me in this script, even when attempting to emulate examples given. I've looked to the documentation, consulted the author's book, and looked at forum examples. I've tried several variations, and I'm frankly a little stumped, though I'm sure there's something silly that I'm doing wrong as I'm not very experienced at this.
from pyparsing import *
lineId = Word(nums)
topicString = Word(alphanums+'-'+' '+"'")
expr = Forward()
full_entry = Group(lineId('responsenumber') + expr)
def new_line():
return '\n' + lineId.responsenumber # <-- here is the line that causes the error
expr << topicString + Optional(nestedExpr(content=delimitedList(expr))) + Optional((Literal(';').setParseAction(new_line) + expr))
for line in input:
inputParseResults = delimitedList(full_entry).parseString(line).asList()
print inputParseResults
What this portion of the code is attempting to do is to take this input:
1768 dummy data; things
27483 other things
And have it break the line at the semicolon, attach the lineId again, and then re-associate it as you see on this line:
1768 dummy data
1768 things
27483 other things
There is other code to handle formatting the output that I've not shown here; my main obstacle is getting the line break + lineId, and I think if I could get setResultsName to work, I might be set.