checking one's type

Ben Artin macdev at
Fri Jan 5 10:16:31 CET 2007

In article <mailman.2314.1167986448.32031.python-list at>,
 belinda thom <bthom at> wrote:

> I've been using the following hack to determine if a type is  
> acceptable and I suspect there is a better way to do it:
> e.g.
> if type(s) == type("") :
>     print "okay, i'm happy you're a string"
> If anyone knows a better way, I'm all ears.

If you want to know whether something is specifically a string, but not a 
Unicode string, then you want isinstance(foo, str). If you want to check whether 
something is a general string (including Unicode strings), you want 
isinstance(foo, basestring).



If this message helped you, consider buying an item
from my wish list: <>

I changed my name: <>

More information about the Python-list mailing list