Importuj instancję klasy z innego modułu
Mam moduł o nazwie katalog i inny moduł o nazwie gatunki. Zawsze będzie tylko jeden katalog bez względu na to, ile mam gatunków.
W module katalogu mam 1 klasę katalogów. Wewnątrz modułu Gatunki mam wiele różnych klas gatunków.
#module named directory
class directory:
def __init__(self):
...
def add_to_world(self, obj, name, zone = 'forrest', space = [0, 0]):
...
#module named species
class Species (object):
def __init__(self, atlas):
self.atlas = atlas
def new(self, object_species, name, zone = 'holding'):
self.object_species = object_species
self.name = name
self.zone = zone
self.atlas.add_to_world(object_species, name)
class Lama(Species):
def __init__(self, name, atlas, zone = 'forrest'):
self.new('Lama', name)
self.at = getattr(Entity, )
self.atlas = atlas
Problem polega na tym, że w każdej z moich klas muszę przekazać obiekt atlasu temu gatunkowi. Jak mogę po prostu powiedzieć gatunkowi, aby dostał instancję z innego modułu.
Przykład, jeśli mam instancję 'atlas' w module o nazwie Entity z klasą Entity, jak mogę powiedzieć wszystkim gatunkom za pomocą kilku wierszy kodu, aby pobrać ten obiekt z Entity?