Planet Python

Real Python: Python Project: Build a Word Count Command-Line App

The wc command is a utility that determines the number of lines, words, and bytes in files or standard input. This command is a staple tool for anyone working with text files on Unix-like systems. In this practice exercise, you will build a simplified version of the wc command from scratch using Python. This challenge will solidify your understanding of file handling and text processing and give you a taste of how to structure command-line utilities in Python. By the end of the challenge, you will have a functional version of the wc command that can reproduce the outputs you're accustomed to seeing in a Unix terminal. However, it won't be an exact replica of the wc command, as you'll omit or adapt some features for simplicity. You'll gain hands-on experience with several modules from Python's standard library, such as pathlib and argparse. The challenge is broken down into tasks, each with clear instructions and illustrative examples, and you'll receive automated feedback on your solutions. If you run into issues or have questions, you can ask for help in the comments section or join live conversations during Office Hours. Completing each task unlocks the next one, and you can compare your code with the sample solution provided in the following lesson.
favicon
realpython.com
realpython.com