Some problems with classes

ssecorp circularfunc at
Mon Sep 1 03:39:14 CEST 2008

Why/how is it possible to add variables like this? I don't understand
this mechanism:

class Employee:

john = Employee() # Create an empty employee record

# Fill the fields of the record = 'John Doe'
john.dept = 'computer lab'
john.salary = 1000


Also, I can't get multiple inheritance to work.

Don't mind that the a vegan obviously don't inherit from an animal and
a vegetable. I didn't come up with anything better, it is just to
learn about inheritance.

class Animal(object):
    def __init__(self, name, weight): = name
        self.weight = weight

    def speak(self):
        print "speak"

class Vegetable(object):
    def __init__(self, name, volume): = name
        self.volume = volume

    def split(self):
        print "tjoff"

class Vegan(Animal, Vegetable):
    def __init__(self, name, attacks): = name
        self.attacks = attacks


Traceback (most recent call last):
  File "C:/Python25/Progs/XXXX/", line 42, in <module>
    class ActionComedy(Movie, ActionMovie):
TypeError: Error when calling the metaclass bases
    Cannot create a consistent method resolution
order (MRO) for bases Movie, ActionMovie

also, when inheriting, can I inherit __init__() somehow? If I want the
same attributes but perhaps some additional methods for example.

More information about the Python-list mailing list