diff options
author | Guido van Rossum <guido@python.org> | 1993-11-30 13:43:54 (GMT) |
---|---|---|
committer | Guido van Rossum <guido@python.org> | 1993-11-30 13:43:54 (GMT) |
commit | ae3b3a33d85134b51505b3f0f3fdaf6afbffa79b (patch) | |
tree | ed5f31c45378ce3be6e096f559fa645ea5f02a42 /Lib/UserList.py | |
parent | 590baa4a7a43b596119b47f605e3e570c2b3b0ee (diff) | |
download | cpython-ae3b3a33d85134b51505b3f0f3fdaf6afbffa79b.zip cpython-ae3b3a33d85134b51505b3f0f3fdaf6afbffa79b.tar.gz cpython-ae3b3a33d85134b51505b3f0f3fdaf6afbffa79b.tar.bz2 |
* test_*.py: new lambda syntax (also affects tests for filter, map,
reduce)
* ftplib.py: added default callback for retrlines; added dir() method
* ftplib.py: don't return self in self.connect(); added hack so that if
'CDUP' is not understood, 'CWD ..' is tried.
* ftplib.py: second method called init() should have been called
connect(); if __init__ sees more than one argument, it will also try to
login().
Diffstat (limited to 'Lib/UserList.py')
-rw-r--r-- | Lib/UserList.py | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/Lib/UserList.py b/Lib/UserList.py new file mode 100644 index 0000000..9fbcc02 --- /dev/null +++ b/Lib/UserList.py @@ -0,0 +1,39 @@ +# A more or less complete user-defined wrapper around list objects + +class UserList: + def __init__(self, *args): + if len(args) > 1: raise TypeError, 'too many args' + self.data = [] + if args: + list = args[0] + if type(list) == type(self.data): + self.data[:] = list + else: + self.data[:] = list.data[:] + def __repr__(self): return repr(self.data) + def __cmp__(self, list): + if type(list) == type(self.data): + return cmp(self.data, list) + else: + return cmp(self.data, list.data) + def __len__(self): return len(self.data) + def __getitem__(self, i): return self.data[i] + def __setitem__(self, i, item): self.data[i] = item + def __delitem__(self, i): del self.data[i] + def __getslice__(self, i, j): + userlist = UserList() + userlist.data[:] = self.data[i:j] + return userlist + def __setslice__(self, i, j, list): + if type(list) == type(self.data): + self.data[i:j] = list + else: + self.data[i:j] = list.data + def __delslice__(self, i, j): del self.data[i:j] + def append(self, item): self.data.append(item) + def insert(self, i, item): self.data.insert(i, item) + def remove(self, item): self.data.remove(item) + def count(self, item): return self.data.count(item) + def index(self, item): return self.data.index(item) + def reverse(self): self.data.reverse() + def sort(self, *args): apply(self.data.sort, args) |