I want to create a class in python, which should work like this:
Data assigned, maybe bound to a variable (eg a = exampleclass(data)
or just exampleclass(data)
)
Upon being inserted data, it should automatically determine some properties of the data, and if some certain properties are fullfilled, it will automatically...
... change class to another class
The part 3 is the part that i have problem with. How do i really change the class inside of the class? for example:
If I have two classes, one is Small_Numbers
, and the other is Big_numbers
; now I want any small_number
smaller than 1000 to be transferred into a Big_number
and vice versa, testcode:
a = Small_number(50)
type(a) # should return Small_number.
b = Small_number(234234)
type(b) # should return Big_number.
c = Big_number(2)
type(c) # should return Small_number.
Is this possible to do?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…