简体   繁体   中英

accessing the “local” variable

def get(self):
    if self.request.get('fmt')=='json':
        KeyofQuestion = self.request.path[1:]
        QuestionText = Question.get_by_key_name(KeyofQuestion).question
        AnswersQuery = Question.get_by_key_name(KeyofQuestion).answers_collection
        a=[]
        Jsonobject = {'Question':QuestionText}
        for each in AnswersQuery:
            a = a.append(each.answer)

Hey, i am just confused that when I run the codes above, I got an error that says, Nonetype variable:a doesnt have method append, but I declared the a as a list before I called and they are inside the same function "get", so I assumed they are all treated as local variables. How come it cant map it? Thank you

You are assigning None to a . Change this:

a = a.append(each.answer)

to:

a.append(each.answer)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM