0

I have a module parser.py in local directory with

class Parser(object):
    . . . .
    . . . . 

class Parser2(object):
    . . . .
    . . . . 

I'd like to import those in mainScript.py, however i'm getting an

error no name 'Parser' in module parser

from parser import Parser
4
  • 2
    Are you sure you aren't importing from parser? Commented Jul 21, 2014 at 15:17
  • no... I created my own Parser() class in parser.py (a local module) Commented Jul 21, 2014 at 15:23
  • If i rename the class, same issue :( Commented Jul 21, 2014 at 15:24
  • Can you import parser; is it just when you from parser import Parser that you get problems? Does parser.__file__ give the expected location? Commented Jul 21, 2014 at 15:25

2 Answers 2

2

Parser is already a Python module. Rename your module (for example from "parser.py" to "myParseModule.py") and you shouldn't have a problem.

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

2 Comments

That's unlikely. If anything it is usually the other way round: local files shadow standard library ones.
That's what I thought, but I recreated the error and fixed it by renaming it from "parser.py" to something else.
0

check your sys.path. if /usr/lib/pythonX/lib-dynload is before '' you will be importing the official parser module from the standard library instead of your module.

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.