How to use import statement to load a module
Load a modules
To import only one function with a given name.
After using 'from module import function
',
you can use the function without its module prefix.
from math import sqrt
print sqrt(9)
The code above generates the following result.
Modules can be imported directly using the package or module name.
Items in submodules must be accessed explicitly including the full package name.
import os
print os.path.abspath(".")
The code above generates the following result.
The following code shows the difference between import module and from module import.
import types # w w w. j a v a2s. co m
print types.FunctionType
from types import FunctionType
print FunctionType
The code above generates the following result.