I cannot understand what I am doing wrong, because when I try to use it on a "small scale", it works there.
I have a class called Play()
I go like this:
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
...
Then I have another class called Score()
class Score(Play): def __init__(self): self.initialScore = 0 def letterGuess(self): self.initialScore += 1 return self.errList
...
I created both instances:
game = Play() points = Score()
And if I do this:
print points.letterGuess()
This gives me an error:
Traceback (most recent call last): File "/home/trufa/workspace/hangpy/src/v2.py", line 188, in <module> startGame() File "/home/trufa/workspace/hangpy/src/v2.py", line 134, in startGame print points.letterGuess() File "/home/trufa/workspace/hangpy/src/v2.py", line 79, in letterGuess return self.errList AttributeError: Score instance has no attribute 'errList'
I do not understand why, since I can do this without much trouble:
class One(): def __init__(self): self.list= [1,2] class Two(One): def meth(self): return self.list uan = One() tu = Two() print uan.list print tu.meth()
I am very new to OOP, so I can make all kinds of stupid mistakes, but I can't figure out where!
I think I posted all the relevant code, but I think the error may be in another place, I can provide it.
As I said, I'm very new, so this has nothing to do with inheritance. I just think this is called when you get โsomethingโ from another class (you should now scream on the screen)