statement, in effect, executes the
module file. Typically, the files we import are defined as sequences of
definitions. Since our main program often begins with a series of
statements, these modules are imported into
the global namespace. Python also optimizes the modules brought in by
statement so that they are only imported
statement can execute a file, a string
of Python code, as well as a
code created by the
compile function. Unlike the
statement, it doesn't optimize module
definitions or create and save a new namespace.
execfile do essentially the same thing.
execfile functions are dangerous
tools. These break one of the Fundamental Assumptions: the source you
are reading is the source that is being executed. A program that uses
function is incorprating other source statements into the program
dynamically. This can be hard to follow, maintain or enhance.
statement is something
that must be used with some care. The most common use is to bring in a
set of configuration parameters written as simple Python assignment
statements. For example, we might use a file like the following as the
configuration paramaters for a program.