On Wed, Jan 13, 2010 at 11:15 PM, Guilherme P. de Freitas
<guilhe...@gpfreitas.com> wrote:
> Ok, I got something that seems to work for me. Any comments are welcome.
>
>
> class Member(object):
>    def __init__(self):
>        pass
>
>
> class Body(object):
>    def __init__(self):
>        self.members = []
>
>    def __setattr__(self, obj, value):
>        if isinstance(value, Member):
>            self.members.append(obj)
>            object.__setattr__(self, obj, value)
>        else:
>            object.__setattr__(self, obj, value)

That's fine but there is no need to duplicate the object.__setattr__() call:
   def __setattr__(self, obj, value):
       if isinstance(value, Member):
           self.members.append(obj)
       object.__setattr__(self, obj, value)

>    def __delattr__(self, obj):
>        if isinstance(getattr(self, obj), Member):
>            self.members.remove(obj)
>            object.__delattr__(self, obj)
>        else:
>            object.__delattr__(self, obj)

Same here.

Kent
_______________________________________________
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor

Reply via email to