title: CSV Level Loading Function Won't Set the Player Variable in the Game Class, but Why?
body: <p>I've tried to set up a csv file loading system in my pygame project, to make it easier to make the levels and load them up in the game. I've followed the advice of some others, which led me to make these functions in a class I titles &quot;game&quot;.</p>
  <pre><code>#CSV convert
  def convert_csv_to_2d_list(csv_file: str):
      tile_map = []
      with open(csv_file, &quot;r&quot;) as f:
          for map_row in csv.reader(f):
              tile_map.append(map_row)
      return tile_map
  
  #CSV Based Level Loading, needs fixing (part of game class, henceforth the self. before all variables
          self.tile_map = convert_csv_to_2d_list(csv_file=&quot;Levels/Platforming/Level Map Potentially.csv&quot;)
          for row in range(len(self.tile_map)):
              for col in range(len(self.tile_map[row])):
                  if self.tile_map[row][col] == 1:
                      sprites.Tile(row * 32, col * 32, 1, self.tile_group)
                  
                  if self.tile_map[row][col] == 2:
                      sprites.Tile(row * 32, col * 32, 2, self.tile_group, self.platform_group)
                  
                  if self.tile_map[row][col] == 3:
                      sprites.Tile(row * 32, col * 32, 3, self.tile_group, self.platform_group)
                  
                  if self.tile_map[row][col] == 4:
                      sprites.Tile(row * 32, col * 32, 4, self.tile_group, self.platform_group)
                  
                  if self.tile_map[row][col] == 5:
                      self.player = sprites.Player(row * 32, col * 32, self.player_group, self.platform_group)
                  
                  if self.tile_map[row][col] == 6:
                      sprites.Tile(row * 32, col * 32, 6, self.tile_group, self.platform_group)
          
                  if self.tile_map[row][col] == 7:
                      sprites.Tile(row * 32, col * 32, 7, self.tile_group)
  </code></pre>
  <p>But the problem is that when I run my main script, I get a error like this:</p>
  <blockquote>
  <pre class="lang-none prettyprint-override"><code>AttributeError: 'Game' object has no attribute 'player'
  </code></pre>
  </blockquote>
  <p>I have no idea why this is, as I set the attribute in this for loop. <a href="https://drive.google.com/file/d/1rQSTW0phqfH9xKlEFoJV3dpPeoWrm5Un/view?usp=sharing" rel="nofollow noreferrer">Here is the link</a> to my entire script to keep this post short and sweet.</p>