A similar question was asked here . However, the responses didn't really help me grasp how some parts of the program worked. The program is as follows:
from sys import exit
from random import randint
class Game(object):
def __init__(self, start):
self.pie = [ 'pie test']
self.start = start
def play(self):
next_room_name = self.start
while True:
print "\n--------"
room = getattr(self, next_room_name)
next_room_name = room()
def rooom(self):
print "Test worked. good job"
return "piez"
def piez(self):
print "pie room"
exit(1)
a_game = Game("rooom")
a_game.play()
The first question is how is the following working?
def play(self):
next_room_name = self.start
while True:
print "\n--------"
room = getattr(self, next_room_name)
next_room_name = room()
I know that somehow the following is generating the room name so the program can go to where it needs to. I'm just not seeing how it is happening.
My second question is:
self.start = start
I sort of understand self.pie is doing. But I'm not sure what self.start = start is suppose to accomplish. Thanks again for your assistance.