more robust:

* split(maxsplit=1) will raise ValueError if split into two strings is not
  possible
* int('a') will raise ValueError if 'a' cannot be interpreted as an
  integer
This commit is contained in:
Martin Diehl 2020-01-26 10:34:30 +01:00
parent 6fed655500
commit ed9347e9bd
1 changed files with 2 additions and 2 deletions

View File

@ -76,11 +76,11 @@ class Table():
try:
N_comment_lines,keyword = f.readline().strip().split(maxsplit=1)
if keyword != 'header':
raise TypeError
raise ValueError
else:
comments = [f.readline().strip() for i in range(1,int(N_comment_lines))]
labels = f.readline().split()
except TypeError:
except ValueError:
f.seek(0)
comments = []
line = f.readline().strip()