Here is a simple code snippet to do that. Saving it to an individual file and import it in other module to use it.
Using exec statement is also good, but need to pass globals() or locals() dictionary to the function executing exec statement.
Doing dirty things in Python is really not easy...:/