floatref

Tino Wildenhain tino at wildenhain.de
Thu Jul 15 05:48:24 EDT 2010


Hi John,

Am 15.07.2010 09:14, schrieb John Nagle:
> On 7/14/2010 12:56 AM, Roald de Vries wrote:
>> I know, I just wondered if there is a *standard* solution.
>
> Yes, there is.
>
> class floatref(object) :
> def __init__(self, initialval) :
> self.__dict__["_val"] = initialval
> def __getattr__(self, attrname) :
> if attrname == 'val' :
> return(self._val)
> else :
> raise AttributeError(attrname)
> def __setattr__(self, attrname, val) :
> if attrname == 'val' :
> self.__dict__["_val"] = val
> else :
> raise AttributeError(attrname)

Uhm. How would that be different to:

class floatref(object):
     def __init__(self,val):
         self.val=val


?

>
> x = floatref(1.0)
> y = x
>
> print(x.val)
> x.val = 10.0
> print(x.val)
> print(y.val)


Regards
Tino




More information about the Python-list mailing list