Open jzztf opened 6 years ago
__name__
__main__
"__main__"
# 测试文件 #!/usr/bin/env python3 """测试__name__ == '__main__'""" def tester(): print("this is main") if __name__ == '__main__': tester() ===================================== # shell $ python3 test_name.py this is main $ python3 ===================================== # python3 >>> import test_name >>> test_name.__name__ 'test_name'
关于
__name__
和__main__
__name__
属性为字符串"__main__"
__name__
属性为其作为模块的名称