Login and get coding
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:# Unix command $ wc wc.py 22 85 771 wc.py # your script $ python wc.py wc.py 22 85 771 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 so for content Hello\nworld Unix'
wcwould return 12 (not 11):$ cat hello hello world $ wc hello 2 2 12 hello
As this is a Beginner Bite we can save you some head aches by suggesting you to use
splitlinesfor the line counts!
See the tests for more info. Thanks Brian for introducing us to
Have fun and keep coding in Python!