Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7874237
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T02:45:08+00:00 2026-06-03T02:45:08+00:00

The following code gives me the error ‘no such attribute _ParseResuls__tokdict’ when run on

  • 0

The following code gives me the error ‘no such attribute _ParseResuls__tokdict’ when run on an input with more than one line.

With single-line files, there is no error. If I comment out either the second or third line shown here, then I don’t get that error either, no matter how long the file is.

for line in input:
    final = delimitedList(expr).parseString(line)
    notid = delimitedList(notid).parseString(line)
    dash_tags = ', '.join(format_tree(notid))

    print final.lineId + ": " + dash_tags

Does anyone know what’s going on here?

EDIT: As suggested, I’m adding the complete code to allow others to reproduce the error.

from pyparsing import *

#first are the basic elements of the expression

#number at the beginning of the line, unique for each line
#top-level category for a sentiment
#semicolon should eventually become a line break

lineId = Word(nums)
topicString = Word(alphanums+'-'+' '+"'")
semicolon = Literal(';')

#call variable early to allow for recursion
#recursive function allowing for a line id at first, then the topic,
#then any subtopics, and so on. Finally, optional semicolon and repeat.
#set results name lineId.lineId here
expr = Forward()
expr << Optional(lineId.setResultsName("lineId")) + topicString.setResultsName("topicString") + \
Optional(nestedExpr(content=delimitedList(expr))).setResultsName("parenthetical") + \
Optional(Suppress(semicolon).setResultsName("semicolon") + expr.setResultsName("subsequentlines"))

notid = Suppress(lineId) + topicString + \
Optional(nestedExpr(content=delimitedList(expr))) + \
Optional(Suppress(semicolon) + expr)



#naming the parenthetical portion for independent reference later
parenthetical = nestedExpr(content=delimitedList(expr))


#open files for read and write
input = open('parserinput.txt')
output = open('parseroutput.txt', 'w')

#defining functions

#takes nested list output of parser grammer and translates it into
#strings suited for the final output
def format_tree(tree):                                                                                            
    prefix = ''
    for node in tree:
        if isinstance(node, basestring):
            prefix = node
            yield node
        else:
            for elt in format_tree(node):
                yield prefix + '_' + elt

#function for passing tokens from setResultsName
def id_number(tokens):
    #print tokens.dump()
    lineId = tokens
    lineId["lineId"] = lineId.lineId

def topic_string(tokens):
    topicString = tokens
    topicString["topicString"] = topicString.topicString

def parenthetical_fun(tokens):
    parenthetical = tokens
    parenthetical["parenthetical"] = parenthetical.parenthetical

#function for splitting line at semicolon and appending numberId
#not currently in use
def split_and_prepend(tokens):
    return '\n' + final.lineId


#setting parse actions
lineId.setParseAction(id_number)
topicString.setParseAction(topic_string)
parenthetical.setParseAction(parenthetical)


#reads each line in the input file
#calls the grammar expressed in 'expr' and uses it to read the line and assign names to the tokens for later use
#calls the 'notid' varient to easily return the other elements in the line aside from the lineId
#applies the format tree function and joins the tokens in a comma-separated string
#prints the lineId + the tokens from that line
for line in input:
    final = delimitedList(expr).parseString(line)
    notid = delimitedList(notid).parseString(line)
    dash_tags = ', '.join(format_tree(notid))

    print final.lineId + ": " + dash_tags

The input file is a txt document with the following two lines:

1768    dummy; data
1768    dummy data; price
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T02:45:11+00:00Added an answer on June 3, 2026 at 2:45 am

    Reassigning of notid breaks the second iteration when used in delimitedList. Your third line destroys the notid expression defined earlier in the code, so it will only work the first iteration. Use a different name for the notid assignment.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

The following code gives me this error Token Error: EOF in multi-line statement. What
I have the following code and it gives an error hello.l,line 31: premature EOF
The following code snippet gives the error message at run time of: Debug assertion
The following code gives a compiler error (gcc-4.7 run with -std=c++11 ): #include <iostream>
The following C++ code gives an error while compiling: #include<iostream> using namespace std; class
I have following asp.net code but it gives error when I change dropdown selected
The code below gives me the following error: incompatible types when assigning to type'char[10]'
The following code gives an error: [1.0-ml] XDMP-UNDVAR: (err:XPST0008) Undefined variable $ename However if
The following code gives an error when it's supposed to output just std::endl :
The following code gives me an error from django.db import connection cursor = connection.cursor()

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.