I need to execute a file inside a python shell.
I can
exec(open('Test.py').read()) But I need to call it from inside a function.
"Test.py" will set variable C=10
So,
#x.py def load(file): exec(open(file).read(),globals()) >>> import x >>> x.load('Test.py') >>> C >>> NameError: name 'C' is not defined I have passed in the globals, but I still cant access the varibales from exec. References:
In Python, why doesn't an import in an exec in a function work?
execfile("filepath")