You are doing great. The function os.listdirdoes not open files, so in the end you are fine. You must use the instruction withwhen reading a text file or similar file.
operator example with:
with open('yourtextfile.txt') as file:
lines=file.readlines()
source
share