[Zope-Coders] unicode question
Guido van Rossum
guido@python.org
Fri, 05 Oct 2001 10:06:29 -0400
> Or even this:
>
> if type(names) in (types.StringType, types.UnicodeType):
> names=(names,)
No!
> Although, I'm sure using isinstance is better than comparing types.
Indeed. Using isinstance is VERY important with an eye on migrating
to new-style types/classes in Python 2.2: the argument could be a
subclass of types.StringType, and then tests using "type(x) is T" or
"type(x) in T" will fail. The isinstance(x, T) test will succeed
though.
(I'm still thinking about whether to provide a common base for str and
unicode; the more I see this kind of examples, the more I think there
should be one. But what to call it? abstractstring? String? string?)
--Guido van Rossum (home page: http://www.python.org/~guido/)