0

I am using dataclass in python.

@dataclassese.dataclass(eq=True)
class ExampleClass:
    x: int = 12
    y: int = x*2

example1 = ExampleClass(x=6)
example2 = ExampleClass(x=6, y=6*2)

In above example, example1 has y set to 24, and example2 y set to 12. Is there a way to have y set to 12 automatically if x is set to another value?

kong0329
  • 81
  • 5
  • 1
    Sounds like you want to make that a `@property` which gets calculated based on `x`… – deceze Apr 12 '20 at 05:47
  • 1
    look here: https://stackoverflow.com/questions/51079503/python-dataclass-and-property-decorator – VPfB Apr 12 '20 at 05:48

0 Answers0