[Tutor] Keeping a list of attributes of a certain type

Alan Gauld alan.gauld at btinternet.com
Thu Jan 14 13:52:22 CET 2010


"Guilherme P. de Freitas" <guilherme at gpfreitas.com> wrote

> Here is my problem. I have two classes, 'Body' and 'Member', and some
> attributes of 'Body' can be of type 'Member', but some may not. The
> precise attributes that 'Body' has depend from instance to instance,
> and they can be added or deleted. I need any instance of 'Body' to
> keep an up-to-date list of all its attributes that belong to the class
> 'Member'. How do I do this?

Check the type of the attribute? Using isinstance()?

I'm not sure of the rationale - why it needs to know the type etc
But isinstance is the most obvious way that I can think of.

Alan G.



More information about the Tutor mailing list