Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.
By contrast, the basic import statement runs the file only once per process, and it makes the file a separate module namespace so that its assignments will not change variables in your scope. The price you pay for the namespace partitioning of modules is the need to reload after changes. Version skew note: Python 2.6 also includes an execfile('module.py') built-in function, in addition to allowing the form exec(open('module.py')) , which both automatically read the file's content. Both of these are equivalent to the exec(open('module.py').read()) form, which is more complex but runs in both 2.6 and 3.0. Unfortunately, neither of these two simpler 2.6 forms is available in 3.0, which means you must understand both files and their read methods to fully understand this technique today (alas, this seems to be a case of aesthetics trouncing practicality in 3.0). In fact, the exec form in 3.0 involves so much typing that the best advice may simply be not to do it--it's usually best to launch files by typing system shell command lines or by using the IDLE menu options described in the next section. For more on the file interfaces used by the 3.0 exec form, see Chapter 9. The IDLE User Interface So far, we've seen how to run Python code with the interactive prompt, system com-