Apply everything from CS 111 by building a complete command-line application from scratch.
Work through the concepts using Python in your editor or Replit. Use the knowledge check below to test yourself.
Open a Python file and implement the core concepts from this lesson. Start small, test each part, then combine.
In a CLI application, what does parsing arguments mean?
Argument parsing reads command-line flags and values (like --output file.txt) and makes them available to your program.
Parsing processes input (command-line arguments). Printing is output to the user.
Python stays Python. Argument parsing is about processing sys.argv or using argparse to handle CLI input.
Which module provides argument parsing for CLI tools?
sys.argv is a list of raw string arguments. argparse parses them into named flags and values with help text.
os.path, os.getcwd(), etc. are for file system operations. argparse handles command-line arguments.
json.loads() parses JSON strings. argparse parses command-line arguments.
What is the purpose of a __main__.py file in a package?
__main__.py makes a package runnable with 'python -m packagename'. It's the entry point for package execution.
__main__.py is the entry point when running a package as a script. Constants can be defined anywhere.
__init__.py runs when a package is imported. __main__.py runs when a package is executed with -m.
Which is the best approach for error handling in a CLI tool?
Tracebacks expose internals and confuse users. Catch exceptions, print clear messages, and exit with a non-zero status code.
Swallowing exceptions hides bugs and leaves users confused. Handle errors explicitly with clear messages.
A single global try/except loses context about where the error occurred. Handle exceptions at the appropriate level.
When should you break a large script into modules?
Single-file scripts are fine for small programs. As a project grows, modules improve organization and testability.
A 500-line file with unrelated functions is worse than a 1000-line file that's well-organized. Split by logical responsibility.
Module splitting is about logical organization and reuse, not a fixed function count threshold.