checking one's type
Ben Artin
macdev at artins.org
Fri Jan 5 04:16:31 EST 2007
In article <mailman.2314.1167986448.32031.python-list at python.org>,
belinda thom <bthom at cs.hmc.edu> 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).
hth
Ben
--
If this message helped you, consider buying an item
from my wish list: <http://artins.org/ben/wishlist>
I changed my name: <http://periodic-kingdom.org/People/NameChange.php>
More information about the Python-list
mailing list