What is the class of myobj?

Xiao-Qin Xia xx758 at cam.ac.uk
Wed Oct 16 06:29:57 EDT 2002


I guess the following code is what you want:

Class MyClass: pass
myobj = MyClass()
if myobj.__class__.__name__ == "MyClass": print "OK!"
if myobj.__class__ == MyClass: print "OK!"

Cheers,
Xiao-Qin Xia


JXStern wrote:

> I want to write something like:
> 
> If ClassOf(myobj) == "MyClass": print "OK!"
>   or
> If ClassOf(myobj) == MyClass: print "OK!"   # no quotes on class
> 
> The best I've found in Python is based on str(myobj.__class__).
> 
> What's the official way?
> 
> Thanks.
> 
> Newbie still,
> Joshua Stern




More information about the Python-list mailing list