Running Python code contained in a string
问题 I'm writing a game engine using pygame and box2d, and in the character builder, I want to be able to write the code that will be executed on keydown events. My plan was to have a text editor in the character builder that let you write code similar to: if key == K_a: ## Move left pass elif key == K_d: ## Move right pass I will retrieve the contents of the text editor as a string, and I want the code to be run in a method in this method of Character: def keydown(self, key): ## Run code from