Python execfile() Function
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 Built-in Functions