Suppose I have a Python Enum were each instance of the Enum should reference another instance of the same enum. How do I do that?
When I try something like this:
class Direction(Enum):
NORTH = (1,0, Direction.EAST, Direction.WEST)
SOUTH = (-1,0, Direction.WEST, Direction.EAST)
EAST = (0,1, Direction.SOUTH, Direction.NORTH)
WEST = (0, -1, Direction.NORTH, Direction.SOUTH)
def __init__(self, y, x, r, l):
self.y = y
self.x = x
self.r = r
self.l = l
I get an error that looks a bit like this:
Traceback (most recent call last):
File "lol.py", line 2, in <module>
class Direction(Enum):
File "lol.py", line 3, in Direction
NORTH = (1,0, Direction.EAST, Direction.WEST)
NameError: name 'Direction' is not defined
I get the same issue when I replace "Direction" with "self" in the above example.
Is there a way to do this?