[Python-Dev] Need a way to test for 8-bit-or-unicode-string
Michael Hudson
mwh@python.net
08 Oct 2001 05:55:33 -0400
aahz@rahul.net (Aahz Maruch) writes:
> [I know we've already reached agreement, but I feel the need to stick my
> oar in.]
>
> Barry A. Warsaw wrote:
> >
> > 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.
>
> Ewww, gross, spit spit spit. ;-)
>
> At least with the latter, you can do:
>
> stringtype = (str, unicode)
> isinstance(x, stringtype)
>
> Hmmmm... Or can you?
Yes, and with the former, you can do
stringtype = (str, unicode)
isinstance(x, *stringtype)
not-that-I-care-ly y'rs
M.
--
Indeed, when I design my killer language, the identifiers "foo" and
"bar" will be reserved words, never used, and not even mentioned in
the reference manual. Any program using one will simply dump core
without comment. Multitudes will rejoice. -- Tim Peters, 29 Apr 1998