while True:
print "\n--------"
room = getattr(self, next)
next = room()
My question stems from the block of code above, found in Learn Python The Hard Way - Exercise 43. I understand that the third line stores the getattr()
function results (in this case, self.next
) into the room
variable (unless I'm wrong there...?)
What is hanging me up right now is the fourth line, where the function room()
is stored into the variable next
. Fundamentally, I don't understand the room()
part as this isn't a defined function in the code block. Does Python allow the user to define a function based on a preceding variable? (For example: writing room()
for the first time creates a function called room()
based on what is stored in the variable room
).
Any help would be greatly appreciated!