Keep getting error message "KeyError: 'name'" #241
-
Dear Community, I am trying to add a questionnaire the same way I have added other questionnaires into the experiment. For some reason I keep getting a naming error. Please help! Thank you advance! :) import alfred3 as al
import random
exp = al.Experiment()
list_choices = [
"1",
"2",
"3",
"4",
"5",
"6",
"7"
]
choice_labels = [
"überhaupt nicht",
"",
"",
"",
"",
"",
"sehr",
]
KeckTang_questions = [
{"name": "KT_sat_sat1", "toplab": "Ich würde gerne in Zukunft mit dieser Gruppe zusammenarbeiten"},
{"name": "KT_sat_sat2", "toplab": "Ich habe gerne mit dieser Gruppe zusammengearbeitet"},
{"Name": "KT_sat_sat3", "toplab": "Ich fand die Gruppe nett"},
{"name": "KT_agree_agree1", "toplab": "Ich habe mich darauf konzentriert, der Gruppe zu helfen, schnell eine Einigung zu erzielen"},
{"name": "KT_agree_agree2", "toplab": "Ich änderte meine anfänglichen Meinungen, um der Gruppe zu helfen, eine Einigung zu erzielen"},
{"name": "KT_agree_agree3", "toplab": "Ich habe versucht, dafür zu sorgen, dass alle Gruppenmitglieder Kompromisse eingehen, damit wir eine Einigung erzielen können"},
{"name": "KT_IP_IP1", "toplab": "Während der Gruppendiskussion habe ich intensiv über alle Informationen und Meinungen der anderen nachgedacht"},
{"name": "KT_IP_IP2", "toplab": "Während der Gruppendiskussion habe ich versucht, hilfreiche Beiträge zu leisten"},
{"name": "KT_IP_IP3", "toplab": "Während der Gruppendiskussion habe ich versucht, alle verfügbaren Informationen zu nutzen, um mein persönliches Verständnis für die Aufgaben zu verbessern"}
]
random.shuffle(KeckTang_questions)
@exp.member
class KeckTangQuestions(al.Page):
title = "Fragen zur Gruppenphase"
name = "KeckTangQuestion_page"
def on_exp_access(self):
self += al.Card(
body="Bitte geben Sie an:")
self += al.ButtonLabels(choice_labels, leftlab=" ", button_style="btn-secondary")
self += al.VerticalSpace()
for i in KeckTang_questions:
# The following two lines will skip the remaining iterations when the
# item list runs out of items, giving the code way more flexibility.
item = i
self += al.SingleChoiceButtons(
list_choices,
leftlab=item['toplab'],
name=item["name"],
width="full",
force_input=True,
font_size="small",
position="center"
)
if __name__ == "__main__":
exp.run() |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 6 replies
-
Hi @slussinator, would you post the error message? Also, I see that you have posted a very reduced version of your experiment, which is nice! 😊 Still, I think there is probably room to remove more code, such that only the part that produces the error remains. If you would provide such a minimal example, that makes it much easier for me to find a solution. Thanks and best regards! |
Beta Was this translation helpful? Give feedback.
You have a typo in your example from the opening question. In the third entry of the
KeckTang_questions
list, you wrote"Name"
instead of"name"
.If you want to debug something like this, it can be very helpful to print of some intermediate information. In the code above, you could add
print(item)
to the for-loop. That way you could directly see, which entry of your list causes the problem.