A discussion from my undergrad seminar: [Tutorial](https://docs.python.org/3/tutorial/inputoutput.html#reading-and-writing-files) says: > It is good practice to use the with keyword when dealing with file objects. Should this be followed in * https://github.com/QuantEcon/lecture-python.myst/blob/main/lectures/short_path.md#exercise-1-1 and * https://github.com/QuantEcon/lecture-python.myst/blob/main/lectures/finite_markov.md#exercise-2-1 ?
Activity
mmcky commentedon Oct 7, 2021
thanks @oyamad this is good feedback.
Context managers are good in practice as they ensure
openfiles areclosedetc.https://book.pythontips.com/en/latest/context_managers.html#context-managers
We do have
infile.close()in that example as the file is built line-by-line.But if the
pythontutorial says we should do -- maybe we should :-).jstac commentedon Dec 27, 2022
@HumphreyYang , could you please address this issue when you have time?