Here is my code snippet:-
class Board:
def __init__(self,level):
self.lvl=level
self.val=0
class State:
def __init__(self):
self.p=Board(0)
self.p.val=100
self.u=self.p
I want that u has a level of 1 and val of 100. I know i can modify separately, but i want to pass reference of p while initializing u and a level value 1. Something like self.u=Board(1) would not solve my purpose.
Boardacceptvalas a second parameter…?!self.u = Board(1, 100)…?!self.p = self.u = Board(0, 100)…?! But why have two references to the same object in the first place?u.valandp.valto have the same initial value but change independantly or if what you're asking for is that wheneverp.valchangesu.valchanges accordingly...self.p = self.u = Board(0, 100)This would actually go wrong if I am using a list or any other structure with recursion. Simply, the state of u has to be same as p with a level of +1.