Допустим есть 2 класса:
-класс коллекционер
-класс машина
Коллекционер может иметь много машин, машина имеет только одного коллекционера.
Прошу простить, если “это” больно читать.
Коллекционер:
from Car import *
from Exceptions import *
class Collectioner(object):
def __init__(self, name, car=None):
self.__dict__['cars'] = [car]
self.__dict__['name'] = name
def addCar(self, car):
if type(car) != Car:
raise SomeException()
if car.owner != self:
raise SomeException()
self.__dict__['cars'].append(car)
def removeCar(self, oldCar):
if type(oldCar) != Car:
raise SomeException
if oldCar.owner == self:
oldCar.changeOwner(None)
self.__dict__['cars'].remove(oldCar)
from Collectioner import *
from Exceptions import *
class Car(object):
def __init__(self,collectioner,model):
if type(collectioner) == Collectioner:
self.__dict__['owner'] = collectioner
self.__dict__['model'] = model
@property
def owner(self):
return self.__dict__['owner']
def changeOwner(self, newOwner):
if newOwner == None:
self.__del__(self)
return
if type(newOwner) != Collectioner:
raise SomeException()
self.__dict__['owner'] = newOwner
Ругается на якобы глобальную Collectioner и Car. Посоветуйте как поступить
Стандартная задача.