vendredi 29 août 2014

Pythons ConfigParser reading my file as a list


Vote count:

0




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. Heres 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()
mapFile = open('level1.ini')
makeLevel.MapMake(AllSprites,mapFile)

AllSprites.draw()


I made sure the level1.ini file is in the same folder as the main.py file. Hopefully the problem isnt something so obvious.



asked 29 secs ago







Pythons ConfigParser reading my file as a list

Aucun commentaire:

Enregistrer un commentaire