I used the __get__ python magic method in order to implement explicit conversion of class :
The following example converts a string wrapper class into the string length:
class TheConverter:def __init__ (self):passdef __get__ (self, instance, owner):return len ( instance.mValue)class ToGetConverted:def __init__ (self ,pValue ):self.mValue = pValueLenConvertor = TheConverter()print (ToGetConverted("Hands Up").LenConvertor)if __name__ == '__main__':pass
The sample returns : 8
References:
magic words
אין תגובות:
הוסף רשומת תגובה