I have some code from a much-maligned Python resource, if you ask SO, but I am trying to divine Python’s parse routine from it, regardless its didactic merits.
def princess_lives_here():
#<some messages and conditionals to keep you going in the text-based game>
#<one of the conditionals end in a `return 'death'`, another function in ROOMS>
ROOMS = {
'death': death,
'princess_lives_here': princess_lives_here,
}
def runner (map, start):
next = start
while True:
room = map[next]
print "\n--------"
next = room()
runner(ROOMS, 'princess_lives_here')
What I am not sure about is how
princess_lives_hereis ever run in the while loop. I can only assume that it is run is the last line, but what looks like an assignment to me must be an execution ofroom(), i.e.princess_lives_here. Why, when and how is this execution performed?My second question is how, when, and why the while loop is run again, when the parsing routines hits
return 'death'.
I’ve created a gist with the entire code, in case you want the greater picture. It just takes up a lot of lines of code: https://gist.github.com/848228.