February 2024
Beginner
352 pages
8h 16m
English
Remember your checklist for functions, and then do this exercise paying close attention to how functions and files can work together to make useful stuff. You should also continue to type only a few lines before running your code. If you catch yourself typing too many lines, then delete them and do it again. Doing this uses python to train your understanding of Python.
Here’s the code for this exercise. Once again, it’s long, so if you find Jupyter is difficult to use, then write a ex20.py file and run it that way.
Listing 20.1: ex20.py
1 from sys import argv
2
3 input_file = "ex20_test.txt"
4
5 def print_all(f):
6 print(f.read())
7
8 def rewind(f):
9 f.seek(0)
10
11 def print_a_line ...Read now
Unlock full access