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
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.