Python shallow/deep copy error -


no, not duplicate.

i have following classes: -board -player

when player instantiated, creates new board object player.

i have function switches current , latent players:

from copy import deepcopy   switch_players(self):     temp_val = deepcopy(self.current_player)     # self.current_player = none     self.current_player = deepcopy(self.latent_player)     # self.latent_player = none     self.latent_player = deepcopy(temp_val)     temp_val = none 

this works fine players' names when call self.current_player.name, when use self.current_player.board.display, or write it, references same board both players.

i added code create deepcopy() of board switch this, i'm still experiencing same issue. fundamentally wrong way this? or approach correct, , should elsewhere in code? (i have way of doing this, i'm not understanding theory behind why current approach doesn't work.)

it works so, because name string, board class instance copied, 1 level deeper, not copied deepcopy. deepcopy not meant recursively.


Comments

Popular posts from this blog

account - Script error login visual studio DefaultLogin_PCore.js -

xcode - CocoaPod Storyboard error: -