I would use two dicts. One maps keys to actions, like {"up": "move_up"}
, and one maps actions to functions like {"move_up": player.move_up}
(where player.move_up is a function). The key to action dict can be loaded from a config file, and the action to function can be hardcoded.
import pygame
from ConfigParser import SafeConfigParser
action2function = {
"up": player.move_up,
"down": player.move_down,
"left": player.move_left,
"right": player.move_right
}
config = SafeConfigParser()
config.read(CONFIG_DIRS)
key2action = config.items()
...
for event in pygame.event.get():
if event.type == KEYDOWN:
action2function[key2action[pygame.key.name(event.key)]]()
...