我用python创建了一个类,并试图创建它的deepCopy,但是当我修改原始类时,“deepCopy”的值仍然发生了变化。
class boardState():
def __init__(self, board, orient,actions,expl):
self.board
self.orientations = orient
self.actions = actions
self.explored = expl
def __deepcopy__(self):
return boardState(self.board, self.orientations, self.actions, self.explored)
board = []
orientations = {} #this stores the orientations of the cars in the current problem.
actions = [] #this is a list of the moves made to get to this current position.
explored = []
^上面是我正在使用并想复制的类。
referencestate = copy.deepcopy(state)
print(id(referencestate))
print(id(state))
^运行完这条线路后,显示它们具有相同的id,我想让它们独立。
任何帮助都将不胜感激!