I'm trying to do this MOOC
And on this class
I wrote exactly the same code but it doesn't work the same for me. I don't understand.
My full code is on github.
class Zone:
ZONE = []
MIN_LONGITUDE_DEGREES = -180
MAX_LONGITUDE_DEGREES = 180
MIN_LATITUDE_DEGREES = -90
MAX_LATITUDE_DEGREES = 90
WIDTH_DEGREES = 1
HEIGHT_DEGREES = 1
def __init__(self, corner1, corner2):
self.corner1 = corner1
self.corner2 = corner2
self.inhabitants = 0
@classmethod # etand donner qu'on ne sommes plus dans l'instance, masi oui dans la classe il faut changer self par cls
def initialize_zones(cls):
for latitude in range(cls.MIN_LATITUDE_DEGREES, cls.MAX_LATITUDE_DEGREES):
for longitude in range(cls.MIN_LONGITUDE_DEGREES, cls.MAX_LONGITUDE_DEGREES, WIDTH_DEGREES):
bottom_left_corner = Position(longitude, latitude)
top_right_corner = Position(longitude + cls.WIDTH_DEGREES, latitude + cls.HEIGHT_DEGREES)
zone = Zone(bottom_left_corner, top_right_corner)
cls.ZONE.append(zone)
#zone = Zone(bottem_letf_corner, top_right_corner)
print(len(cls.ZONES))
def main():
for agent_attributes in json.load(open("agents-100k.json")):
latitude = agent_attributes.pop('latitude')
longitude = agent_attributes.pop('longitude')
position = Position(longitude, latitude)
agent = Agent(position, **agent_attributes)
Zone.initialize_zones()
main()
ERROR was:
Traceback (most recent call last):
File "model.py", line 64, in
main()
File "model.py", line 62, in main
Zone.initialize_zones()
File "model.py", line 46, in initialize_zones
for longitude in range(cls.MIN_LONGITUDE_DEGREES, cls.MAX_LONGITUDE_DEGREES, WIDTH_DEGREES):
NameError: name 'WIDTH_DEGREES' is not defined