S
Sergey Krushinsky
Hello all,
Is there a common way to emulate constructor overloading in Python class?
For instanse, I have 3 classes:
1/ Polar - to hold polar coordinates;
2/ Cartesian - to hold cartesian coordinates;
3/ Coordinates3D, which holds synchronized instances of the both in
__p__ and __c__ fields respectively.
I want to design Coordinates3D so that when instantiated with Polar
argument, self.__p__=argument passed to constructor, and self.__c__ is
calculated. When argument is Cartesian, self.__c__=argument, and
self.__p__ is calculated. Runtime type checking works, but maybe there
is a better way?
Thanks in advance,
Sergey
Is there a common way to emulate constructor overloading in Python class?
For instanse, I have 3 classes:
1/ Polar - to hold polar coordinates;
2/ Cartesian - to hold cartesian coordinates;
3/ Coordinates3D, which holds synchronized instances of the both in
__p__ and __c__ fields respectively.
I want to design Coordinates3D so that when instantiated with Polar
argument, self.__p__=argument passed to constructor, and self.__c__ is
calculated. When argument is Cartesian, self.__c__=argument, and
self.__p__ is calculated. Runtime type checking works, but maybe there
is a better way?
Thanks in advance,
Sergey