Skip to content
Snippets Groups Projects
Commit 0e3571eb authored by Frisinghelli Daniel's avatar Frisinghelli Daniel
Browse files

Added a new utility function to check if an item exists in an enum.Enum

parent 5ddd6ab4
No related branches found
No related tags found
No related merge requests found
......@@ -490,3 +490,14 @@ def doy2date(year, doy):
datetime.timedelta(days=(int(doy) - 1)))
return date
def item_in_enum(name, enum):
# check whether the input name exists in the enumeration
if name not in enum.__members__:
raise ValueError('{} is not in {} enumeration. Valid names are: \n {}'
.format(name, enum.__name__,
'\n'.join('- {}'.format(n) for n in
enum.__members__)))
else:
return enum.__members__[name].value
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment