Using context manager. Improving docstring

This commit is contained in:
Patrick Shriwise 2022-03-11 14:33:34 -06:00
parent 1cdd7084fc
commit 87bde4d72c

View file

@ -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
-------