execfile()

Python 内置函数 Python 内置函数

描述

execfile() 函数可以用来执行一个文件。

语法

以下是 execfile() 方法的语法:

execfile(filename[, globals[, locals]])

参数

返回值

返回表达式执行结果。

实例

以下展示了使用 execfile 函数的实例:

假设文件 hello.py,内容如下:

print('w3xue');

execfile 调用该文件

>>>execfile('hello.py') w3xue

Python 内置函数 Python 内置函数