[Tutor] List mimicing

Andrew Wilkins toodles@yifan.net
Thu, 7 Jun 2001 11:12:30 +0800


Okay I've fixed it now. Thanks Kalle, I looked through the source of
UserList and found the prob :)
Also I've subclassed it now, and changed the way it works so it cuts a lot
of method definitions out...I'll post this to Rob for Useless later if
anyone is even remotely interested. heh

Andrew Wilkins

> -----Original Message-----
> From: tutor-admin@python.org [mailto:tutor-admin@python.org]On Behalf Of
> Kalle Svensson
> Sent: Wednesday, 6 June 2001 11:14 PM
> To: tutor@python.org
> Subject: Re: [Tutor] List mimicing
>
>
> Sez Andrew Wilkins:
> > Hi folks,
> >
> > I'm creating a class somewhat like shelve that stores a list as
> a file, and
> > provides a very list-like interface to it. I'm having troubles
> with __iadd__
> > and __imul__ however.
> [snip]
>
> You want to take a look at the class UserList in the module
> UserList in the
> standard library.
>
> > -------- code ----------
> >
> > import cPickle,types,os
> >
> > class ListShelf:
> [snip]
> > 	def __iadd__(self,other):
> > 		"ie. list+=other"
> > 		_list=self._load()
> > 		_list+=other
> > 		self._dump(_list)
>
>                 return self
>
> > 	def __imul__(self,other):
> > 		"ie. list*=other"
> > 		_list=self._load()
> > 		_list*=other
> > 		self._dump(_list)
>
>                 return self
>
> Peace,
>   Kalle
> --
> Email: kalle@gnupung.net     | You can tune a filesystem, but you
> Web: http://www.gnupung.net/ | can't tune a fish. -- man tunefs(8)
> PGP fingerprint: 0C56 B171 8159 327F 1824 F5DE 74D7 80D7 BF3B B1DD
>  [ Not signed due to lossage.  Blame Microsoft Outlook Express. ]
>
> _______________________________________________
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor
>