Back to Course
Python Essentials: The Engineering Approach
Module 10 of 20
10. Modules & Packages
The Import System
When you import a file, Python runs the entire file from top to bottom.
__name__ == "__main__"
This pattern prevents code from running when a file is imported.
pythondef run(): print("Running app...") if __name__ == "__main__": # This block only runs if you do: python file.py # It does NOT run if you do: import file run()
Packages
A folder becomes a package if it has an __init__.py file (though optional in recent Python, it's still good practice).