How to check if variable is a specific class in python? -


i have variable "myvar" when print out type(myvar)

the output is:

<class 'my.object.kind'> 

if have list of 10 variables including strings , variables of kind.. how can construct if statement check whether object in list "mylist" of <type 'my.object.kind'>?

use isinstance, return true if instance of subclass:

if isinstance(x, my.object.kind) 

or:

type(x) == my.object.kind #3.x 

if want test in list:

if any(isinstance(x, my.object.kind) x in alist) 

Comments

Popular posts from this blog

image - ClassNotFoundException when add a prebuilt apk into system.img in android -

I need to import mysql 5.1 to 5.5? -

Java, Hibernate, MySQL - store UTC date-time -