Python模块

1.引入其他模块

from printme import sayHi
sayHi()

或者

import printme
printme.sayHi()

 

当一个模块被第一次输入的时候,这个模块的主块将被运行。

如果我们只想程序本身被使用的时候运行主块,而在它被其他模块输入的时候不运行主块

编写primtme.py

def sayHi():
    pass

if __name__ == '__main__':
    print 'This is run by self'
else:
    print 'This is run by other module'

编写printmeTest.py

import printme
printme.sayHi()

2.查看模块中内容

dir(模块名)

3.模块安装

python setup.py install
posted @ 2016-06-12 14:51  Kimisme  阅读(167)  评论(0)    收藏  举报