Attributeerror: тип объекта 'mastertrainer' не имеет атрибута 'latitude'
import math import csv import numpy from math import radians, sin, cos, acos class venue: venueGeoLat = [] venueGeoLon = [] venueName = [] def __init__(self,name,latitude,longitude): self.name = name self.latitude = latitude self.longitude = longitude with open('venueData.csv') as csvDataFile: csvReader = csv.reader(csvDataFile) for row in csvReader: venueGeoLat.append(row[1]) venueGeoLon.append(row[2]) venueName.append(row[0]) class masterTrainer: #class generated for the master trainers for the whole state distanceFromVenues = [] nearestVenues = [] latitude = None longitude = None def __init__(self,name,location,subject,latitude,longitude): self.name = name self.location = location self.subject = subject self.latitude = latitude self.longitude = longitude i = 1 j = 1 while i < 2: while j < len(venue.venueGeoLat): masterTrainer.distanceFromVenues.append(masterTrainer.distanceCalculator(float(masterTrainer.latitude),float(masterTrainer.longitude),float(venue.venueGeoLat[j]),float(venue.venueGeoLon[j]))) j = j + 1 i = i + 1 MAX = 100000 firstmin = MAX secmin = MAX thirdmin = MAX k = 0 l = 0 m = 0 for i in range(0, len(distanceFromVenues)): if distanceFromVenues[i] < firstmin: thirdmin = secmin secmin = firstmin firstmin = distanceFromVenues[i] k = i elif distanceFromVenues[i] < secmin: thirdmin = secmin secmin = distanceFromVenues[i] l = i elif distanceFromVenues[i] < thirdmin: thirdmin = distanceFromVenues[i] m = i nearestVenues.append(venue.venueName[k+1]) nearestVenues.append(venue.venueName[l+1]) nearestVenues.append(venue.venueName[m+1]) def distanceCalculator(latitude1,longitude1,latitude2,longitude2): slat = radians(latitude1) slon = radians(longitude1) elat = radians(latitude2) elon = radians(longitude2) dist = 6371.01 * acos(sin(slat)*sin(elat) + cos(slat)*cos(elat)*cos(slon - elon)) return dist #mt1 = masterTrainer("Suhit Kumar", "Kanpur","Mathematics","30.7996","75.9042") #print(mt1.distanceFromVenues) #print(mt1.nearestVenues) masters = [] with open('mtData.csv') as csvDataFile: csvReader = csv.reader(csvDataFile) for row in csvReader: masters.append(masterTrainer(row[0],row[1],row[4],row[2],row[3])) #for m in masters: #print(m.distanceFromVenues) print(masters[1].nearestVenues)
Что я уже пробовал:
Когда я попытался скомпилировать этот код, то получил ошибку атрибута, говорящую:
AttributeError: type object 'masterTrainer' has no attribute 'latitude'