Understanding Python’s __name__ Variable


Use __name__ to determine if a module is being run directly or being imported.

Source Code

if __name__ == "__main__":
    print("This script is being run directly")
else:
    print("This script is being imported")
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments