Changes to UserList.py

Niels Diepeveen niels at endea.demon.nl
Thu Jan 6 09:54:26 EST 2000


Jakob Schiotz schreef:
> I feel that the optimal solution would be a change in UserList.py, but
> I cannot figure out how the optimal solution should be.  

This looks like the best solution to me:
    def __init__(self, initial=None):
        if initial is None:
            self.data = []
        elif isinstance(initial, UserList): 
            # avoid going through __getitem__
            self.data = list(initial.data)
        else:
            self.data = list(initial)

> Perhaps
> UserList.__init() should be changed to be similar to __cmp__, and then
> the build-in function list() should be extended to work on any object
> having a __getitem__ method.  The latter change should probably be done
> anyway in a later version of Python.

It has already been done, in 1.5.2.

-- 
Niels Diepeveen
Endea automatisering




More information about the Python-list mailing list