Modules and several files

Split a program into files and import them; what the standard library offers without installing anything.

Runs in Zerethon IDE · Python 3.12 Official Python documentation ↗
main.py
from geometry import area
import math

print(area(3, 4))
print(round(math.pi, 3), math.sqrt(16))
geometry.py
def area(width, height):
    return width * height

Output

12
3.142 4.0
Two files: main.py (the entry, run by Run) and geometry.py next to it.
  • A file geometry.py is imported as geometry; a folder utils/ with utils/text.py is imported as utils.text.
  • The whole standard library is available (math, random, datetime, collections, itertools, json, re, …).
  • Third-party packages (pip install) are not available: runs have no network and nothing is installed during a run.

Related topics

Official references