The code
import config
just import the module named config,if you want to use a method of it,you need to use something like myname = config.getName()
.
The code
from config import *
will import everything exported by config
to current namespace. Now if you want to use the getName method in config,the code is something like myname = getName()
We always use the first importing way,because you can use different methods with the same name exported by more than one module. For example,we can use two getName
method below:
import config
import mydata
print config.getName()#print Jim
print mydata.getName()#print Tom
When you do it in the second way like,the last import code will import the getName
method replace the one you has imported by the first import code:
from config import *
from mydata import *
print getName()#print Tom
So you can see,the current namespace is polluted by the second way.