• Issue with locals dictionary in exec()

 

I would like to give some feedback about exec(). When I run my code for this mission, it has this error message:

NameError: name 'self' is not defined

<listcomp>, 11

corners, 11

<module>, 32

Here's the listconp on line 11:

[exec("self."+direction,globals(),locals()) for direction in corner.split("-")]

Here's the rest of the code I was using:

    class Building:
        def __init__(self, south, west, width_WE, width_NS, height=10):
            self.south,self.west,self.width_WE,self.width_NS,self.height=south,west,\
            width_WE,width_NS,height
        def corners(self):  
            self.north=self.south+self.width_NS
            self.east=self.west+self.width_WE
            D={}
            for corner in ("north-west", "north-east", "south-west", "south-east"):
                D[corner]=[exec("self."+direction,globals(),locals()) for direction in corner.split("-")]
            return D

        def area(self):
            return width_NS*width_WE

        def volume(self):
            raise NotImplementedError

        def __repr__(self):
            return "Building("+str([self.south, self.west, self.width_WE, \
            self.width_NS, self.height]).strip("[]")+")"
    From: https://checkio.org/mission/building-base/solve/

HTTP_USER_AGENT:

Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/52.0.2743.116 Safari/537.36