Version: 1.1.0

Modules and packages

A Mojo file is a module. A directory with an __init__.mojo is a package. Other files import names from either one.

Essentials

  • import math then call math.sqrt.
  • from math import sqrt binds the name locally.
  • The package name matches the folder name.
  • Cycles between modules are a design problem, not a feature.
  • Tests can live beside the code or in a test package.

Example

from math import sqrt

def main():
    print(sqrt(2.0))

Keep in mind

See Packaging when the module should be installed by other projects.