First, I recommend using factory methods.
If you really need one method, give it something to send parameter processing.
def __init__(self, method, *args, **kw): getattr(self, '_init_'+method)(*args, **kw) def _init_coponents(self, r, g, b): ... def _init_fromColor(self, color): ...
And use like:
c1 = Color('components', 0, 0, 0,) c2 = Color('fromColor', c1)
While this parameter adds another parameter, it is still better than type tests, and it saves explicit data. It provides excellent box exceptions for illegal calls and is easily extensible even in subclasses.
Jürgen Strobel Oct. 16 2018-11-11T00: 00Z
source share