if __name__=='__main__':
这段代码下面的代码不会被其他模块运行,只能在自己的模块中运行
例:
a.py
def hello():
print('Hello World!')
b.py
import a
a.hello()
#result:Hello World!
c.py
if __name__=='__main__':
def hello():
print('Hello World')
d.py
import c
c.hello()
#result:AttributeError: module 'c' has no attribute 'hello'
posted on
浙公网安备 33010602011771号