I'm pretty new to OOP.
I'm trying to simulate cars moving along a road in a graph-like fashion. Each Road object has a source and destination. When a car reaches the end of the road, I want the road to send it to the beginning of the next road. My code looks as follows for the Road class:
from collections import deque
class Road:
length = 10
def __init__(self, src, dst):
self.src = src
self.dst = dst
self.actualRoad = deque([0]*self.length,10)
Road.roadCount += 1
def enterRoad(self, car):
if self.actualRoad[0] == 0:
self.actualRoad.appendleft(car)
else:
return False
def iterate(self):
if self.actualRoad[-1] == 0:
self.actualRoad.appendleft(0)
else:
dst.enterRoad(actualRoad[-1]) #this is where I want to send the car in the last part of the road to the destination road!
def printRoad(self):
print self.actualRoad
testRoad = Road(1,2)
testRoad.enterRoad("car1")
testRoad.iterate()
In the code above, the problem is at the else part of the method iterate(): How do I call another Object's method from the current Object's Method? Both methods are in the same class.
Thank you VERY much for your help in advance.
Daniel