[Tutor] List mimicing
Kalle Svensson
kalle@gnupung.net
Wed, 6 Jun 2001 17:14:14 +0200
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. ]