Using answers from the form component


Im trying to create an experiment in which participants are shown a list of items (e.g., names). For each item, they need to indicate whether it is significant for them (yes or no). Hence, I used the form component in psychopy - it nicely presents all my items (as a list) with a no/yes option next to it.

In the next phase of the experiment I only want to use the items to which participants answered “no”. Hence, I tried to retrieve the form-data using a code component (please see below) - so, I can later on use it (in a new routine). However, it doesnt seem to work. My formData variable doesnt seem to include the answers (yes vs no; 1 vs 0)…

Any help will be much appreciated!

formData = form.getData()
formData_array = np.array(formData)
formData_array [formData_array [“ratings”]!= “0”]

Hi There,

What happens if you try to print the response of one of your questions? e.g. in the ‘end routine’ tab use:

print(form.getData()[0]['response']) #print response to first question


Thank you for the quick reply!
I get the following error:…

KeyError: 0

Hi There,

OK thanks for trying that! just to clarify, is the name of your form component ‘form’ ? also what does print(form.getData()) return for you? (also just double checking this is in the ‘end routine’ tab of your code component)


Thank you Becca!

It was indeed not at the end of my routine (mys mistake!). So, this sees to work, it gives me now

{‘itemIndex’: deque([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16]), ‘questions’: deque([‘Shahar’, ‘Daniel’, ‘Liran’, ‘Kobi’, ‘Dor’, ‘Robin’, ‘Henrik’, ‘Johan’, ‘Tony’, ‘Sander’, ‘Peter’, ‘Ori’, ‘Yogi’, ‘Henk’, ‘Twan’, ‘Idan’]), ‘ratings’: deque([0.0, 0.0, 1.0, 0.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0]), ‘rt’: deque([1.6194260999998278, 2.0471399999998994, 2.5758710000000065, 3.1075969000000896, 4.135673999999881, 4.486945099999957, 5.39977829999998, 2.8812066999998933, 1.800512499999968, 2.4931022999999186, 2.7095413000001827, 1.891126199999917, 4.43662200000017, 3.2584360999999262, 3.1499235000001136, 3.6464947999998003])}

However, this still doesnt work: print(form.getData()[0][‘response’]). I get the error:
KeyError: 0

I dont realy understand also what the format of the “form” is? It’s not an array?..

Thank you very much!

It’s called a dictionary. Instead of addressing the contents using a number you use keys (words).

The error sounds like your dictionary doesn’t have a key called response.

Yep, looks like your responses might actually be something like ‘rating’ instead (see your deque where there is a list of binary values stored)

A deque is essentially an ordered list. So try something like responses= form.getData[‘ratings’] then you should be able to get elements from that list using something like responses[0]

Thank you!
However, now I get the following error…

responses= form.getData[‘ratings’]
TypeError: ‘method’ object is not subscriptable

Also, I had 1 more question… As I wrote in my 1st message, I would like to select all items that pp rated as NO (i…e, 0). However, afterwards, I would like to add another item to this list (e…g, pp own name). Will that be possible (using dictionary)?..

Hi again,

So, just to clarify, this works:

responses = form.getData()

However, this doesnt…

KeyError: 0

Also, what is strange is that when I do print(responses[‘ratings’]): there are -0, 0, and 1 values. However, there are only 2 options: yes and no…

Thank you for all the help!

Hi There,

is there a systematic pattern where the -0 occur? and have responses been made to all items ?


Hi again!

Nope… I pressed now for example 8 times in a row YES, sometimes it wrote down 0 and sometimes -0. After, I pressed 8 times NO, and got 8 times 1!..

What I need in the end is to select, randomly, 4 items from all items that were answered with yes (so only those that are either 0 or -0). Then, later on in the experiment I want to present these items again. Any idea how I can accomplish this?..

Thank you very much!


Yes this is possible. The main problem is that at the moment there is no option to set the items of a form ‘on every repeat’, which means it is more difficult to update this field ‘on the fly’ (for example in your case, based on prior responses). The other issue is that I think you might be wanting a ‘choice’ response rather than a ‘rating’ for yes/no answers.

To help I made a quick demo that you can download here

In this demo participants respond to a set of questions with ‘yes’/ ‘no’ responses, then, a second form is presented showing only those questions to which the participant responded yes. This sounds similar to what you need so hopefully it helps to build from.


PS. if you want this to work online currently this is not possible unfortunately (in this demo we make a new dictionary and feed it into the next form) - but this has given us some ideas to try and make this possible.

Hi Becca!

Thank you so much! I realy appraciate it :)…

However, I have 1 more problem… Even when using the exact same xlsx file that you ceated, i get the following error:

ValueError: In Forms, {‘choice’} is not allowed. You can only use type [‘rating’, ‘slider’, ‘textbox’, ‘radio’]. Please amend your item types in your item list

I tried to use ‘rating’, but then I seem to get other problems…

Finally, I will have to add to the 2nd form one more item (e.g., participants name, which I will ask them at the beginning of the experiment). This item needs to be part of the 2nd form, but can never appear at the beginning. Basically, al items needs to be randomied with the personal item appearing somewhere in between or at the end…

Thank you!

Hi Nathalie,

Please can I check we are using the same version of psychopy - I made this demo using 2020.2.4 on windows (although I would recommend installing the new release that was made available yesterday


Hi Becca,

You are absolutely right! Thank you, this is amazing :).

What happens now is that the newForm (with all items answered with yes) is presented and doesnt disapear from the screen when my experiment continues… I tried to change this, but dont succeed…

What I actually need:

Is to save all items answered with yes in a seperate form or list (as you did).
Add the participants personal item (i.e., name) to this form/list, which I collect at the bgeinning of the experiment.
Present all items from the newForm after some more instructions. Importantly, however, the items need to be presented one by one (not as a form with yes & no options)… Also, the order of presentation should be randomized (with one excepton, the personal item cannot appear at the beginning)…

Thank you!

wonderful - please can you mark the answer as a ‘solution’ so that future users can easily navigate the solution.

Pleased it works for you now!

Dear Becca,

I still dont get it too work exactly as I need…

After saving all items answered with “yes” to a new form, I need to:

  1. Add another item to this form -> this item needs to be obtained at the begining of the experiment (e.g., participants own name), by typing.
  2. Present the new list (only the items, without a no/yes answer option) in a serial and random manner (while participants own name can appear at each location, except at the beginning)…

Thank you in advance!