Murtaza Kamal
Murtaza Kamal

Reputation: 133

Python: cannot find reference to class when using import

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

Upvotes: 0

Views: 1707

Answers (2)

kosayoda
kosayoda

Reputation: 398

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.

Upvotes: 1

Murtaza Kamal
Murtaza Kamal

Reputation: 133

I changed the module name to mparser and it works!

Upvotes: 0

Related Questions