Is a list an instance of a class?

Jp Calderone exarkun at divmod.com
Sun Nov 14 16:51:57 EST 2004


On Sun, 14 Nov 2004 21:50:14 +0100, Fran=?ISO-8859-1?B?5w==?=ois Granger <fgranger at fgranger.com> wrote:
>Le 14/11/04 21:33, =AB=A0Kent Johnson=A0=BB <kent3737 at yahoo.com> a =E9crit=A0:
> 
> > Is this still correct or was it made obsolete by Python 2.2? Lists and
> > files have __class__ attributes, at least:
> 
> As you disovered, this is obsolete. You even have some emulation you can
> built on :
> 
> Python 2.3 (#1, Sep 13 2003, 00:49:11)
> [GCC 3.3 20030304 (Apple Computer, Inc. build 1495)] on darwin
> Type "help", "copyright", "credits" or "license" for more information.
> >>> import UserList
> >>> dir (UserList)
> ['UserList', '__builtins__', '__doc__', '__file__', '__name__']
> 
> For me, this file resides in:

  UserList (UserDict, UserString) are also mostly obsolete:

    >>> class foo(list):
    ...     def __str__(self):
    ...             return 'foo list: ' + super(foo, self).__str__()
    ... 
    >>> print foo(range(3))
    foo list: [0, 1, 2]

  Jp



More information about the Python-list mailing list