0

I am new to python. I am using the anaconda prompt to run my code. I am trying to import a class from another module but I keep getting errors such as cannot find reference to the class.

P.S please don't negative mark this, or else I will lose the privilege of asking questions


I have already provided an __init__ function.
The module itself runs just fine.
I have used from parser import Parser
I have used from parser import * statement as well

My Parser class

class Parser(object):
     def __init__(self, tokens):
        self.tokens = tokens
        self.token_index = 0

My main class

from parser import Parser

I expected it to normally import the class, but it is unable to.

I keep getting the cannot import name 'Parser' from 'parser' (unknown location) when I use from parser import Parser

2 Answers 2

1

parser is also the name of a Python module in the standard library. It's likely there is a name conflict, and that Python is importing the module from the standard library.

Sign up to request clarification or add additional context in comments.

Comments

0

I changed the module name to mparser and it works!

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.