I'm creating a game with pygame and I'm using ConfigParser to parse various things for map tiles. But when I get to the part where I do
parse.read(filename) It outputs this error
self.level = self.config.get("level","map") AttributeError: 'list' object has no attribute 'get' I'm guessing parse.read(filename) returned a list instead of its intended object. Here is my code I suppose. I've been searching google but couldn't find anything related to this.
import pygame import ConfigParser parse = ConfigParser.ConfigParser() class MakeLevel(): def MapMake(self,spriteList,filename): self.config = parse.read(filename) self.level = self.config.get("level","map") self.LegendDict = self.config.get("dictionary") self.Proper = [] self.newTile = None self.x = 0 self.y += 50 #Get propper legend stats for items in LegendDict: for row in level: for col in row: if col == items: #LegendDict[items] self.image = self.config.get(items, "image") self.newTile = MapTile(self.image,self.x,self.y) return spriteList.add(self.newTile) x += 50 y += 50 x = 0 class MapTile(pygame.sprite.Sprite): def __init__(self,image,x,y): pygame.sprite.Sprite.__init__(self) self.image = pygame.image.load(image) self.rect = Rect(x, y, 32, 32) class Controller(): def __init__(self): pass def Keys(self): for event in pygame.event.get(): if event.type == pygame.KEYDOWN: if event.key == pygame.K_a: return 'a' if event.key == pygame.K_d: return 'd' if event.type == pygame.KEYUP: if event.key == pygame.K_a: return 'a up' if event.key == pygame.K_d: return 'd up' AllSprites = pygame.sprite.Group() makeLevel = MakeLevel() makeLevel.MapMake(AllSprites,"level1.ini") AllSprites.draw() I also tried opening the file beforehand and it still did not work.
mapFile = open("level1.ini") makeLevel.MapMake(AllSprites, mapFile) I made sure the level1.ini file is in the same folder as the main.py file. Hopefully the problem isn't something so obvious.