类方法更改变量

时间:2019-11-10 22:41:56

标签: python python-3.x

我是python的新手,因此我遇到了很多麻烦,因为出于某种原因,即使我没有碰过它,我的类方法中的该值也会自行更新。我什至不能使其保持不变...这是实现它的相关代码。

被称为的方法

def swapping(self,pos,puzzle):

    print('Old puzzle \n',puzzle)
    # Getting Zero point index 
    zero = obj.null_pos(puzzle)  

    # Getting Index of varied position
    var = puzzle[pos[0]][pos[1]]

    #Swappping values
    puzzle[zero[0,0],zero[0,1]] = var
    puzzle[pos[0], pos[1]] = 0
    new_puzzle = puzzle

    print('New_puzzle \n',new_puzzle)
    return new_puzzle 

# The code has been snipped into relevant parts only
for i in range(len(child_node)):
        # Check the hn of each node
        print(child_node[i])
        #where it occurs:
        num_mispl = obj.misplaced_tiles(nod.swapping(child_node[i],new_puz))
# <-- new_puz #value changes and i didn't assign it to anything
        temp_stor.append(num_mispl)

0 个答案:

没有答案