So far, every program has been a single file. Real projects span many files, grouped into folders. Modules are single files of Python code; packages are folders that hold them.

What’s in this section

  1. Importing modules — import, from, and as
  2. Creating your own modules — splitting a script into reusable files
  3. Packages — folders of modules
  4. The standard library — a tour of what comes with Python
  5. Running modules as scripts — python -m and if __name__ == "__main__"

Once you can split code across files cleanly, you’re ready to read and write programs at any scale.

Toggle theme (T)