[Python-Dev] Need a way to test for 8-bit-or-unicode-string
Tim Peters
tim.one@home.com
Mon, 8 Oct 2001 03:36:19 -0400
[Aahz]
> At least with the latter, you can do:
>
> stringtype = (str, unicode)
> isinstance(x, stringtype)
>
> Hmmmm... Or can you?
Yes -- it's the value of the expression that counts, not how it's spelled.
You can even nest these tuples:
>>> int_types = int, long
>>> file_types = file,
>>> def fori(x):
... return isinstance(x, (int_types, file_types))
...
>>> fori(43)
1
>>> fori(43L)
1
>>> import sys
>>> fori(sys.stdin)
1
>>> fori(43.0)
0
>>>