您的位置:首页 > 编程语言 > Python开发

Python模块

2016-06-12 14:51 405 查看
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
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: