Coincido con Andrei :)<br><br>En cuanto a lo que comentas, Manuel, no puedes llamar al padre usando old-style, la que estarías mezclando objetos y tipos. Para mantener la interfaz de getattr funciona así:<br><br>class EasyDict:<br>
    def __init__(self):<br>        self._values = {}<br><br>    def add(self, k, v):<br>        self._values[k] = v<br><br>    def __getattr__(self, name):<br>        if name in self._values:<br>            return self._values[name]<br>
        raise AttributeError<br><br>    def __str__(self):<br>        return str(self._values)<br><br>y creo que te referías a este otro cuando hablas de llamar al padre:<br><br>class EasyDict(dict):<br>    def add(self, k, v):<br>
        self[k] = v<br><br>    def __getattr__(self, name):<br>        try:<br>            return super(EasyDict, self).__geattr__(name)<br>        except AttributeError:<br>            if name in self:<br>                return self[name]<br>
            raise AttributeError<br><br>al estar extendiendo un diccionario propiamente dicho, aquí si puedes hacer la llamada al padre.<br><br>Un saludo,<br>Vicente Ruiz<br><br><div class="gmail_quote">El 12 de abril de 2012 09:23, Andrey Antoukh <span dir="ltr"><<a href="mailto:andsux@gmail.com">andsux@gmail.com</a>></span> escribió:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Usar oldclass hoy en día debe ser un crimen penal! xD<div><br></div><div>Andrei. ;)<br><br><div class="gmail_quote">El 12 de abril de 2012 09:13, Manuel de la Peña <span dir="ltr"><<a href="mailto:etil15@gmail.com" target="_blank">etil15@gmail.com</a>></span> escribió:<div>
<div class="h5"><br>

<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div><p><br>
On Apr 12, 2012 8:54 AM, "Vicente Ruiz" <<a href="mailto:vruiz2.0@gmail.com" target="_blank">vruiz2.0@gmail.com</a>> wrote:<br>
><br>
> Hola Miguel Ángel,<br>
><br>
> es una pregunta muy buena :) La verdad es que me ha costado un rato dar con el problema. Prueba cambiar esto:<br>
><br>
> class EasyDict: --> class EasyDict(object):<br>
><br>
> Esto se debe a que en las versiones anteriores a Python 3.x existen 2 tipos de clases: new-style y old-style. Esto desaparece en Python 3, siendo todas new-style. Puedes leer más sobre el tema aquí: <a href="http://docs.python.org/reference/datamodel.html#new-style-and-classic-classes" target="_blank">http://docs.python.org/reference/datamodel.html#new-style-and-classic-classes</a><br>




><br>
> Un saludo,<br>
> Vicente Ruiz</p>
</div><p>Buenas,</p>
<p>Acá van mis 2c, la implementación no es totalmente correcta ya que tiene los siguientes fallos:</p>
<p>1. Estas devolviendo None cuando el valor no está en el dict. Esto rompe la interfaz de getattr, lo correcto sería lanzar la excepción AtributeError.<br>
2. No estas llamando al getattr del parental class cosa que es probablemente recomendable, yo haría algo como:</p>
<p>def __getattr__(self, name):<br>
    try:<br>
        return super(Easydict, self).__geattr__(name)<br>
    except AttributeError:<br>
        if name in self.dict:<br>
            return self.dict [name]<br>
        raise AttributeError</p>
<p>Creo recordar que si era un new class puedes usar super de está forma, pero no lo he probado por que estoy en el metro : P.</p>
<p>Saludos</p><div><div><br>
><br>
> El 12 de abril de 2012 08:25, Kiko <<a href="mailto:kikocorreoso@gmail.com" target="_blank">kikocorreoso@gmail.com</a>> escribió:<br>
><br>
>><br>
>><br>
>> El 12 de abril de 2012 07:58, Miguel Angel <<a href="mailto:miguelangel.garcia@gmail.com" target="_blank">miguelangel.garcia@gmail.com</a>> escribió:<br>
>><br>
>>> Hola!<br>
>>><br>
>>> Tengo un problema y no sabía muy bien dónde preguntar... No sé si esta lista se utiliza sólo para las reuniones o las preguntas también tienen cabida. <br>
>><br>
>><br>
>> A priori no hay ningún problema con las preguntas pero la finalidad de esta lista es un poco de organización de python-madrid, las quedadas y cosas así.<br>
>><br>
>> Seguro que muchos de esta lista te podrán responder pero para el futuro es más adecuado que para las dudas técnicas de python acudas a:<br>
>><br>
>>  -la lista python-es  (<a href="http://mail.python.org/mailman/listinfo/python-es" target="_blank">http://mail.python.org/mailman/listinfo/python-es</a>).<br>
>>  -a python.majibu (<a href="http://python.majibu.org/" target="_blank">http://python.majibu.org/</a>)<br>
>><br>
>> Donde hay mucha más gente que en esta lista y cuyo objetivo es ese, resolver dudas técnicas<br>
>><br>
>> Saludos.<br>
>><br>
>> -- <br>
>> Grupo de usuarios de python ubicados en Madrid<br>
>> <a href="http://groups.google.es/group/python-madrid" target="_blank">http://groups.google.es/group/python-madrid</a><br>
>> <a href="http://python-madrid.es" target="_blank">http://python-madrid.es</a><br>
>> <a href="http://twitter.com/#%21/python_madrid" target="_blank">http://twitter.com/#!/python_madrid</a><br>
>> Para darte de baja del grupo envía un mensaje a <a href="mailto:python-madrid%2Bunsubscribe@googlegroups.com" target="_blank">python-madrid+unsubscribe@googlegroups.com</a><br>
><br>
><br>
><br>
><br>
> -- <br>
> Disponible en:<br>
><br>
> <a href="http://www.vicenteruiz.es/" target="_blank">http://www.vicenteruiz.es/</a><br>
> <a href="http://www.menudoproblema.es/" target="_blank">http://www.menudoproblema.es/</a><br>
> Twitter - LinkedIn<br>
><br>
> -- <br>
> Grupo de usuarios de python ubicados en Madrid<br>
> <a href="http://groups.google.es/group/python-madrid" target="_blank">http://groups.google.es/group/python-madrid</a><br>
> <a href="http://python-madrid.es" target="_blank">http://python-madrid.es</a><br>
> <a href="http://twitter.com/#%21/python_madrid" target="_blank">http://twitter.com/#!/python_madrid</a><br>
> Para darte de baja del grupo envía un mensaje a <a href="mailto:python-madrid%2Bunsubscribe@googlegroups.com" target="_blank">python-madrid+unsubscribe@googlegroups.com</a><br>
</div></div><p></p><div><div>

<p></p>

-- <br>
Grupo de usuarios de python ubicados en Madrid<br>
<a href="http://groups.google.es/group/python-madrid" target="_blank">http://groups.google.es/group/python-madrid</a><br>
<a href="http://python-madrid.es" target="_blank">http://python-madrid.es</a><br>
<a href="http://twitter.com/#%21/python_madrid" target="_blank">http://twitter.com/#!/python_madrid</a><br>
Para darte de baja del grupo envía un mensaje a <a href="mailto:python-madrid%2Bunsubscribe@googlegroups.com" target="_blank">python-madrid+unsubscribe@googlegroups.com</a><br>
</div></div></blockquote></div></div></div><span class="HOEnZb"><font color="#888888"><br><br clear="all"><div><br></div>-- <br>Andrei Antoukh - <<a href="mailto:niwi@niwi.be" target="_blank">niwi@niwi.be</a>><br><a href="http://www.niwi.be/page/about/" target="_blank">http://www.niwi.be/page/about/</a><br>


<a href="http://www.kaleidos.net/A5694F/" target="_blank">http://www.kaleidos.net/A5694F/</a><br><br>"Linux is for people who hate Windows, BSD is for people who love UNIX"<br>"Social Engineer -> Because there is no patch for human stupidity"<br>



</font></span></div><div class="HOEnZb"><div class="h5">

<p></p>

-- <br>
Grupo de usuarios de python ubicados en Madrid<br>
<a href="http://groups.google.es/group/python-madrid" target="_blank">http://groups.google.es/group/python-madrid</a><br>
<a href="http://python-madrid.es" target="_blank">http://python-madrid.es</a><br>
<a href="http://twitter.com/#%21/python_madrid" target="_blank">http://twitter.com/#!/python_madrid</a><br>
Para darte de baja del grupo envía un mensaje a <a href="mailto:python-madrid%2Bunsubscribe@googlegroups.com" target="_blank">python-madrid+unsubscribe@googlegroups.com</a><br>
</div></div></blockquote></div><br><br clear="all"><br>-- <br><i><span style="color:rgb(102,102,102)">Disponible en:</span></i><span><font color="#888888"><br><br></font></span><div style="margin-left:40px"><span><font color="#888888"><a href="http://www.vicenteruiz.es/" target="_blank">http://www.vicenteruiz.es/</a></font></span><br>
<span><font color="#888888"><a href="http://es.linkedin.com/in/alvarohurtado" target="_blank">http://www.menudoproblema.es/</a></font></span><br><span><font color="#888888"><a href="http://twitter.com/menudoproblema" target="_blank">Twitter</a> - <a href="http://es.linkedin.com/in/vicenteruiz" target="_blank">LinkedIn</a></font></span><br>
<span></span></div><span></span><br>

<p></p>

-- <br />
Grupo de usuarios de python ubicados en Madrid<br />
<a href="http://groups.google.es/group/python-madrid">http://groups.google.es/group/python-madrid</a><br />
<a href="http://python-madrid.es">http://python-madrid.es</a><br />
<a href="http://twitter.com/#!/python_madrid">http://twitter.com/#!/python_madrid</a><br />
Para darte de baja del grupo envía un mensaje a python-madrid+unsubscribe@googlegroups.com<br />