I'm having trouble understanding how to instantiate a class, and update that instances variables. If I __init__
a series of self.x
variables, then instance that class, I want to update self.x = 40. However, self.x
always stays constant.
I have a feeling I'm not wrapping my head around the class variable, init variable, and instanced class variables. I can always access them, I just can't seem to change them. I have coded an example of what I am trying to do.
class Engine(object):
def __init__(self, board):
self.board = board
def play_game(self):
print(self.board.sheet[0])
number_one = int(input("Please enter a number."))
self.board.a = number_one
number_two = int(input("Please enter another number."))
self.board.b = number_two
number_three = int(input("Please enter a third number."))
self.board.c = number_three
number_four = int(input("Please enter a final number."))
self.board.d = number_four
print("Thank you! List updated.")
print(self.board.sheet[0])
class ScoreBoard(object):
def __init__(self):
self.a = "_____"
self.b = "_____"
self.c = "_____"
self.d = "_____"
self.sheet = [f"""
1. Number One: {self.a}
2. Number Two: {self.b}
3. Number Three: {self.c}
4. Number Four: {self.d}
"""]
new_board = ScoreBoard()
new_game = Engine(new_board)
new_game.play_game()
When I print self.board.sheet[0]
I would like to show the numbers instead of the lines for self.a
through self.d
.