0

I am importing a module

from Boards import CheckerBoardModule 

CheckerBoardModule includes a class called CheckerBoard

When I want to use it, I need to call CheckerBoardModule.CheckerBoard, rather than just CheckerBoard. e.g.

class SnakesAndLaddersBoard(CheckerBoardModule.CheckerBoard): def __init__(self,width,canvas): CheckerBoardModule.CheckerBoard.__init__(self,width,canvas) self.snakes = [] self.ladders = [] 

Why can't I just used CheckerBoard, without the CheckerBoardModule prefix?

1 Answer 1

4

Because you imported the CheckerBoardModule module object, not the CheckerBoard class. If you want to use just CheckerBoard, import that:

from Boards.CheckerBoardModule import CheckerBoard 

All that importing does, apart from executing the module if that hasn't already happened, is bind the imported name in your own namespace. from foo import bar binds bar to whatever bar was bound to from foo. from foo import bar as baz lets you specify a new name.

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

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.