Hi Jake, Try the issubclass and isinstance functions: >>> class A:pass >>> class B(A):pass >>> class C(A):pass >>> q = [A(),B(),C()] >>> for z in q: ... print z.__class__ ... print isinstance(z,A), isinstance(z,B),isinstance(z,C) __main__.A 1 0 0 __main__.B 1 1 0 __main__.C 1 0 1 >>> print issubclass(B,A) 1 >>> print issubclass(A,A) 1 >>> print issubclass(C,A) 1 >>> print issubclass(C,B) 0 -Dave ----- Original Message ----- From: "Jake Baker" <jbaker at ummelec.com> To: <python-list at python.org> Sent: Thursday, April 19, 2001 9:46 AM Subject: Newbie question: how to determine "is-a" relationship Gosh. I've been using Python since 96 and I don't know this! Wow! Say I have a class heirarchy that looks like A, B <- A, C <- A, etc.... I have a list of objects (which I know arbitrarily are all A or sublasses of A) and want to filter them based on which subclass they are. How do I go about doing this? You help is greatly appreciated! Thanks, - Jake Baker -- http://mail.python.org/mailman/listinfo/python-list
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4