I have a compiled Python file, path/program.pyc.
I want to execute it with my current globals() and locals(). I tried:
with open('path/program.pyc','rb') as f:
code = f.read()
exec(code, globals(), locals())
More specifically, what I want to have is:
a.py:
a = 1
# somehow run b.pyc
b.py:
print(a)
When I run a.py, I want to see the output: 1.
Actually execfile() does exactly what I want, but it only works for .py files not .pyc files. I am looking for a version of execfile() that works for .pyc files.