14 lines
317 B
Python

from pathlib import Path
filenames = ['cats.txt', 'dogs.txt']
for filename in filenames:
print(f"\nReading file: {filename}")
path = Path(filename)
try:
contents = path.read_text()
except FileNotFoundError:
print(" Sorry, I can't find that file.")
else:
print(contents)