Python体验(02)-模块Module
Module:mymodule.py
#!/usr/bin/python
#filename:mymodule.py
def sayhi():
print "Hi,This is Phoenix IKKI. From Module: mymodule."
version = '0.1'
#End of mymodule.py
#filename:mymodule.py
def sayhi():
print "Hi,This is Phoenix IKKI. From Module: mymodule."
version = '0.1'
#End of mymodule.py
实例1:直接导入模块,调用模块内函数及变量需要采用模块前缀。
#!/usr/bin/python
#filename:mymodule_demo.py
import mymodule
mymodule.sayhi()
print 'Version:',mymodule.version
#filename:mymodule_demo.py
import mymodule
mymodule.sayhi()
print 'Version:',mymodule.version
实例2:显式导入模块函数及变量,调用模块的函数及变量不能加前缀。
#!/usr/bin/python
#filename:mymodule_demo2.py
from mymodule import sayhi,version
#from mymodule import *
sayhi()
print 'Version:',version
#dir(mymodule)
#filename:mymodule_demo2.py
from mymodule import sayhi,version
#from mymodule import *
sayhi()
print 'Version:',version
#dir(mymodule)