title: Python Error - TypeError: argument of type 'method' is not iterable
body: <p>I'm creating a chess game but I'm having a problem with my code. I have two files, the chess engine file (ChessEngine.py):</p>
  <pre><code>class GameState():
  def __init__(self):
      # 8x8 2d board, each element has 2 characters.
      self.board = [
          [&quot;bR&quot;, &quot;bN&quot;, &quot;bB&quot;, &quot;bQ&quot;, &quot;bK&quot;, &quot;bB&quot;, &quot;bN&quot;, &quot;bR&quot;],
          [&quot;bp&quot;, &quot;bp&quot;, &quot;bp&quot;, &quot;bp&quot;, &quot;bp&quot;, &quot;bp&quot;, &quot;bp&quot;, &quot;bp&quot;],
          [&quot;--&quot;, &quot;--&quot;, &quot;--&quot;, &quot;--&quot;, &quot;--&quot;, &quot;--&quot;, &quot;--&quot;, &quot;--&quot;],
          [&quot;--&quot;, &quot;--&quot;, &quot;--&quot;, &quot;--&quot;, &quot;--&quot;, &quot;--&quot;, &quot;--&quot;, &quot;--&quot;],
          [&quot;--&quot;, &quot;--&quot;, &quot;--&quot;, &quot;--&quot;, &quot;--&quot;, &quot;--&quot;, &quot;--&quot;, &quot;--&quot;],
          [&quot;--&quot;, &quot;--&quot;, &quot;--&quot;, &quot;--&quot;, &quot;--&quot;, &quot;--&quot;, &quot;--&quot;, &quot;--&quot;],
          [&quot;wp&quot;, &quot;wp&quot;, &quot;wp&quot;, &quot;wp&quot;, &quot;wp&quot;, &quot;wp&quot;, &quot;wp&quot;, &quot;wp&quot;],
          [&quot;wR&quot;, &quot;wN&quot;, &quot;wB&quot;, &quot;wQ&quot;, &quot;wK&quot;, &quot;wB&quot;, &quot;wN&quot;, &quot;wR&quot;]]
      self.whitetoMove = True
      self.moveLog = []
  
  def makeMove(self, move):
      self.board[move.startRow][move.startCol] = &quot;--&quot;
      self.board[move.endRow][move.endCol] = move.pieceMoved
      self.moveLog.append(move)
      self.whitetoMove = not self.whitetoMove
  
  def undoMove(self):
      if len(self.moveLog) != 0:
          move = self.moveLog.pop()
          self.board[move.startRow][move.startCol] = move.pieceMoved
          self.board[move.endRow][move.endCol] = move.pieceCaptured
          self.whitetoMove = not self.whitetoMove
  
  def getValidMoves(self):
      return self.getAllPossibleMoves()
  
  def getAllPossibleMoves(self):
      moves = [Move((6, 4), (4, 4), self.board)]
      for r in range(len(self.board)):
          for c in range(len(self.board[r])):
              turn = self.board[r][c][0]
              if (turn == 'w' and self.whitetoMove) and (turn == 'b' and not self.whitetoMove):
                  piece = self.board[r][c][1]
                  if piece == 'p':
                      self.getPawnMoves(r, c, moves)
                  elif piece == 'R':
                      self.getRookMoves(r, c, moves)
      return moves
  
  def getPawnMoves(self, r, c, moves):
      pass
  
  def getRookMoves(self, r, c, moves):
      pass
  
  class Move():
  ranksToRows = {&quot;1&quot;: 7, &quot;2&quot;: 6, &quot;3&quot;: 5,
                 &quot;4&quot;: 4, &quot;5&quot;: 3, &quot;6&quot;: 2, &quot;7&quot;: 1, &quot;8&quot;: 0}
  rowsToRanks = {v: k for k, v in ranksToRows.items()}
  filesToCols = {&quot;a&quot;: 0, &quot;b&quot;: 1, &quot;c&quot;: 2,
                 &quot;d&quot;: 3, &quot;e&quot;: 4, &quot;f&quot;: 5, &quot;g&quot;: 6, &quot;h&quot;: 7}
  colsToFiles = {v: k for k, v in filesToCols.items()}
  
  def __init__(self, startSq, endSq, board):
      self.startRow = startSq[0]
      self.startCol = startSq[1]
      self.endRow = endSq[0]
      self.endCol = endSq[1]
      self.pieceMoved = board[self.startRow][self.startCol]
      self.pieceCaptured = board[self.endRow][self.endCol]
      self.moveID = self.startRow * 1000 + \
          self.startCol*100 + self.endRow*10 + self.endCol
      print(self.moveID)
  
  def __eq__(self, other):
      if isinstance(other, Move):
          return self.moveID == other.moveID
      return False
  
  def getChessNotation(self):
      return self.getRankFile(self.startRow, self.startCol) + self.getRankFile(self.endRow, self.endCol)
  
  def getRankFile(self, r, c):
      return self.colsToFiles[c] + self.rowsToRanks[r]
  </code></pre>
  <p>and my actual game file (ChessMate.py):</p>
  <pre><code>import pygame as p
  import ChessEngine
  
  WIDTH = HEIGHT = 512
  DIMENSION = 8
  SQ_SIZE = HEIGHT//DIMENSION
  MAX_FPS = 15
  IMAGES = {}
  
  
  def loadImages():
      pieces = ['wp', 'wR', 'wN', 'wB', 'wK',
                'wQ', 'bp', 'bR', 'bN', 'bB', 'bK', 'bQ']
      for piece in pieces:
          IMAGES[piece] = p.transform.scale(
              p.image.load('Chess/Images/' + piece + '.png'), (SQ_SIZE, SQ_SIZE))
  
  
  def main():
      p.init()
      screen = p.display.set_mode((WIDTH, HEIGHT))
      clock = p.time.Clock()
      screen.fill(p.Color(&quot;white&quot;))
      gs = ChessEngine.GameState()
      validMoves = gs.getValidMoves()
      moveMade = False
  
      loadImages()
      running = True
      sqSelected = ()
      playerClicks = []
  
      while running:
          for e in p.event.get():
              if e.type == p.QUIT:
                  running = False
              elif e.type == p.MOUSEBUTTONDOWN:
                  location = p.mouse.get_pos()
                  col = location[0]//SQ_SIZE
                  row = location[1]//SQ_SIZE
                  if sqSelected == (row, col):
                      sqSelected = ()
                      playerClicks = []
                  else:
                      sqSelected = (row, col)
                      playerClicks.append(sqSelected)
                  if len(playerClicks) == 2:
                      move = ChessEngine.Move(
                          playerClicks[0], playerClicks[1], gs.board)
                      print(move.getChessNotation())
                      if move in validMoves:
                          gs.makeMove(move)
                          moveMade = True
                      sqSelected = ()
                      playerClicks = []
              elif e.type == p.KEYDOWN:
                  if e.key == p.K_z:
                      gs.undoMove()
                      moveMade = True
  
          if moveMade:
              validMoves = gs.getValidMoves
              moveMade = False
  
          drawGameState(screen, gs)
          clock.tick(MAX_FPS)
          p.display.flip()
  
  
  def drawGameState(screen, gs):
      drawBoard(screen)
      drawPieces(screen, gs.board)
  
  
  def drawBoard(screen):
      colors = [p.Color(&quot;light yellow&quot;), p.Color(&quot;dark green&quot;)]
      for r in range(DIMENSION):
          for c in range(DIMENSION):
              color = colors[((r+c) % 2)]
              p.draw.rect(screen, color, p.Rect(
                  c*SQ_SIZE, r*SQ_SIZE, SQ_SIZE, SQ_SIZE))
  
  
  def drawPieces(screen, board):
      for r in range(DIMENSION):
          for c in range(DIMENSION):
              piece = board[r][c]
              if piece != &quot;--&quot;:
                  screen.blit(IMAGES[piece], p.Rect(
                      c*SQ_SIZE, r*SQ_SIZE, SQ_SIZE, SQ_SIZE))
  
  
  if __name__ == '__main__':
      main()
  </code></pre>
  <p>And the exact error I'm getting:</p>
  <pre><code>Traceback (most recent call last):
    File &quot;/Users/Name/Documents/Python/AI/Chess/Chess/ChessMate.py&quot;, line 94, in &lt;module&gt;
      main()
    File &quot;/Users/Name/Documents/Python/AI/Chess/Chess/ChessMate.py&quot;, line 51, in main
      if move in validMoves:
  TypeError: argument of type 'method' is not iterable
  </code></pre>
  <p>I've checked other posts which say that the person who is asking the question is missing brackets somewhere for their function but I have scanned through my code numerous times and I still can't find anything</p>
  <p>Please help, I'm really stuck.</p>