Design a Package Layout

Medium ⏱ 12 min 51% acceptance ★★★★☆ 4.4
You are structuring an analytics package with submodules loaders and reports, where reports needs load_csv from loaders. Write the content of analytics/reports.py showing (1) the explicit relative import of load_csv, and (2) a function weekly_report(path) that calls it and returns f'rows: {len(rows)}' where rows is the loaded list.

Examples

Example 1
Input
weekly_report('data.csv')  # loaders.load_csv returns 10 rows
Output
'rows: 10'
Explanation

The relative import binds the sibling module function.

Constraints

  • Use from .loaders import load_csv (relative form).
  • Do not import the whole package absolutely.

Topics

Modules & Packagespackage structure

Companies

GoogleAtlassianServiceNow

Hints

Hint 1

A single leading dot means "same package".

Hint 2

Relative imports only work inside packages — worth saying in an interview.

Loading the Python runtime… Run executes your code and shows printed output; Submit checks your function against this problem's examples.