diff --git a/openmc/weight_windows.py b/openmc/weight_windows.py index 7cb9d1036a..1a54c1b9bd 100644 --- a/openmc/weight_windows.py +++ b/openmc/weight_windows.py @@ -419,38 +419,39 @@ def __wwinp_reader(path): path : str or pathlib.Path Location of the wwinp file """ - fh = open(path, 'r') - # read the first line of the file and - # keep only the first four entries - while(True): - line = next(fh) - if line and not line.startswith('c'): - break + with open(path, 'r') as fh: - values = line.strip().split()[:4] - for value in values: - yield value + # read the first line of the file and + # keep only the first four entries + while True: + line = next(fh) + if line and not line.startswith('c'): + break - # the remainder of the file can be read as - # sequential values - while(True): - line = next(fh) - # skip empty or commented lines - if not line or line.startswith('c'): - continue - values = line.strip().split() + values = line.strip().split()[:4] for value in values: yield value + # the remainder of the file can be read as + # sequential values + while True: + line = next(fh) + # skip empty or commented lines + if not line or line.startswith('c'): + continue + values = line.strip().split() + for value in values: + yield value + def wwinp_to_wws(path): """Creates WeightWindows classes from a wwinp file Parameters ---------- - path : str - Path to the wwinp file. + path : str or pathlib.Path object + Path to the wwinp file Returns -------