Re: [Tutor] problem creating a subclass
by Lloyd Kvam other posts by this author
Feb 29 2004 10:37PM messages near this date
Re: [Tutor] problem creating a subclass
|
Re: [Tutor] problem creating a subclass
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 televi
sion 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@[...].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@[...].org
http://mail.python.org/mailman/listinfo/tutor
Thread:
Christopher Spears
Alan Gauld
Alan Gauld
Lloyd Kvam
Nick Lunt
|