W WolfCode · CSC 141
Chapter 08

Command-Line Interface

命令行接口

Scripts become tools. sys.argv for the raw approach, argparse for proper ones — with --help, type validation, defaults, and exit codes for free. Build a Unix wc clone.

Strict source: ATBS Appendix B + Python stdlib sys and argparse

Note: browser playgrounds can't run with real sys.argv. The function-takes-argv pattern (parse_args([...])) works everywhere.

Lessons in this chapter

  1. 08.00 Worked Example
    Walkthrough: sys.argv Greeter
    例题: 命令行问候
    python-cmdline
    8 min
  2. 08.01 Exercise
    Sum from argv
    命令行求和
    python-cmdline
    15 min
  3. 08.02 Exercise
    argparse Basics
    argparse 入门
    python-cmdline
    20 min
  4. 08.03 Exercise
    argparse Defaults
    argparse 默认值
    python-cmdline
    20 min
  5. 08.04 Homework
    Homework: wc Clone
    作业: wc 克隆
    python-cmdline python-file-io python-functions
    45 min