module 模块

atestmodule.py

#!/usr/bin/env python3
# -*- coding: utf-8 -*-

'a test module'

def addFunc(a,b):
    return a+b

if __name__ == '__main__':
    print('atestmodule计算结果:',addFunc(1,1))

anothertestmodule.py

SRE实战 互联网时代守护先锋,助力企业售后服务体系运筹帷幄!一键直达领取阿里云限量特价优惠。
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

' a test module '

import atestmodule

print('调用anothermodule模块执行的结果是:',atestmodule.addFunc(12,23))

__name__ == 'main'的作用是为了使得Make a script both importable and executable,也就是说可以让模块既可以导入到别的模块中用,另外该模块自己也可执行。

参考文章

python使用模块

扫码关注我们
微信号:SRE实战
拒绝背锅 运筹帷幄