tunaLandslide / HonorsContract

This is a project for a computational methods class, its purpose is to generate random sentences following the statistical rules of the input text. This project is free to use.
0 stars 0 forks source link

use `with` to open files #3

Closed orbeckst closed 6 years ago

orbeckst commented 6 years ago

Use a context manager (with the with statement) to open files: https://github.com/tunaLandslide/HonorsContract/blob/7d98ccf87a8593f45be11f56e839f2aecfb3c598/mchain.py#L5

with open(file, 'r') as tex:
    ref = tex.read().split()

and tex.close() is not needed. See footnote on HW4, problem 4.4 in assignment_04.pdf

orbeckst commented 6 years ago

Btw, the same trick works for all other cases where you open a file.