[Tutor] importing another classes's __init__

Alan Gauld alan.gauld at blueyonder.co.uk
Sun Feb 29 20:05:40 EST 2004


> import UserList
> 
> class UList(UserList.UserList):
>     def __init__(self, initlist=None):
>         UserList.UserList.__init__(self,
>                                    initlist=None)
> 
> >>> a = UList.UList(list)
> >>> a
> []
> 
> What gives?  I thought the line
> UserList.UserList.__init__(self, initlist=None) would
> import UserList's __init__ method.

It doesn't import it, it calls it. And you passed a list 
value of None so that's what it gave you...

I suspect you meant to do this:

class UList(UserList.UserList):
  def __init__(self, initlist=None):
     UserList.UserList.__init__(self, initlist)

Note no "=None" in the call to UserList.__init__()

Alan G
Author of the Learn to Program web tutor
http://www.freenetpages.co.uk/hp/alan.gauld



More information about the Tutor mailing list