W WolfCode · CSC 141

Homework: wc Clone

作业: wc 克隆

≈ 45 min · python-cmdline python-file-io python-functions · Open in WolfCode

A clone of Unix wc. Five functions: three counters, one orchestrator, one parser.

The five functions

  • count_lines(path) — int
  • count_words(path) — int
  • count_chars(path) — int (includes newlines)
  • count_all(path) — tuple, calls the three above
  • parse_args(argv) — argparse with path + 3 flags

The shape

Python · runnable

Acceptance criteria

  • All 8 tests pass
  • Each counter uses with open(...)
  • count_all calls at least 2 of the 3 counters
  • parse_args accepts path + --lines / --words / --chars