Home / Python Tips Generated By ChatGPT / The if __name__ == “__main__” Block in Python Execute code only when the file is run directly, not when imported. Source Code if __name__ == "__main__": print("This runs when the script is executed, not when it's imported.")