title: How to appropriately call functions from another class with a changing variable?
body: <p>I am trying to use a while loop to call functions from a class in another file, and then change the function to be called next based on what the original function returned. You may recognize some of this from "Learning Python the Hard Way." </p>
  
  <p>I have two files: engine.py and rooms.py. Engine.py contains the while loop that calls functions from a class in rooms.py called 'Rooms'.</p>
  
  <p>An example from rooms.py:</p>
  
  <pre><code>class Rooms(object):    
      def __init__(self): #add start as arg for one class game
          from random import randint
          from sys import exit
  
      def princess_lives_here(self):
          print "Cake"
  
          eat_it = raw_input("1\n2\n3\?&gt; ")
  
          if eat_it == "1":
              return 'death'
  
          elif eat_it == "2":
              return 'death'
  
          elif eat_it == "3":
              return 'gold_koi_pond'
  
          else:
              return 'death'
  </code></pre>
  
  <p>This is a simple mockup of the actual game to make sure I can get the mechanism to work correctly. 'death' and 'gold_koi_pond' are all functions contained within the class Rooms.</p>
  
  <p>I have three samples of the engine that I want to compare. I'll call them 1, 2 and 3 respectively.</p>
  
  <p>#1 works:</p>
  
  <pre><code>class Engine(object):
      def __init__(self, start):
          self.start = start
  
      def play(self):
          next = self.start
  
          while True:
              g = Rooms()
              room = getattr(Rooms, next)
              next = room(g)
  
  
  from rooms import Rooms
  
  a = Engine("princess_lives_here")
  a.play()
  </code></pre>
  
  <p>#2 works:</p>
  
  <pre><code>class Engine(object):
      def __init__(self, start):
           self.start = start
  
      def play(self):
           next = self.start
  
          while True:
               next = getattr(Rooms, next)(Rooms())
  
  
  from rooms import Rooms
  
  a = Engine("princess_lives_here")
  a.play()
  </code></pre>
  
  <p>#3 does not work:</p>
  
  <pre><code>class Engine(object):
      def __init__(self, start):
          self.start = start
  
      def play(self):
          next = self.start
  
          while True:
              room = getattr(Rooms, next)
              next = room()
  
  
  from rooms import Rooms
  
  a = Engine("princess_lives_here")
  a.play()
  </code></pre>
  
  <p>I'm having a hard time understanding the difference between the three options. Is one better than the other? What exactly is happening in python that makes 1 and 2 work, but not 3? Is there a better way to accomplish what I want to do?</p>
  
  <p>Also, randint and exit don't import when Rooms is run from engine.py. Why is this?</p>
  
  <p>Thanks for any help! I'm open to all advice and critiques, not just about the questions I'm interested in.</p>