from enum import Enum
from typing import Optional
class LaunchMode(Enum):
WINDOW = "new_window"
TAB = "new_tab"
@classmethod
def from_name(cls, name: str) -> Optional["LaunchMode"]:
for member in cls:
if member.name == name:
return member
return None
@classmethod
def from_value(cls, value: str) -> Optional["LaunchMode"]:
try:
return cls(value)
except ValueError:
return None
print(LaunchMode.from_name("TAB"))
print(LaunchMode.from_name("random"))
print(LaunchMode.from_value("new_window"))
print(LaunchMode.from_value("random"))
To embed this project on your website, copy the following code and paste it into your website's HTML: