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/017760.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-stringBarry A. Warsaw barry@zope.com
Fri, 5 Oct 2001 11:27:01 -0400
    GvR> if isinstance(x, str) or isinstance(x, unicode): > > is
    GvR> apparently too much typing.

    NS> Perhaps we could extend isinstance().  How about

    NS>     isinstance(x, str, unicode)

    NS> or

    NS>     isinstance(x, (str, unicode))

    NS> This is a common problem not limited to string types.  I often
    NS> want to test if something is a tuple or a list for example.

That's an interesting idea, but please use the former signature, not
the latter.

And what would it return?  It needs to return a true value on success,
but maybe instead of returning 1, it might be more useful to return
the type argument that matched, e.g.:

>>> isinstance('', str, unicode)
<type 'str'>
>>> isinstance(u'', str, unicode)
<type 'unicode'>
>>> isinstance((), list, dictionary, tuple)
<type 'tuple'>
>>> isinstance(7, list, dictionary, tuple)
0

-Barry



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