I recently found out you can use enums in Python, but I'm not happy with how my code is working and I'm wondering if there is a cleaner way to implement it.
from enum import Enum
class Hex:
def __init__(self, hex_code: str):
self.code = hex_code
class Rgb:
def __init__(self, R: int, G: int, B: int):
self.r = R
self.g = G
self.b = B
class Color(Enum):
HEX = Hex
RGB = Rgb
def main():
hex_color = Color.HEX.value('#00FF00')
rgb_color = Color.RGB.value(255, 255, 255)
if __name__ == "__main__":
main()
In this example I have to instantiate by calling the .value()
enum method. but when you instantiate a class normally, all you do is Class(value)
. Would it be possible to implement something similar to enum variants that holds a class?
For example:
Color.HEX('#00FF00')
# Instead of:
Color.HEX.value('#00FF00')