Py学习  »  Python

TypeError:“list”对象不可调用Python面向对象编程[closed]

WolfGirl • 3 年前 • 1447 次点击  

我正在尝试创建一个包含问题和答案(对或错)的题库。我有一个叫做数据的文件。请回答以下问题:

question_data = [
    {"text": "A slug's blood is green.", "answer": "True"},
    {"text": "The loudest animal is the African Elephant.", "answer": "False"},
    {"text": "Approximately one quarter of human bones are in the feet.", "answer": "True"},
    {"text": "The total surface area of a human lungs is the size of a football pitch.", "answer": "True"},
    {"text": "In West Virginia, USA, if you accidentally hit an animal with your car, you are free to take it home to eat.",
     "answer": "True"},
    {"text": "In London, UK, if you happen to die in the House of Parliament, you are entitled to a state funeral.",
     "answer": "False"},
    {"text": "It is illegal to pee in the Ocean in Portugal.", "answer": "True"},
    {"text": "You can lead a cow down stairs but not up stairs.", "answer": "False"},
    {"text": "Google was originally called 'Backrub'.", "answer": "True"},
    {"text": "Buzz Aldrin's mother's maiden name was 'Moon'.", "answer": "True"},
    {"text": "No piece of square dry paper can be folded in half more than 7 times.", "answer": "False"},
    {"text": "A few ounces of chocolate can to kill a small dog.", "answer": "True"}
]

我还有一个问题课:

class Question:
    def __init__(self, text, answer):
        self.question_text = text
        self.question_answer = answer

这是我的代码:

from question_model import Question
from data import question_data

question_bank = []

for question in question_data():
    q_text = question["text"]
    q_answer = question["answer"]
    new_q = Question(q_text, q_answer)
    print(new_q)
    question_bank.append(new_q)
    print(question_bank)

每当我运行代码时,它都会给出错误:

for question in question_data():
TypeError: 'list' object is not callable

我该修什么?

Python社区是高质量的Python/Django开发社区
本文地址:http://www.python88.com/topic/130146
 
1447 次点击  
文章 [ 2 ]  |  最新文章 3 年前