Python execfile

Posted on Thursday May 19th, 2016

Python3 has removed execfile() which is still referred to by some documentation as I encountered when attempting to make a Flask based website live with wsgi in Apache - see here.

With a little help from google it appears it's easy to replace with your own implementation:

def execfile(path, global_vars=None, local_vars=None):
    with open(path, 'r') as f:
        code = compile(f.read(), path, 'exec')
        exec(code, global_vars, local_vars)