小编Pia*_*rus的帖子

Python,重写继承的类方法

我有两节课,FieldBackground.他们看起来有点像这样:

class Field( object ):
    def __init__( self, a, b ):
        self.a = a
        self.b = b
        self.field = self.buildField()

    def buildField( self ):
        field = [0,0,0]
        return field

class Background( Field ):
    def __init__( self, a, b, c ):
        super(Background, self).__init__( a, b )
        self.field = self.buildField( c )

    def buildField( self, c ):
        field = [c]
        return field

a, b, c = 0, 1, 2
background = Background( a, b, c )
Run Code Online (Sandbox Code Playgroud)

这个错误指向Field的buildField() …

python methods inheritance overwrite super

44
推荐指数
4
解决办法
6万
查看次数

标签 统计

inheritance ×1

methods ×1

overwrite ×1

python ×1

super ×1