I have recently started with Python again, and I am trying to write a module where lots of problems of the following kind occur:
An object Problem
can hold a variable Unit
. Unit can only be either "inches", "millimeters" or "meters".
The module is supposed to be used by others, so I want the most easily usable solution to this. If possible I want the user to receive an error if they try to assign anything but one of those values.
I see this would be possible with objects where I define a unitClass
class that inherits to daughter classes inchesClass
, millimetersClass
and metersClass
. I would then make an instance of each, that the user can assign to the variable in question. But I think this might be confusing, unless that is a standard way to go about such a problem?
The other solution I came up with was set methods but since I don't use them for other variables, I wanted to avoid them in this case as well if possible.
Is there another way to do this using just the modules provided by a standard python installation?
Regards,
RTT