Next / Previous / Contents / TCC Help System / NM Tech homepage

13.7. The import statement

Like the from statement above, the import statement gives your program access to objects from external modules. The general form is:

import M0, M1, ...

where each Mi is the name of a module.

However, unlike the from statement, the import statement does not add the objects to your local name space. Instead, it adds the name of the module to your local name space, and you can refer to items in that module using the syntax M.name where M is the name of the module and name is the name of the object.

For example, there is a standard module named math that contains a variable named pi and a function named sqrt(). If you import it using

import math

then you can refer to the variable as math.pi and the function as math.sqrt().

If instead you did this:

from math import *

then you could refer to them simply as pi and sqrt().