rex.utilities.utilities.parse_year
- parse_year(inp, option='raise')[source]
Attempt to parse a year out of a string.
- Parameters:
inp (str) – String from which year is to be parsed
option (str) –
- Return option:
“bool” will return True if year is found, else False.
Return year int / raise a RuntimeError otherwise
- Returns:
out (int | bool) – Year int parsed from inp, or boolean T/F (if found and option is bool).
Examples
>>> year_str = "NSRDB_2018.h5" >>> parse_year(year_str) 2018
>>> year_str = "NSRDB_2018.h5" >>> parse_year(year_str, option='bool') True
>>> year_str = "NSRDB_TMY.h5" >>> parse_year(year_str) RuntimeError: Cannot parse year from NSRDB_TMY.h5
>>> year_str = "NSRDB_TMY.h5" >>> parse_year(year_str, option='bool') False