S 0en s 1en__
- 2020-05-09 18:48:55
- OfStack
1. If the module is imported, the value of s 1en__ is the module name
2. If the module is to be directly executed, the value of 's s 3en__ is' s s 4en__'
Py1.py
# ! /usr/bin/env python
def test():
print '__name__ = ',__name__
if __name__ == '__main__':
test()
Py2.py
# ! /usr/bin/env python
import Py1.py
def test():
print '__name__ = ',__name__
if __name__ == '__main__':
test()
print ' Py1.py __name__ = ',Py1.__name__
Execution results:
__name__=__main__
Py1.py __name__=Py1
As can be seen from the results, Py2.py is directly executed, then the value of the built-in variable s = s = s = s = s = s = s = s = s = s = s = s = s = s = s = s = s = s = s = s = s = s = s = s = s = s = s = s = s = s = s = s = s = s = s = s = s = s = s = s = s = s = s = s = s = s = s
if __name__ == '__main__':
test()