[Tutor] problem creating a subclass

Nick Lunt nick at javacat.f2s.com
Sun Feb 29 17:52:18 EST 2004


Maybe I'm missing something obvious here but I don't see how Chris'
UList class is going to work at all. The class has no UList method, so
how is 'a = UList.UList(alist)' going to work ?

Nick.


On Sun, 29 Feb 2004 17:37:34 -0500 Lloyd Kvam <pythontutor at venix.com>
wrote:

> You didn't pass the list that came in, you passed None.
> 
> Christopher Spears wrote:
> 
> > I am creating a new class based on UserList called
> > UList.  Here is the code:
> > 
> > import UserList
> > 
> > class UList(UserList.UserList):
> >     def __init__(self, initlist=None):
>                                   ^^^^^ defines a default value
> >         UserList.UserList.__init__(self,
> > initlist=None)
>            ^^^^^ passes None
> 
> You want (the slightly odd looking) initlist=initlist
> which will pass your variable named initlist to the argument that
> has the same name, initlist.
> 
> > 
> > When I tested the class, the following happened:
> > 
> > 
> >>>>import UList
> >>>>list = [1,2,3]
> >>>>a = UList.UList(list)
> >>>>a
> > 
> > []
> > 
> > What gives?
> > -Chris
> > 
> > =====
> > "I'm the last person to pretend that I'm a radio.  I'd rather go out
> > and be a color television set."-David Bowie
> > 
> > "Who dares wins"
> > -British military motto
> > 
> > "The freak is the norm." - "The Infernal Desire Machines of Dr.
> > Hoffman" by Angela Carter
> > 
> > _______________________________________________
> > Tutor maillist  -  Tutor at python.org
> > http://mail.python.org/mailman/listinfo/tutor
> > 
> 
> -- 
> Lloyd Kvam
> Venix Corp.
> 1 Court Street, Suite 378
> Lebanon, NH 03766-1358
> 
> voice:	603-653-8139
> fax:	801-459-9582
> 
> 
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor



More information about the Tutor mailing list