Pyparsing attribute error setResultsName: "no such attribute"

I am having trouble getting setResultsName to work in this script, even when trying to emulate the above examples. I looked through the documentation, consulted the author’s book and looked at the examples on the forum. I tried several options, and I am frankly a little puzzled, although I am sure there is something stupid that I am doing wrong, because I am not very experienced in 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 piece of code is trying to do is take this input:

1768    dummy data; things
27483   other things

And let it break the line at the semicolon, append lineId again, and then re-associate it, as you see in this line:

1768    dummy data
1768    things
27483   other things

, ; - + lineId, , setResultsName , .

+3
2

, , , :

def new_line(tokens): 
    return '\n' + tokens.responsenumber
+1

setParseAction forward - , (, , , ).

, , delimitedList . , :

from pyparsing import *

topicParser = Word(nums)("line") + \
              delimitedList(Word(alphanums+'-'+' '+"'"),';')("list")

for line in input:
    topics = topicParser.parseString(line)
    lineid = topics['line']
    for topic in topics['list']:
        print "{0} {1}".format(lineid,topic)
+1

All Articles