Hello, I'm having problems retrieving data I think I've put into my program. I have a class and a function. I'm reading in from a personally made text file of the data needed for the class. The FieldsDictionary needs to be accesable outside the function, but my problem is this: the print FieldsDictionary[key].Fieldname (which I should have just created because of the line above), returns: AttributeError: 'list' object has no attribute 'Fieldname' am I just accessing it wrongly? I was under the impression that Fields Dictionary should contain a key referencing to a list of instances of the class. i.e. FieldsDictionary{key:[instance1, instance2, instance 3]} Is this not what I've programmed?
class FieldClass(object): def __init__(self,Fieldname="",Fieldlength=0,Type=["A","S","N"],Location=["D","C","L","H","TBA"]): self.Fieldname=Fieldname self.Fieldlength=Fieldlength self.Type=Type self.Location=Location def EnterDictionary(FieldsDictionary,key,myfile,FIELD_QUANTITY_OFFSET,LINE_START,LINE_END): data=myfile.readline().strip() for i in range(int(data[FIELD_QUANTITY_OFFSET:])): args =myfile.readline().strip()[LINE_START:LINE_END].split(",") print args FieldsDictionary.setdefault(key, []).append(FieldClass(*args)) print FieldsDictionary[key].Fieldname -- http://mail.python.org/mailman/listinfo/python-list