detecting variable types

Alex Martelli aleaxit at
Thu Sep 23 15:38:04 CEST 2004

Scott David Daniels <Scott.Daniels at Acm.Org> wrote:
>      if isinstance(vbl, (string, unicode)):

Nope!  Use isinstance(vbl, basestring) instead.  basestring exists for
that one and only reason... besides str (not 'string') and unicode, any
user-coded type that _wants_ to be "treated as a string for all intents
and purposes" may choose to inherit from basestring instead of object
(it's supposed to get no effect whatsoever from that _except_ from code
that does this specific kind of typechecking specifically).


More information about the Python-list mailing list