相关疑难解决方法(0)

错误:尝试从类继承时"x实例没有属性y"

我无法真正理解我做错了什么,因为当我在"小规模"尝试时它正在那里工作.

我有一个名为的班级 Play()

我是这样的:

class Play():
    def __init__(self):
        file = open("/home/trufa/Desktop/test", "r")
        self.word = random.choice(file.readlines()).rstrip()
        self.errAllowed = 7
        self.errMade = 0
        self.errList = []
        self.cheatsAllowed = 2##chetas not incrementing
        self.cheatsMade =0
        self.wordList = ["*"]*len(self.word) ##this one is the one I want to have available in another class
Run Code Online (Sandbox Code Playgroud)

...

然后我有另一个叫做的课 Score()

class Score(Play):
    def __init__(self):
        self.initialScore = 0

    def letterGuess(self):
        self.initialScore += 1
        return self.errList
Run Code Online (Sandbox Code Playgroud)

...

我实例化了两个:

game = Play()
points = Score()
Run Code Online (Sandbox Code Playgroud)

如果我这样做:

print points.letterGuess()
Run Code Online (Sandbox Code Playgroud)

它给了我一个错误:

Traceback (most recent call …
Run Code Online (Sandbox Code Playgroud)

python inheritance attributes instance

5
推荐指数
1
解决办法
1万
查看次数

标签 统计

attributes ×1

inheritance ×1

instance ×1

python ×1