Python 的特殊变量 __name__

This commit is contained in:
YuCheng Hu 2021-03-18 23:42:29 -04:00
parent 59f60078cb
commit 3daaced0ee
No known key found for this signature in database
GPG Key ID: 1E5CBEF8B550FB7D
2 changed files with 27 additions and 0 deletions

View File

@ -0,0 +1,13 @@
# -*- coding: utf-8 -*-
# Python __name__ module ImportVarName
# Author - HoneyMoose(huyuchengus@gmail.com)
# Link Article - https://www.ossez.com/t/python-name/13393
print("ImportVarName __name__ = %s" % __name__)
if __name__ == "__main__":
print("ImportVarName is being run directly")
else:
print("ImportVarName is being imported")

View File

@ -0,0 +1,14 @@
# -*- coding: utf-8 -*-
# Python __name__ module Test
# Author - HoneyMoose(huyuchengus@gmail.com)
# Link Article - https://www.ossez.com/t/python-name/13393
import ImportVarName
print("Main VarName __name__ = %s" % __name__)
if __name__ == "__main__":
print("VarName is being run directly")
else:
print("VarName is being imported")