liveBook · Manning

Command-line argument

As explained in Build Your Own Robot: Using Python, CRICKIT, and Raspberry Pi

A value supplied to a program when it is launched from a command line.

A command-line argument is a value supplied when a program launches. In robot projects, it lets one application accept a target, command, or other run-specific input without changing its source code. section 4.8 section 10.5

Practical uses include:

  • Pass Python code directly to the interpreter with the -c option. section 4.8
  • Provide a QR-code name as the first argument so the robot can stop at the requested location. section 10.5
  • Combine command-line execution with a robot shell that drives movement commands. section 4.8

Selecting a QR-code destination

Launch the robot application with a target QR-code name as its first command-line argument. The robot then drives forward, scans continuously, and stops when that target is first detected. section 10.5

Evaluating code at launch

Run `python -c 'print(1+1)'` to pass code directly to the Python interpreter; the command prints `2`. section 4.8

How Build Your Own Robot: Using Python, CRICKIT, and Raspberry Pi covers it

How deep it goes
Defines the role and demonstrates uses, but does not show argument-parsing implementation details.
Examples
Demonstrates Python's -c option and a robot application receiving a target QR-code name.
What it assumes
Assumes familiarity with launching Python programs and robot behavior while leaving argument parsing itself unexplained.
What you can do after
Apply it via Python launches to evaluate code or direct a robot toward a selected QR-code destination.
How it connects
Connects command-line arguments with the robot shell, Python interpreter, QR code detection, and robot movement.

Also explained in

Compare how 14 books explain command-line argument →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Build Your Own Robot: Using Python, CRICKIT, and Raspberry Pi. The section links point to the parts of the book it draws on.