GH avatar Bite 96. Build Unix' wc program in Python

In this Bite you will convert Unix' wc command into Python. Your function takes a file (absolute path), reads it in and calculates the lines/words/chars. It returns a string of these numbers and the filename, like as a typical wc output, for example:

$ wc
      13      56     514

Don't worry about the amount of white space between the columns, you can use tabs or spaces.

Unix files add an extra newline to the end, you don't have to make that assumption here, so 'Hello\nworld' == 11 chars not 12 as Unix' wc would return. Let's keep it simple. Do note that newline (\n) counts as a char.

See the tests for more info. Thanks Brian for introducing us to pytest's tmp_path fixture!

Have fun and keep coding in Python!

Will you be Pythonista #75 to crack this Bite?
It takes an average of ~47 minutes to solve this Bite (submissions 5-240 min).
Pythonistas rate this Bite 2.0 on a 1-10 difficulty scale.
» You can do it! 😌

Login and get coding
We use Python 3.7