Some problems with classes

ssecorp circularfunc at gmail.com
Mon Sep 1 04:59:14 CEST 2008


It works when I inherit from 2 classes but not when I inherit from 2
subclasses.


-----------------------------------------------------

from __future__ import division

class Movie(object):
    def __init__(self, movieId, grades, date):
        self.movieId = movieId
        self.grades = grades
        self.date = date

    def newGrade(self, grade):
        self.grades.append(grade)

    def spam(self):
        print "inherits all the way down?"

    def averageGrade(self):
         return sum(grade for grade in self.grades) / \
                len(self.grades)

class ActionMovie(Movie):
    #super(Movie, self)
    def __init__(self, movieId, grades, date, kills):
        self.movieId = movieId
        self.grades = grades
        self.date = date
        self.kills = kills

    def newGrade(self, grade, date):
        self.grades.append(grade)
        self.date = date

    def prd(self):
        print self.date

class Comedy(ActionMovie):
    def __init__(self, movieId, grades, date):
        self.movieId = movieId
        self.grades = grades
        self.date = date

    def donk(self):
        print "im a donkey!"

##class ActionComedy(Movie, ActionMovie):
##    def __init__(self, movieId, grades, date):
##        self.movieId = movieId
##        self.grades = grades
##        self.date = date



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

    def speak(self):
        print "speak"

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

    def split(self):
        print "tjoff"

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




More information about the Python-list mailing list