[Tutor] Classes
Remco Gerlich
scarblac@pino.selwerd.nl
Wed, 4 Apr 2001 08:30:25 +0200
On Tue, Apr 03, 2001 at 06:52:28PM -0600, VanL wrote:
> Here is my second question:
>
> I am investigating python's inheritance structure. Given the class
> LinkedList:
>
> class LinkedList:
>
> """ This class provides a generic node for linked lists. Other
> python classes or
> objects can inherit from this class to get the ability to represent
> themselves as
> a linked list. """
>
> def __init__(self, name, object=None):
> self.__label = name
> if object: self.__link = object
> else: self.__link = None
>
> [snip to end]
>
>
> and the class NewClass:
>
> class NewClass(LinkedList):
>
> def __init__(self):
> NewString = "This is a new string"
LinkedList.__init__(self, "somename")
>
> def NewString(self):
> print NewString
>
>
> How do I supply the superclass constructor arguments when instancing an
> object of type newclass? How does this change if I inherit from
> multiple classes?
If you inherit from multiple classes you can call __init__ in each of them,
if necessary.
Btw, the NewString doesn't work, the variable has to be 'self.NewString',
and the function needs a different name (otherwise the self.NewString
assignment in __init__ would overwrite the function).
--
Remco Gerlich