compare types?
Gerhard Häring
gerhard.haering at gmx.de
Tue Dec 31 13:28:17 EST 2002
* pythonhda <pythonhda at yahoo.com.replacepythonwithlinux> [2002-12-31 13:16 -0500]:
> 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'>":
This is not a good idea, and the best answer has already been mentioned:
use isinstance!
OTOH if you really really want to check for the exact type (and not
possible subclasses thereof), you can do:
type(item) is DateTimeType
But as there's probably no reason to do so please use
isinstance(item, DateTimeType) :-)
Gerhard
--
Favourite database: http://www.postgresql.org/
Favourite programming language: http://www.python.org/
Combine the two: http://pypgsql.sf.net/
Embedded database for Python: http://pysqlite.sf.net/
More information about the Python-list
mailing list