DatalogiForAlle / AgentsPy

Agent-based simulation for education in Python
GNU General Public License v3.0
5 stars 0 forks source link

Problem in onClose event for epidemic.py #85

Open dybber opened 3 years ago

dybber commented 3 years ago

This happens when running the current version of epidemic.py, and then closing the window. To replicate, just run python epidemic.py and close the window (also happens if setup have been pushed)

AgentsPy) dpr964@dybber:~/Development/educational/AgentsPy/examples$ python epidemic.py
Traceback (most recent call last):
  File "/Users/dpr964/.virtualenvs/AgentsPy/lib/python3.8/site-packages/agents/ui.py", line 387, in closeEvent
    self.model.close()
  File "/Users/dpr964/.virtualenvs/AgentsPy/lib/python3.8/site-packages/agents/model.py", line 565, in close
    self._close_func(self)
  File "epidemic.py", line 108, in print_infections
    print("Total infections are " + str(model["infected"]))
  File "/Users/dpr964/.virtualenvs/AgentsPy/lib/python3.8/site-packages/agents/model.py", line 589, in __getitem__
    return self.variables[key]
KeyError: 'infected'
Abort trap: 6
JensKanstrupLarsen commented 3 years ago

The problem is that the model no longer uses a dictionary-style for its local variables, but just assigns them directly as attributes. To fix, change this line in print_infections

print("Total infections are " + str(model["infected"]))

to this

print("Total infections are " + str(model.infected))