Jump to content

View more

Image of the Day

The night is still, but the invasion brings chaos. #screenshotsaturday #hanako #indiegame #gameart #ue4 #samurai https://t.co/cgILXuokoS
IOTD | Top Screenshots

The latest, straight to your Inbox.

Subscribe to GameDev.net Direct to receive the latest updates and exclusive content.


Sign up now

Checking list for class instance

4: Adsense

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.


  • You cannot reply to this topic
2 replies to this topic

#1 Munchkin9   Members   

125
Like
0Likes
Like

Posted 06 March 2012 - 04:54 PM

In python:

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


Thank you,
Munchkin9

#2 e‍dd   Members   

2109
Like
1Likes
Like

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.

#3 Munchkin9   Members   

125
Like
0Likes
Like

Posted 06 March 2012 - 06:40 PM

Thank you, that is a bit more complicated than I would have liked but I'm not really surprised about that.




Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.