oh, .readings. Unfortunately you'd need to develop a custom
collection class which achieves this and make it available by a
@property on Sensor:
class Sensor(...):
@property
def readings(self):
return MagicReadingCollection(self)
then you do the __getitem__ / __setitem__ thing on MagicReadingCollection:
class MagicReadingCollection(object):
def __init__(self, sensor):
self.sensor = sensor
def __setitem__(self, field, values):
start_appending_at = len(self.sensor.readings)
for index, value in enumerate(values):
if index > start_appending_at:
reading = Reading()
self.sensor.readings.append(reading)
else:
reading = self.sensor.readings[index]
setattr(reading, field, value)