Python 3 isinstance

James Mills prologic at shortcircuit.net.au
Wed Jan 14 22:11:51 EST 2009


On Thu, Jan 15, 2009 at 1:03 PM, Lambert, David W (S&T)
<LambertDW at corning.com> wrote:
> Overly terse.  I do mean that this is illegal:
>
> isinstance(s, {str, bytes})
>
> tuples have order, immutability, and the possibility of repeat items.
>
> A set is most reasonable in a mathematical sense.

What's wrong with:

>>> a = ""
>>> b = bytes()
>>> any([isinstance(a, x) for x in {str, bytes}])
True
>>> any([isinstance(b, x) for x in {str, bytes}])
True
>>>

cheers
James



More information about the Python-list mailing list