title: How to reinitialize a class in Python
body: <p>Suppose I have a class <code>Game</code> which plays a game. Once the game is over, I'd like to immediately start a new game. I thought this might possible in a recursive way by instantiating a new <code>Game()</code> within its own class definition. Is this possible?</p>
  
  <p>To give a specific example, I'm writing a Tic Tac Toe game with a GUI using Tkinter:</p>
  
  <pre><code>import numpy as np
  import Tkinter as tk
  
  class Game:
      def __init__(self, master, player1, player2):
          frame = tk.Frame()
          frame.grid()
          self.master = master
          self.player1 = player1
          self.player2 = player2
          self.current_player = player1
          self.empty_text = ""
          self.board = Board()
  
          self.buttons = [[None for _ in range(3)] for _ in range(3)]
          for i in range(3):
              for j in range(3):
                  self.buttons[i][j] = tk.Button(frame, height=3, width=3, text=self.empty_text, command=lambda i=i, j=j: self.callback(self.buttons[i][j]))
                  self.buttons[i][j].grid(row=i, column=j)
  
          self.reset_button = tk.Button(text="Reset", command=self.reset)
          self.reset_button.grid(row=3)
  
      def callback(self, button):
          if button["text"] == self.empty_text:
              button.configure(text=self.current_player.mark)
              info = button.grid_info()
              move = (info["row"], info["column"])
              self.board.place_mark(move, self.current_player.mark)
              if self.board.over():
                  print "The game is over. The player with mark %s won!" % self.current_player.mark
                  self.master.quit()
              else:
                  self.switch_players()
  
      def reset(self):
          print "Resetting..."
          self.master.destroy()
          self = Game(self.master, self.player1, self.player2)
  
      def switch_players(self):
          if self.current_player == self.player1:
              self.current_player = self.player2
          else:
              self.current_player = self.player1
  
  
  class Board:
      def __init__(self, grid=np.ones((3,3))*np.nan):
          self.grid = grid
  
      def winner(self):
          rows = [self.grid[i,:] for i in range(3)]
          cols = [self.grid[:,j] for j in range(3)]
          diag = [np.array([self.grid[i,i] for i in range(3)])]
          cross_diag = [np.array([self.grid[2-i,i] for i in range(3)])]
          lanes = np.concatenate((rows, cols, diag, cross_diag))      # A "lane" is defined as a row, column, diagonal, or cross-diagonal
  
          any_lane = lambda x: any([np.array_equal(lane, x) for lane in lanes])   # Returns true if any lane is equal to the input argument "x"
          if any_lane(np.ones(3)):
              return 1
          elif any_lane(np.zeros(3)):
              return 0
  
      def over(self):
          return (not np.any(np.isnan(self.grid))) or (self.winner() is not None)
  
      def place_mark(self, pos, mark):
          num = self.mark2num(mark)
          self.grid[tuple(pos)] = num
  
      def mark2num(self, mark):
          if mark == "X":
              return 1
          elif mark == "O":
              return 0
          else:
              print "The player's mark must be either 'X' or 'O'."
  
  
  class HumanPlayer:
      def __init__(self, mark):
          self.mark = mark
  
  
  root = tk.Tk()
  app = Game(root, player1=HumanPlayer(mark="X"), player2=HumanPlayer(mark="O"))
  root.mainloop()
  </code></pre>
  
  <p>The first time I play the game all is well: the button labels change as expected and a winner is declared (see below).</p>
  
  <p><a href="https://i.stack.imgur.com/fLhIa.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/fLhIa.png" alt="enter image description here"></a>
  <a href="https://i.stack.imgur.com/PFM3c.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/PFM3c.png" alt="enter image description here"></a></p>
  
  <p>The problem is that when I press the "Reset" button, although I do get a blank GUI again, the <code>Game</code> still 'thinks' that it is over and keeps printing the winner's declaration:</p>
  
  <p><a href="https://i.stack.imgur.com/vwJku.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/vwJku.png" alt="enter image description here"></a>
  <a href="https://i.stack.imgur.com/oSVnv.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/oSVnv.png" alt="enter image description here"></a></p>
  
  <p>Is it possible to 're-initialize' the class without resetting each attribute to its initial value?</p>