Checking list for class instance
2 replies to this topic
Members - Reputation: 2097
Posted 06 March 2012 - 05:24 PM
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.