Unix wc clone written in python - The program takes a file as an input and returns number of lines, words and bytes of the file passed. the program can also read multiple files passed together
To use the program, firt clone the project using below shown code:
git clone https://github.com/akamanzi/WordCount.git
Navigate to the project root directory cd WordCount
. In order to run the program, use the command below:
Python3 wc.py path_to_file_name
You could also run the program using any of the sample files located in the testinputs
directory as indicated belwo:
Python3 wc.py testinputs/test_1.txt
just like Unix's wc, this program accepts options:
-L, -l
: for displaying number of lines in a passed file
-w
: displays number of words in a given file
-c
: displays number of bytes of a given file
-L
: displays length of the longest line in a given file
--help
: help for how the program is used
--version
: displays version wc program
--files0-from
: read input from NUL terminated files
-
: reads from standard input
This program uses unittest
testing framework. in order to run tests use the -m
flag to specify unittest
framework as below:
Python3 -m unittest unittest_wc.py
Additionally you could also run the doctests by running the following command:
Python3 doctest_unit_wc.py
NOTE: all the commands above should be run in the root directory. Test files used are located in the testinputs
directory.
- Compatible with python 3.3 and above
- The program does not return accurate values of bytes and words when passed with binary files.