Skip to main content
GameDev.net gamedev.net
🔒 Locked

Checking list for class instance

Started by Munchkin9 Mar 6, 2012 at 10:54 PM 1 replies 1.5k views
Original Post
Munchkin9
Munchkin9
In python:

Is there a way to check for an instance (any instance) of a specific class in a list?


Thank you,
Munchkin9
the_edd
the_edd

for element in thelist:
if isinstance(element, TheClass):
print 'found an instance'


The usual warnings apply; you shouldn't typically have to care about the exact type of an object, only the behaviours it supports. Consider your design carefully.
Munchkin9
Munchkin9
Thank you, that is a bit more complicated than I would have liked but I'm not really surprised about that.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.