class UpdatedDict(dict):

    def __setitem__(self, key, value):
        if key != 'var1':
            super(UpdatedDict, self).__setitem__(key, value)
u = UpdatedDict({'var1': 10, '__name__': '__main__'})
exec(open('temp.py').read(), u)
How to import a module and change a variable value inside module and execute it