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?

Martijn Pieters
1.1m326 gold badges4.2k silver badges3.5k bronze badges
asked Jul 16, 2013 at 9:19

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.

answered Jul 16, 2013 at 9:20
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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.