Python execfile() Function

Python 内置函数Python Built-in Functions


Description

The execfile() function can be used to execute a file.

Syntax

The following is the syntax of the execfile() method:

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

Parameters

  • filename -- The file name.
  • globals -- Variable scope, global namespace. If provided, it must be a dictionary object.
  • locals -- Variable scope, local namespace. If provided, it can be any mapping object.

Return Value

Returns the result of expression execution.


Example

The following shows an example using the execfile function:

Assume the file hello.py has the following content:

print('example');

execfile calls the file

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

Python 内置函数Python Built-in Functions

Other Extensions