class _DynamicModule(object):

    def __init__(self, name):
        self._name = name

def load(self, code):
    execdict = {'__builtins__': __builtins__}
exec(compile(code, '<string>', 'exec'), execdict)
for key in execdict:
    if not key.startswith('_'):
        if not isinstance(execdict[key], str):
            pass
Dynamically reading in a python file and executing it safely