pythonpython-3.xincludeexecfile

What alternative is there to execfile in Python 3? / How to include a Python file?


It seems like in Python 3 they've removed all of the easy ways to quickly load a script, by removing execfile().

What alternative is there to include a Python file in another one, and execute it?


Solution

  • According to the Python documentation, instead of this:

    execfile("./filename") 
    

    Use this:

    exec(open("./filename").read())
    

    See Python's docs for: