myFirstProperty

← разместить еще код

Расшаренный код:

class IdGiver(object):
    __id = 0

    @classmethod
    def get_id(cls):
        cls.__id += 1

    @property
    def id(self):
        self.get_id()
        return self.__id


class Car(IdGiver):
    pass


class Driver(IdGiver):
    pass


class DriverOne(Driver):
    def __init__(self):
        object_id_collector = self.id


class DriverTwo(Driver):
    def __init__(self):
        object_id_collector = self.id


class BigCar(Car):
    def __init__(self):
        object_id_collector = self.id


print DriverOne().id, DriverOne().id, BigCar().id, DriverTwo().id, DriverOne().id