[Tutor] Overloading in UserList - Corrected

jazariel@libero.it jazariel@libero.it
Sat, 8 Jul 2000 16:04:39 +0200


I=20just=20discovered=20that=20the=20Linux=20e-mail=20client=20kmail=0D=0A=
lost=20all=20the=20identation.=20Hope=20it=20works=20from=20the=20web.=0D=
=0ASo=20the=20code=20is:=0D=0A=0D=0Afrom=20UserList=20import=20UserList=0D=
=0A=0D=0Aclass=20TestList(UserList):=0D=0A=20=20=20=20"""=20Class=20TestL=
ist=20based=20on=20class=20UserList=20"""=0D=0A=20=20=20=20def=20__init__=
(self,=20list):=0D=0A=20=20=20=20=20=20=20=20UserList.__init__(self,=20li=
st)=0D=0A=0D=0A=20=20=20=20def=20purge(self,=20value):=0D=0A=20=20=20=20=20=
=20=20=20"""=20Method=20to=20check=20if=20a=20value=20is=20in=20list=20an=
d=20remove=20all=20its=0D=0A=20=20=20=20=20=20=20=20=20=20=20=20entries=20=
=20"""=0D=0A=09while=20value=20in=20self.data:=0D=0A=20=20=20=20=20=20=20=
=20self.data.remove(value)=0D=0A=0D=0A=20=20=20=20def=20ensure(self,=20va=
lue):=0D=0A=20=20=20=20=20=20=20=20"""=20Method=20to=20add=20a=20value=20=
if=20it=20is=20not=20already=20in=20list=20"""=0D=0A=09if=20not=20value=20=
in=20self.data:=0D=0A=20=20=20=20=09self.data.append(value)=0D=0A=0D=0A=20=
=20=20=20def=20copy(self):=0D=0A=20=20=20=20=20=20=20=20"""=20Makes=20a=20=
copy=20of=20the=20instance=20"""=0D=0A=20=20=20=20=20=20=20=20return=20Te=
stList(self.data[:])=0D=0A=0D=0A>>>=20a=20=3D=20[1,2,3,4]=0D=0A>>>=20A1=20=
=3D=20UserList(a)=0D=0A>>>=20A2=20=3D=20TestList(a)=0D=0A=0D=0A>>>=20A1[:=
]=0D=0A[1,=202,=203,=204]=0D=0A>>>=20A2[:]=0D=0ATraceback=20(innermost=20=
last):=0D=0A=20=20File=20"<pyshell#14>",=20line=201,=20in=20?=0D=0A=20=20=
=20=20A2[:]=0D=0A=20=20File=20"C:\Programmi\Python\Lib\UserList.py",=20li=
ne=2023,=20in=20__getslice__=0D=0A=20=20=20=20userlist=20=3D=20self.__cla=
ss__()=0D=0ATypeError:=20not=20enough=20arguments;=20expected=202,=20got=20=
1=0D=0A>>>=20A2.copy()=0D=0A[1,=202,=203,=204]=0D=0A=0D=0ASorry,=20Thomas=
=0A=0A=