with open('foo.txt', 'w') as f:
f.write('hello world\n')
Using print for that doesn't bring much on the table and a newcomer reading the code would wonder why.Plus really most IRL works just need:
Path('foo.txt').write_text('hello world\n')
Also you never really use readline(), since files are iterable, you generally just loop with for on it.I don't think that's the point of the author. The point is that they look like enough if you remove the cruft, that you can make helpful associations to learn the one you don't know.