Repository navigation
devs/eventlist: Add repr method to print EventList pretty - #2195
Conversation
Add __str__ and __repr__ methods to print EventList in a useful format. In models, this allows doing things like `self.simulator.event_list` to validate the events queued in your simulator.
|
Performance benchmarks:
|
|
Tha ks! This should probably be done for a lot more classes of mesa. Just a note though: it is more common to just define repr and then if str is not defined, but called, it will automatically use the repr definition |
Thanks. I think the current implementation is more |
__str__ will follow from it
Add
__repr__method to printEventListobjects in a useful format.In models, this allows doing things like
print(self.simulator.event_list)to validate the events queued in your simulator.Output of
print(self.simulator.event_list):<mesa.experimental.devs.eventlist.EventList object at 0x00000186E42AF830>EventList([Event(time=7.046389752627814, priority=5, id=0), Event(time=8.305480965357855, priority=5, id=9), Event(time=10.904561103085891, priority=5, id=6)])