This is Coding Challenge #1 by John Crickett.
The goal of this project is to create a Python-based command-line tool that replicates the functionality of the Unix wc
(word count) command. This tool allows users to count the number of bytes, lines, words, and characters in a given file or from standard input.
Initially, the script was written as mentioned in main.py
- Lack of Standard Input Handling: The initial script did not handle input from standard input (pipes).
- Hardcoded Argument Parsing: The argument parsing was done manually, making the script less flexible and harder to maintain.
- Redundant File Openings: Each function opened the file separately, which was inefficient.
- Error Handling: The error handling was basic and could be improved for better user feedback.
The improved version of the script addresses these issues by using the argparse
library for better argument parsing and support for standard input handling.
- Standard Input Handling: The script now supports reading from standard input using the
-
option. - Efficient Argument Parsing: The
argparse
library simplifies argument parsing and improves maintainability. - File Handling: The script uses context managers to handle file operations efficiently.
- Better Error Handling: Improved error handling and user feedback.
git clone <repository-url>
cd <repository-directory>
Rename the script to ccwc
and make it executable:
mv ccwc.py ccwc
chmod +x ccwc
Move the script to a directory in your PATH:
sudo mv ccwc /usr/local/bin/
ccwc -c <fileName>
ccwc -l <fileName>
ccwc -w <fileName>
ccwc -m <fileName>
echo "Hello, World!" | ccwc -w