[Tutor] Advantage of subclassing UserDict and UserList

karthik Guru karthikg@aztec.soft.net
Thu, 29 Nov 2001 13:23:12 +0530


hi all,

What are the advantages of subclassing UserDict and UserList classes??

import UserList

class myclass(UserList.UserList):

    def __init__(self):
            UserList.UserList.__init__(self)
    def append(self,item):
            import types
            if type(item) == types.IntType:
                    UserList.UserList.append(self,item)
            else:
                    raise "Sorry only ints!"


ok here i have restricted the user from entering any other type other than
"ints"
by overriding append().

Is there any other advantsge of subclassing these classes other than
imposing such restrictions?.

thanks in advance,
karthik.