title: type object Player has no attribute rect
body: <p>I'm currently writing a game where your player is a png file, and you have to avoid rocks. I keep getting the error "type object Player has no attribute rect". I'm new with OOP, so any help will be appreciated! The code is as follows:</p>
  
  <pre><code>import pygame
  import os
  import random
  import sys
  
  random.seed()
  
  _image_library = {}
  def get_image(path):
      global _image_library
      image = _image_library.get(path)
      if image == None:
          canonicalized_path = path.replace('/', os.sep).replace('\\', os.sep)
          image = pygame.image.load(canonicalized_path)
          _image_library[path] = image
      return image
  
  y = 250
  
  class Player(object):
  
      def __init__(self):
          self.rect = pygame.Rect(0, y, 50, 50)
  
      def move(self, dx, dy):
  
      # Move each axis separately. Note that this checks for collisions both times.
          if dx != 0:
              self.move_single_axis(dx, 0)
          if dy != 0:
              self.move_single_axis(0, dy)
  
      def move_single_axis(self, dx, dy):
  
      # Move the rect
          self.rect.x += dx
          self.rect.y += dy
  
  pygame.init()
  screen = pygame.display.set_mode((500, 500))
  done = False
  clock = pygame.time.Clock()
  
  rockXList = []
  rockYList = []
  
  y = 250
  xrand = 750
  speed = 1
  loop = 0
  
  while not done:
      for event in pygame.event.get():
          if event.type == pygame.QUIT:
              done = True
  
      pressed = pygame.key.get_pressed()
      if pressed[pygame.K_UP]:
          if(y &gt; 3):
              y -= 3
      if pressed[pygame.K_DOWN]:
          if(y &lt; 497):
              y += 3
  
      a = 0
      while(a &lt; len(rockXList)):
          rx = rockXList[a]
          rx = rx - speed
          rockXList[a] = rx
          a = a + 1
  
      screen.fill((153, 76, 0))
      screen.blit(get_image("race-toad.png"), (0, y))
      i = 0
      while(i &lt; len(rockXList)):
          rx = rockXList[i]
          ry = rockYList[i]
          pygame.draw.rect(screen, (160, 160, 160), pygame.Rect(rx, ry, 32, 32))
          execstr = "end_rect"+str(i)+" = pygame.Rect(rx, ry, 32, 32)"
          exec execstr
          i = i + 1
  
      b = 0
      while(b &lt; len(rockXList)):
          rx = rockXList[b]
          ry = rockYList[b]
          name = "if Player.rect.colliderect(end_rect" + str(b) + "):\n   speed = 0\n print 'YOU LOSE!'"
          exec name
          b = b + 1
  
      xadd = random.randint(10, 125)
      rockX = xrand + xadd
      xrand = rockX
      rockY = random.randint(0, 450)
  
      rockXList.append(rockX)
      rockYList.append(rockY)
  
      if(loop &gt; 600):
          speed = speed + 1
          loop = 0
      else:
          loop = loop + 1
  
      pygame.display.flip()
      clock.tick(60)
  </code></pre>