← All notes

Python cmd: a framework for line-oriented command interpreters

Answer: Cmd is a simple framework for writing line-oriented command interpreters.

How a session works

A command interpreter built with this class typically presents the user with an interactive prompt.

It reads input one line at a time.

It then dispatches each command to a method named do followed by the command name.

cmdloop repeatedly issues a prompt, accepts input, and dispatches to action methods.

How to extend it

These interpreters are often useful for test harnesses, administrative tools, and prototypes.

There is no good reason to instantiate Cmd itself.

It is useful as a superclass of an interpreter class you define yourself.

Most of the interpreter behavior is defined by the do methods you add in your own subclass.

See also

Claims

Sources

License: this note is CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Summary by iinventedlight (AI-assisted). Sources: Python Software Foundation, cmd — Support for line-oriented command interpreters; CPython, cmd documentation (source). PSF-2.0 (https://docs.python.org/3/license.html). Copyright Python Software Foundation. Text was condensed and changed from the originals.

License: CC-BY-4.0 · Summary by iinventedlight (AI-assisted). Sources: Python Software Foundation, cmd — Support for line-oriented command interpreters; CPython, cmd documentation (source). PSF-2.0 (https://docs.python.org/3/license.html). Copyright Python Software Foundation.

Cite this

Permanent ID: iil:note:zekmd162

iinventedlight. 2026. "Python cmd: a framework for line-oriented command interpreters." iinventedlight Library, iil:note:zekmd162, version of 2026-11-24. https://iinventedlight.com/library/notes/python-cmd/. License: CC-BY-4.0.

@misc{iil_note_zekmd162,
  author = {{iinventedlight}},
  title = {{Python cmd: a framework for line-oriented command interpreters}},
  howpublished = {iinventedlight Library},
  year = {2026},
  date = {2026-11-24},
  url = {https://iinventedlight.com/library/notes/python-cmd/},
  note = {Permanent ID iil:note:zekmd162. License: CC-BY-4.0.},
}

Markdown

Spotted a mistake? Use the MCP feedback tool or email hello@iinventedlight.com. Or Report a correction (no account needed).

Extra files beside this note

These files use this note's license, shown below. Paper extras retain their reproduction status; a link is not a reproduction.

All artifact files (JSON index)

For language models and agents: start at /llms.txt | /agents.md | /.well-known/agent-library.json. This page in Markdown: /library/notes/python-cmd.md.