Here is my import structure:
inputs.py (It includes user inputs and it calls the simulator where simulator runs)
from simEngine import simulator
# user inputs
simulator(A, B)
simEngine.py
import Building
import ResidentArrivalSetup
def simulator(A, B):
building = Building(...)
resident = ResidentArrivalSetup(...)
Building.py
import inputs
class Building:
def __init__(self, blaBla)
self.blaBla = blaBla
self.residentDic = {}
ResidentArrivalSetup.py
import Resident
import Building
class ResidentArrivalSetup:
def __init___(self, C):
self.C = C
self.building = Building(residentDic)
def someMethod(self):
resident = Resident(K,L,M)
Resident.py
import inputs
class Resident:
def __init__(self, X, Y):
self.X = X
self.Y = Y
self.buildingHeight = inputs.buildingHeight
- When I run the inputs.py, it gets the input from the user and it calls
simulator
function. - Then
simulator
callsBuilding
andResidentArrivalSetup
classes (Building.py
is constructed from theinputs.py
). ResidentArrivalSetup
creates an instance ofResident
.Building
has a dictionary where I store theResident
instances when I create a Resident fromResidentArrivalSetup
. So, I import that dictionary by importingBuilding
intoResidentArrivalSetup
.
When I run the inputs.py
, I get
ImportError: cannot import name 'simulator' from 'simEngine'
I added the current path to the sys.path already. I think my problem is about circular dependency. How can I solve this?
Read more here: https://stackoverflow.com/questions/66341377/circular-dependency-on-python-oop
Content Attribution
This content was originally published by kerim at Recent Questions - Stack Overflow, and is syndicated here via their RSS feed. You can read the original post over there.