Reputation:
How can i find out if the obj returned by a func is a int or something else (like a sqlite cursor)
Upvotes: 1
Views: 402
Reputation: 295815
Use isinstance(item, type)
-- for instance:
if isinstance(foo, int):
pass # handle this case
However, explicit type checking is not considered a good practice in the Python world -- it means that much of the power of duck typing is lost: Something which walks and quacks like a duck should be allowed to be a duck, even if it isn't! :)
Upvotes: 12