Custom 'Float' class. Am I right here?
animator333 at yahoo.com
Wed Jul 16 16:53:13 CEST 2008
Custom float datatype with addtional attributes.
value=0.0, #default value
name='', # string
range=(0.0, 1.0) # tuple
self.name = name
self.range = range
self.pos = (1, 1)
return float.__new__(self, value)
print ('Invalid value : Float = %s %s' % (str(value), sys.exc_info()[:2]))
def setpos(self, value):
self.pos = value
p = property(getpos, setpos)
myFloat = Float(0.23)
I am trying to create a custom 'float' datatype by subtyping default 'float'. There are few things I would like to know here:
1. How to make 'name' & 'range' only readable attributes.
2. The property 'p' is not working as it has to. What's wrong here?
3. I would be heavily instancing this class, and I won't be creating any new attribute on instance. Is there any way to optimize? __slots__?
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Python-list