Connecting Tech Pros Worldwide Help | Site Map

checking type of my own objects

Tobiah
Guest
 
Posts: n/a
#1: Jul 18 '05
Hi,

I have a module that defines a few classes.
one of them is Event. If I do:

e = Event()
print type(e)

I get back:

<class 'score.Event'>

now to check to see whether a given object
is an Event or not, I could parse the string
output of type, but that does not seem correct.

What is the best way to check the type?

Thanks,

Tobiah

Erik Max Francis
Guest
 
Posts: n/a
#2: Jul 18 '05

re: checking type of my own objects


Tobiah wrote:
[color=blue]
> What is the best way to check the type?[/color]

e.__class__ is Event

or if you want to include subclasses:

isinstance(e, Event)

--
Erik Max Francis && max@alcyone.com && http://www.alcyone.com/max/
__ San Jose, CA, USA && 37 20 N 121 53 W && &tSftDotIotE
/ \ If the sun comes up / And you're not home / I'll be strong
\__/ India Arie
Tobiah
Guest
 
Posts: n/a
#3: Jul 18 '05

re: checking type of my own objects


[color=blue]
> e.__class__ is Event[/color]

I appreciate that, thank you.

Tobiah

Closed Thread