compare types?

Dan Bishop danb_83 at yahoo.com
Tue Dec 31 16:30:28 EST 2002


Kenneth Godee <Ken at perfect-image.com> wrote in message news:<mailman.1041318305.18298.python-list at python.org>...
> I'm trying to iterate thru a tuple and find 
> any DateTime objects.....
> 
> print type(item)
> returns....
> <type 'DateTime'>
> 
> So I thought I could....
> 
> if type(item) == 'DateTime': (or many other variations I tried)
> just can't seem to get a match

Of course you can't.  type doesn't return a string.

if type(item) == DateTime:
would work if you're looking for exact type equality, but you probably want

if isinstance(item, DateTime):
which would also be true if type(item) were a subclass of DateTime.



More information about the Python-list mailing list