0

Lets say an Object has three numerical properties that I would like to have as member variables (eg, if talking about a Person, perhaps height, age, and income.) Call these a, b, and c. However, they are not independent: c = a / b.

I would like to be able to create an Object using either a and b, or c and one of a and b. In other words, object = Object(a = 1, b = 2) and object = Object(a = 1, c = 0.5) should both work, and then we would have object.a == 1 and object.b == 2 and object.c == 0.5. object = Object(a = 1, b = 2, c = 10) should produce an error.

In other languages I might design Object with multiples constructors, one for each possible combination.

What is the cleanest way to implement something like this in Python?

Heisenbugs
  • 33
  • 4

0 Answers0