Still the __new__ hell ...

Alex Martelli aleax at mac.com
Tue Mar 20 02:28:54 EDT 2007


Steve Holden <steve at holdenweb.com> wrote:

> greg wrote:
> > Paulo da Silva wrote:
> >> As a relatively inexperient
> >> in python, how could I know that a 'string' is an instance of
> >> basestring?
> > 
> >    isinstance(x, basestring)
> > 
> > This works because basestring is defined as the
> > tuple (str, unicode) and isinstance accepts a
> > tuple of types as well as just a single type.
> > 
> The idea is right, but the detail is completely wrong.
> 
> basestring is a *type*.
> 
>   >>> basestring
> <type 'basestring'>
> 
> It's the base class of which both str and unicode are subclasses.

I believe it used to be a tuple back in Python 2.2 (sorry, don't have a
Python 2.2 installation to check this right now).


Alex



More information about the Python-list mailing list