On 12 Feb 2012 05:23, "Tonu Mikk" <tm...@umn.edu> wrote: > > I am learning Python using the "Learn Python the Hard Way" book by Zed Shaw. I reached exercise 42 where we learn about Python classes. The exercise shows a game with one class that includes all the definitions for playing the game. For extra credit we are asked to create another version of this game where we use two classes - one for the room definitions and the other for the playing the game. > > May attempt at creating two classes is here http://codepad.org/963vUgSt . I get the following error which I have been un-able to resolve. Any suggestions are welcome. > > Traceback (most recent call last): > File "ex42_3.py", line 233, in <module> > run() > File "ex42_3.py", line 231, in run > room1.doIt() # plays the game > File "ex42_3.py", line 32, in doIt > self.obj.play() # use object > File "ex42_3.py", line 20, in play > room = getattr(self, next) > AttributeError: 'Engine' object has no attribute 'central_corridor'
Hi, Your code is longer than I feel like reading carefully. (Not a complaint; just cautioning you about how closely I looked.) Also, the line numbers of your code sample do not agree with those of your traceback. (That is a mild complaint; it makes it harder to help you.) Notice that you defined central_corridor as a method of Room. The last line of your traceback is (it seems) in Engine.play; the code there looks for central_corridor in Engine and doesn't find it. If that help, great. If not, try to trim down your code to a smaller version that exhibits the problem and post again, this time making sure the posted code and the code that generate the traceback are the same. Best, Brian vdB
_______________________________________________ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor