newbie class-building question

Gabriel Genellina gagsl-py at yahoo.com.ar
Thu Nov 9 13:29:42 EST 2006


At Thursday 9/11/2006 09:30, jrpfinch wrote:

>I am constructing a simple class to make sure I understand how classes
>work in Python (see below this paragraph).
>
>It works as expected, except the __add__ redefinition.  I get the
>following in the Python interpreter:
>
> >>> a=myListSub()
> >>> a
>[]
> >>> a+[5]
>Traceback (most recent call last):
>   File "<stdin>", line 1, in ?
>TypeError: 'str' object is not callable
> >>>
>
>     def __getattr__ (self,attrib):
>         return getattr(self.wrapped,attrib,'attribute not found')

This is the culprit; should raise AttributeError when not found, not 
return a string.
Just return getattr(self.wrapped, attrib) and let the error propagate.


-- 
Gabriel Genellina
Softlab SRL 

__________________________________________________
Correo Yahoo!
Espacio para todos tus mensajes, antivirus y antispam ¡gratis! 
¡Abrí tu cuenta ya! - http://correo.yahoo.com.ar



More information about the Python-list mailing list