I'm not clear how to pose this question. If I did, I'd probably be a lot closer to a solution.. I need some insight into inheritance.
I want to make a custom subtype of float
. But I want the instance of this subtype to re-evaluate it's value before performing any of the normal float methods (__add__
,__mul__
, etc..). In this example it should multiply it's value by the global FACTOR:
class FactorFloat(float):
# I dont think I want to do this:
## def __new__(self, value):
## return float.__new__(self, value)
def __init__(self, value):
float.__init__(self, value)
# something important is missing..
# want to do something with global FACTOR
# when any float method is called
f = FactorFloat(3.)
FACTOR = 10.
print f # 30.0
print f-1 # 29.0
FACTOR = 2.
print f # 6.0
print f-1 # 5.0
This is a just a sanitized example that I think gets my point across. I'll post a more complex "real" problem if necessary.