execfile¶
-
execfile
(filename, globals=globals())¶ Execute file
- Parameters
filename (string) - name of file to execute
globals (dictionary) - the environment for evaluation
- Description
Python 3 removed the
execfile
builtin function. CASA provides a convenience function that attempts to reproduce the behavior of the Python 2.7 builtinexecfile
function.execfile
evaluates contents offilename
in the environment specified byglobals
.When
execfile
is used within thefilename
being evaluated, it is necessary to addglobals( )
as the second argument to those execfile calls in order for the secondary script to know about the global variables of the calling script. For example, within a script ‘mainscript.py’, calls to another script ‘myscript.py’ should be written asexecfile(‘myscript.py’, globals())
.