Login and get codingIn 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 typicalwc
output, for example:# Unix command $ wc wc.py 22 85 771 wc.py # your script $ python wc.py wc.py 22 85 771 wc.pyDon'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 so for content Hello\nworld Unix'
wc
would return 12 (not 11):$ cat hello hello world $ wc hello 2 2 12 helloAs this is a Beginner Bite we can save you some head aches by suggesting you to use
splitlines
for the line counts!See the tests for more info. Thanks Brian for introducing us to
pytest
'stmp_path
fixture!Have fun and keep coding in Python!
414 out of 427 users completed this Bite.
Will you be the 415th person to crack this Bite?
Resolution time: ~45 min. (avg. submissions of 5-240 min.)
Our community rates this Bite 4.2 on a 1-10 difficulty scale.
» Up for a challenge? 💪