<html><head><style type="text/css"><!-- DIV {margin:0px;} --></style></head><body><div style="font-family:times new roman, new york, times, serif;font-size:12pt"><div>import sys<br><br>class Float(float):<br>    """<br>    Custom float datatype with addtional attributes.<br>    """<br><br>    def __new__(self,<br>                        value=0.0, #default value<br>                        name='', # string<br>                        range=(0.0, 1.0) #
 tuple<br>                        )<br>                        <br>        try:<br>            self.name = name<br>            self.range = range<br>            self.pos = (1, 1)<br>            return float.__new__(self, value)<br>        except:<br>            print ('Invalid value : Float = %s %s' % (str(value), sys.exc_info()[:2]))<br><br>    <br>    def
 setpos(self, value):<br>        self.pos = value<br>    def getpos(self):<br>        return self.pos*2.0<br>    p = property(getpos, setpos)<br><br>myFloat = Float(0.23)<br>print myFloat.pos<br><br>I am trying to create a custom 'float' datatype by subtyping default 'float'. There are few things I would like to know here:<br><br>1. How to make 'name' & 'range' only readable attributes.<br>2. The property 'p' is not working as it has to. What's wrong here?<br>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__?<br><br>Thanks<br></div></div><br>

      </body></html>