Forums
New posts
Search forums
Members
Current visitors
Log in
Register
What's new
Search
Search
Search titles only
By:
New posts
Search forums
Menu
Log in
Register
Install the app
Install
Forums
Archive
Archive
Python
instance and class-hierarchy ?
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Reply to thread
Message
[QUOTE="I V, post: 1872191"] If I understand you correctly, isinstance ought to do the job: class A(object): pass class B(A): pass class C(B): pass c = C() assert isinstance(c, C) assert isinstance(c, B) assert isinstance(c, A) However, I'm not sure it's great style to have to inquire about the type of an object, as I would worry it would be fragile if you redesign your class hierarchy. Maybe an alternative would be to add a method to your 'C' class to accomplish whatever it is you need to do? Still, if that doesn't work (sometimes algorithms just are tightly coupled to the specific class hierarchy, and you can't avoid it), isinstance should work. [/QUOTE]
Verification
Post reply
Forums
Archive
Archive
Python
instance and class-hierarchy ?
Top