What is the command to determine an object's type?

Mark McEahern marklists at mceahern.com
Tue Feb 5 15:48:49 EST 2002


> MDK wrote:
> How can I tell if an object is a string, a list, or a dictionary in a
> program using if and ifelse so that I can perform a differnent action
> depending on the object's type?

I posted code that will do the trick and then realized, I should probably
add this...

It goes without saying, of course, that you may want to investigate the
Strategy design pattern.  Eliminating that sort of conditional type checking
is Strategy's strong suit.

Cheers,

// mark





More information about the Python-list mailing list