A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://mail.python.org/pipermail/python-dev/2001-October/017835.html below:

[Python-Dev] Need a way to test for 8-bit-or-unicode-string

[Python-Dev] Need a way to test for 8-bit-or-unicode-string [Python-Dev] Need a way to test for 8-bit-or-unicode-stringTim 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
>>>




RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4