Sean McIlroy a écrit :
> hi all
> 
> is there a way to do this ...
> 
> class clown:
>       def __init__(self):
>               self.x = 0
>               self.y = ALIAS(self.x) ## FEASIBLE ?

class Alias(object):
    def __init__(self, attrname):
      self._attrname = attrname

    def __get__(self, instance, cls):
      if instance is None:
        return self
      return getattr(instance, self._attrname)

    def __set__(self, instance, value):
      setattr(instance, self._attrname, value)

class Clown2(object):
   def __init__(self):
     self.x = 0

   y = Alias('x')



-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to