Python has three module import function 1, import module using ImportImport ModName: A module is a piece of code that can be used interactively or accessed from another Python program. Whenever you import a module, you can reference any of its public functions, classes, or properties. Modules can use the functionality of other modules in this way.
Importing a module with an import statement establishes a reference to the module in the current namespace (namespace). This reference must use the full name, that is, when you use a function defined in the imported module, you must include the module. So you can't just use funcname, but you should use Modname.funcname.Note: You can add the following to enable Python to support Chinese annotations
#coding: GBK or #coding:utf-8 or ##-*-CODING:GBK-*-
Modules for importing systems
For example, I create a m.py file in the home directory, we import a lot of system modules, such as time,string and so on. This is similar to the Include in C + +
#!/bin/env pythonimport timeimport stringimport reimport socketimport threadingtime.sleep (Ten) print "Java"
Import a private module m.py file
#!/bin/env python#coding:gbk#coding:utf-8# above loading is supported in Chinese note def plus (A, B): # "" "" XXX "" "is a description of the function or use" "" "" "" " this is a test + "" a = a+b return a+b
Load m.py module with import
#!/bin/env python#coding:gbk#coding:utf-8 "Importing the path of the specified Python file using the Sys module" Import syssys.path.append ("./") "Importing Python files" Import Mprint m.plus (12,3) print help (M.plus)
2.From modname Import * Mode loading module
from modname Import funcname
from modname import FA, FB, FC 
or from modname import *
* means that all common objects of the module (public objects) are imported into the current namespace. That is, anything that is not started with "_" will be imported.  
modname is not defined, so modname.funcname this way does not work. Also, if funcname is already defined, it will be replaced by the new version (the version in the Import module). If FuncName is changed to point to other objects, ModName cannot but be aware.  
recommendation:
1) If you want to access the properties and methods of the module frequently, and do not want to knock the module name over and over, use the From module import
2) If you want to selectively import certain properties and methods without any other, use the From module import
3) If the module contains properties and methods that have the same name as one of your modules, you must use the Import module to avoid name collisions
4) Minimize the use of the From module import *, because it is difficult to determine where a particular function or attribute comes from, and it makes debugging and refactoring more difficult.
#!/bin/env python#coding:gbk#coding:utf-8 "Importing the path of the specified Python file using the Sys module" Import syssys.path.append ("./") "Another import Python file" From M import plusprint Plus (12,3) print help (plus)
3, using the Restrained function __import__In addition to the previous two methods of using the Import keyword, we can also use the built-in function __import__ () to import the module. The difference between the two is that the import must follow a type, and the __import__ () argument is a string, which may come from a configuration file, or it may be the result of an expression evaluation. For example
MyModule = __import__ (' module_name ')
notes:
1) The contents of the module are placed in a module file, such as mymodule content should be placed in a mymodule.py in the Pythonpath directory, except for C implementation
2) packages can be organized into several module namespaces, such as A.B, which represents a submodule B in package a
#!/bin/env python#coding:gbk#coding:utf-8 "Importing the path of the specified Python file using the Sys module" Import syssys.path.append ("./") "Another import Python file" my = __import__ ("M") print My.plus (12,3) print help (My.plus)
Resources:1, http://www.cnblogs.com/allenblogs/archive/2011/11/15/2055149.html2, http://blog.csdn.net/chenguolinblog/article/details/11521611
Python Introductory Learning---module import three ways and Chinese notes