[pyar] Fwd: Como reemplazar todas las referencias a n objeto con otro?

Claudio Freire klaussfreire en gmail.com
Mie Jun 9 11:11:40 ART 2010


2010/6/9 Juanjo Conti <jjconti en gmail.com>

>
>
> 2010/6/8 Claudio Freire <klaussfreire en gmail.com>
>
>> class Maybe:
>>
>>    def __init__(self, value):
>>        self.__dict__["__val"] = value
>>    def borrar(self):
>>        self.__dict__["__val"] = "borrado"
>>    def __getattr__(self, name):
>>        if name in self.__dict__:
>>             return self.__dict__[name]
>>        return getattr(self.__dict__["__val"], name)
>>    def __setattr__(self, name, value):
>>        if name in self.__dict__:
>>             self.__dict__[name] = value
>>             return
>>        return setattr(self.__dict__["__val"], name, value)
>>    def __delattr__(self, name):
>>        if name in self.__dict__:
>>             del self.__dict__[name]
>>             return
>>        return delattr(self.__dict__["__val"], name)
>>
>
> Puede servir. Cual es el propósito de los chequeos del tipo if name in
> self.__dict__ ?


Para poder llamar a borrar().
------------ próxima parte ------------
Se ha borrado un adjunto en formato HTML...
URL: <http://listas.python.org.ar/pipermail/pyar/attachments/20100609/76f7bbf2/attachment.html>


More information about the pyar mailing list