26 out of 26 users completed this Bite ...
Will you be Pythonista #27 to crack this Bite?
Average Bite difficulty 1-10 rating: 1.0
» You can do it! 😌
In this Bite you will convert Unix'
wccommand 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
wcoutput, for example:$ wc wc.py 13 56 514 wc.py
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'
wcwould return. Let's keep it simple. Do note that newline (\n) counts as a char.
See the tests for more info. We used
tempfile.NamedTemporaryFileto work with temp files, pretty useful module.
Have fun and keep coding in Python!