Is a list an instance of a class?

Chad Crabtree flaxeater at gmail.com
Mon Nov 15 17:44:24 CET 2004


Jp Calderone <exarkun at divmod.com> wrote in message news:<mailman.6360.1100469121.5135.python-list at python.org>...
> 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

However I must point out that UserList and Dict are not *REALLY*
obsolete because they give someone a pure python implementation to
look at in order to know _what_ to subclass to attain the behavior
they like.



More information about the Python-list mailing list