1

I found the following piece of code and I'm wondering about the scope of the variable percepts. I can't understand why the reference to this variable is considered valid and not catched by the garbage collector once the __init__ method ends:

class TDA():

    def __init__(self, table):
        percepts = []
        def program(percept):
            percepts.append(percept)
            action = table.get(tuple(percepts))
            return action
        self.program = program
Nick
  • 10,309
  • 21
  • 97
  • 201

0 Answers0