Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.
See Part V, Modules in Appendix B for the solutions.
Import basics. Write a program that counts the lines and characters in a file (similar in spirit to wc on Unix). With your text editor, code a Python module called mymod.py that exports three top-level names:
A countLines(name)
function that reads an input file and counts the number of
lines in it (hint: file.readlines does most of the work
for you, and len does the
rest).
A countChars(name)
function that reads an input file and counts the number of
characters in it (hint: file.read returns a single
string).