py3 execfile实现


def execfile(file_path, globals=None, locals=None):
if globals is None:
globals = {}
globals.update({
"__file__": file_path,
"__name__": "__main__",
})
with open(file_path, 'rb') as file:
exec(compile(file.read(), file_path, 'exec'), globals, locals)
posted @ 2022-07-13 09:57  不带R的墨菲特  阅读(104)  评论(0)    收藏  举报