Answer : The 2to3 script replaces execfile(filename, globals, locals) by exec(compile(open(filename, "rb").read(), filename, 'exec'), globals, locals) This seems to be the official recommendation. You may want to use a with block to ensure that the file is promptly closed again: with open(filename, "rb") as source_file: code = compile(source_file.read(), filename, "exec") exec(code, globals, locals) You can omit the globals and locals arguments to execute the file in the current scope, or use exec(code, {}) to use a new temporary dictionary as both the globals and locals dictionary, effectively executing the file in a new temporary scope. execfile(filename) can be replaced with exec(open(filename).read()) which works in all versions of Python Newer versions of Python will warn you that you didn't close that file, so then you can do this is you want to get rid of that warning: with open(filename) as infile: ...