Medium
A Writer That Counts Lines
Write a class
CountingWriter(path): __enter__ opens the file and returns self, it has write_line(s) that writes s plus a newline and counts it, and __exit__ closes the file and prints wrote N lines. Write each input word on its own line to out.txt, then print the file.Input
Words separated by spaces.
Output
Lines.
Sample 1
Input
a b c
Output
wrote 3 lines a b c
Sample 2
Input
hello
Output
wrote 1 lines hello
Output appears here