理解__name__==__main__

@one.py

1
2
3
4
5
6
7
8
9
def ():
print("This is one.py")

print("Top-level in one.py")

if __name__ == "__main__":
print("one.py is being run directly")
else:
print("one.py is being imported into another module")

@two.py

1
2
3
4
5
6
7
8
9
import one 

print("Top_level in two.py")
one.func()

if __name__ == "__main__":
print("two.py is being run directly")
else:
print("two.py is being imported into another module")