I am working on an assignment where I create "instances" of cities using rows in a .csv, then use these instances in methods to calculate distance and population change. Creating the instances works fine (using steps 1-4 below), until I try to call printDistance:
##Step 1. Open and read CityPop.csv
with open('CityPop.csv', 'r', newline='') as f:
try:reader = csv.DictReader(f)##Step 2. Create "City" classclass City:##Step 3. Use _init method to assign attribute valuesdef __init__(self, row, header):self.__dict__ = dict(zip(header, row))##Step 4. Create "Cities" listdata = list(csv.reader(open('CityPop.csv')))instances = [City(i, data[0]) for i in data[1:]]##Step 5. Create printDistance method within "Cities" class def printDistance(self, othercity, instances):dist=math.acos((math.sin(math.radians(self.lat)))*(math.sin(math.radians(othercity.lat)))+(math.cos(math.radians(self.lat)))*(math.cos(math.radians(othercity.lat)))*(math.cos(math.radians(self.lon-othercity.lon)))) * 6300 (self.lat, self.lon, othercity.lat, othercity.lon)
When I enter instances[0].printDistance(instances1) in the shell, I get the error:
`NameError: name 'instances' is not defined`
Is this an indentation problem? Should I be calling the function from within the code, not the shell?