Sahaj.blogs

Day page

26 Sept 2023

Study

Python · Modules and imports

How import finds modules, the different import forms, packages with __init__.py, and the if __name__ == "__main__" guard.

  • A module is just a .py file, and importing it runs it once and caches it in sys.modules.
  • The __name__ == "__main__" guard keeps test code from running when the file is imported.

Read the post →