class Test:

    def __init__(self):
        exec(a, globals())
x()


class Test:

    def __init__(self):
        scope = {}
exec(a, scope)
scope['x']()
Using a function defined in an exec'ed string in Python 3