user34537
user34537

Reputation:

python, how to tell what type of obj was returned

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

Answers (2)

Charles Duffy
Charles Duffy

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

Johan
Johan

Reputation: 636

Use the built-in "type" function, e.g. type(10) -> .

Upvotes: -1

Related Questions