Movatterモバイル変換


[0]ホーム

URL:


Newbie question: how to determine "is-a" relationship

Dave Brueckdbrueck at edgix.com
Thu Apr 19 12:14:10 EDT 2001


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__.A1 0 0__main__.B1 1 0__main__.C1 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 AMSubject: Newbie question: how to determine "is-a" relationshipGosh. 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 ofA) 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


More information about the Python-listmailing list

[8]ページ先頭

©2009-2025 Movatter.jp