This recipe allows you to create a restricted python function from a string, the intent being to allow an application to be safely scripted by user written functions in a controlled fashion. A cautionary follow-up to this which mentions that the rexec function is known to have security issues and is being removed from Python.[1] [2]