I am following a tutorial using curses to make the snake game. I wanted to use match/case instead of if/else statements to detect key presses.
key = win.getch()
match key:
case ord("q"): # => "TypeError: called match pattern must be a type"
sys.exit("Game terminated by user.")
case curses.KEY_RIGHT:
snakehead = (snake[0][0], snake[0][1] + 1)
case curses.KEY_LEFT:
snakehead = (snake[0][0], snake[0][1] - 1)
case ord("q")
raises a TypeError, but if I replace with case 113
it works.
ord("q") == 113
evaluates as True
.
I can get the key press to work by making a conditional statement outside the match/case with if key == ord("q")
, but I still would like to find the reason for the exception.