compare types?
pythonhda
pythonhda at yahoo.com.replacepythonwithlinux
Tue Dec 31 13:16:42 EST 2002
It looks like you're trying to compare a "type" object to a "string" object. So they will never match.
You could try to do something like convert the first part to a string:
if str(type(item)) == "<type 'DateTime'>":
Take a look at the "types" module cause there should be a better way than above...
On Tue, 31 Dec 2002 00:03:25 -0700
Kenneth Godee <Ken at perfect-image.com> wrote:
> 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
>
> The only way I found to match is like this...
>
> if type(item) == type(DateTime.now()):
>
> I understand why the above types match
> it just seems like there should be a easier
> way to compare a DateTime type?
> Or is this the way it should be done?
>
>
>
More information about the Python-list
mailing list