[pyar] Problemas de memory leak

Ale peralta.alejandro en gmail.com
Mar Oct 5 16:03:17 ART 2010


2010/10/5 Roberto Alsina <ralsina en netmanagers.com.ar>

> On Tuesday 05 October 2010 15:51:29 John Rowland Lenton wrote:
> > > Hice así:
> > >
> > >         def __init__(self):
> > >             self.__getattr__ = self.__getitem__
> > >             self.__setattr__ = self.__setitem__
> > >             self.__delattr__ = self.__delitem__
> > >
> > >
> > > Y quedó andando bien.
> >
> > de curioso: por qué en la instancia y no en la clase?
>
> Ya sabiendo que en la instancia no funciona:
>
> >>> class C(dict):
> ...     __getattr__=__getitem__
> ...
> Traceback (most recent call last):
>  File "<stdin>", line 1, in <module>
>  File "<stdin>", line 2, in C
> NameError: name '__getitem__' is not defined
>


Pregunta: No queres entonces esto?
In [1]: class C(dict):
   ...:     __getattr__ = dict.__getitem__
   ...:
   ...:

In [2]: c = C()

In [3]: c['a'] = 42

In [4]: c.a
Out[4]: 42



> _______________________________________________
>



>  pyar mailing list pyar en python.org.ar
> http://listas.python.org.ar/listinfo/pyar
>
> PyAr - Python Argentina - Sitio web: http://www.python.org.ar/
>



-- 
Ale.
------------ próxima parte ------------
Se ha borrado un adjunto en formato HTML...
URL: <http://listas.python.org.ar/pipermail/pyar/attachments/20101005/078fc7e1/attachment.html>


More information about the pyar mailing list